Deleting certain classes on running an external tool in eclipse? - eclipse

I've set an external tool (sablecc) in eclipse (3.4) that generates a bunch of classes in the current project. I need to run this tool and regenerate these classes fairly frequently. This means that every time I want to run sablecc, I have to manually delete the packages/classes that sablecc creates in order to ensure that I don't have conflicts between the old and new generated classes. Is there some easy way to automate this from within eclipse or otherwise?

Not sure if I understand your point right, I suppose you need to delete old classes before running sablecc because some of them would not be eventually created in new run.
It is probably best to write short Ant build.xml with the target, which first removes the classes (Ant delete task) and then runs sablecc (Ant exec task). It is also possible to preset eclipse so that it refreshes workspace after Ant finishes.
Put the build.xml anywhere to project, right click, Run As/Ant Build.
Just for the sake of the clean style, you could then call sablecc with its Ant task (implemented by org.sablecc.ant.taskdef), instead of running it externally in new process.

You can tell Eclipse to refresh the workspace (or parts of it) after an external tool has been run. This should force Eclipse to detect any new/deleted classes.

JesperE is referring to the option Refresh->Refresh resources on completion in your external tools configuration for running sablecc.

Related

How can I prevent endless builds using eclipse?

There are conditions where Eclipse builds Codename One projects endlessly.
This is always the case when "Refresh using native hooks or polling" is activated for the workspace.
I am wondering why this is happening. Eclipses automatic build tracks changes in source folders and automaticalls builds when changes occur.
Any idea what causes those endless builds with Codename One projects?
Adding a resource filter in the dist-folders properties is to no avail.
Our build process generates files since it uses Ant, it replaces existing project files (especially if you use the new GUI builder) so this is probably throwing Eclipse for a spin which re-runs the build which regenerates the files resulting in endless loop.
I'd love to improve building on Eclipse but I'm not really sure how we can do that in a way that still works well with the whole build process.

Scripted builds of C++ Eclipse Managed Makefiles

I have a collection of C++ projects that use managed makefiles inside Eclipse. I build them all, and run an existing deploy script to place all the compiled results into a target directory on the system.
I'd like a way to automate the build process without having to open the IDE, but due to external constraints from the project owner, I have to use managed make.
Once I kickoff a build for the first time inside the Eclipse IDE, the Debug / Release directories are created, and the makefiles are autogenerated. Once they are all present, I can call make from the command line, across all the projects, run an overall deploy script, etc. This will work up until the point that code changes would cause the makefiles to differ (adding/removing source files, or changing build parameters) The big problem with this is that it requires me to open eclipse and manually cause the generation of the makefiles.
I see two options:
Check the generated makefiles into revsion control (even though they're generated, I know), and commit them whenever they, after generation, have differed from the previous content.
Find a way to either open eclipse in a scriptable way, and cause makefile generation, or to find some alternate way to generate the makefiles from the .project files.
Option 1 is obviously subject to problems if I or other developers don't remember to commit the files, or if we update the Debug makefile but not the Release makefile, etc. It also makes me feel dirty to commit a generated file.
Option 2 seems much better, if its feasible.
Does a method to do option 2 exist? Are there other options I haven't considered?
I recognize similarity with a continouous integration server, but This is not the same use case. Essentially I'm building a package that gets installed on a development system as a testing release of a system library. So I'm operating as a developer, I just want to reduce variance out of the deploy process itself.

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

Stop Eclipse deleting resource files when it builds

I have some data resources that I would like eclipse to not copy every time it builds. I put them as part of the build path so they get copied, but I don't want that to happen every time as it's time consuming.
Any idea on a better strategy?
I don't even want them to be deleted when clean is invoked. In Visual Studio one can mark a resource file as "copy once" is there such a thing in Eclipse.
Thank You
Having eclipse not copy some file that you have modified even after a clean will be a nightmare: you'll have to remember to copy it manually each time it's modified.
And Eclipse only copies files which have been modified when building incrementally.
If it's so slow, it probably means you have too many such files, and they should perhaps be put in a jar in the build path.
As you ask for a strategy, then ...
Eclipse is not a build tool, it's IDE. So you better not try to setup some build logic based on it. Use eclipse for coding and for performing specific tasks during build use build tools like maven or ant.

Writing an Eclipse-aware Ant task

I would like to write a simple Ant task that would interact with an Eclipse workspace to get some information from it. I would like to be able to use the various Eclipse API's (for example, IWorkspace).
My question is what would be the simplest way to go about doing this.
I have excellent knowledge of the Eclipse platform as a user of it - but none with development for Eclipse. I understand that, in runtime, my Ant task will have to be invoked under the same JRE as the workspace - that's a restriction I'm willing to be bound to.
I started by creating a Java project to hold my Ant task. I believe that the only thing in my way now is how to define the JAR dependency on Eclipse's JARs. I obviously don't want to depend on one specific Eclipse JAR as these are versioned (for example, Eclipse's "Resources" plugin). Is it possible to have my Java project buildtime-depend on "whatever the current JAR is for the Resources plugin"?
I think this article quite much addresses your problem: http://www.ibm.com/developerworks/rational/library/09/eclipsecustomanttasks/
It is targeted to the IBM Rational Application Developer, but that one is based on Eclipse and AFAIS there is not overly much non-eclipse-specific happening here, at least not regarding the specifics about how to make the task available in Eclipse (writing the plugin definition etc).
So, you want an Ant task that runs within Eclipse. And as you say, it's clear that those tasks are using the Eclipse API. As of this moment, I don't really understand how they're doing it. I've looked at the source of a couple of them and I still have questions.
To find the locations of all the Ant tasks contributed by Eclipse, do a Plug-in Search for org.eclipse.ant.core.antTasks. When I do that, I see twenty or so extensions, many of which define multiple tasks.
If you get the source bundle for a plugin that contributes one of these tasks, you can look at the source for it. RefreshLocalTask is in org.eclipse.core.resources; unfortunately, when I import this bundle into my workspace as a source project, the source for the Ant tasks doesn't get linked correctly. There is a separate jar (inside the bundle) for them, and, while the source is in the bundle, it's not clear how the jar is compiled. The upshot is that I don't have the Ant task source compiling in my workspace.
You can also Google for the Ant task source; here's the 3.6.0 source for RefreshLocalTask.
Anyway, in the source you can see calls to org.eclipse.core.resources.ResourcePlugin that are illustrative of what you probably need.
Ah, I see in the extension point description - right-click on one of those search results and choose "Show Description", or go there from the Manifest editor - that there is a flag you can set, "eclipseRuntime"; the text implies that if it is set, Eclipse will launch the task in the same VM.
You should probably say more about what you want to do, because there are several routes you can take.
Eclipse provides some Ant tasks that you can use in your build scripts. Here are a few. There are more, so search for "ant tasks" in the Eclipse docs; they're scattered throughout different pages. Eclipse Preferences (Window..Preferences, then select Ant/Runtime, and look at the "Contributed Entries" in the Classpath tab) shows you a list of Ant tasks that Eclipse contributes to the runtime whenever Ant is invoked from Eclipse; you can invoke any of these tasks yourself as long as you include the right jar.
It's possible to start up Eclipse from within an Ant task, because it's possible to start Eclipse from Java. You need to include the right jars and make the right calls; you also need to configure Eclipse correctly. "org.eclipse.core.runtime.adaptor.EclipseStarter" should give you some detail.
Perhaps you can use one or more of the variables Eclipse defines for use when launching Ant (or any other program). Try creating an External Tool Configuration (at the bottom of the Run menu) - select an Ant Build and try customizing it with arguments (from the Main tab) or environment variables (from the Environment) tab. Both give you access to Eclipse variables. But of course these are just values you can pass into your Ant script, not handles to anything you can invoke a method on.
What you can't do: I'm pretty sure that when Eclipse launches Ant, it is always in a separate VM, with no way to call back into Eclipse.
So perhaps you should say more about what you want to do.