I'm calling an ant script from an ant script. The calling script contains:
<ant antfile="calledant.xml" >
<property name="par1" value="mypar"/>
</ant>
I can't figure out how to obtain the passed value in the script that is called.
I would expect the following to work but it doesn't:
<echo message="in calledscript, value is ${par1}" />
Nevermind. When I updated my PATH so that a JDK was found before a JRE, an error message went away and it started working.
Related
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 have an Ant script like this:
<target name="create_report_file">
<echo file="${testResultsDir}/test_report.xml">
<testsuite name="${platformTask}">
</testsuite>
</echo>
</target>
What do the tags between <echo> and </echo> mean? Will Ant run them or output? Or both?
file is an echo parameter. It's the file to write the message to.
testsuite is possibly a JUnit task.
The Ant target runs the test suite and outputs the results to the test_report.xml file.
Does your Ant script work? What about if it attempts to execute the create_report_file target?
Usually, echo tasks simply echo the contents to either the console or to a file if the file parameter is specified.
However, as written, it makes <testsuite> is a sub-entity of the <echo/> task, and it's not. In fact, there's no documented sub-entities in the <echo/> task. In fact, <echo> doesn't even take <condition/> sub-entity tasks like <fail/> would.
This is why I'm asking whether or not your build file is even working.
It appears they might want to log the testsuite being executed. There are two ways to do this to make this work:
Change all < and > to character entities:
<target name="create_report_file">
<echo file="${testResultsDir}/test_report.xml">
<testsuite name="${platformTask}">
</testsuite>
</echo>
</target>
Use <echoxml> instead of <echo>:
<target name="create_report_file">
<echoxml file="${testResultsDir}/test_report.xml">
<testsuite name="${platformTask}">
</testsuite>
</echoxml>
</target>
Another possibility
It is possible that you're using some Ant plugin that has a <testsuite> task. I don't know what this would be. The <testsuite> task isn't part of JUnit or TestNG. However, if there is an Ant plugin being used that defines a <testsuite> task, it might redefine the <echo> task which it's at it. Does your build script have a <taskdef> in it? If so, what's the class reference?
It could be that the user defines their own <testsuite> macro in your build script. However, that wouldn't redefine the <echo> task and it still wouldn't work.
I have a master build file which is calling other build.xml files of different projects.
One of my build file needs a command line argument for the execution
ant -Denv=81 -buildfile build_war.xml
I wrote one task in master build.xml to call build_war.xml
<target name="buildDataExtractor">
<ant antfile="..\SEFTooling\build_war.xml" inheritall="false" />
</target>
How do I pass the "-Denv=81" parameter so that build_war.xml will be executed correctly.
Try passing properties to the ant task:
<ant antfile="..\SEFTooling\build_war.xml" inheritall="false">
<property name="env" value="${env}"/>
</ant>
NOTE: in order for this to work properly, you will need to call your main build with ant -Denv=81 or set a property in the main build.xml as such:
<property name="env" value="81"/>
According to the man page of make, -n option does the following job:
Print the commands that would be executed, but do not execute them.
I am looking for an option which acts the same in Apache Ant.
Horrific, but here it is. We can hack the targets at runtime using some code inside a <script> tag*. The code in do-dry-run below sets an unless attribute on each of your targets, and then sets that property so that none of them executes. Ant still prints out the names of targets that are not executed because of an unless attribute.
*(JavaScript script tags seem to be supported in Ant 1.8+ using the Oracle, OpenJDK and IBM versions of Java.)
<?xml version="1.0" encoding="UTF-8"?>
<project default="build">
<target name="targetA"/>
<target name="targetB" depends="targetA">
<echo message="DON'T RUN ME"/>
</target>
<target name="targetC" depends="targetB"/>
<target name="build" depends="targetB"/>
<target name="dry-run">
<do-dry-run target="build"/>
</target>
<macrodef name="do-dry-run">
<attribute name="target"/>
<sequential>
<script language="javascript"><![CDATA[
var targs = project.getTargets().elements();
while( targs.hasMoreElements() ) {
var targ = targs.nextElement();
targ.setUnless( "DRY.RUN" );
}
project.setProperty( "DRY.RUN", "1" );
project.executeTarget( "#{target}" );
]]></script>
</sequential>
</macrodef>
</project>
When I run this normally, the echo happens:
$ ant
Buildfile: build.xml
targetA:
targetB:
[echo] DON'T RUN ME
build:
BUILD SUCCESSFUL
Total time: 0 seconds
But when I run dry-run, it doesn't:
$ ant dry-run
Buildfile: build.xml
dry-run:
targetA:
targetB:
build:
BUILD SUCCESSFUL
Total time: 0 seconds
Ant has no dry-run option as make or maven have. But you could run the ant file step by step it in debugging mode under eclipse.
No I belive. There is no such way by default in Ant. And many unstisfying attempts you would find on google. But I have searched once and was unsuccessful.
It would be a useful feature, but not easily implemented.
Make and ANT are architecturally quite different. ANT doesn't run external OS commands, instead, most ANT "tasks" execute within the same Java thread.
It would be possible to emulate a "dry run" as follows:
<project name="Dry run" default="step3">
<target name="step1" unless="dry.run">
<echo>1) hello world</echo>
</target>
<target name="step2" depends="step1" unless="dry.run">
<echo>2) hello world</echo>
</target>
<target name="step3" depends="step2" unless="dry.run">
<echo>3) hello world</echo>
</target>
</project>
Running ANT as follows will print the target name but won't execute the enclosed tasks:
$ ant -Ddry.run=1
Buildfile: build.xml
step1:
step2:
step3:
BUILD SUCCESSFUL
Total time: 0 seconds
Create a special target in your buildscript that does some echoing only i.e. to check whether properties, path .. are resolved correctly.
see https://stackoverflow.com/a/6724412/130683 for a similar question answered.
For checking the details of your ant installation use ant -diagnostics
I have setup an ant script as eclipse builder to automatically run all my tests, like below:
<project name="auto-test" default="test">
<property name="tst-dir" location="C:\STAF\services\custom\TopCoder\bin" />
<path id="classpath.base" />
<path id="classpath.test">
<pathelement location="D:\eclipse\eclipse\plugins\org.junit4_4.3.1\junit.jar" />
<pathelement location="${tst-dir}" />
<path refid="classpath.base" />
</path>
<target name="test" description="Run the tests">
<junit>
<classpath refid="classpath.test" />
<formatter type="brief" usefile="false" />
<test name="testDataGenerator.test.AllTests" />
</junit>
</target>
</project>
It was all good before I changed a test fixture file from absolute path to relative path:
SAXReader reader = new SAXReader();
Document document = reader.read(new File(".").getCanonicalPath()+"\\conf\\TestData.xml");
The ant task now try to open D:\eclipse\eclipse\conf\TestData.xml, instead of C:\STAF\services\custom\TopCoder\conf\TestData.xml, I've also try to run AllTests manually from Eclipse and it's all good.
Has anyone met similar problem before?
Thanks in advance.
PS. ANT_HOME=D:\eclipse\eclipse\plugins\org.apache.ant_1.7.0.v200706080842
Follow up:
I tried to run the ant script from command line, and find below:
C:\STAF\services\custom\TopCoder>ant -f c:\STAF\services\custom\TopCoder\task\build.xml, the ant script works correctly.
C:>ant -f c:\STAF\services\custom\TopCoder\task\build.xml, the script will claim: [junit] C:\conf\TestData.xml (The system cannot find the path specified)
I've also checked eclipse builder setting, there seems nothing to change the path to D:\eclipse\eclipse.
Java resolves relative paths against the current user directory, which is typically the directory from where the java program was invoked.
One way to overcome this issue is to define an environmental variable for your base path. Then, you could easily use "relative paths" (meaning, create absolute paths by concatenating the base path and the relative path).
Here is the solution I find:
Just as kgiannakakis mentioned, Ant also start executing its task from the location it was invoked, so we just need to change the working directory setting of our custom eclipse builder.
In the JRE tab, choose "Execution Environment".
Change the Working directory to your current workspace.
Looks like I've missed the karma but anyway...
We do this:-
Build.xml
<project name="whatever">
<property file="build.${env.COMPUTERNAME}.properties"/>
<property file="build.properties"/>
build.properties
project.root=..
build.file.dir=${project.root}/buildfiles
deploy.dir=${project.root}/deploy
which of course you can override by creating your OWN build.computername.properties to allow for developer path differences etc