How Can I Get FDT & Ant To Loop Through Builds? - eclipse

I want to have FDT loop through a list (or directory) of .AS files and output corresponding .SWFs.
I want to do this via Ant, instead of using FDT's launcher chain, and found the 'fdt.launch.application' Ant task in the documentation here. Can I use it to help me?

Not directly, you can simulate loops with Ant by using the 'for' or 'foreach' Ant tasks. But you'll need to first install the tasks, which do not ship with Ant by default. See here for more info on getting those tasks.
You can then define the files and outputs to compile in a separate properties file - which perhaps you can also generate via Ant or just edit by hand. In the above link, the answer shows how to work with an external properties file.
When you do that you'll need to include the fdt <fdt.launch.application> compile task in your loop and use the variables you extract from the properties file.

Related

How to add predefines to the .cproject file after running a Build Target

I'm trying to import a C project to eclipse (CDT) that is managed by waf. There is a list of predefines generated by waf (when running ./waf configure). That list has to be imported to Project->Properties->C/C++ General/Paths and Symbols/Symbols/GNU C so that the indexer knows about them and does not print errors. That list (when using the GUI) is stored to the .cproject file. I created a Build Target that runs ./waf configure and stores the list to a file named DEFINES.txt. How do I automatically update the list of .cproject with the values of DEFINES.txt after running the Build Target?
I thought about the following solutions and their follow-up problems:
Solution: Writing a plug-in.
Problem: What is the appropriate extension point?
Solution: Writing an external program that calls ./waf configure reads DEFINES.txt and writes the list to .cproject. That program replaces the old Build Target.
Problem: How safe is this? Am I allowed to change the .cproject file by an external program without causing any problems?
Solution: Implementing the .cproject updating algorithm in wscript file.
Problem: This is not a solution for me, because the project is used by others, too, that do not use eclipse as IDE. So the modified wscript will cause errors if the other developers want to build the project.
Does anybody have better ideas or some advice?
Here is how to go about it:
Writing a plug-in: What I recommend you do is write an extension to the LanguageSettingsProvider. The FAQ has some more info, but the summary is that provider does:
This extension point is used to contribute a new Language Settings
Provider. A Language Settings Provider is used to get additions to
compiler options such as include paths (-I) or preprocessor defines
(-D) and others into the project model.
CMake has an option to generate .cproject as part of its configure state, so you could do something similar. See the CMake Wiki for inspiration, but the summary is that you don't store and .cproject/.project in source control and have CMake (or waf in your case) generate the IDE specific files.
You could also just pick up the build settings using the build output parser and ignore the DEFINES.txt altogether. That requires running the build once from within Eclipse for CDT to see all the commands, and requires the commands to be parseable in the build output.

Eclipse: script compiler as part of a project

This question is not limited to lex and yacc, but how can I add a custom script compiler as part of a project? For example, I have the following files in the project:
grammar.y
grammar.l
test.script
The binary 'script_compiler' will be generated using grammar.y and grammar.l compiled by lex, yacc and g++. And then I want to use that generated script_compiler to compile test.script to generate CompiledScript.java. This file should be compiled along with the rest of the java files in the project. This setting is possible with XCode or make, but is it also possible with Eclipse alone? If not, how about together with Maven plugin?
(I might setup the script compiler as a separate project, but it would be nice if they can be put in the same project so that changes to the grammar files can be applied immediately)
Thanks in advance for your help!
You can add a custom "Builder" from the project properties dialog. This can be an ant script (with an optional target) or any other script or executable.
There are also maven plugins for ant and other scripting languages
If you just want to run an external program in Maven this is what you want: http://mojo.codehaus.org/exec-maven-plugin/ -- you can then run Maven targets from your IDE or command line and it should do the right thing either way.
To integrate with the normal compilation bind the plugin to the "generate-sources" phase and add the location where the Java files are generated to the "sourceRoot" option of the exec plugin. That way the compiler will pick them up.
Ideally you generate the code into a folder "target/generated-sources/MY_SCRIPT_NAME". That is the standard location for generated sources in the Maven world and e.g. IntelliJ IDEA will pick up source files inside of that location. Note that this doesn't work if the files are directly in "target/generated-sources".
The other option is to write your own Maven plugin, which is actually quite easy as well. See e.g. https://github.com/peterbecker/maven-code-generator

Autorun a jar/java file 'after' eclipse builds project?

I'm playing around with ActiveJDBC and it has a post-compile step for 'instrumentation' (i.e. crudely speaking it post-process byte-code to add the parent's static members to the class as per the ActiveRecord pattern).
You constantly have to run the following command:
java -cp=$CLASSPATH -DoutputDirectory=build activejdbc.instrumentation.Main
for the post processing to take place. Is there some way to integrate this with Eclipse (Helios) so that the whenever it builds the project it triggers the above? Anyway to automate it?
I do not use Maven/Ant and do not wish to learn it just for the sake of ActiveJDBC (Maven is its only dependency, which I find is a bit annoying).
The above could be done by encapsulating it in a java file and running that file - so if there is a way to run a java file after build that'll be fine too :)
Any ideas?
If you do not want to use Ant, then you can configure a second builder in Eclipse:
Project -> Properties -> Builders -> New
Then you can configure to execute a shell script or a batch file with that command. Once you have that builder configured (took 5 minutes for me), you can build entire project pressing Ctrl+B, which will execute the standard builder as well as your script.
However, I'd suggest that you copy this Ant script: http://code.google.com/p/activejdbc/wiki/Instrumentation#Bare_bones_Ant_script
And simply configure it for your environment. E-Riz correctly stated info about the builders, but you do not need to take an hour to write an Ant script if you are going to go this route. Configuring a new builder with Ant script instead of a shell is even simpler.
I wrote about adding custom builders a few years ago: http://bewarethepenguin.blogspot.com/2008/08/customizing-builds-for-your-eclipse.html
One of the options when creating a new builder is to run any arbitrary program. I don't see why you couldn't run the ActiveJDBC java command above.
Even if that doesn't work for some reason, you could probably write an Ant script to invoke that Java class in less than an hour, including learning and testing, using Ant's "java" task: http://ant.apache.org/manual/Tasks/java.html

Netbeans project to scripted build

I'm trying to convert a Netbeans 6.9.1 project into a scripted build (without netbeans). Of course, it fails (or I wouldn't be asking for help).
In the failure it says that the org.apache.commons.httpclient package does not exist. (Of course, it worked when we ran the build in Netbeans).
Now I know exactly where the commons-httpclient.jar file is located in my project structure, but I can't seem to tell it to the compiler via the ant build files and the netbeans property files.
Perhaps related to this is when I ran "ant -v" to build my software, it said,
Property lib.mystuff.classpath has not been set. This variable is important, I guess, because
the file nbproject/project.properties uses lib.mystuff.classpath in its definition of javac.classpath, which of course tells the Java compiler where to find the JARs.
So...when moving a Netbeans project to a netbeans-independent scripted build, how can the build script set these properties? Also, how can I ensure that the jar file gets included in the ant build?
I appreciate any help I can get, as I am a Java newbie.
UPDATE AFTER ACCEPTING ANSWER FROM vkraemer:
There are a few best practices for build scripts for production software:
Put everything needed for a build under a single directory tree. (Netbeans = fail)
Put everything in source code control. (I did that)
The first line of the build script should clear all environment variables.
The next section of the build script should explicitly set all environment variables to values which are known to work.
The next part of the build should be able to execute using command-line programs such as javac, ant, cc, etc, and must not depend on firing up an IDE such as Eclipse or Netbeans.
It is a shame that Netbeans makes this hard.
I did a quick look in a Java Application project and found the following...
javac.classpath = ${libs.MyStuff.classpath}
libs.MyStuff.classpath is defined in %HOME%/.netbeans/6.9.1/build.properties.
You may be able to get by doing the following...
ant -Dlibs.MyStuff.classpath=c:\a\b\c.jar
You would need to do more if you have multiple jar files in the MyStuff library that you created in NetBeans.

How do I detect whether an Eclipse build failed?

Following on from this question, I now want to know how to stop an ANT script from executing if the preceding build failed. I can't see a way in the Build setup in Eclipse of chaining builds together based on their success.
I think I am lookikng for either a way to pass the previous build status into my ANT script so I can terminate or to never call the ANT script at all if the first build fails.
Any ideas?
No native way, AFAIK.
What you can do is modify your ant script to check if .class files produced by Eclipse are newer than WAR. If not, stop.
You should be able to store the success into a file. If you make sure the content of the file is a property file content the next ant task can use that file to fill in a property (like build.success) and can act on that.