How Can I Call Another Ant Created Testing Suite From Any Target - java

<target name="Regression_Test" depends="displayEnvironment">
<property name="TestSuite" value="RegressioonTestSuite.xml"/>
<ant antfile="TestNG.xml" dir="${tools.loc}" target="runTestNG" inheritAll="true"/>
<!--<antcall target="buildAndTest" inheritAll="true"/>-->
</target>
In Above Code..
<property name="TestSuite" value="RegressioonTestSuite.xml"/>
Is Not Working, It does not pass to RegreessionTestSuite.xml
Created a file for regression testing Named as RegreessionTestSuite.xml
if i write
this code outside of target then it works but inside any target it won't

as per comments above, it would be helpful if you could post the error/exception you are getting.
In the meanwhile, a few tips to debug it could be:
call ant via the exec task (you can also do an echo of the command you are executing, to double check for typos etc.)
are the target you want to invoke in a different file? is this file 'imported' into your master build file?

Thank You for your support..
I am newer in Ant
Found Solution...Made a silly mistake
<ant antfile="TestNG.xml" dir="${tools.loc}" target="runTestNG" inheritAll="true">
<property name="TestSuite" value="RegressioonTestSuite.xml"/>
</ant>

Related

Manipulating directories in Java Ant

I have an Ant xml file. In this file I want to set two properties based on the current working directory. The current working directory is always of the form /some/base/dir/SRC/sub/dir.
The first property must be set to the current working directory. The second property must be set to the part of the current working directory up to /SRC.
I can set the first property without any issue using the PWD environment variable , but I cannot figure out the second.
<property name="my.dir" value="${env.PWD}" />
<property name="src.dir" value="{what do I put here?}" />
I've heard this can be done with bash-style string manipulation (e.g. ${PWD%*/SRC}/SRC) using StringOps, but I cannot find any good examples.
One approach is to use the <pathconvert> task, perhaps like this:
<property name="my.dir" value="/some/base/dir/SRC/sub/dir"/>
<pathconvert property="src.dir">
<path path="${my.dir}"/>
<mapper type="regexp" from="^(.*)/SRC" to="\1" />
</pathconvert>
<echo message="src.dir=${src.dir}" />
Which gives:
[echo] src.dir=/some/base/dir
There are other mappers available which might work better for you than regexp.

Java Packager Tool : custom install location

I'm working around "Self-Contained Application" generation using Java Packager Tool. By default, the '.exe' bundle is installed under "C:\Program Files (x86)" but I would like install it to a custom location : "C:\MyApp" for example.
To generate my bundle, I'm using an Ant Task inside a Maven build :
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property name="jre.dir" value="${env.JAVA_HOME}/jre" />
<property name="version" value="0.0.3" />
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant" classpath="${env.JAVA_HOME}/lib/ant-javafx.jar" />
<echo message="// ----------------------------------- //" />
<echo message="// START JAVAPACKAGER ANT TASK //" />
<echo message="// ----------------------------------- //" />
<fx:deploy nativeBundles="exe" outdir="${basedir}/packager"
outfile="MyApp_${version}">
<fx:application name="MyApp" mainClass="com.myfirm.myapp.bootstrap.BootstrapMain">
<fx:argument>-bundlesDir=./bundles/</fx:argument>
</fx:application>
<fx:resources>
<fx:fileset dir="${project.basedir}/target"
includes="${project.name}-${project.version}-jar-with-dependencies.jar" />
<fx:fileset dir="${project.basedir}" includes="bundles/*.jar" />
</fx:resources>
<fx:info title="MyApp ${version}" vendor="MyFirm">
<fx:icon href="${project.basedir}/myapp.ico" kind="default" width="32" height="32" depth="8" />
</fx:info>
<fx:preferences install="true" shortcut="true" />
<fx:platform basedir="${jre.dir}"/>
</fx:deploy>
</target>
Has anybody work around this ? And could tell me more about how to configure more precisely the generated native bundle ?
Thanks by advance.
EDIT
Under Windows, I have found a way to do it : by editing file com\oracle\tools\packager\windows\template.iss in jar %JAVA_HOME%\lib\ant-javafx.jar. But this solution seems to be ugly and not portable ! So I'm now looking for a way to override it in my ant task...
For extra documentation, what Tib Us did was edit %JAVA_HOME%\lib\ant-javafx.jar. You can use 7-Zip (or others) to open that jar file and update it's contents.
In com\oracle\tools\packager\windows\template.iss, change this line:
DefaultDirName=APPLICATION_INSTALL_ROOT\APPLICATION_NAME
To:
DefaultDirName={pf}\APPLICATION_NAME
{pf} is a Inno Setup constant pointing to 32-bit or 64-bit Program Files folder. See Inno Setup Help.
If you'd like to install in Program Files, then it is helpful to change:
PrivilegesRequired=APPLICATION_INSTALL_PRIVILEGE
To:
PrivilegesRequired=admin
Also, if your program is going to be used by non-admin users and will be writing to its folder in Program Files, then you'll need some special folder permissions. Here is some background on permissions for an app running in Program Files.
You might also like to add this, to ensure that the new install location is used:
UsePreviousAppDir=No
This solution isn't ideal, but is better than nothing.
Getting the template from the jar file is fine—or download it here—but you don't need to edit it where it is.
Once you have that template, you can just use it as a drop-in resource. All the variables that look like SOME_VARIABLE, that is, upper case and which use underscores, will still be replaced by the javapackager.
This solution is much more portable because it doesn't involve editing the JDK; just include your template in package/windows/ as YourAppName.iss.
User Option -BinstalldirChooser=true

Stopping only a portion of build script

I have run into a problem regarding the build script. Presently I have a main build.xml file that calls each internal build.xml files from a directory. The internal build.xml has 2 stages to execute wherein at the end i get a jar file.
My requirement is that if anything foes wrong in the 1st step of the internal build.xml file, i should not get the jar file, but the main build should continue execution and go to the next internal build.xml file.
In the internal build.xml based on some condition i want to stop that internal build.What changes should i make in my code to stop that particular build?
Thanks in advance.
Set failonerror="false" on your subant tasks you're using to call the other build files.
If you can afford to add ant-contrib to your build, then it is easy. In your main task, do:
<target name="xxx">
<var name="firstStepOK" value="true"/>
<trycatch>
<try>
<!-- call first sub build -->
</try>
<catch>
<var name="firstStepOK" value="false"/>
</catch>
</trycatch>
<!-- call second sub build, pass value of firstStepOK -->
</target>
Unfortunately, ant-contrib has never made it into ant proper, which is a pity. It contains very useful tasks.

ANT- Loading Multiple Java files from Several packages

I have several files scattered across several packages. I need to load the file one by one and perform operations using ANT but whenever I try, only one file gets loaded. For ex. I have 2 classes - com.abc.one.One and com.bcd.two.Two . The following script print both file name but only the first file as loaded file in both loop iterations
<target name="build" description="My Task">
<for param="file">
<path>
<fileset dir="C:\workspace\AntTest1" includes="**\*.java" />
</path>
<sequential>
<echo message="#{file}" />
<loadfile property="loadedFile" srcfile="#{file}" />
<echo message="${loadedFile}" />
</sequential>
</for>
</target>
I have tried searching the documentation but could not find the concise explanation on how to use loadfile task. I suspected that this might be because ant uses immutable string but could not get workaround. I tried to split the job by creating new target but that does not help me either. Any help is highly appreciated
Ant property can only be set once, and after it is set, it is immutable.
It has been some time since my Ant days, but perhaps the following solution can work: For each file, make an antcall call, with the file name as parameter. then, in the new target, load the file and perform your task. Notice that antcall can impact severely the runtime performance.

"Ant all" not working for me

I have got involved in a project. This project uses ant which is not something I am comfortable with. I have checked out the source code and tried running ant on the most outer directory.
Running 'ant' in commando prompt takes 1 sec and I get a BUILD SUCCESFULL message. If I run 'ant all' I get a
BUILD FAILED. Java.io.IOExceptio: Cannot run program "ant": CreateProcess=2, the system cannot find the file specified and then a long stacktrace.
Most of the people on the project runs OS-X while I use Windows XP.
Any help or information is appreciated :)
EDIT:
<target name="-all-submodules">
<subantlight target="all">
<filelist refid="ordered_build_files"/>
</subantlight>
</target>
In another xml file
<macrodef name="subantlight">
<attribute name="target"/>
<element name="files" optional="no" implicit="true" description="Filessets/lists of build files"/>
<sequential>
<apply executable="ant" failonerror="true">
<arg value="-f"/>
<srcfile/>
<arg value="#{target}"/>
<files/>
</apply>
</sequential>
</macrodef>
This is what throws IOException when it hits the line with "apply executeable..".
UPDATED EDIT:
If i set the absolute path like this
<macrodef name="subantlight">
<attribute name="target"/>
<element name="files" optional="no" implicit="true" description="Filessets/lists of build files"/>
<sequential>
<apply executable="MyAbsolutePathHereToAnt.bat" failonerror="true">
<arg value="-f"/>
<srcfile/>
<arg value="#{target}"/>
<files/>
</apply>
</sequential>
</macrodef>
Everything works.
I have set ANT_HOME to my ant directory. I have set my JAVA_HOME to Java JDK directory. In my PATH I have set %ANT_HOME%\bin;%JAVA_HOME%\bin
Calling echo %ANT_HOME% produces the right path.
I can't see what I am during wrong here.
ant with no attributes calls the default target on the build.xml file on the curent path. 'ant all' will call the 'all' target on the same build file.
First - double check the default ant target - is it 'all' or something different? I guess, the default target is not 'all' in your case and the 'all' build includes a build target, that itself calls ant. And this causes the problem.
Hard to tell from here, but scan the build file for an <ant> task inside some <target>. The IO error smells a bit like a violation of user access rights or missing files near/within this <ant> task.
EDIT
the build.xml starts with something like
<project name="Name" default="compile" basedir="/src">
The 'default' attribute names the default target. If the attribute is missing, all top level targets are executed (since ant 1.6) which should include all in your case.
If it works 'for everyone else' then 'everyone else' might have a different environment. Have a look at the environment variable ant references in the script (like 'env.JAVA_HOME' and so on) and compare with the actual environment. Maybe you find a broken path.
Do you have the bin directory of your Ant installation in your PATH? If not, then add it.
It looks like the all target tries to execute Ant (recursively) but can't find it.

Categories

Resources