JavaFX classpath definition to include WiX config file on Windows - ant

On the last few weeks I've been working on a JavaFX Application to deploy for both Unix and Windows. At the moment, I'm trying to customize the install scripts/ config files.
On MacOS I simply included the script to the class path using <property> on my ANT build file like this:
<property name="classpath" location="package/macosx/App-dmg-setup.scpt"/>
But when I try to do the same on Windows, doesn't work (continues using the default config file). I've already tried absolute path, env.CLASSPATH instead of classpath, and some other alternatives, with no success.
Thanks a lot ;)
Cheers!

Ok sorry this question, actually I was inadvertently changing the basedir variable. The correct definition should only be:
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
<file name="${basedir}"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
Without another (re)definition.
Once again, thanks!

Related

Using Ant to remove sections from a manifest file (unsigning JARs)

Context of problem
I am trying to write a bit of ant to unsign a JAR. In order to do this, I am trying to make the following 2 changes to an existing signed JAR file:
Remove META-INF/SF, META-INF/.DSA and META-INF/*.RSA files from the JAR
Remove signature related sections from the JAR's manifest
I can remove the signature related files using the zip and zipfileset tasks, however, I am struggling to edit the manifest file to remove signature sections.
Problem to solve
I need an automated way using Ant to create or edit a manifest file which originally looks like:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Application-Name: My Application
Class-Path: lib/my-jar-one.jar lib/my-jar-two.jar
Built-By: Developer Name
Name: org/mycompany/myapplication/MyApplicationClassOne.class
SHA1-Digest: dsaf89y342t24grg9grn90gh24g
Name: org/mycompany/myapplication/MyApplicationClassTwo.class
SHA1-Digest: sdfgviuonw0423t42h9brbr4
into this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Application-Name: My Application
Class-Path: lib/my-jar-one.jar lib/my-jar-two.jar
Built-By: Developer Name
Any help on this would be greatly appreciated. I have been searching online in various ways, but I cannot find a solution to solving this problem
Additional Scenario
Some lines continue onto the next line, such as in the following manifest file
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Application-Name: My Application
Class-Path: lib/my-jar-one.jar lib/my-jar-two.jar
Built-By: Developer Name
Name: org/mycompany/myapplication/blah/blah/blah/MyApplicationClassOne
.class
SHA1-Digest: dsaf89y342t24grg9grn90gh24g
Name: org/mycompany/myapplication/MyApplicationClassTwo.class
SHA1-Digest: sdfgviuonw0423t42h9brbr4
The solution I got working for this problem is as follows:
<copy file="MANIFEST.MF" tofile="MANIFEST.MF.EDITED" overwrite="true">
<filterchain>
<replaceregex pattern="\nName:(.+?)\nSH" replace="SH" flags="gis" byline="false"/>
<replaceregex pattern="SHA1-Digest:.*" replace="" flags="gis" byline="false"/>
</filterchain>
</copy>
This seems to work although I have got this working by trial and error and do not fully understand the solution in place. If somebody could clarify, it would be very helpful
You may use FilterChains to achieve this. For instance, code below will copy an original MANIFEST file skipping the lines you wanted to remove:
<copy file="MANIFEST.MF.ORIGIN" tofile="MANIFEST.MF" overwrite="true">
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="^Name:.*$"/>
</linecontainsregexp>
<linecontainsregexp negate="true">
<regexp pattern="^SHA1-Digest:.*$"/>
</linecontainsregexp>
</filterchain>
</copy>

How do I convert textile to Eclipse help using ant?

I've been using the Mylyn WikiText User Guide to learn how to convert textile files to Eclipse help but I also want to be able to do this using ant because, ultimately, I want to have many textile files contribute to a single textile file then convert to Eclipse help to enable multiple developers to create help pages with minimal conflicts.
The following ant script should take all *.textile files in the 'doc' folder and convert them to Eclipse help:
<?xml version="1.0"?>
<project name="helpwikitext" default="generate-help">
<property name="wikitext.standalone" value="doc" />
<path id="wikitext.classpath">
<fileset dir="${wikitext.standalone}">
<include name="org.eclipse.mylyn.wikitext.*core*.jar" />
</fileset>
</path>
<taskdef classpathref="wikitext.classpath" resource="org/eclipse/mylyn/wikitext/core/util/anttask/tasks.properties" />
<target name="generate-help" description="Generate Eclipse help from textile source">
<wikitext-to-eclipse-help markupLanguage="Textile" multipleOutputFiles="true" navigationImages="true" helpPrefix="help">
<fileset dir="${basedir}">
<include name="doc/*.textile" />
</fileset>
<stylesheet url="styles/help.css" />
<stylesheet url="styles/main.css" />
</wikitext-to-eclipse-help>
</target>
</project>
I get the following error:
[taskdef] Could not load definitions from resource org/eclipse/mylyn/wikitext/core/util/anttask/tasks.properties. It could not be found.
build.xml:11: Problem: failed to create task or type wikitext-to-eclipse-help
I'm fairly sure that I have all the Mylyn features installed so it looks like the ant script doesn't know where to find them. Does anyone know how to fix this?
Do you have the wikitext standalone package installed in your doc directory?
That is what is expected as you define the path used by the taskdef like this:
<property name="wikitext.standalone" value="doc" />
I'll take a guess that your wikitext package is in a different dir.
You then use the same dir as the root for your textfiles. I would suggest to keep the wikitext standalone package separate from your textfiles.

BND Ant task - wrap non-OSGi jars

I'm trying to use Ant bndwrap task to wrap non-OSGi jars in a directory. My current Ant configuration for this is:
<target name="wrap-jars" description="Wrap non-OSGi jars">
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="${biz.aQute:bnd:jar}"/>
<bndwrap output="${dist.dir}/app-modules">
<fileset dir="${dist.dir}/app-modules" includes="*.jar" />
</bndwrap>
<move overwrite="true" todir="${dist.dir}/app-modules" >
<fileset dir="${dist.dir}/app-modules" includes="*.bar" />
<mapper type="glob" from="*.bar" to="*.jar" />
</move>
</target>
This works fine, but the problem is that it also wraps existing OSGi jar, which causes problems. For instance, I noticed it changes Bundle-SymbolicName header to some default value. It might be changing something else, which I don't want. I only want it to operate on jars that have no OSGi info at all.
Is there some way to tell BND to ignore existing OSGi headers in manifest, or complete jars that are already OSGi-fied?
I would store non-OSGi jars in a separate folder and modify the fileset to process only that folder.
I've noticed that recent bnd versions (for example, 2.1.0) now honour the Bundle-SymbolicName when rewrapping OSGi jars.
just change your fileset to exclude that jar

where to find missing optional ant tasks?

I wanted to have a look which system properties are set here (and to which values), so the easiest way (if not writing a new Java program here) would be adding some lines to my ant build script:
<target name="properties">
<echoproperties/>
</target>
But running ant gives my this error message:
/u/ebermann/projektoj/stackoverflow-examples/build.xml:19: Problem: failed to create task or type echoproperties
Cause: the class org.apache.tools.ant.taskdefs.optional.EchoProperties was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/u/ebermann/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
Okay, so I don't panic, but wonder what to do.
I have Ant 1.7.1 here (an OpenSUSE system), and sadly no documentation for this version, and I'm not root to install either a current ant version or the documentation for the old version (I just downloaded it and it still does not say which jar file is needed here). Of the directories listed above, only /usr/share/ant/lib exists, but it contains nothing like optional.
I would want to download the necessary jar file and put it in my home directory, but where to find it? The ant download archive contains nothing like that, and I have no idea where else to search. (I did google a bit, but did not find anything.
So, can someone give me some pointers where to find the right jar file?
(I suppose the solution is quite easy, and something is just blocking my view.)
After vahapt's answer, I downloaded the file from the apache repository, and put it into the directory /u/ebermann/.ant/lib mentioned by the error message. Running ant properties again - the same result as above.
$ jar -tf /u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar | grep 'EchoProperties.class'
org/apache/tools/ant/taskdefs/optional/EchoProperties.class
This looks like it should work - is the error message simply wrong?
If I put it directly into the CLASSPATH, it works:
$ CLASSPATH=/u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar ant properties
Buildfile: build.xml
properties:
[echoproperties] #Ant properties
[echoproperties] #Thu Mar 10 00:46:22 CET 2011
...
[echoproperties] user.name=ebermann
[echoproperties] user.timezone=
BUILD SUCCESSFUL
Total time: 0 seconds
I don't want to change my normal CLASSPATH variable, and it should work by putting it into this directory, or did I understand something wrong?
Any ideas, or is this an ant bug?
(Also, why is this file nowhere mentioned in the ant documentation?)
Edit:
After the answer from vahapt, my ant build-file looks like this:
<project name="stackoverflow-examples" basedir=".">
<target name="echoproperties.prepare">
<available property="echoproperties.works"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
/>
</target>
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${user.home}/.ant/lib">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
<target name="properties" depends="echoproperties.init">
<echoproperties/>
</target>
</project>
This re-registers the task only if it is not already in the ant classpath. (Thus it should also work for complete ant installations which do not have this file in the home directory).
I would still say that This is not a bug; it is a configuration problem is not totally right, even more as putting the file in the indicated directory does not help.
One more interesting observation: The nodeps.jar in ${user.home}/.ant/lib (i.e. now /u/ebermann/.ant/lib/ant-nodeps.jar) is already in the class path (the one shown by ${java.class.path}, but this seems not to help for <echoproperties> to work without this taskdef.
So, this works too:
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
classpath="${java.class.path}" />
</target>
When you make a google search, results point to ant-nodeps-1.7.1.jar
Make sure that jar exists and you've added it into the classpath
For the second part of your question:
SOLUTION 1. You do not need to modify your CLASSPATH variable. Instead you might add it by adding the parameter -cp [JAR FILE LOCATION] (-cp is for "java" executable)
SOLUTION 2. Jar files are simply zip files, open ant-nodeps.jar copy its content to ant.jar throw away ant-nodeps.jar
SOLUTION 3. See the sample below. taskdef is a ant feature that loads a jar or a class into ClassLoader hierarchy. (You load the class before using it, works like a charm)
<?xml version="1.0" encoding="ASCII"?>
<project name="Test" default="properties" basedir=".">
<target name="properties" depends="init">
<echoproperties/>
</target>
<target name="init">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${ant.library.dir}">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
</project>
I downloaded Ant 1.7.1 and looked in the documentation that came with it. There it described echoproperties as an optional task, but didn't mention where to get the jarfile for this optional task.
Looking inside the lib folder, I discovered the ant-nodeps.jar. Apparently, it was included with Ant 1.7.1.
I would recommend that you download and install Ant 1.8. Since Ant is a Java jar file, it's not really all that difficult to install the latest and greatest version.
I looked on my Mac, and /usr/bin/ant is a link to /usr/share/ant/bin and /usr/share/ant/ is a link to /usr/share/java/ant-1.8.2. So, all I have to do is point /usr/share/ant/bin/ to the correct version of Ant.
In Ant 1.8.2, echoproperties is now a standard task.

Relative path problem in ANT junit task

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

Resources