I'm looking for information on how to perform Acceleo source generation with an Ant script. I've done some Googleing, but I haven't really found any straightforward way to do that. I'm looking first to do it in Eclipse, but a headless (is that the right word?) script would also be nice for semi-automatic builds.
Can anyone offer any help? Or are my expectations of what Acceleo can do unreasonable?
I believe all you need to do is to use a ant task to call your generation class.
The generation class is the one generated along your mtl file that contains an "#main" annotation.
Beware though, the generation will run in standalone mode, so don't use services that rely on eclipse API!
The ant task should look like this:
<java classname="your.generation.class.GenerateJava"
classpathref="your.classpath.defined.in.ant">
<arg value="your/input/model/example.uml"/>
<arg value="your/target/folder" />
</java>
Hope this will help...
Related
I'm attempting to optimize our build procedure for our applications we have here. I'd like to skip the compilation of our backend .dll file should the file timestamp not have change using Netbeans Ant scripts.
I've been using Incremental and fast build using Ant and Advanced Free-form project configuration as a reference point but it seems to require 2 build targets to create the .timestamp comparison in the first link.
Is there a way to circumvent the need for 2 targets and check the timestamp of the .dll file instead? or do I simply need to add another tag inside of my call to make the comparison, or is what I'm trying to do not feasible?
Any help would be greatly appreciated or if better methods of doing this are known I am open to listening to it.
We use Netbeans to compile our projects, and uses Ant by default. I've included a snippit of my build.xml Ant script so far.
Thanks in advance!
<target name="init-skip-dll" description="initializes the skip property for the Ada dll">
<uptodate srcfile="create-ada-dll.timestamp" targetfile="ada-dll.timestamp" property="ada-dll.skip" value="true" />
</target>
<target name="-build-dll" description="builds the Ada dll if needed" depends="init-skip-dll">
<exec executable="gprbuild.exe">
<arg value="-P"/>
<arg file="..\DLL\ifccs_dll.gpr"/>
</exec>
<touch file="create-ada-dll.timestamp"/>
</target>
I don’t use Ant, but the same problem exists with Make; the Ada dependency rules are complex, and best handled by unconditionally letting gprbuild do whatever it needs to to bring the DLL up-to-date. Gprbuild will do nothing besides checking dependencies if the DLL is actually up-to-date.
In Make, this involves a phony target: e.g. for a real target testbed,
testbed: force
gprbuild -p -P testbed
.PHONY: force
or for an already-phony target
all:
gprbuild -p -P build_runtime.gpr
.PHONY: all
By the way, note the -p, which says to create needed directories, e.g. an object directory.
I've got a jar file that will match a certain pattern, but contains a version number that will change over time (it's placed there using a dependency manager). It is the only jar file that will ever be in that directory. Is there a way I can invoke Ant's java task using the directory and (if necessary) a pattern to find the jar file rather than statically specifying the filename? I'd rather not have to update build.xml every time the version changes.
So given something like this:
/path/to/some/jarfile-3.24.8.jar
... that might later look like this:
/path/to/some/jarfile-4.3.2.jar
Can I achieve the equivalent of this?
<java jar="path/to/some/jarfile-*.jar" fork="true" spawn="true" />
Thoughts
I was thinking maybe I could rig something up using the fileset task, but I couldn't find a way to reference it from the java task (and the java task doesn't support the <include> nested tag like some other tasks do).
... after further research, pathconvert looks like it might help. I'm not familiar enough with the mechanics to see how to piece things together though.
After some trial and error, I found a solution using fileset and pathconvert - here's my simplified solution:
<fileset dir="/path/to/some" id="jarfile-path-contents" includes="jarfile-*.jar" />
<pathconvert property="file.jarfile" refid="jarfile-path-contents" />
<java jar="${file.jarfile}" fork="true" spawn="false" />
I used fileset in order to specify the pattern and location of the jar.
I used pathconvert to place the found jar file reference into a property.
Then I was able to simply reference that property in my java task.
I have several java projects on the same machine which really need to be built with different java compilers, one with java 1.6 and one with java 1.7. (No, it's not sufficient to build them with the higher version of java and specify source and target for the project that requires the lower version-- the differences between them produce test failures).
My colleagues do not have this problem -- they have only one project that requires 1.6. I would like to put in some configuration that enables me to override the java compiler without requiring them to add environment variables. I'm imagining something like this:
<javac executable='${java.executable.path}' srcdir='${src.dir}' destdir='${dest.dir.classes}' source='1.6' target='1.6' fork='true' />
where ${java.executable.path} is defined earlier in the file as:
<condition property="java.executable.path" value="${env.PROJ_JAVA_HOME}" else="${DEFAULT_JAVAC}">
<isset property="env.PROJ_JAVA_HOME" />
</condition>
except... there is no ${DEFAULT_JAVAC} that I can find. Is there a better way to do this that I'm missing? Or is ant just not built for things like this?
you could default to whatever javac is on the path.
its possible to set an ant property by executing a shell script, so you'll need to execute something like which javac
I would like to run the GWT compiler from my Ant buildfile with the compiler the following flags:
-compileReport
-XsoycDetailed
-extra
-XfragmentCount <x> (where <x> is an integer that I'll determine over time)
I looked into ant-gwt, which seemed pretty stable, however after a thorough inspection of the documentation and code, it doesn't seem like that plugin can handle these GWT compiler options.
Checking out the GWT command-line tools, I see a code snippet for an Ant task that runs a GWT class called com.google.gwt.dev.Compiler from inside a buildfile:
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg value="com.example.foo.Foo"/>
</java>
Is this the correct way to run the GWT compiler from Ant (that ant-gwt probably wraps)? I think the word dev in the package name is throwing me off: is this some smart compiler stub or is it actually the GWT compiler?
If not, then what is the proper way to run GWT from inside of Ant? The only other thing I can think of would be to kick off a Python script from inside the Ant task, and have the Python script call the GWT compiler, but even then, not sure what command-line tool to call from that Python script (maybe webAppCreator?). Thanks in advance.
After downloading GWT from http://code.google.com/p/google-web-toolkit/downloads/list, extract the content from zip folder. Please refer the build scripts "build.xml" provided by GWT team in "sample" folder projects like "Hello" .
or
Example Hello World Ant build.xml
Modify 4th line to add your compiler options - <property name="gwt.args" value="-draftCompile -ea -style pretty -logLevel TRACE -workDir work" />
com.google.gwt.dev.Compiler is the GWT compiler; dev is for developer tools: compiler, DevMode, etc.
BTW, the documentation for the compiler is here.
As an experiment we want to build our products using the Eclipse java compiler (ecj-3.5.jar downloaded from eclipse.org) on the runtime version of Java 6 instead of the JDK, and as I understand it, it is a matter of adding this jar to the ant classpath, and setting the build.compiler property to point to the adapter.
By including
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
in my build.xml and invoking ant with a JRE, I get the expected error that the adapter cannot be found, and by adding ecj-3.5.jar to the classpath in the Eclipse panel I can compile my code as expected. I believe the same functionality to be available with "-lib foo.jar" from the command line with modern ants.
Now, I want to specify from within build.xml that I want ecj-3.5.jar on my classpath satisfying the same as above. We can already do this with ant tasks, so I believe it is possible.
So the question is: How can I add to the classpath used by javac to locate the compiler only from within build.xml?
It appears that the upcoming ant4eclipse 1.0 includes the Eclipse compiler (which is what I wanted to use this for), so by upgrading to that (from 0.5) should solve the problem we have.
2010-09-24: Ant4Eclipse is still at M4 without indication of when the release will happen.
2011-12-01: We have now migrated from ant to maven. The build.xml scripts hit the complexity wall and a fresh approach was needed. Anyone needing to choose what to do - do not go the ant4eclipse path except for trivial projects.
2012-11-30: A year later, the maven experience is still mostly good. There is a lot of quirks and changes in mindset but most make sense in the context. Maven can specify the compiler level on individual projects easily. We are looking into using ecj instead of javac (for several reasons) but for most purposes javac works nicely.
One way is to specify a reference to a componentdef when using javac.
<componentdef name="ecj"
classname="org.eclipse.jdt.core.JDTCompilerAdapter"
classpath="ecj-3.7.1.jar" />
<javac ....>
<ecj/>
</javac>
Another option is to set build.compiler as you have or the compiler attribute for javac and then specify a compilerclasspath for javac. This is a normal path like structure to hold the classpath for loading your compiler adapter.
<javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter" ....>
<compilerclasspath>
...
</compilerclasspath>
</javac>
See the javac task documentation in the Ant manual for more details. Note that both these both solutions only work from Ant 1.8 onwards.
Reading Running Ant via Java. I think you can write a simple wrapper that will properly set a classpath and add your jar file to the resulting class path.
Here I'm just cutting and pasting the sample from the above link with addition of the library that you are interested in to the classpath:
<java
classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="${sub.builddir}"
timeout="4000000"
taskname="startAnt"
>
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
<pathelement location="/path/to/ecj-3.5.jar"/>
</classpath>
<arg value="-buildfile"/>
<arg file="${sub.buildfile}"/>
<arg value="-Dthis=this"/>
<arg value="-Dthat=that"/>
<arg value="-Dbasedir=${sub.builddir}"/>
<arg value="-Dthe.other=the.other"/>
<arg value="${sub.target}"/>
</java>
I think you can even reuse the same build file, just give a different target as an entry point.