I have few target that I need to execute. I create a target naming all of them but I think it's not the way to do it ? Here is the target run that call all other target :
<target name="test.all" depends="build
echolaunching agent /echo
antcall target="RunJtfTests" /
antcall target="launchOpenAgent" /
antcall target="run.test" //target
target name="run.test" depends="build, launchOpenAgent, runJtfTests"
echo Launching test/echo
echo message="${toString:iControlSilk4J.classpath}" /
<java classname="com.miranda.icontrol.silk4j.installation.AdministrationCtrl"
classpath><fileset dir="${lib.dir}"
include name="**/*.jar" />
/fileset
pathelement path="${iControlSilk4J.classpath}" /
pathelement location="${jarPath}/Admin.jar" /
/classpath
</java>
</target>
It doesn't run and I do it to get the report and I get nothing ? What is wrong ? From what I read, antcall is like a goto loop which is not good. I want to call tests instead.
-> Here are all the tests I want to execute :
init
clean
AdministrationCtrl.Rollback
AdministrationCtrl.LatestInstallation
AdministrationCtrl.BackupiControl,
AdministrationCtrl.ChangeService
AdministrationCtrl.DefaultSetting
AdministrationCtrl.InitFailOver
AdministrationCtrl.RunDensite2Service
AdministrationCtrl.RunDensiteService
AdministrationCtrl.RunGSMService
AdministrationCtrl.RunLoudnessAnalyzerService
AdministrationCtrl.RunLoudnessLoggerService
AdministrationCtrl.RunRouterManagerService
AdministrationCtrl.RunttyR0Service
AdministrationCtrl.RunVirtualService
AdministrationCtrl.RestoreBkp
but this can be more general (regarding tests I will add in Silk4J). Is there a way to be more generic ?
Repeat after me:
Ant is not a programming language. It's a dependency matrix language.
This is an important distinction. You don't tell Ant what to execute. You tell Ant what you need, and Ant will figure out what to do.
I can tell you're having problems understanding Ant with all of those <antcall/>. That is a no-no because it could make you execute tasks more than once. Your build file also makes no sense.
Use the target's dependency parameter. For example, here's a skeleton build.xml file:
<project>
<target name="clean"/>
<target name="prepare"/>
<target name="compile"
depends="prepare"/>
<target name="package"
depends="compile"/>
<target name="test-compile
depends="compile"/>
<target name="test"
depends="test-compile"/>
<target name="deploy"
depends="package"/>
<target name="post-test-results"
depends="test"/>
<target name="all"
depends="clean,post-test-results,deploy"/>
</project>
When I want to run my target all, I mainly mean I want to do a clean build, post my test results, and deploy the build. This is true with Makefiles too. I don't list all of my tasks. Why do I care if I do my prep work for compilation? It's not my concern.
So I call, all, and that will call clean, post-test-results, and deploy. I have no idea what Ant will do beyond calling these three targets.
Wait... What do I need to do in order to post my test results? Well, I may need to run my tests. Therefore, I have a dependency to test for my post-test-results target. But, in order to run my tests, I may have to compile them. So, there's a dependency to test-compile on my test target.
In order to compile my tests, I have dependencies on the regular Java code. So, test-compile will depend upon compile. In order to compile, I have to prepare. Maybe that's building the necessary structure, or downloading the required jars. That's called before compile. Now, I can deploy. However, before I can deploy, I need to package my deployment. So, deploy depends upon package.
Package itself depends upon compile, but so did my compile-test. Since I've already called compile, my package target doesn't have to do that. All it has to do is package up the already compiled class files.
Thus, I'll probably execute the following targets in this order:
clean
prepare
compile
test-compile
post-test-results
package
deploy
My all target does hit all of my other targets, but I didn't have to list them all as dependencies or force them to build via <antcall/>s.
It looks like you need to learn about Ant and how it works. Your sample Ant file is simply not valid. Ant uses an XML style structure. All tasks are XML style entities.
Fortunately, there are a lot of good books on Ant. I would recommend Manning's Ant in Action as a good starting point.
One of the things you will find out is that you can specify batches of junit tests in a single <junit> task. This can be done via one or more <batchtest> sub-entities on the <junit> task. The <batchtest> will run all classifies that match a particular criteria. You can also use the <test> sub-entity on the <junit> task. The <test> sub-entity allows you to specify individual classfiles to run. Many times, these classfiles may simply call a specified set of other Junit classifies. This way, the developer can specify what tests to run and what tests to skip.
You can control what tests to run or not run by using properties and not by creating dozens of testing tasks. This allows you to specify sets of tests without having to spawn multiple JUnit processes.
Related
Is there a way to get ant to execute multiple depend targets multiple times. Consider this:
<target name="buildall" depends="mycommon,myDAO" />
<target name="myCommon" depends="initCommon, clean, makedir, compile" description="">
<echo> Build completed for myCommon </echo>
</target>
<target name="myDAO" depends="initDAO, clean, makedir, compile" description="">
<echo> Build completed for myDao </echo>
</target>
I would like buildAll to call myCommon, which calls initCommon, clean, makedir, compile, then call myDAO which calls initDAO, clean, makedire, compile.
So I want the clean, makedir and compile tasks to be executed multiple times. They are generic and run based on properties set in the initXXX task.
I tried this:
<target name="buildall">
<antcall target="myCommon" />
<antcall target="myDao" />
</target>
but that runs everything outside of tasks everytime which is not what I want. Any thoughts?
First: Do not use <antcall/> it's usually a sign you've done something wrong.
Now, understand that Ant is not a programming language where you tell Ant what you want to do and the order you want it to be done. Ant is a matrix dependency language. You merely tell Ant what you want (I want to build this jar), and let Ant figure out what it should do. Ant does its very best not to run a target multiple times.
For example, both myCommon and myDAO call the clean target. Ant duly notes that both require clean target, and then calls clean once and only once before it runs both of your targets. It's the way Ant is suppose to work.
So, let Ant do its job. First, Thou shall not clean under normal circumstances. Builds are suppose to minimize rebuilding in order to speed up a task. If you haven't modified a *.java file, why should you force me to rebuild the corresponding *.class file?
Second: Don't double up dependencies: For example, if I want to build the target myDAO, I want to compile the code (maybe build a jar or war). That's all my myDAO target should depend upon. Now, when I compile, I might need to make my directory, and when I make my directory, I might need to do my init:
<target name="clean">
<echo>Clean up my working directory to be nice and sparkly</echo>
</target>
<target name="initDAO">
<echo>Initialize stuff for my DAO build</echo>
<echo>Maybe setup some properties?</echo>
</target>
<target name="makedir"
depends="initDAO">
<echo>I need my directories for building.</echo>
<echo>But first, I need to setup stuff"</echo>
</target>
<target name="compile"
depends="makedir">
<echo>I need to compile my dao source"</echo>
<echo>But first, I need to make the necessary directories</echo>
<target>
<target name="myDAO"
depends="compile">
<echo>Here's where I package up my DAO</echo>
<echo>But I have to compile stuff before I can package it</echo>
</target>
Note the above structure. If I run the target myDAO, Ant will look at the dependencies and then run initDAO, makedir, compile, and finally myDAO to package everything up. Again, I have a clean target that will restore my working space to pristine (before anything was built) condition, but I don't call it as part of a package because I don't want to redo work.
"Ah!", you say, "But I have to clean up because myCommon and myDAO use the same directories for building and packaging."
Well don't do that. Instead, make sure your two packages use different target directories for building and packaging. This way, you don't have to clean up the mess from one to another. And, you can change a single source file, rebuild, and not have to recompile everything again.
You can save yourself from trouble by defining macros to handle stuff in common between the two. For example, you might be able to define a compile macro that takes as its parameters the name of a source directory and it will create a destdir based upon that source directory name and compile your common and DAO targets.
So, let Ant work its magic. Use dependencies not as a means of telling Ant how to do something, but merely telling Ant that a particular target depends upon another target. Let Ant figure out the order of execution. Also, don't set up your tasks to require you to scrub directories and reinitialize everything. You want Ant to help minimize the build by not having to rebuild or recopy over files that haven't changed.
I have this Java project there I import an Ant build.xml file with some tasks, like this:
ant.importBuild 'build.xml'
task myTaskA(dependsOn: ':Modules:MyModule:assemble') << {
// do stuff here...
}
compileJava.dependsOn(myTaskA)
configure(jar) {
include 'classes.dex'
}
jar.dependsOn(antCompile)
The task antCompile comes from the Ant build.xml script. However, for some reason, this task is being called at start up when invoke gradlew assemble, it doesn't even wait for the jar task to start.
Also, the antCompile task is defined as the following target in build.xml:
<target name="antCompile" depends="-setup">
</target>
That Ant target, -compile is always the first task to be executed when I invoke gradlew assemble. This doesn't make any sense. That task is never invoked anywhere, it's only a dependency of antCompile. Why is it being executed?
This is, obviously, not what I want... How can I prevent such behaviors?
Seems to work as expected. The build script makes jar depend on antCompile, which according to your words depends on -compile. assemble depends on jar, so executing gradle assembmle should run -compile first.
In any case, it should be said that ant.importBuild has known limitations, and can result in differences in behavior compared to running the Ant build directly. Also you'll lose many of Gradle's advantages when not describing the build in terms of Gradle's own abstractions. Therefore I recommend to port the build to Gradle, rather than using ant.importBuild (which isn't used that often in the real world). Note that it's perfectly fine to reuse Ant tasks in cases where Gradle doesn't provide any equivalent.
I've been searching for a possibility to generate ANT targets from top-level macro.
Details:
We have heterogenic build system. ANT+IVY is used as top-level (inherited solutin, can't be changed). Some projects are built via MSBuild, called from ANT via exec task. For each of these projects, there's at least two distinct calls to msbuild (wrapped with macro for brevity), one in "build" target, and one in "clean". Two of them are different only by "target" parameter. So I was guessing, if there's possibility for something like this:
Extension nodes:
<extensionpoint name="build-ext-point" />
<extensionpoint name="clean-ext-point" />
<target name="build" depends="build-ext-point" />
<target name="clean" depends="clean-ext-point" />
My magic macro:
<macrodef name="msbuild-proj" />
<attribute name="project" />
<sequential>
<target name="#{project}-build" >
<msbuild project="#{project}" target="Build" />
</target>
<target name="#{project}-clean" >
<msbuild project="#{project}" target="Clean" />
</target>
</sequential>
</macrodef>
How it would be used:
<msbuild-proj project="CPP-proj" />
Thanks!
P.S: Yeah I know that I can define those build and clean overridden, or via ext point, or whatever. The question is actually whether I can remove some code duplication.
UPD: I'd answer this by myself. At the point, there's no such possibility. Mainly, because Target class is a task container, but not a task. So, it cannot be placed into container. So I guess I'll write some kind of extensible task.
ANT has a couple of mechanisms for building modular builds.
First of all I think your main question was on how to build "extension points" to your build? The following ANT tasks are designed to import common build logic from another build file:
import
include
Since you're already planning to extend your build using macrodefs, I'd recommend packaging these as a reusable ANTlib. The ANTlib can live within your project, but it's really designed to be packaged within a jarfile which another build can pickup, for example by installing it in the standard ANT lib directory:
$ANT_HOME/lib
$HOME/.ant/lib
Finally, if you're already using ivy and you package your taskdefs as ANT libs, you could version your build logic by installing it in a Maven repository manager like Nexus. This addresses one of the key problems with large ANT builds. Over time they become so big it's impossible to change the common logic without impacting older builds (Demonstrating that the builds are not properly isolated from each other).
Actually done this.
Does its job, although some caveats are present.
For those interested: https://bitbucket.org/targetsan/ant-events
I seem to be getting run-time errors in my project when using javac for incremental builds. Is this type of workflow supported? For example, if A.java depends on B.java, and B.java is modified; will javac recompile A.java because its dependency changed?
Right now I'm using a javac ant build-task for compiling:
<javac destdir="${classes.dir}"
srcdir="${src.dir}"
source="${javac.version}"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
includeantruntime="build.sysclasspath=last">
<classpath refid="compile.classpath" />
<classpath refid="junit.classpath" />
</javac>
Since you're using ant, check out the depend task.
The javac command line compiler will compile every source file given on the command line, and additionally everything on which these depend, if they don't have newer class files.
The ant javac task tries to be a bit smarter, to avoid compiling always everything - it recompiles only those files which have changed (i.e. are newer than their respective class files). This does not pay attention to the case that maybe the dependency of some class changed, and thus other classes need to be recompiled too.
In my current project, I simply do ant clean whenever I have problems on tests (and of course before any production deployment), which deletes all class files. But as vanza said, there is the depend task whose task is to find and delete all classes who depend on your changed classes - run this before your javac task and you should be good.
It depends on what has changed in B.java. If nothing changed that affected how the class is presented to A, then javac doesn't need to recompile A.java for the changes to take effect.
That said, if you are seeing behavior where you believe old code is being loaded and run, I'd be more suspicious of the deployment/packaging process than the compilation process. YMMV.
We have some projects in cruise control, set up roughly like this:
Cruise Control
<ant antfile="build.xml" dir="A" target="compile" inheritAll="false" />
in A the compile target calls, as a part of its compile, a jar target in B
(in "compile")
<ant antfile="${B.dir}/build.xml" inheritAll="false" target="jar" />
<javac ... >
So B has a jar task.A builds the jar from B and then uses it in it's compile.
The problem I'm running into is that cruise control seems to confuse the paths. Although the A compile task works directly from ant, when run from cruisecontrol it seems to be trying to find it's own internal libraries based on paths from the B jar settings.
To get this to work in ant I had to call B from A using the inheritAll="false" flag, but neither this nor calling javac with fork seems to resolve the problem.
Possibly related- we're running ant # version 1.7, the cc server is at ant version 1.6.5, which I can't easily update.
Any hints?
In your CruiseControl configuration you can specify the anthome or antscript attributes so that you use your version of Ant, so you should be able to get the same behavior from CC that you get at the command-line.