I'm having some trouble freeing component builds from JDeveloper Studio...
I have a reference to aia.jar set up in JDeveloper, which I can't seem to specify correctly on the Ant command line.
Here's my command line:
ant -f c:\...\jdeveloper\bin\ant-sca-package.xml
-D"compositeDir=c:/.../ProcessImpl"
-D"compositeName=ProcessImpl"
-D"revision=1.0"
-D"scac.application.home=c:/.../.adf"
Everything seems to go well at first, until it fails with: package oracle.apps.aia.core.eh.logging does not exist
Here is the solution, for the sake of anyone that has the same issue in future...
My aia.jar lived in jdeveloper/lib ...
I had tried the CLASS_PATH environment variable, the -lib <path> option on the ant command line, and even adding to the classpath property in ant-sca-compile.xml - none of which made any difference.
The aia.jar file apparently HAS to exist in the SCA-INF/lib subdirectory of the project being built. In the end I created a wrapper build.xml file that copies the required dependency to this location and then calls out to ant-sca-package.xml...
<target name="build">
<echo>Copy AIA.jar</echo>
<mkdir dir="${sca-inf.dir}/lib" />
<copy file="${aia.file}" todir="${sca-inf.dir}/lib"/>
<echo>Create Package</echo>
<ant antfile="${script.home}/ant-sca-package.xml" inheritAll="false" target="package">
<property name="compositeDir" value="${path}/${name}"/>
<property name="compositeName" value="${name}"/>
<property name="revision" value="${rev}"/>
<property name="sca.application.home" value="${adf.dir}"/>
<property name="scac.application.home" value="${adf.dir}"/>
</ant>
</target>
I am trying to pass parameters to an ant target in another build file in a different location .
Here is what I did :-
<target name="run">
<ant dir="../${dir}" target="package" inheritAll="false"/>
<property name="-Darg.vendor" value="arm"/>
<property name="-Darg.tech" value="tsmc40g"/>
</ant>
</target>
I pass the dir from command line and run the target package from the build file there.
I am trying to pass the parameters but it is not accepting them.
Can anyone please help me fix this
Don't include the command line switches :
<target name="run">
<ant dir="../${dir}" target="package" inheritAll="false"/>
<property name="arg.vendor" value="arm"/>
<property name="arg.tech" value="tsmc40g"/>
</ant>
</target>
build.xml
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true">
<property name="messages" value="NOT_FOO_BAR"/>
</ant>
</target>
build-foo.xml
<target name="foo">
<property name="messages" value="FOO"/>
<ant antfile="build-bar.xml" dir="${basedir}" target="bar"
inheritAll="false" useNativeBasedir="true">
</ant>
</target>
build-bar.xml
<target name="bar">
<property name="messages" value="BAR"/>
<echo message="messages = ${messages}"/>
</target>
Tried:
ant -buildfile build-foo.xml foo
the messages is BAR, as expected.
ant -buildfile build.xml main
the messages is NOT_FOO_BAR.
The properties from main is passed multi-level down, even if it is not desired in build-foo.xml: inheritAll=false.
How to prevent the properties from being passed down to its descendant calls? Thanks.
From ant manual ant task :
You can also set properties in the new project from the old project by
using nested property tags. These properties are always passed to
the new project and any project created in that project regardless
of the setting of inheritAll. This allows you to parameterize your
subprojects.
instead :
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true"/>
<property name="messages" value="NOT_FOO_BAR"/>
</target>
meets your expections.
I wrote a small macrodef in separate file:
macrodefs.xml
<macrodef name="do-cool-stuff">
<attribute name="message"/>
<sequential>
<echo message="#{message}" />
</sequential>
</macrodef>
I got a second file, my main build file:
build.xml
<target name="build">
<!-- do this and that -->
<!-- cheking out macrodefs.xml via CVS -->
<ant antfile="macrodefs.xml" target="do-cool-stuff" >
<property name="message" value="Hello, World!" />
</ant>
</target>
As you might guess this dosen't work. The error message is something like:
Target 'do-cool-stuff' does not exist in this project.
The only possible solution I found is to provide a extra target in the macrodefs.xml to forward the ant calls.
Is there a possibility to invoke the macrodef from within another file?
Thanks in advance.
You can import the file and use the macro like this:
<import file="macrodefs.xml" />
<do-cool-stuff message="Hello, World!" />
Note that in the macro definition you should use #{curlybrackets} when referencing macro attributes:
<sequential>
<echo message="#{message}" />
</sequential>
There are some examples at the end of the Ant macrodef task docs.
More
What you're trying to do isn't well supported by Ant. The ant and antcall tasks don't allow the 'callee' to affect the caller directly. You can write files in the called task, then load those in the caller. But as you have observed, the pre-process tasks import and include cannot be called from within a target. The ant/antcall tasks only allow you to run targets in subsidiary builds, not macros.
One workaround method (this might be similar to the one you mention, but allows you to put all the real work in the top-level build) would be to have an inner buildfile that includes the top-level import of the macrodefs.xml.
Something like the following. The macrodefs.xml file is as before. (But note that the imported files - including the macro definitions - need to be complete Ant project files, so they must include a project element.)
build.xml:
<target name="build">
<!-- cvs actions -->
<ant antfile="inner-build.xml" target="target-runner">
<property name="target" value="top-target" />
</ant>
</target>
<!-- this target will fail unless invoked from the inner build -->
<target name="top-target">
<do-cool-stuff message="Hello, World!" />
</target>
inner-build.xml:
<project>
<import file="macrodefs.xml" />
<target name="target-runner">
<ant antfile="build.xml" target="${target}" />
</target>
</project>
Effectively you would be doing
build.xml --> inner-build.xml --> build.xml (again)
(cvs) (import macros) (use macros)
The inner buildfile could potentially be generated on-the-fly by the main build - say if you wanted to import multiple macro definition files - but that's getting perhaps too unwieldy.
I'm not very good with Ant, but we're using it as a build tool. Right now, we can run "ant test" and it'll run through all the unit tests.
However, I'd love to be able to do something like ant test some_module and have it accept some_module as a parameter, and only test that.
I haven't been able to find how to pass command line args to Ant - any ideas?
One solution might be as follows. (I have a project that does this.)
Have a separate target similar to test with a fileset that restricts the test to one class only. Then pass the name of that class using -D at the ant command line:
ant -Dtest.module=MyClassUnderTest single_test
In the build.xml (highly reduced):
<target name="single_test" depends="compile" description="Run one unit test">
<junit>
<batchtest>
<fileset dir="${test.dir}" includes="**/${test.module}.class" />
</batchtest>
</junit>
</target>
You can also define a property with an optional default value that can be replaced via command line, e.g.
<target name="test">
<property name="moduleName" value="default-module" />
<echo message="Testing Module: ${moduleName}"/>
....
</target>
and run it as:
ant test -DmoduleName=ModuleX
What about using some conditional in your test target and the specifying -Dcondition=true?
<target name="test" depends="_test, _test_if_true>
...
</target>
<target name="_test_if_true" if="condition">
...
</target>
<target name="_test" unless="condition">
...
</target>
Adapted a bit from the ant faq.
You can define a property on commandline when invoking ant:
ant -Dtest.module=mymodulename
Then you can use it as any other ant property:
...
<fileset dir="${test.dir}" includes="**/${test.module}.class" />
...
Have a look at Ant's manual.
I tried the solutions posted here for the very same original question. Yes just use ant -D<arg_name>. THe -D is a "keyword" I guess. I'm no ant expert and have not read the manuals in detail. Then inside the ant XML files can be accessed like: ${arg_name}
For instance you can have an argument name like: arg.myarg, so in XML ${arg.myarg}.
Ant really doesn't have parameters_ for the build file. I can think of a few ways to do this:
Use a special target to specify the tests. You can use the <for/> task from AntContrib to allow you to specify multiple tests. You'll need to download the Ant-Contrib jar file. I recommend placing it inside your project under the `${basedir}/antlib/antcontrib" directory. That way, when others checkout your project, they get the needed Ant-Contrib jar file.
<property name="antlib.dir" value="${basedir}/antlib"/>
<property name="antcontrib.dir" value="${antlib}/antcontrib"/>
<!-- Set up the ant contrib tasks for your use -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${antcontrib.dir}"/>
</classpath>
</taskdef>
<target name="select-test"
description="Select the tests to run"
depends="test-compile"
if="junit-tests">
<for parameter="module"
list="${junit-tests}"
delimiter=" ">
<sequential>
<junit
fork="true"
...>
<batchtest todir="$target/unit-tests">
<fileset dir="${test.destdir}">
<include name="**/#{module}.class"/>
</fileset>
</junit>
</sequential>
</for>
</target>
You cab now run multiple tests like this:
$ ant -D"test-one test-two test-three" select-test
You could try this to access one target at a time. Add these lines to your build.xml file :
<project name="whatever" default="default">
<input message="Please select module:" addproperty="mod" />
<target name="default" depends="${mod}/>
...
</project>
This allows you to enter the module you want to execute and execute that itself instead of running the whole build.xml
You might need to make a few more changes to your build.xml for this to work perfectly.
For the arguments , there is Facility called property. You need to set the property. As in ANT plain arguments is taken as target name.
Lest say you have two modules in your project ModuleX and ModuleY where ModuleX has 2 testcases to run and ModuleY with 10 testcases.
You could do something like this :
ant runTestsOnModule -Dtestmodule="ModuleX"
OR to test all modules by calling
ant tests
<target name="runTestsOnModule">
<antCall target="testcase${testmodule}"/>
</target>'
<! -- run single module -->
<target name="runTestsOnModule">
<antCall target="testcase${testmodule}"/>
</target>
<!--run all tests-->
<target name="tests">
<antcall target="testcaseModuleX">
<antcall target="testCaseModuleY">
</target>
<target name="testcaseModuleX">
..run junit task to call 2 testcase
</target>
<target name="testcaseModuleY">
....run junit task to call 10 testcase
</target>