views:

298

answers:

4

I'm a lone Emacs user in a group that's hung up on Eclipse. Time and again, code diffs are made larger by imports that have been "organized" or "cleaned up" by Eclipse.

I don't have a strong opinion on the subject of import style in Java, but I do want to minimize our diffs. What can I do?

We use Maven2 for builds; is there a plugin that can help me? Can a piece of Eclipse be abstracted out & turned into a Maven plugin? I currently use ImportScrubber and have encountered a few other stand-alone pieces that do the same thing. What I'm really looking for is a Maven plugin that can integrate with the build.

Barring the above, I'll put an ImportScrubber invocation into my .git/hooks/post-commit.

+1  A: 

I think all of you (Eclipse, Emacs or whatever users) should use something like Jalopy which supports both Eclipse and Maven. This way you it becomes irrelevant where the code was modified as long as it has been run trough pretty-printer as part of checking code in. Said that - I'm not sure if Jalopy supports organizing imports beyond sorting these up

DroidIn.net
A: 

Does your shop have code standards for how imports should be organized? If so then you are out of luck. Minimizing diffs is a small sacrifice to make towards incremental code improvement.

Kelly French
We have no standards other than "make sure it works". :) Seriously though, we can't even get past the "Windows/Unix line endings" inconvenience. Those of us who are privy to `diff -b` don't care.
Max A.
+1  A: 

The Hybridlabs beautifier which is used internally in the openArchitectureWare project (an open source generator framework) is doing what you're looking for. As explained in this blog entry, the beautifier is available as a Google Code project and its documentation describes a maven 2 plugin:

<plugin>
    <groupId>org.hybridlabs</groupId>
    <artifactId>maven-beautifier-plugin</artifactId>
    <executions>
         <execution>
             <goals>
                 <goal>beautify-imports</goal>
             </goals>
         </execution>
     </executions>
    <configuration>
         <!-- Recursively scan for *.java and beautifies imports -->
         <inputDirectory>${pom.basedir}/..</inputDirectory>
         <!--outputDirectory>${pom.basedir}/..</outputDirectory>
         <runBeautifier>true/runBeautifier>
         <runJalopy>false</runJalopy-->
    </configuration>
</plugin>

There is indeed a mojo in the source tree but it doesn't match the groupId mentioned above (this is a bit confusing) and I've not been able to find the plugin in maven's public repository.

Maybe you'll be more lucky with the version available in AndroMDA plugin repository as documented in this thread (the plugin is indeed present in http://team.andromda.org/maven2/).

The plugin is under org.apache.maven.plugins.maven-beautifier-plugin. It can be run with the short form: mvn beautifier:beautify-imports. It can also be run as part of a project pom by adding the plugin declaration under <build><plugins>:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-beautifier-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>beautify-imports</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <inputDirectory>${pom.basedir}/target/src</inputDirectory>
    </configuration>
</plugin>

Or contact the project's author (e.g. through twitter or by mail).

Pascal Thivent
A: 

I have also found an ImportScrubber plugin. Can't as of yet attest to its quality.

Max A.