Eclipse: build should stop when one of the builders fails - eclipse

Let's say my project has two builders: The first one is an Ant builder (or possibly just a simple command line builder) that compiles Protocol Buffer files with protoc to generate intermediate java files. The second builder compiles java files including the generated protobuf files.
The problem is that the build process should halt when there is a build error in the first builder phase, but it doesn't. When a builder fails, it just proceeds to the next phase. Is there a way to make it stop when it fails?
Thanks in advance for your help!

There isn't an easy way to do this. Even though Eclipse builders are ordered they aren't treated as step-by-step instructions for building the project. Each builder is invoked regardless of the output of the previous one. It is up to implementation of each builder to detect problems that are so disruptive that there is no point to running the rest of the builder's logic. For instance, Java Builder aborts if it detects certain types of build path problems.
You can force the behavior that you are after by disabling all of the builders and implementing the entire build as an Ant script, but you'd be giving up a lot to achieve this behavior.

Related

Output folder of the Kotlin compiler in Eclipse

The Jetbrains Kotlin compiler in Eclipse outputs to a hidden folder inside the Eclipse compiler plugin. This hidden folder is then made available through the Eclipse Kotlin classpath container.
In bndtools we need a normal file system folder since bnd can run both from the file system as well as in Eclipse. Since the folder is a linked resource there is no known way to translate it outside Eclipse.
Anybody knows how to tell the Kotlin compiler to just output it in the bin folder?
Currently, this is not possible in the Kotlin Eclipse plugin.
To make it possible that Kotlin code can be used from Java, Kotlin plugin produce so-called lightweight class files to this folder. These class files do not contain bodies for methods and they are stored in memory.
Actual class files, that are used to run an application, are being built only before launch and they are produced to the default output folder. For now, we cannot produce class files on each save reasonably fast as there is no incremental compilation in the plugin yet:
Feel free to upvote for this issue.
From the short analysis of the code of Kotlin plugin, it looks like the proper method is KotlinCompiler.compileKotlinFiles. It is being called in two contexts:
KotlinBuilder.build — this is the one called on the project build; it makes a call stack trick (or rather a hack...) to check if being called from the LaunchConfigurationDelegate, and depending on the results, either compiles whole project (via its own private fun compileKotlinFiles), or just makes stubs in memory.
KotlinCompilerUtils.compileWholeProject — this is in fact being called from 1.; nice static method, perfect for abuse until the problem is correctly solved in the plugin. :)
So, I'd use the method from 2. wrapped in a similar way as compileKotlinFiles from file in 1.

Make eclipse detect compilation errors in gwt client code

Is it possible to configure Eclipse such that it will detect use of classes and methods not available to GWT and fail compilation early or maybe hide them from autocomplete ?
NO, there is no option in the google-eclipse-plugin yet.
In theory it could be feasible to call the gwt-compiler in draft mode after any single saving action, but this could be extremely slow.
With new features in last gwt version for super-devmode, this could be much faster because the compiler is able to perform incremental compilation. But I think it would not be faster enough.
Anyway you can try to add a task to compile your project any time you save a file:
Right click on the project -> Properties -> Builders -> New (call a script or an ant/maven task ...)
If you take a look to CodeServer and Recompiler classes you could figure out a way for coding a class with a very simple main() for recompiling your project from command line.

How to get Ant build errors inside Eclipse "Problems" view

When I set up an Ant script to run as an Ant builder in an Eclipse project, the only options I have for handling the output are to:
show it in Console view
capture it in a file
Is there any way to tell Eclipse how to parse the output and add entries to the Problems view accordingly?
I don't think you are going to find a solution, but if you do it would have to be a third-party plugin implementing a replacement Ant Builder. As you've discovered, Eclipse Ant build integration doesn't support this.
You may also want to consider opening an enhancement request at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform site. While there is no guarantee that someone will step up to implement this feature, you never can tell.

How to find Junit tests that are using a given Java method directly or indirectly

Assume there are Java project and Junit project in an Eclipse workspace. And All the unit tests are located in the Junit project and dependent on the application Java project. When making changes to a Java method, I need to find the unit tests that are using the method directly or indirectly, so that I can run the corresponding tests locally in my PC before checking into source control. I don't want to run the entire junit project since it takes time.
I could use Eclipse call hierarchy to expand caller methods one by one until I find a test method. But for a project including more than 1 million lines of source code, digging down the call hierarchy takes time too.
The search scope within call hierarchy view doesn't seem help much.
Appreciate any help.
Use a test coverage tool. See my answer:
How do I find all the unit tests that may directly or indirectly call a given method? (.net)
Why not right click on the changed method and select "References->Workspace (or Working Set if configured properly)".
This should give you a list of methods invoking the one you just changed. The search results can be organized by package or project. Select project organization and expand the JUnit project and what you are looking for will likely be the only thing there.

How to filter ressources during build in Eclipse project?

I have an application that uses several configuration files (let just consider appli.properties here).
These files contain several values that depend on the environment. We can find some information such as:
server.port=${envi.server.port}
On other side, I have a set of properties files, one per environment (dev.properties, homolo.properties, etc.).
They contain the values for some properties in configuration files. We can find here this kind of properties:
envi.server.port=4242
My build is handled by Maven2. Everything is working fine.
However, I now need to import my project into Eclipse.
My main concern is about the configuration files filtering. Indeed, if I do not modify anything in my Eclipse parameter for my project (after a mvn eclipse:eclipse command), then all my configuration file will keep the property keys (i.e. ${envi.server.port}) instead of their values. And with such configuration files, my application will not run inside Eclipse...
So I tried two solutions:
A full-Maven solution, using m2eclipse plugin. I add a Maven Builder in the project configuration, and then, each time a build is made, the filtering is done on the files.
Ant (which is only used inside Eclipse). I've hardly defined a task that simulates the Maven2 filtering of files in Ant. This task is only dedicated to the filtering, no compilation.
The common problem of these two solutions is that the filtering is made at every operation (essentially saves on Java class edition), and then take time. The second solution is however quicker (3 seconds) than the first one (more than 10 seconds).
What do you think of my approach?
How would you do that, in a better way?
If the resources are not changed that often, you can set the Maven build to only run after a Clean build, then it won't interfere so much, this doesn't do anything to speed up the build however.
As far as making the filtering quicker, I don't know of any other simple mechanism that will help, as you've said you need either Ant or Maven to run the filtering, and they both take some time to set up before building, resulting in the slow down.
If this is causing you a lot of problems, you can write a custom Incremental Eclipse builder that performs the filtering on the deltas. This should be considerably quicker, but obviously a lot more effort to write.