How to determine build architecture (32bit / 64bit) with ant? - java

We have inherited an ant build file but now need to deploy to both 32bit and 64bit systems.
The non-Java bits are done with GNUMakefiles where we just call "uname" to get the info. Is there a similar or even easier way to mimic this with ant?

Late to the party, but what the heck...
${os.arch} only tells you if the JVM is 32/64bit. You may be running the 32bit JVM on a 64bit OS. Try this:
<var name ="os.bitness" value ="unknown"/>
<if>
<os family="windows"/>
<then>
<exec dir="." executable="cmd" outputproperty="command.ouput">
<arg line="/c SET ProgramFiles(x86)"/>
</exec>
<if>
<contains string="${command.ouput}" substring="Program Files (x86)"/>
<then>
<var name ="os.bitness" value ="64"/>
</then>
<else>
<var name ="os.bitness" value ="32"/>
</else>
</if>
</then>
<elseif>
<os family="unix"/>
<then>
<exec dir="." executable="/bin/sh" outputproperty="command.ouput">
<arg line="/c uname -m"/>
</exec>
<if>
<contains string="${command.ouput}" substring="_64"/>
<then>
<var name ="os.bitness" value ="64"/>
</then>
<else>
<var name ="os.bitness" value ="32"/>
</else>
</if>
</then>
</elseif>
</if>
<echo>OS bitness: ${os.bitness}</echo>
EDIT:
As #GreenieMeanie pointed out, this requires the ant-contrib library from ant-contrib.sourceforge.net

you can get at the java system properties (http://java.sun.com/javase/6/docs/api/java/lang/System.html#getProperties()) from ant with ${os.arch}. other properties of interest might be os.name, os.version, sun.cpu.endian, and sun.arch.data.model.

Here is an answer that works (I tested on Kubuntu 64, Debian 32, Windows 2000 and Windows XP) without the need of external or optional ANT dependencies. It was based on #phatypus's answer.
<project name="FindArchitecture" default="check-architecture" basedir=".">
<!-- Properties set: unix-like (if it is unix or linux), x64 (if it is 64-bits),
register- size (32 or 64) -->
<target name="check-architecture" depends="check-family,check-register" >
<echo>Register size: ${register-size}</echo>
<echo>OS Family: ${os-family}</echo>
</target>
<target name="check-family" >
<condition property="os-family" value="unix" else="windows">
<os family="unix" />
</condition>
<condition property="unix">
<os family="unix" />
</condition>
</target>
<target name="check-register" depends="reg-unix,reg-windows">
</target>
<!-- Test under GNU/Linux -->
<target name="reg-unix" if="unix">
<exec dir="." executable="uname" outputproperty="result">
<arg line="-m"/>
</exec>
<!-- String ends in 64 -->
<condition property="x64">
<matches string="${result}" pattern="^.*64$"/>
</condition>
<condition property="register-size" value="64" else="32">
<isset property="x64"/>
</condition>
</target>
<!-- Test under MS/Windows-->
<target name="reg-windows" unless="unix">
<!-- 64 bit Windows versions have the variable "ProgramFiles(x86)" -->
<exec dir="." executable="cmd" outputproperty="result">
<arg line="/c SET ProgramFiles(x86)"/>
</exec>
<!-- String ends in "Program Files (x86)" -->
<condition property="x64">
<matches string="${result}" pattern="^.*=.*Program Files \(x86\)"/>
</condition>
<condition property="register-size" value="64" else="32">
<isset property="x64"/>
</condition>
</target>
</project>

You can just pass a parameter into the build file with the value you want. For example, if your target is dist:
ant -Dbuild.target=32 dist
or
ant -Dbuild.target=64 dist
and then in your Ant build script, take different actions depending on the value of the ${build.target} property (you can also use conditions to set a default value for the property if it is not set).
Or, you can check the value of the built-in system properties, such as ${os.arch}.

os.arch does not work very well, another approach is asking the JVM, for example:
~$ java -d32 test
Mon Jun 04 07:05:00 CEST 2007
~$ echo $?
0
~$ java -d64 test
Running a 64-bit JVM is not supported on this platform.
~$ echo $?
1
That'd have to be in a script or a wrapper.

BTW, the os.arch (arch property of the os tag) I got for 64-bit Linux was amd64.

Assuming you are using ANT for building Java Application, Why would you need to know if it is a 32 bit arch or 64-bit? We can always pass parameters to ant tasks. A cleaner way would be to programmaticaly emit the system properties file used by Ant before calling the actual build. There is this interesting post http://forums.sun.com/thread.jspa?threadID=5306174.

Related

Building a universal Appbunder build for java on MacOS M1 machine

I have been building MacOs Java application on Intel MacMini for number of years, essentially
Compile/Build with maven
Make cutdown embedded jre using jlink
Make Appbundle using TheInfiniteKind AppBundler fork
Sign and notarize
Package up as a dmg using DmgCanvas
Now have it building on MacOS M1 and it builds okay. When I run on Mac M1 it works but when I try to run on Intel Macmini it fails with Unable to load JRE Environment
This kind of makes sense because when I build it I am just providing a single jre based on the M1 version of Adoptium Terium 17. But I dont understand how I provide two JRE's if this is what I need to do
Below I show the main build script
#!/bin/bash
#set -x
cd $HOME/code/jthink/songkong/src/main/scripts
hiutil -C -fapplehelpbook/SongKongHelp/SongKongHelp.helpindex applehelpbook/SongKongHelp/
cd $HOME/code/jthink/songkong
sudo rm -fr /Applications/SongKong.app
mvn -f pommacos.xml clean
mvn -f pommacos.xml -DskipTests=true install
rm -fr target/songkong-8.2
unzip target/songkong-8.2-distribution.zip -d target
ant
while read line; do
echo "$line"
if [[ "$line" = "<string>1.0</string>" ]]; then
cat mergefile.txt # or echo or printf your extra lines
fi
done < /Applications/SongKong.app/Contents/Info.plist > Info.new
while read line; do
echo "$line"
if [[ "$line" = "<false/></dict>" ]]; then
cat mergefile2.txt
fi
done < Info.new > Info.new2
rm /Applications/SongKong.app/Contents/Info.plist
rm Info.new
mv Info.new2 /Applications/SongKong.app/Contents/Info.plist
sudo cp -r target/songkong-8.2/applehelpbook/SongKongHelp /Applications/SongKong.app/Contents/Resources
export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate"
/usr/bin/codesign --timestamp --options runtime \
--entitlements $HOME/code/jthink/songkong/songkong.entitlements \
--sign "Developer ID Application: P Taylor" \
--force --deep --verbose /Applications/SongKong.app
/usr/bin/codesign -vvv --deep --strict /Applications/SongKong.app
spctl -a -t exec -vv /Applications/SongKong.app
cd $HOME/code/jthink/SongKong
/usr/local/bin/dmgcanvas $HOME/code/jthink/SongKong/dmgCanvas_songkong.dmgCanvas $HOME/songkong-osx.dmg -v SongKong -identity "Developer ID Application: P Taylor" -notarizationAppleID paultaylor#jthink.net -notarizationPassword xxxxxxxxxxxxxxxxxxxxxx -notarizationPrimaryBundleID songkong
and the ant file used by the appbundler task
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="songkong">
<property environment="env"/>
<property name="songkongsrc" value="/Users/paultaylor/code/jthink/SongKong/target/songkong-8.2"/>
<property name="resources" value="/Users/paultaylor/code/jthink/SongKong/src/main/resources"/>
<property name="songkonglib" value="${songkongsrc}/lib"/>
<property name="songkongtargetroot" value="/Applications"/>
<property name="songkongtarget" value="${songkongtargetroot}/SongKong.app"/>
<property name="songkongcontentstarget" value="${songkongtarget}/Contents"/>
<!-- Obtain path to the selected JRE -->
<exec executable="/usr/libexec/java_home"
failonerror="true"
outputproperty="runtime">
<arg value="-v"/>
<arg value="17"/>
</exec>
<taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask"/>
<bundleapp outputdirectory="${songkongtargetroot}"
name="SongKong"
displayname="SongKong"
executableName="SongKong"
identifier="com.jthink.songkong"
shortversion="8.2"
mainclassname="com.jthink.songkong.cmdline.SongKong"
signature="sgkg"
applicationCategory="public.app-category.music"
icon="${songkongsrc}/songkong.icns"
>
<classpath dir="${songkonglib}">
<include name="**/*.jar"/>
</classpath>
<classpath dir="${songkongsrc}">
<include name="songkong.properties"/>
</classpath>
<librarypath dir="${songkongsrc}">
<include name="fpcalc_osx"/>
<include name="libAppleScriptEngine.dylib"/>
</librarypath>
<option value="-Dcom.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog"/>
<option value="-Dorg.jboss.logging.provider=jdk"/>
<option value="-Djava.util.logging.config.class=com.jthink.songkong.logging.StandardLogging"/>
<option value="-Dapple.laf.useScreenMenuBar=true"/>
<option value="-Dapple.awt.brushMetalLook=true"/>
<option value="-Dsun.java2d.metal=true"/>
<option value="-XX:+HeapDumpOnOutOfMemoryError"/>
<plistentry key="NSRequiresAquaSystemAppearance" type="boolean" value="false"/>
<plistentry key="AppleWindowTabbingMode" value="manual"/>
<bundledocument extensions="mp3,wma,ogg,flac,wav,aif,aiff,aifc"
name="Music Files"
role="editor"
isPackage="false">
</bundledocument>
<jlink runtime="${runtime}">
<jmod name="java.desktop"/>
<jmod name="java.datatransfer"/>
<jmod name="java.logging"/>
<jmod name="java.management"/>
<jmod name="java.naming"/>
<jmod name="java.net.http"/>
<jmod name="java.prefs"/>
<jmod name="java.scripting"/>
<jmod name="java.sql"/>
<jmod name="jdk.management"/>
<jmod name="jdk.unsupported"/>
<jmod name="jdk.jcmd"/>
<jmod name="jdk.crypto.ec"/>
<jmod name="jdk.dynalink"/>
<argument value="--compress=2"/>
<argument value="--release-info=${runtime}/release"/>
</jlink>
</bundleapp>
<copy file="${resources}/create_itunes_model.scpt" tofile="${songkongcontentstarget}/Java/create_itunes_model.scpt"/>
<copy file="${resources}/create_music_model.scpt" tofile="${songkongcontentstarget}/Java/create_music_model.scpt"/>
<copy file="${resources}/get_playlist_folder.scpt" tofile="${songkongcontentstarget}/Java/get_playlist_folder.scpt"/>
<copy file="${resources}/get_music_playlist_folder.scpt" tofile="${songkongcontentstarget}/Java/get_music_playlist_folder.scpt"/>
<copy file="${songkongsrc}/songkong.properties" tofile="${songkongcontentstarget}/songkong.properties"/>
<copy file="${songkongsrc}/songkong1.properties" tofile="${songkongcontentstarget}/songkong1.properties"/>
<copy file="${songkongsrc}/songkong2.properties" tofile="${songkongcontentstarget}/songkong2.properties"/>
<copy file="${songkongsrc}/songkong2.properties" tofile="${songkongcontentstarget}/songkong3.properties"/>
<copy file="${songkongsrc}/songkong2.properties" tofile="${songkongcontentstarget}/songkong4.properties"/>
<copy file="${songkongsrc}/songkong5.properties" tofile="${songkongcontentstarget}/songkong5.properties"/>
<copy file="${songkongsrc}/renamemask.properties" tofile="${songkongcontentstarget}/renamemask.properties"/>
<copy file="${songkongsrc}/general.properties" tofile="${songkongcontentstarget}/general.properties"/>
<copy file="${songkongsrc}/license.properties" tofile="${songkongcontentstarget}/license.properties"/>
<copy file="${songkongsrc}/genrelist.txt" tofile="${songkongcontentstarget}/genrelist.txt"/>
<copy file="${songkongsrc}/classical_composers.txt" tofile="${songkongcontentstarget}/classical_composers.txt"/>
<copy file="${songkongsrc}/classical_conductors.txt" tofile="${songkongcontentstarget}/classical_conductors.txt"/>
<copy file="${songkongsrc}/classical_people.txt" tofile="${songkongcontentstarget}/classical_people.txt"/>
<copy file="${songkongsrc}/not_classical_release.txt" tofile="${songkongcontentstarget}/not_classical_release.txt"/>
<copy file="${songkongsrc}/license.txt" tofile="${songkongcontentstarget}/license.txt"/>
<copy file="${songkongsrc}/index.html" tofile="${songkongcontentstarget}/index.html"/>
<copy file="${songkongsrc}/pdfOSX/help.pdf" tofile="${songkongcontentstarget}/help.pdf"/>
<copy file="${songkongsrc}/osx/bin/songkong.sh" tofile="${songkongcontentstarget}/bin/songkong.sh"/>
<copy file="${songkongsrc}/osx/bin/songkongremote.sh" tofile="${songkongcontentstarget}/bin/songkongremote.sh"/>
<copy todir="${songkongcontentstarget}/style"><fileset dir="${songkongsrc}/style"/></copy>
<copy todir="${songkongcontentstarget}/lang"><fileset dir="${songkongsrc}/lang"/></copy>
<chmod file="${songkongcontentstarget}/bin/songkong.sh" perm="777"/>
<chmod file="${songkongcontentstarget}/bin/songkongremote.sh" perm="777"/>
</project>
Edit 1:.
So when you say, you want to create a universal app, as I understand:
you want to have a single jar that will run on both platforms
you want to bundle both jre's in same build as you want to run on two separate platforms.
You will have both jre's present on your host system from which you are bundling app.
You want single app with both jre's included for both mac platforms.
If you want to achieve 1-4, there is a hard road ahead:
You can also customize an appbundler by forking this repository
You need to focus on this class first:
https://github.com/TheInfiniteKind/appbundler/blob/master/appbundler/src/com/oracle/appbundler/AppBundlerTask.java
How it works:
Challenge we need to solve is Appbundler takes only 1 runtime at any given time.
https://github.com/TheInfiniteKind/appbundler/blob/master/appbundler/src/com/oracle/appbundler/AppBundlerTask.java#L235
Later it copies the runtime contents to a directory called PlugIns
https://github.com/TheInfiniteKind/appbundler/blob/master/appbundler/src/com/oracle/appbundler/AppBundlerTask.java#L467
You can extend AppBundlerTask and override public void execute() method.
Here you can provide List<Runtime> instead of single Runtime.
now, this execute method creates a Info.plist file, you can create two instead with different runtime elements.
https://stackoverflow.com/a/54569519/1811348
I am highly in doubt if this will work for following three issues in my mind:
a. How Plugins directory is loaded in the app and how its used is not known to me, so two runtimes in same dir, no idea if its okay.
b. If at all we can have two plist file in same app how to toggle them with device environment variable from app side is not known to me. This env variable will decide what plist file to select.
c. app size post bundling two jre's in single app.
Also note, accordingly you will have to update your ant task to provide two directories for 2 jre's.
If only 1,2,3 are correct, you can bundle two jre's in two different applications:
I think answer still remains the same as the exec tag itself is just setting your java runtime. However you can try following way as well.
Just add condition for this exec
<!-- Obtain path to the selected JRE -->
<exec executable="/usr/libexec/java_home"
failonerror="true"
outputproperty="runtime">
<arg value="-v"/>
<arg value="17"/>
</exec>
kindly note that: this exec tag is doing same thing that <runtime dir="${env.JAVA_HOME}" /> is doing in provided article.
https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
eg:
<?xml version="1.0" encoding="UTF-8"?>
<target name="set-runtime">
<echo level="info">setting-runtime</echo>
<if>
<equals arg1="${os.family}" arg2="mac" />
<then>
<echo message="setting to mac desktop jre" />
<!-- Obtain path to the selected JRE -->
<exec executable="/usr/libexec/java_home" failonerror="true" outputproperty="runtime">
<arg value="-v" />
<arg value="17" />
</exec>
</then>
<else>
<echo message="setting to mac mini jre" />
<!-- Obtain path to the selected JRE -->
<exec executable="path to java home for mac mini on my system" failonerror="true" outputproperty="runtime">
<arg value="-v" />
<arg value="17" />
</exec>
</else>
</if>
</target>
From what I am guessing you are loading the jre in exec tag of ant xml.
You can use Ant conditionals if you want to negotiate based on some criteria eg: device, os, os version and so on.
<condition property="isMacOsButNotMacOsX">
<and>
<os family="mac"/>
<not>
<os family="unix"/>
</not>
</and>
</condition>
also ref:
https://stackoverflow.com/a/19272061/1811348
Additionally, if you want to do anything special
eg: package jar for two different platforms altogether with different jdk versions you can:
https://www.zghurskyi.com/maven-package-to-multiple-java-versions/

Conditional task execution in ANT Scripts

My requirement is pretty simple, I have an ANT task which is handling exceptions internally and not throwing any exception, instead it is throwing custom messages [these are not exceptions] to the console. A sample is shown below with the test "The workspace with the specified name does not exist".
My requirement here is, if there is any such message apart from "Build Successful", I should make sure my ANT script is failed so that it won't go further. But I am unable to do so as I don't know how do I read that custom message which was written to console.
I tried exploring on 'Record' task but I was unsuccessful as this log was written only to console and not to the file (don't know why). But even if it was written to a file I should ideally read each line of file to find out a particular text present or not.
Is there a simple way to try and read things from console which were executed before?
<target name="build">
<record name="test.txt" action="start" append="true" loglevel="verbose" />
<echo>Welcome to Apache Ant! Building the project in Cordys Middleware</echo>
<property environment="env"/>
<property name="bop.install.dir" value="${env.CORDYS_HOME}"/>
<exec executable="${bop.install.dir}/components/cws/scripts/linux/CWSPackage.sh" failonerror="true" resultproperty="output">
<env key="CLASSPATH" value="/opt/Cordys/Oracle_Jar/ojdbc6.jar"/>
<arg value="${ORG_NAME}"/>
<arg value="${WORKSPACE_NAME}"/>
<arg value="${PROJECT_NAME}"/>
</exec>
<echo>Finishing the build</echo>
<record name="test.txt" action="stop"/>
<echo>${output}</echo>
<fail>Something wrong here.</fail> <!-- I want to throw this error conditionally -->
</target>
What you're looking for is the exec task's outputproperty attribute.
You can do something like this:
<exec executable="${my.executable}" outputproperty="exec.output">
<arg value="${my.arg}" />
</exec>
<fail message="Invalid output from exec task">
<condition>
<contains string="${exec.output}" substring="The workspace with the specified string does not exist." />
</condition>
</fail>
Multiple conditions (any level of complexity in the boolean is allowed):
<fail message="Invalid output from exec task">
<condition>
<and>
<not>
<contains string="${exec.output}" substring="SUCCESS" />
</not>
<or>
<contains string="${exec.output}" substring="ERROR" />
<contains string="${exec.output}" substring="FAILED" />
<or>
</and>
</condition>
</fail>
Regex:
<fail message="Invalid output from exec task">
<condition>
<matches string="${exec.output}" pattern="The .* does not exist." />
</condition>
</fail>
<!-- * This is an ANT script to build the project in development environment.
Steps involved in this are
* Building the project
* Publishing the project
* Creating the package for the project
-->
<!--
Sample command to execute this
ant build -DORG_NAME=businessservices3 -DWORKSPACE_NAME=ConfigurationManagement -DPROJECT_NAME='ConfigurationManagement'
-->
<project name="Building Project" default="build">
<property file="${PROJECT}" />
<target name="build">
<echo>Welcome to Apache Ant! Building the project in Cordys Middleware</echo>
<property environment="env"/>
<property name="bop.install.dir" value="${env.CORDYS_HOME}"/>
<exec executable="${bop.install.dir}/components/cws/scripts/linux/CWSPackage.sh" outputproperty="exec.output">
<env key="CLASSPATH" value="/opt/Cordys/Oracle_Jar/ojdbc6.jar"/>
<arg value="${ORG_NAME}"/>
<arg value="${WORKSPACE_NAME}"/>
<arg value="${PROJECT_NAME}"/>
</exec>
<fail message="Build not successful for the project ${PROJECT_NAME}">
<condition>
<not>
<contains string="${exec.output}" substring="Operation completed successful" />
</not>
</condition>
</fail>
</target>
</project>
This worked for me after so much of trail and error methods.
Thanks Austin. Even though this is the ANT which is working, I would accept your answer only as this is a modified version of what you told :)

Bulding an multi-platform SWT application using Ant

I'm writing an SWT application which can be used on Windows (32/64 bit) and Mac OSX (32/64 bit).
Apart from the JRE I rely on the SWT library found here. I can find four versions of the SWT library depending upon my target platforms (as mentioned above).
When building my application, how can I compile using the correct SWT Jar? If possible, I'd like to try and avoid hard-coding the Jar version, platform and architecture. The SWT Jars are named like this:
swt-win32-x86_64.jar
swt-win32-x86_32.jar
swt-macosx-x86_32.jar
swt-macosx-x86_64.jar
(My project will be an open source project. I'd like people to be able to download the source and build it and therefore I've thought of including all the four versions of the SWT Jars in the source distribution. I hope this is the correct approach of publishing code relying on third-part libraries.)
Thanks everyone.
I've tried to accomplish it like this: I've installed the Ant Contrib tasks because it supports if statements. I've modified my build file to use to detect the OS platform and architecture.
When compiling, it uses all the 4 SWT Jars from my lib.dir but after compilation, it copies over only the necessary SWT Jar to my build directory. I guess this would keep my size of my final ZIP much smaller than keeping all four JARs.
<target name="copy" depends="compile">
<if>
<os family="windows"/>
<then>
<exec dir="." executable="cmd" outputproperty="command.ouput">
<arg line="/c SET ProgramFiles(x86)"/>
</exec>
<if>
<contains string="${command.ouput}" substring="Program Files (x86)"/>
<then>
<copy file="${lib.dir}/swt-win32-x86_64.jar" tofile="${jar.dir}/SWT.jar"/>
</then>
<else>
<copy file="${lib.dir}/swt-win32-x86_32.jar" tofile="${jar.dir}/SWT.jar"/>
</else>
</if>
</then>
<elseif>
<os family="unix"/>
<then>
<exec dir="." executable="/bin/sh" outputproperty="command.ouput">
<arg line="/c uname -m"/>
</exec>
<if>
<contains string="${command.ouput}" substring="_64"/>
<then>
<copy file="${lib.dir}/swt-macosx-x86_64.jar" tofile="${jar.dir}/SWT.jar"/>
</then>
<else>
<copy file="${lib.dir}/swt-macosx-x86_32.jar" tofile="${jar.dir}/SWT.jar"/>
</else>
</if>
</then>
</elseif>
</if>
</target>
This seems to work so far. I'll test it some more and add a comment.

Eclipse Equinox, how to configure auto load the bundles in plugin folder

I've followed http://www.eclipse.org/equinox/documents/quickstart-framework.php but it seems to be old and not valid.
There is no such bundles as described org.eclipse.update.configurator_3.2.100.jar
I tried with the org.eclipse.equinox.simpleconfigurator_1.0.200.v20100503, but doesn't work.
Anyone can tell me how to make Equinox auto load the bundles inside plugins folder?
Simplest approach would be to use Apache Felix File Install. It works just fine with Equinox, you only need to put File Install configuration parameters into the configuration/config.ini. Note though that if you launch Equinox via launcher JAR or via binary, the working directory would be parent of configuration/ or plugins/ directory.
Excerpt from our project config.ini:
# Start File Install itself
osgi.bundles=reference\:file\:org.apache.felix.fileinstall_3.1.0.jar#1\:start
# The name of the directory to watch
felix.fileinstall.dir=./plugins
# A regular expression to be used to filter file names
# We have all bundles in plugins/ directory, this regexp
# forbids monitoring bundles that are started via osgi.bundles property
felix.fileinstall.filter=^(?!org.apache.felix.fileinstall|org.eclipse.osgi).*
# Determines if File Install waits felix.fileinstall.poll milliseconds before doing an initial scan or not.
felix.fileinstall.noInitialDelay=true
# Not sure why we have this...
felix.fileinstall.start.level=2
Other possible solution would be to use Eclipse P2. It is much more advanced and powerful, though I find it quite difficult to use.
Good thing is that if your application is agnostic to the way bundles are provisioned (and it should be this way), you can always change your mind later.
Here is the fragment from my automated eclipse installer written in ant.
This installs all features from the custom update site. The code is 'as is', but I sure would have liked to have something like this to guide me when I wrote it.
This script also uses antcontrib extension to ant. Antcontrib tasks are have 'ac:' namespace prefix
Hope this helps.
<property name="real.eclipse.home" location="${eclipse.home}/eclipse"/>
<property file="${real.eclipse.home}/configuration/config.ini" prefix="ECLIPSE_CONFIG"/>
<property name="eclipse-plugins.dir" location="${real.eclipse.home}/plugins"/>
<path id="newest.equinox.launcher-library.path.id">
<dirset dir="${eclipse-plugins.dir}">
<include name="org.eclipse.equinox.launcher.*"/>
</dirset>
</path>
<property name="equinox.launcher-library.full-path" refid="newest.equinox.launcher-library.path.id"/>
<basename property="equinox.launcher-library.dir" file="${equinox.launcher-library.full-path}"/>
<echo message="equinox.launcher-library.dir='${equinox.launcher-library.dir}'"/>
<path id="newest.equinox.launcher.path.id">
<fileset dir="${eclipse-plugins.dir}">
<include name="org.eclipse.equinox.launcher_*.jar"/>
</fileset>
</path>
<property name="equinox.launcher.jar" refid="newest.equinox.launcher.path.id"/>
<basename property="equinox.launcher.jar.basename" file="${equinox.launcher.jar}"/>
<echo message="equinox.launcher.jar='${equinox.launcher.jar}'"/>
<java jar="${equinox.launcher.jar}"
fork="true"
failonerror="true"
>
<arg value="-consolelog"/>
<arg value="-application"/>
<arg value="org.eclipse.equinox.p2.director"/>
<arg value="-repository"/>
<arg value="http://${repository.server}/custom-update-site"/>
<arg value="-list"/>
<redirector
logError="true"
outputproperty="features.list"
>
<outputfilterchain>
<linecontains>
<contains value="feature.group="/>
</linecontains>
<replaceregex pattern="(.*feature\.group)=.*$" replace="\1"/>
</outputfilterchain>
</redirector>
</java>
<ac:for list="${features.list}" delimiter="${line.separator}" trim="true" param="feature">
<sequential>
<ac:if>
<isset property="feature.comma.list"/>
<then>
<ac:var name="feature.comma.list" value="${feature.comma.list},#{feature}"/>
</then>
<else>
<property name="feature.comma.list" value="#{feature}"/>
</else>
</ac:if>
</sequential>
</ac:for>
<echo message="Found following features to install"/>
<echo message="${features.list}"/>
<java jar="${equinox.launcher.jar}"
fork="true"
failonerror="true"
>
<arg value="-consolelog"/>
<arg value="-application"/>
<arg value="org.eclipse.equinox.p2.director"/>
<arg value="-repository"/>
<arg value="http://${repository.server}/custom-update-site"/>
<arg value="-destination"/>
<arg file="${real.eclipse.home}"/>
<arg value="-installIU"/>
<arg value="${feature.comma.list}"/>
<arg value="-profile"/>
<arg value="${ECLIPSE_CONFIG.eclipse.p2.profile}"/>
</java>
P.S. For its usefulness and complexity Eclipse P2 is surely one of the most underdocumented features.
In your eclipse installation folder you have the file bundles.info, for example:
eclipse-3.6.1/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info
You can modify the file to add any bundle you want, and also the start level. But the simplest method of adding bundles to an eclipse installation is to add them to the "dropins" folder. This will lead to an automatic modification of the bundle.info file.

Ant, NetBeans Platform project - how to pass command line arguments and access via System.getProperties?

All,
I have a NetBeans Platform project (not just a project I wrote in NetBeans, but one using the rich client framework provided by NetBeans). I can run the project via an ant run command. Now, I want to pass in an argument that will work its way through ant to be accessible via the System.getProperty method.
I understand that I need to use a <sysproperty> node to actually inject the key/value pair into the runtime environment, but for the life of me I cannot figure out how to get this to work with the convoluted build tree that NetBeans creates for you (build.xml depends on build-impl.xml, which in turn depends on ${harness.dir}/suite.xml, which in turn depends on ${harness.dir}/run.xml)
The simplest example I've found is
<target name="run" depends="compile">
<java classname="prop"
fork="true">
<sysproperty key="test.property"
value="blue"
/>
</java>
</target>
but the problem is that none of my xml files have an easily accessible <java> node like that. I think I've managed to trace the execution flow to where something is actually invoked (in ${harness.dir}/run.xml)
<target name="run" depends="-prepare-as-app,-prepare-as-platform">
<touch file="${cluster}/.lastModified"/> <!-- #138427 -->
<property name="run.args" value=""/>
<property name="run.args.ide" value=""/>
<property name="run.args.extra" value=""/>
<condition property="run.args.mac" value="-J-Xdock:name=${app.name}" else="">
<os family="mac"/>
</condition>
<exec osfamily="windows" executable="${run.exe}" failonerror="no" resultproperty="result.prop">
<arg value="--jdkhome"/>
<arg file="${run.jdkhome}"/>
<arg line="${run.args.common}"/>
<arg line="${run.args.prepared}"/>
<arg line="${run.args}"/>
<arg line="${run.args.ide}"/>
<arg line="${run.args.extra}"/>
</exec>
<exec osfamily="unix" dir="." executable="sh"
failonerror="no" resultproperty="result.prop">
<arg value="${run.sh}"/>
<arg value="--jdkhome"/>
<arg file="${run.jdkhome}"/>
<arg line="${run.args.common}"/>
<arg line="${run.args.prepared}"/>
<arg line="${run.args}"/>
<arg line="${run.args.ide}"/>
<arg line="${run.args.extra}"/>
<arg line="${run.args.mac}"/>
</exec>
<fail>
The application is already running within the test user directory.
You must shut it down before trying to run it again.
<condition>
<and>
<isset property="result.prop" />
<or>
<!-- unknown option exit code as returned from IDE by org.netbeans.api.sendopts.CommandLine -->
<equals arg1="${result.prop}" arg2="50346" />
<!-- unknown option exit code as returned from platform app by org.netbeans.CLIHandler -->
<equals arg1="${result.prop}" arg2="2" />
</or>
</and>
</condition>
</fail>
</target>
As you can see, there is no <java> node underneath which I can put my custom sysproperty. Furthermore, it seems like a very wrong thing to do to have to muck around with harness xml files to inject a property that only affects one of my projects, not all of them. So what's the correct way to ensure that a command line property I pass to ant run ends up within a NetBeans Platform project?
There is a folder etc in the distribution of your RCP app and in that folder is file yourapp.conf i think there is an answer you seek. For example from one of mine NB RCP app:
# ${HOME} will be replaced by user home directory according to platform
default_userdir="${HOME}/.${APPNAME}/dev"
default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}/dev"
# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--laf Metal --branding xmled -J-Xms24m -J-Xmx64m"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea
# default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch
#jdkhome="/path/to/jdk"
# clusters' paths separated by path.separator (semicolon on Windows, colon on Unices)
#extra_clusters=

Categories

Resources