cruisecontrol phpunit creates no output - phpunit

I cannot seem to figure out why the phpunit target does not output any test results even though I have tests in position.
The problem I am finding is there is no indication as to what the problem is! Incredibly frustrating.
The output is as follows:
<build error="C:\Program Files (x86)\CruiseControl\projects\myProject\build.xml:46: exec returned: 255" time="1 second">
<message priority="debug"><![CDATA[Adding reference: ant.PropertyHelper]]></message>
<message priority="debug"><![CDATA[Detected Java version: 1.6 in: C:\Program Files (x86)\Java\jdk1.6.0_18\jre]]></message>
<message priority="debug"><![CDATA[Detected OS: Windows Vista]]></message>
<message priority="debug"><![CDATA[Adding reference: ant.ComponentHelper]]></message>
<message priority="debug"><![CDATA[Setting ro project property: XmlLogger.file -> log.xml]]></message>
<message priority="debug"><![CDATA[Setting ro project property: cclastgoodbuildtimestamp -> 20100604161400]]></message>
<message priority="debug"><![CDATA[Setting ro project property: cctimestamp -> 20100604194749]]></message>
<message priority="debug"><![CDATA[Setting ro project property: cvstimestamp -> 2010-06-04 18:47:49 GMT]]></message>
<message priority="debug"><![CDATA[Setting ro project property: projectname -> myProject]]></message>
<message priority="debug"><![CDATA[Setting ro project property: buildforced -> true]]></message>
<message priority="debug"><![CDATA[Setting ro project property: label -> build.153]]></message>
<message priority="debug"><![CDATA[Setting ro project property: cclastbuildtimestamp -> 20100604192123]]></message>
<message priority="debug"><![CDATA[Setting ro project property: lastbuildsuccessful -> false]]></message>
<message priority="debug"><![CDATA[Setting ro project property: ant.file -> C:\Program Files (x86)\CruiseControl\projects\myProject\build.xml]]></message>
<message priority="debug"><![CDATA[Adding reference: ant.projectHelper]]></message>
<message priority="debug"><![CDATA[Adding reference: ant.parsing.context]]></message>
<message priority="debug"><![CDATA[Adding reference: ant.targets]]></message>
<message priority="debug"><![CDATA[parsing buildfile C:\Program Files (x86)\CruiseControl\projects\myProject\build.xml with URI = file:/C:/Program%20Files%20(x86)/CruiseControl/projects/myProject/build.xml]]></message>
<message priority="debug"><![CDATA[Setting ro project property: ant.project.name -> binarydreams]]></message>
<message priority="debug"><![CDATA[Adding reference: myProject]]></message>
<message priority="debug"><![CDATA[Setting ro project property: ant.file.myProject-> C:\Program Files (x86)\CruiseControl\projects\myProject\build.xml]]></message>
<message priority="debug"><![CDATA[Project base dir set to: C:\Program Files (x86)\CruiseControl\projects\myProject]]></message>
<message priority="debug"><![CDATA[ +Target: ]]></message>
<message priority="debug"><![CDATA[ +Target: build]]></message>
<message priority="debug"><![CDATA[ +Target: phpunit]]></message>
<message priority="debug"><![CDATA[Attempting to create object of type org.apache.tools.ant.helper.DefaultExecutor]]></message>
<message priority="debug"><![CDATA[Adding reference: ant.executor]]></message>
<message priority="debug"><![CDATA[Build sequence for target(s) `build' is [phpunit, build]]]></message>
<message priority="debug"><![CDATA[Complete build sequence is [phpunit, build, ]]]></message>
<message priority="debug"><![CDATA[Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.]]></message>
<message priority="debug"><![CDATA[Execute:Java13CommandLauncher: Executing 'phpunit.bat' with arguments:
'--log-junit'
'C:\Program Files (x86)\CruiseControl\projects\myProject/build/logs/phpunit.xml'
'--coverage-clover'
'C:\Program Files (x86)\CruiseControl\projects\myProject/build/logs/phpunit.coverage.xml'
'--coverage-html'
'C:\Program Files (x86)\CruiseControl\projects\myProject/build/coverage'
'tests/'
The ' characters around the executable and arguments are
not part of the command.]]></message>
<target name="phpunit" time="1 second">
<task location="C:\Program Files (x86)\CruiseControl\projects\myProject\build.xml:46: " name="exec" time="1 second">
<message priority="debug"><![CDATA[Current OS is Windows Vista]]></message>
<message priority="debug"><![CDATA[Executing 'phpunit.bat' with arguments:
'--log-junit'
'C:\Program Files (x86)\CruiseControl\projects\myProject/build/logs/phpunit.xml'
'--coverage-clover'
'C:\Program Files (x86)\CruiseControl\projects\myProject/build/logs/phpunit.coverage.xml'
'--coverage-html'
'C:\Program Files (x86)\CruiseControl\projects\myProject/build/coverage'
'tests/'
The ' characters around the executable and arguments are
not part of the command.]]></message>
</task>
</target>
<stacktrace><![CDATA[C:\Program Files (x86)\CruiseControl\projects\myProject\build.xml:46: exec returned: 255
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:636)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:662)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:487)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
]]></stacktrace>
</build>
My build.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myProject" default="build" basedir=".">
<target name="build" depends="phpunit"/>
<target name="phpunit">
<exec executable="phpunit.bat" dir="${basedir}/source" failonerror="on">
<arg line="--log-junit '${basedir}/build/logs/phpunit.xml'
--coverage-clover '${basedir}/build/logs/phpunit.coverage.xml'
--coverage-html '${basedir}/build/coverage' tests/" />
</exec>
</target>
</project>
My system:
Vista, PHP 5.2.9, PHPUnit 3.4, PHPUnderControl, CruiseControl

I had the same problem: when runing tests using Cruisecontrol project's build.xml I was getting the expected output:
me#developer-laptop:$ cd cruisecontrol/projects/myproject/
me#developer-laptop:$ ../../apache-ant-1.7.0/bin/ant phpunit
... this created correct unit-tests output
But when looking via the PHPUnderControl browser it was showing as 0 tests.
I found that this was due to not having correct paths set up for publishers in cruisecontrol's config.xml.
Here's my sample that works:
<log dir="logs/${project.name}">
<merge dir="projects/${project.name}/build/logs/"></merge>
</log>
<publishers>
<artifactspublisher dir="projects/${project.name}/build/coverage" dest="artifacts/${project.name}" subdirectory="coverage"></artifactspublisher>
<execute command="phpuc graph logs/${project.name} artifacts/${project.name}"></execute>
</publishers>
Hope this helps!

nuqqsa:
Yep, the expected log files do not appear. The tests do seem to be run though as I had to fix my require_once paths.
In the command prompt I would do the following in my source folder:
phpunit.bat --log-junit "C:\Program Files(x86)\CruiseControl\projects\myProject/build/logs/phpunit.xml"
--coverage-clover "C:\Program Files(x86)\CruiseControl\projects\myProject/build/logs/phpunit.coverage.xml"
--coverage-html "C:\Program Files(x86)\CruiseControl\projects\myProject/build/coverage" tests/
I hope it's nothing to do with the space in the path or the slashes the other half of the paths.
I have had a thought. I have debugged (using PHPEdit) when running the build and PHPUnit does seem to be executed but I haven't put a breakpoint in any of the tests to see if they are executed. I will do that when I get home and report back.

Related

Wix: How to get 'TargetFramework' | 'TargetFrameworkVersion' of the application beeing installed / packed

I have a WPF project which TargetFramework is net461. The output folder is my.wpf.app\bin\Release\net461. Is it possible to get the TargetFramework or net461 value in the msbuild or wix build pipeline?
I need it to heat the directory and don't want to write net461 in the my.wpf.app.setup.wixproj file.
my.wpf.app.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net461</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<Project/>
my.wpf.app.setup.wixproj
<Target Name="BeforeBuild">
<Message Text="Gathering libraries..." Importance="high" />
<CreateItem Include="..\my.wpf.app\bin\$(Configuration)\net461\*.dll">
<Output TaskParameter="Include" ItemName="LibraryFiles" />
</CreateItem>
</Target>
gitlab-ci.yml
package:Client:
stage: pack
tags:
- msbuild-ps
- wix-ps
script:
- MSBuild.exe /maxcpucount /nologo /p:Configuration=ClientInstaller /p:WarningLevel=0 /p:BuildProjectReferences=false "src\$env:SLNNAME.sln"
- xcopy /s /y /i src\my.wpf.app.setup\bin\Release\*.msi .\
artifacts:
paths:
- .\*.msi
expire_in: 1 day

Error invoking method. and Failed to launch JVM - Native Package will build but not launch

Can anyone shed any light more specifically on where my problem resides, and how to fix it?
I'm running:
Windows 7
Eclipse Mars.2 Release (4.5.2)
I've followed the instructions closely and repeatedly for Marco's Tutorial on code.makery.ch (code.makery.ch/library/javafx-8-tutorial/part7/)
I've deployed an earlier native package of this program before, with some trouble, but eventually successfully after adding
-vm
C:\Program Files\Java\jdk1.8.0_91\bin\javaw.exe
to eclipse.ini
After finally getting the ant build to run successfully,
do-deploy:
[copy] Copying 2 files to C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\dist\libs
[mkdir] Created dir: C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\build\classes\META-INF
Using base JDK at: C:\Program Files\Java\jdk1.8.0_91\jre
Using base JDK at: C:\Program Files\Java\jdk1.8.0_91\jre
Installer (.exe) saved to: C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\deploy\bundles
BUILD SUCCESSFUL
Total time: 56 seconds
My main file looks like this:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
/**
* Created by Brad on 5/20/2016.
* Solely used to load the FXML and set the icons. Everything else is done in Controller.java
*/
public class Main extends Application {
public static FXMLLoader loader;
//Icon from https://icons8.com
#Override
public void start(Stage primaryStage) throws Exception{
loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/Arrivals_Layout1.fxml"));
Parent root = loader.load();
primaryStage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("resources/images/Pallet-96.png")));
primaryStage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("resources/images/pallet_96_allsizes.ico")));
primaryStage.setTitle("Purchase Order Arrivals");
primaryStage.setScene(new Scene(root));
primaryStage.setMinWidth(820);
primaryStage.setMinHeight(375);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
My Package Explorer looks something like this, if it helps
My PATH: C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IBM\Client Access\Emulator;C:\Program Files (x86)\IBM\Client Access\Shared;C:\Program Files (x86)\IBM\Client Access\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Inno Setup 5
The build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="POA 1.1 - Try 1" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
<file name="${basedir}"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
<target name="setup-staging-area">
<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />
<mkdir dir="externalLibs" />
<copy todir="externalLibs">
<fileset dir="C:\Program Files\Java\sqljdbc_4.2\enu">
<filename name="sqljdbc42.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1\build\dist">
<filename name="POA 1.1 - Try 1.jar"/>
</fileset>
</copy>
<mkdir dir="project" />
<copy todir="project">
<fileset dir="C:\Users\administrator.SUNDANCE\IdeaProjects\POA 1.1 Build Master\POA 1.1 - Try 1">
<include name="src/**" />
</fileset>
</copy>
<mkdir dir="projectRefs" />
</target>
<target name='do-compile'>
<delete dir="build" />
<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />
<!-- Copy project-libs references -->
<copy todir="build/libs">
<fileset dir="externalLibs">
<include name="sqljdbc42.jar"/>
<include name="POA 1.1 - Try 1.jar"/>
</fileset>
</copy>
<!-- Copy project references -->
<!-- Copy project sources itself -->
<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*"/>
</fileset>
</copy>
<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="Cp1252">
<classpath>
<fileset dir="build/libs">
<include name="*"/>
</fileset>
</classpath>
</javac>
<!-- Copy over none Java-Files -->
<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
<delete file="dist"/>
<delete file="deploy" />
<mkdir dir="dist" />
<mkdir dir="dist/libs" />
<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="POA 1.1 - Try 1.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
<fx:fileset dir="dist" includes="resources/**"/>
</fx:resources>
<fx:application id="fxApplication"
name="Purchase Order Arrivals"
mainClass="Main"
version="1.1"
/>
<mkdir dir="build/classes/META-INF" />
<fx:jar destfile="dist/POA 1.1 - Try 1.jar">
<fx:application refid="fxApplication"/>
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes"/>
<manifest>
<attribute name="Implementation-Vendor" value="Ugma Development"/>
<attribute name="Implementation-Title" value="Purchase Order Arrivals"/>
<attribute name="Implementation-Version" value="1.1"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<mkdir dir="deploy" />
<!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
<fx:deploy
embedJNLP="false"
extension="false"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="POA 1.1 - Try 1" nativeBundles="exe"
updatemode="background" >
<fx:platform basedir="${java.home}"/>
<fx:info title="POA 1.1 - Try 1" vendor="Ugma Development"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
</fx:deploy>
</target>
</project>
The .exe is generated and installs the program in /AppData.
The program will compile and run fine in Eclipse, but when I run the installed version, I get:
Error invoking method.
first and then after clicking OK
Failed to launch JVM
I've tried seemingly everything:
I've read multiple similar questions, and have scoured the internet, but have yet to vault this problem. Examples of the many I've read with vague or no answers:
Error invoking method, failed to launch jvm
javafx native pakage error invoking method
Because he is less masterful in deployment, Marco himself said to come ask the mighty world of Stack Exchange:
http://code.makery.ch/library/javafx-8-tutorial/part7/#comment-2233862311
Again, any specific light on where my problem resides, and how to fix it?
I figured it out!
The way I found the problem:
After double, triple checking the dependencies and seeing that it both compiled and then built fine, I suspected the jar file which is located at build/deploy/{yourProjectName}.jar
EDIT: If you're getting the errors only once it is installed, it makes sense to run the jar in the installation directory. ( AppData/Local/{ApplicationTitle}/app/{yourProjectName}.jar )
I ran it on the command line to see if it was throwing an exception:
To easily navigate to the directory I noted where I had saved my project in Explorer and then copied that to the command line.
Open command prompt
Win + r
cmd + Enter
Navigate to the directory
cd {ProjectPath}\build\deploy
Run the jar file
java -jar "{YourJar}.jar"
Because I executed the jar via the command prompt, java had somewhere to show me the exception!
C:\Users\administrator.SUNDANCE\IdeaProjects\PODTester_Layout8\build\deploy>java
-jar "PODTester_Layout8.jar"
java.io.FileNotFoundException: src\resources\Carrier List.txt (The system cannot
find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
Upon reviewing my code, I figured that it wasn't finding the file because of the explicit reference to src. I fixed that and lo and behold! Upon rebuilding, the installed application worked!
So in summary:
If your native package throws you a
Error invoking method.
and a
Failed to launch JVM
run your jar file via the command prompt to see if it throws exceptions.
Now if you want details about my specific problem and the process I went through to fix it, here you go:
The Problem:
I thought it might've been something to do with dependencies (especially with me including the sqljdbc driver), but it turns out it wasn't a dependency issue. The problem was that the .jar was throwing an exception only once installed. What made the error so hard to understand was the oh-so-generic "Could not invoke method." which gave me little new information.
To mitigate future similar problems I added a showExceptionDialog() method (inspired by Marco Jacob's work) :
/**
* Shows a dialog box when an exception occurs instead of just doing nothing.
*
* Once installed this will help to diagnose problems instead of letting
* them go unnoticed.
*
* #param e the exception to print; it's stacktrace will be shown as well
*/
public static void showExceptionDialog(Exception e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Exception Dialog");
alert.setHeaderText("An error occurred:");
String content = "Error: ";
if (null != e) {
content += e.toString() + "\n\n";
}
alert.setContentText(content);
Exception ex = new Exception(e);
//Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
//Set up TextArea
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setPrefHeight(600);
textArea.setPrefWidth(800);
//Set expandable Exception into the dialog pane.
alert.getDialogPane().setExpandableContent(textArea);
alert.showAndWait();
}
Specific details about my problem:
In my program I had a file called Carrier List.txt being read and written to, and it was stored in the resources folder.
In IntelliJ and Eclipse it compiled just fine because it could find src/resources/Carrier List.txt just fine. Things would have been just fine when I manually copied the resources folder as per Marco Jacob's Deployment Tutorial, but I explicitly referenced
src/resources/Carrier List.txt
in my code instead of just
resources/Carrier List.txt

Running unit tests from MSBuild script

I am running unit tests (MSTest) from my MSBuild script:
<Target Name="AfterBuild">
<ItemGroup>
<TestAssemblies Include="$(MSBuildProjectDirectory)\ContinuousDeploymentProof.Web.Tests\bin\$(Configuration)\ContinuousDeploymentProof.Web.Tests.dll"/>
</ItemGroup>
<PropertyGroup>
<MsTestCommand>"$(MsTestExePath)" #(TestAssemblies->'/testcontainer:"%(FullPath)"', ' ') /resultsfile:"TestResults\Results.trx""</MsTestCommand>
</PropertyGroup>
<Message Text="MsTestCommand: #(TestAssemblies->'/testcontainer:$(DoubleQuotes)%(FullPath)$(DoubleQuotes)', ' ')" Importance="high"/>
<RemoveDir Directories="TestResults" Condition="Exists('TestResults')" />
<MakeDir Directories="TestResults" />
<Exec Command="$(MsTestCommand)" ContinueOnError="true" />
</Target>
The tests run but I get two weird errors also:
1.
EXEC : warning : Test Run deployment issue: The assembly or module 'System.Web.
Mvc' directly or indirectly referenced by the test container 'c:\projects\conti
nuousdeploymentproof\development\continuousdeploymentproof.web.tests\bin\debug\
continuousdeploymentproof.web.tests.dll' was not found. [C:\Projects\Continuous
DeploymentProof\Development\ContinuousDeploymentProof.msbuild]
I suspect this is because Mvc is a NuGet package, but not sure. The DLL does exist in the same place as the tests dll
2.
EXEC : warning : Test Run deployment issue: The assembly or module 'log4net' di
rectly or indirectly referenced by the test container 'c:\projects\continuousde
ploymentproof\development\continuousdeploymentproof.web.tests\bin\debug\continu
ousdeploymentproof.web.tests.dll' was not found. [C:\Projects\ContinuousDeploym
entProof\Development\ContinuousDeploymentProof.msbuild]
This one is really weird as I never calll log4net directly. I believe its used in some of the OAuth references in the default Mvc termplate. Do I need to directly refernce these in the MSBuild script?

Using ANT with Flex, building dependent target fails

I have a flex project called framework and another one called commons. Commons depends on framework.
Build script for framework :
<project name="imanager-framework" basedir=".">
<property name="src" location="src"/>
<property name="dist" location="dist"/>
<property name="FLEX_HOME" value="C:/Program Files (x86)/Adobe/Adobe Flash Builder 4.5/sdks/4.6.0"/>
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasksFlash4.jar"/>
<target name="clean">
<delete dir="${dist}"/>
</target>
<target name="dist">
<echo>src dir: ${src}</echo>
<mkdir dir="${dist}"/>
<compc output="${dist}/${ant.project.name}.swc">
<source-path path-element="src" />
<library-path dir="libs" includes="*.swc" append="true"/>
<include-sources dir="${src}" includes="*" />
</compc>
</target>
</project>
Build script for commons :
<?xml version="1.0" encoding="UTF-8"?>
<project name="imanager-commons" basedir=".">
<property name="src" location="src"/>
<property name="dist" location="dist"/>
<property name="FLEX_HOME" value="C:/Program Files (x86)/Adobe/Adobe Flash Builder 4.5/sdks/4.6.0"/>
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasksFlash4.jar"/>
<target name="clean">
<delete dir="${dist}"/>
</target>
<target name="init">
<echo>Running Target: init</echo>
<echo>Running ant dist on framework</echo>
<!-- THIS PART FAILS --> <ant dir="../framework/" target="dist" inheritall="false"/>
<copy file="../framework/dist/imanager-framework.swc" todir="libs"/>
</target>
<target name="dist" depends="init">
<mkdir dir="${dist}"/>
<compc output="${dist}/${ant.project.name}.swc">
<source-path path-element="src" />
<library-path dir="libs" includes="*.swc" append="true"/>
<include-sources dir="${src}" includes="*" />
</compc>
</target>
</project>
Calling <ant> from the commons build file gives me spurious compile errors about bad imports and classes not being found. But running framework's build separately doesn't give any errors.
Here's some of the output I get
Buildfile: E:\flexspace\imanager\commons\build.xml
init:
[echo] Running Target: init
[echo] Running ant dist on framework
Trying to override old definition of task asdoc
Trying to override old definition of task compc
Trying to override old definition of task mxmlc
Trying to override old definition of task html-wrapper
dist:
[echo] src dir: E:\flexspace\imanager\framework\src
[compc] Loading configuration file C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.6.0\frameworks\flex-config.xml
...some warnings from my code here...
[compc] E:\flexspace\imanager\framework\src\com\iwobanas\controls\dataGridClasses\MDataGridColumn.as(72): col: 88 Error: Access of undefined property WildcardFilterEditor in package com.iwobanas.controls.dataGridClasses.filterEditors.
[compc] filterEditor = new ClassFactory(com.iwobanas.controls.dataGridClasses.filterEditors.WildcardFilterEditor);
[compc] ^
[compc] E:\flexspace\imanager\framework\src\com\iwobanas\controls\dataGridClasses\MDataGridColumn.as(24): col: 60 Error: Definition com.iwobanas.controls.dataGridClasses.filterEditors:WildcardFilterEditor could not be found.
[compc] import com.iwobanas.controls.dataGridClasses.filterEditors.WildcardFilterEditor;
[compc] ^
[compc] E:\flexspace\imanager\framework\src\org\syspire\erp\component\tooltip\components\ExtendedToolTip.as(3): col: 48 Error: Definition org.syspire.erp.component.tooltip.skins:ExtendedToolTipSkin could not be found.
[compc] import org.syspire.erp.component.tooltip.skins.ExtendedToolTipSkin;
[compc] ^
[compc] E:\flexspace\imanager\framework\src\org\astrika\shared\components\gridSearch\view\SearchDatePopup.mxml(14): Error: Type was not found or was not a compile-time constant: SearchDateView.
[compc] <gridSearch:SearchDateView id="searchDateView"/>
...similar errors...
BUILD FAILED
E:\flexspace\imanager\commons\build.xml:17: The following error occurred while executing this line:
E:\flexspace\imanager\framework\build.xml:17: compc task failed
Total time: 4 seconds
What's going wrong here?
Thanks
EDIT
As requested, here are the config dumps:
Framework build using Flash Builder: http://pastebin.com/kLai6j7X
Framework build using ANT: http://pastebin.com/FGHBAXZX
Framework build called from commons using ANT: (This is same as the previous dump)
UPDATE
I ended up just changing the structure of my build files to eliminate the <ant> call. I now how one build.xml for all the projects, will all targets in it. Not pretty, but it works for me.
It's a bit off-topic but I found Ant does bad at managing the build of Flex projects, especially when you have dependencies.
Have you considered using Maven with FlexMojos ? Adobe released a series of articles about this great tool. Much recommended !
One thing you can definitely try is to move the taskdef into target, at least that'll get rid of "Trying to override old definition of task" warning.

How to Publish Web with msbuild?

Visual Studio 2010 has a Publish command that allows you to publish your Web Application Project to a file system location. I'd like to do this on my TeamCity build server, so I need to do it with the solution runner or msbuild. I tried using the Publish target, but I think that might be for ClickOnce:
msbuild Project.csproj /t:Publish /p:Configuration=Deploy
I basically want to do exactly what a web deployment project does, but without the add-in. I need it to compile the WAP, remove any files unnecessary for execution, perform any web.config transformations, and copy the output to a specified location.
My Solution, based on Jeff Siver's answer
<Target Name="Deploy">
<MSBuild Projects="$(SolutionFile)"
Properties="Configuration=$(Configuration);DeployOnBuild=true;DeployTarget=Package"
ContinueOnError="false" />
<Exec Command=""$(ProjectPath)\obj\$(Configuration)\Package\$(ProjectName).deploy.cmd" /y /m:$(DeployServer) -enableRule:DoNotDeleteRule"
ContinueOnError="false" />
</Target>
I got it mostly working without a custom msbuild script. Here are the relevant TeamCity build configuration settings:
Artifact paths: %system.teamcity.build.workingDir%\MyProject\obj\Debug\Package\PackageTmp
Type of runner: MSBuild (Runner for MSBuild files)
Build file path: MyProject\MyProject.csproj
Working directory: same as checkout directory
MSBuild version: Microsoft .NET Framework 4.0
MSBuild ToolsVersion: 4.0
Run platform: x86
Targets: Package
Command line parameters to MSBuild.exe: /p:Configuration=Debug
This will compile, package (with web.config transformation), and save the output as artifacts. The only thing missing is copying the output to a specified location, but that could be done either in another TeamCity build configuration with an artifact dependency or with an msbuild script.
Update
Here is an msbuild script that will compile, package (with web.config transformation), and copy the output to my staging server
<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<SolutionName>MySolution</SolutionName>
<SolutionFile>$(SolutionName).sln</SolutionFile>
<ProjectName>MyProject</ProjectName>
<ProjectFile>$(ProjectName)\$(ProjectName).csproj</ProjectFile>
</PropertyGroup>
<Target Name="Build" DependsOnTargets="BuildPackage;CopyOutput" />
<Target Name="BuildPackage">
<MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(Configuration)" />
<MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(Configuration)" />
</Target>
<Target Name="CopyOutput">
<ItemGroup>
<PackagedFiles Include="$(ProjectName)\obj\$(Configuration)\Package\PackageTmp\**\*.*"/>
</ItemGroup>
<Copy SourceFiles="#(PackagedFiles)" DestinationFiles="#(PackagedFiles->'\\build02\wwwroot\$(ProjectName)\$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>
You can also remove the SolutionName and ProjectName properties from the PropertyGroup tag and pass them to msbuild.
msbuild build.xml /p:Configuration=Deploy;SolutionName=MySolution;ProjectName=MyProject
Update 2
Since this question still gets a good deal of traffic, I thought it was worth updating my answer with my current script that uses Web Deploy (also known as MSDeploy).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<ProjectFile Condition=" '$(ProjectFile)' == '' ">$(ProjectName)\$(ProjectName).csproj</ProjectFile>
<DeployServiceUrl Condition=" '$(DeployServiceUrl)' == '' ">http://staging-server/MSDeployAgentService</DeployServiceUrl>
</PropertyGroup>
<Target Name="VerifyProperties">
<!-- Verify that we have values for all required properties -->
<Error Condition=" '$(ProjectName)' == '' " Text="ProjectName is required." />
</Target>
<Target Name="Build" DependsOnTargets="VerifyProperties">
<!-- Deploy using windows authentication -->
<MSBuild Projects="$(ProjectFile)"
Properties="Configuration=$(Configuration);
MvcBuildViews=False;
DeployOnBuild=true;
DeployTarget=MSDeployPublish;
CreatePackageOnPublish=True;
AllowUntrustedCertificate=True;
MSDeployPublishMethod=RemoteAgent;
MsDeployServiceUrl=$(DeployServiceUrl);
SkipExtraFilesOnServer=True;
UserName=;
Password=;"
ContinueOnError="false" />
</Target>
</Project>
In TeamCity, I have parameters named env.Configuration, env.ProjectName and env.DeployServiceUrl. The MSBuild runner has the build file path and the parameters are passed automagically (you don't have to specify them in Command line parameters).
You can also run it from the command line:
msbuild build.xml /p:Configuration=Staging;ProjectName=MyProject;DeployServiceUrl=http://staging-server/MSDeployAgentService
Using the deployment profiles introduced in VS 2012, you can publish with the following command line:
msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=<profile-name> /p:Password=<insert-password> /p:VisualStudioVersion=11.0
For more information on the parameters see this.
The values for the /p:VisualStudioVersion parameter depend on your version of Visual Studio. Wikipedia has a table of Visual Studio releases and their versions.
I came up with such solution, works great for me:
msbuild /t:ResolveReferences;_WPPCopyWebApplication /p:BuildingProject=true;OutDir=C:\Temp\build\ Test.csproj
The secret sauce is _WPPCopyWebApplication target.
I don't know TeamCity so I hope this can work for you.
The best way I've found to do this is with MSDeploy.exe. This is part of the WebDeploy project run by Microsoft. You can download the bits here.
With WebDeploy, you run the command line
msdeploy.exe -verb:sync -source:contentPath=c:\webApp -dest:contentPath=c:\DeployedWebApp
This does the same thing as the VS Publish command, copying only the necessary bits to the deployment folder.
With VisualStudio 2012 there is a way to handle subj without publish profiles. You can pass output folder using parameters. It works both with absolute and relative path in 'publishUrl' parameter. You can use VS100COMNTOOLS, however you need to override VisualStudioVersion to use target 'WebPublish' from %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets. With VisualStudioVersion 10.0 this script will succeed with no outputs :)
Update: I've managed to use this method on a build server with just Windows SDK 7.1 installed (no Visual Studio 2010 and 2012 on a machine). But I had to follow these steps to make it work:
Make Windows SDK 7.1 current on a machine using Simmo answer (https://stackoverflow.com/a/2907056/2164198)
Setting Registry Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7\10.0 to "C:\Program Files\Microsoft Visual Studio 10.0\" (use your path as appropriate)
Copying folder %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v11.0 from my developer machine to build server
Script:
set WORK_DIR=%~dp0
pushd %WORK_DIR%
set OUTPUTS=%WORK_DIR%..\Outputs
set CONFIG=%~1
if "%CONFIG%"=="" set CONFIG=Release
set VSTOOLS="%VS100COMNTOOLS%"
if %VSTOOLS%=="" set "PATH=%PATH%;%WINDIR%\Microsoft.NET\Framework\v4.0.30319" && goto skipvsinit
call "%VSTOOLS:~1,-1%vsvars32.bat"
if errorlevel 1 goto end
:skipvsinit
msbuild.exe Project.csproj /t:WebPublish /p:Configuration=%CONFIG% /p:VisualStudioVersion=11.0 /p:WebPublishMethod=FileSystem /p:publishUrl=%OUTPUTS%\Project
if errorlevel 1 goto end
:end
popd
exit /b %ERRORLEVEL%
found two different solutions which worked in slightly different way:
1. This solution is inspired by the answer from alexanderb [link]. Unfortunately it did not work for us - some dll's were not copied to the OutDir. We found out that replacing ResolveReferences with Build target solves the problem - now all necessary files are copied into the OutDir location.
msbuild /target:Build;_WPPCopyWebApplication /p:Configuration=Release;OutDir=C:\Tmp\myApp\ MyApp.csproj
Disadvantage of this solution was the fact that OutDir contained not only files for publish.
2. The first solution works well but not as we expected. We wanted to have the publish functionality as it is in Visual Studio IDE - i.e. only the files which should be published will be copied into the Output directory. As it has been already mentioned first solution copies much more files into the OutDir - the website for publish is then stored in _PublishedWebsites/{ProjectName} subfolder. The following command solves this - only the files for publish will be copied to desired folder. So now you have directory which can be directly published - in comparison with the first solution you will save some space on hard drive.
msbuild /target:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\Tmp\myApp\;AutoParameterizationWebConfigConnectionStrings=false MyApp.csproj
AutoParameterizationWebConfigConnectionStrings=false parameter will guarantee that connection strings will not be handled as special artifacts and will be correctly generated - for more information see link.
this is my working batch
publish-my-website.bat
SET MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin"
SET PUBLISH_DIRECTORY="C:\MyWebsitePublished"
SET PROJECT="D:\Github\MyWebSite.csproj"
cd /d %MSBUILD_PATH%
MSBuild %PROJECT% /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=%PUBLISH_DIRECTORY%
Note that I installed Visual Studio on server to be able to run MsBuild.exe because the MsBuild.exe in .Net Framework folders don't work.
You must set your environments
< WebSite name>
< domain>
and reference my blog.(sorry post was Korean)
http://xyz37.blog.me/50124665657
http://blog.naver.com/PostSearchList.nhn?SearchText=webdeploy&blogId=xyz37&x=25&y=7
#ECHO OFF
:: http://stackoverflow.com/questions/5598668/valid-parameters-for-msdeploy-via-msbuild
::-DeployOnBuild -True
:: -False
::
::-DeployTarget -MsDeployPublish
:: -Package
::
::-Configuration -Name of a valid solution configuration
::
::-CreatePackageOnPublish -True
:: -False
::
::-DeployIisAppPath -<Web Site Name>/<Folder>
::
::-MsDeployServiceUrl -Location of MSDeploy installation you want to use
::
::-MsDeployPublishMethod -WMSVC (Web Management Service)
:: -RemoteAgent
::
::-AllowUntrustedCertificate (used with self-signed SSL certificates) -True
:: -False
::
::-UserName
::-Password
SETLOCAL
IF EXIST "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727" SET FXPath="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727"
IF EXIST "%SystemRoot%\Microsoft.NET\Framework\v3.5" SET FXPath="%SystemRoot%\Microsoft.NET\Framework\v3.5"
IF EXIST "%SystemRoot%\Microsoft.NET\Framework\v4.0.30319" SET FXPath="%SystemRoot%\Microsoft.NET\Framework\v4.0.30319"
SET targetFile=<web site fullPath ie. .\trunk\WebServer\WebServer.csproj
SET configuration=Release
SET msDeployServiceUrl=https://<domain>:8172/MsDeploy.axd
SET msDeploySite="<WebSite name>"
SET userName="WebDeploy"
SET password=%USERNAME%
SET platform=AnyCPU
SET msbuild=%FXPath%\MSBuild.exe /MaxCpuCount:%NUMBER_OF_PROCESSORS% /clp:ShowCommandLine
%MSBuild% %targetFile% /p:configuration=%configuration%;Platform=%platform% /p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=False /p:DeployIISAppPath=%msDeploySite% /p:MSDeployPublishMethod=WMSVC /p:MsDeployServiceUrl=%msDeployServiceUrl% /p:AllowUntrustedCertificate=True /p:UserName=%USERNAME% /p:Password=%password% /p:SkipExtraFilesOnServer=True /p:VisualStudioVersion=12.0
IF NOT "%ERRORLEVEL%"=="0" PAUSE
ENDLOCAL
You can Publish the Solution with desired path by below code, Here PublishInDFolder is the name that has the path where we need to publish(we need to create this in below pic)
You can create publish file like this
Add below 2 lines of code in batch file(.bat)
#echo OFF
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat"
MSBuild.exe D:\\Solution\\DataLink.sln /p:DeployOnBuild=true /p:PublishProfile=PublishInDFolder
pause
This my batch file
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe C:\Projects\testPublish\testPublish.csproj /p:DeployOnBuild=true /property:Configuration=Release
if exist "C:\PublishDirectory" rd /q /s "C:\PublishDirectory"
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\Projects\testPublish\obj\Release\Package\PackageTmp -c C:\PublishDirectory
cd C:\PublishDirectory\bin
del *.xml
del *.pdb
For generating the publish output provide one more parameter.
msbuild example.sln /p:publishprofile=profilename /p:deployonbuild=true /p:configuration=debug/or any
you can use this command to publish web applications with Publish Profiles.
msbuild SolutionName.sln /p:DeployOnBuild=true /p:PublishProfile=PublishProfileName
This sample Publish Profile can create a release zip file with a version number that's in AssemblyInfo.cs File in the network path (create zip file and remove other published files with PowerShell command is optional).
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<Major>0</Major>
<Minor>1</Minor>
<Build>2</Build>
<Publish>C:\</Publish>
<publishUrl>$(Publish)</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
<Target Name="GetBuildUrl">
<PropertyGroup> <In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs'))</In>
<TargetPath>\\NetworkPath\ProjectName</TargetPath>
<Pattern>^\s*\[assembly: AssemblyVersion\(\D*(\d+)\.(\d+)\.(\d+)\.(\d+)</Pattern>
<Major>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</Major>
<Minor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[2].Value)</Minor>
<Build>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[3].Value)</Build>
<Sub>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[4].Value)</Sub>
<Publish>$(TargetPath)\$(Major).$(Minor).$(Build).$(Sub)\</Publish>
<publishUrl Condition=" '$(Publish)' != '' ">$(Publish)</publishUrl>
<publishUrl Condition=" '$(Publish)' == '' and '$(LastUsedBuildConfiguration)'!='' ">$(LastUsedBuildConfiguration)</publishUrl>
</PropertyGroup>
</Target>
<Target Name="BeforeBuild" DependsOnTargets="GetBuildUrl">
<Message Importance="High" Text="|" />
<Message Importance="High" Text=" ================================================================================================" />
<Message Importance="High" Text=" BUILD INFO " />
<Message Importance="High" Text=" Version [$(Major).$(Minor).$(Build)] found in [$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs] " />
<Message Importance="High" Text=" Build will be saved to [$(publishUrl)] " />
<Message Importance="High" Text=" =================================================================================================" />
<Message Importance="High" Text="|" />
</Target>
<Target Name="Zip" BeforeTargets="AfterBuild">
<Exec Command="PowerShell -command Compress-Archive -Path $(Publish) -DestinationPath $(Publish)Release.zip" />
<Exec Command="PowerShell -command Remove-Item -Recurse -Force $(Publish) -Exclude Release.zip" />
</Target>
</Project>

Resources