I am using ANT to precompile handblebars in build time. I follow the way here http://blog.selvakn.in/2012/05/precompiling-handlerbars-tempates-with.html. And for only one target, it works very well. But then I try to invoke the target twice like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project basedir="." default="echoIt" name="precompile">
<property name="charset" value="utf-8"/>
<target name="echoIt">
</target>
<target name="precompile-templates0" depends="echoIt">
<property name="outputJS" value="../../jsp/jsp_1/js/templates0.js"/>
<property name="templatesPath" value="../../jsp/jsp_1/js/tmpl"/>
<java dir="${basedir}" failonerror="true" fork="true" jar="../../lib/js.jar">
<arg value="../../otherFiles/lib/rhino-handlebars-compiler.js"/>
<arg value="--handlebars"/>
<arg value="../../otherFiles/third-party/handlebars-v1.3.0.js"/>
<arg value="--templates"/>
<arg value="${templatesPath}"/>
<arg value="--output"/>
<arg value="${outputJS}"/>
</java>
<echo>Template Precompiled to web/js/compiled-templates.js</echo>
<echo> is now ready to compress....</echo>
</target>
<target name="precompile-templates1" depends="echoIt">
<property name="outputJS" value="../../jsp/jsp_2/js/templates1.js"/>
<property name="templatesPath" value="../../jsp/jsp_2/js/tmpl"/>
<echo> is now precompiling the second one </echo>
<java dir="${basedir}" failonerror="true" fork="true" jar="../../lib/js.jar">
<arg value="../../otherFiles/lib/rhino-handlebars-compiler.js"/>
<arg value="--handlebars"/>
<arg value="../../otherFiles/third-party/handlebars-v1.3.0.js"/>
<arg value="--templates"/>
<arg value="${templatesPath}"/>
<arg value="--output"/>
<arg value="${outputJS}"/>
</java>
<echo>Template Precompiled to web/js/compiled-templates.js</echo>
<echo> is now ready to compress....</echo>
</target></project>
The output on the console is like this:
Buildfile: F:\AffirmedNetworks\ServerAutomation\cache\subBuildTarget\precompileTarget.xml
echoIt:
precompile-templates0:
[echo] Template Precompiled to web/js/compiled-templates.js
[echo] is now ready to compress....
echoIt:
precompile-templates1:
[echo] is now precompiling the second one
[echo] Template Precompiled to web/js/compiled-templates.js
[echo] is now ready to compress....
BUILD SUCCESSFUL
Total time: 2 seconds
As you can see, the build is successful. However when I check the outputs in the expected directory, only a ‘templates0.js’ is generated in the path:jsp/jsp_1/js/. There is nothing in the path: jsp/jsp_2/js/. However, it should have on named 'templates1.js' in this folder. This is really weird. No errors occurred and the first on is generated successfully, but the second one disappeared. Can someone give me some help on this? Thanks!
the issue is in your re-use of the <property> task!
Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variables. i.e. once you assign a value to an identifier using <property>, it cannot be changed. See HERE
although, you set the values to outputJS and templatesPath within both targets separately, maybe assuming/expecting local scope, that is not the case in ant.
reason: In general properties are of global scope, i.e. once they have been defined they are available for any task or target invoked subsequently
exception: it is not possible to set a property in a child build process created via the ant, antcall or subant tasks and make it available to the calling build process
therefore, the values for outputJS and templatesPath, as defined in the target precompile-templates0, are retained throughout the build.
to solve your issue, you may do either of the following:
change property names, for eg to outputJS1 and templatesPath1 in the target precompile-templates1
(if you're using Ant 1.8.0 or above) use the <local> task instead of the <property> task for declaring outputJS and templatesPath. See HERE for this.
use the <var> task of ant-contrib. See ant-contrib and var task.
Related
i have a taskdef pointing to a class
<taskdef name="configjar" classname="com.bea.alsb.tools.configjar.ant.ConfigJarTask" classpathref="configjar.path">
</taskdef>
Inside this i want to pass java system property. Like how we do in the java task
<java >
<sysproperty key="" value""/>
</java>
The problem is the jar is some library which I can't modify .I can't use a command to set in a build environment we have.
I know i can do this by setting ANT_OPTS,but can i do this from build.xml.How can i make this happen
Not sure it's exact way or not. But found a work around for this
<java classname="org.apache.tools.ant.launch.Launcher" fork="true" failonerror="true">
<sysproperty key="weblogic.home" value="${weblogic.home}"/>
<sysproperty key="osb.home" value="${osb.home}"/>
<arg value="test"/>
</java>
<target name="test">
<configjar debug="${task.debug}"
failonerror="${task.failonerror}"
errorProperty="${task.errorproperty}"
settingsFile="${settingsFile}" >
</configjar>
</target>
I have invoked ant using java command and set the two system properties as shown above.
On running the following command:
ant targetname -Dk1=v1 -Dk2=v2
I want the command line parameters passed down to java, like java whatever -Dk1=v1 -Dk2=v2.
I need to access these parameters from Java code with System.getProperty or System.getenv.
What do I need to write in my ant build script to make this happen?
Or should I take some other approach altogether?
I'm not sure exactly how you want to pass these values, but there are several mechanisms:
Use <sysproperty> to pass system properties you need to set:
Use <arg> to pass command line arguments to your Java class
Use <jvmarg> to pass arguments to your Java command itself
If you fork your Java task, you can also set environment variables too. These are ignored if you don't fork the Java task
This:
$ foo=bar; java -Xlingc com.example.foo.bar -Dsys1=fu -Dsys2=barfu -arg1 -arg2 bar
Becomes:
<java classname="com.example.foo.bar"
fork="true">
<env key="foo" value="bar"/>
<sysproperty key="sys1" value="fu"/>
<sysproperty key="sys2" value="barfu"/>
<jvmarg value="-Xlingc"/>
<arg value="-arg1"/>
<arg value="-arg2"/>
<arg value="bar"/>
</java>
Hope that example helps
Not good in Ant Script but I do something like below :
<target name="execute">
<echo> Running MyClass ......... </echo>
<java classname="pkg.MyClass" classpathref="libs">
<arg value="val1" /> <!-- command line args -->
<arg value="val2" />
<arg value="val3" />
<env key="k1" value="v1" /> <!-- set environmental value -->
</java>
</target>
If you are using Eclipse, you will get suggestions in popup under java tag. I got few more like : <sysproperty/>, <syspropertyset></syspropertyset>, <jvmarg/>
Use the nested <arg> elements in your <java> task:
<java classname="test.Main">
<arg value="${k1}"/>
<arg value="${k2}"/>
<classpath>
<pathelement location="dist/test.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
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.
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=
I have a compiler (and language) I am building that is normally invoked thus:
java -jar nc.jar \
-p some/referenced/package.nc \
-p framework.nc \
source1.ns source2.ns sourceN.ns \
-o output/package.nc
I'd like to include a task in my ANT build file that invokes the compiler to compile the standard library and all test cases, but specifying each separate compiler invocation as a <java> task is painful:
<target name="framework" depends="compiler" description="Build the n framework">
<!-- More compile steps -->
<java jar="nc.jar" fork="true">
<arg value="-p"/>
<arg path="../nframework/build/n.core.nc"/>
<arg path="../nframework/n/debug/DebugPrint.ns"/>
<arg path="../nframework/n/debug/Trace.ns"/>
<arg value="-o"/>
<arg path="../nframework/build/n.debug.nc"/>
</java>
<!-- More compile steps -->
</target>
I would like to create an ANT task of some sort that can simplify this into something like:
<target name="framework" depends="compiler" description="Build the n framework">
<!-- More compile steps -->
<nc output="../nframework/build/n.debug.nc">
<link-package path="../nframework/build/n.core.nc"/>
<src>
<fileset dir="../nframework/n/debug" includes="**/*.ns"/>
</src>
</nc>
<!-- More compile steps -->
</target>
To this end, I tried macrodef:
<macrodef name="nc">
<attribute name="output"/>
<element name="link-package"/>
<element name="src"/>
<sequential>
<java jar="nc.jar" fork="true">
<arg value="-p"/>
<!-- This doesn't do what I want -->
<link-package/>
<!-- Neither does this -->
<src/>
<arg value="-o"/>
<arg path="#{output}"/>
</java>
</sequential>
</macrodef>
I've tried several variations on the above, but each errors out with something like:
/home/jwarner/code/nlang/nc/build.xml:55: java doesn't support nested "fileset" element.
Is there a way to do this without extending ANT itself? Alternatively, would it be fairly easy to add an ant task to my compiler? I'm not terribly picky about the syntax of the final <nc> task.
I have had a similar problem in the past where the out-of-the-box Ant tasks didn't quite do what I wanted them to do. I found that it was very easy to write my own Ant task.
The documentation is concise but does a good job of explaining what you need to do.
http://ant.apache.org/manual/develop.html#writingowntask