Schlagwörter: Plugin Kommentarverlauf ein-/ausschalten | Tastaturkürzel

  • Andreas Höhmann 13:41 am Monday, 24. August 2009 Permalink |
    Tags: code template, , extension point, , m2eclipse, , , Plugin, pom, version   

    Use Maven Artifact Version in Eclipse Code Templates 

    Based on waffel’s blog i wrote a eclipse plugin which provides the current artifact-version of a maven-project to the eclipse editor-templates. Waffel want to add the current plugin id/version to the @since field for class comments, i want to add the current version of my maven-eclipse-project. Let me explain my solution.

    It’s easy to add a new template-variable to eclipse, you can read this. Based on  org.eclipse.jface.text.templates.TemplateVariableResolver we can write a MavenVersionResolver:

     * Resolver to resolve variable <code>pomVersion</code>.
     * @author hoehmann
     * @since 1.0.0
    public class MavenVersionResolver extends TemplateVariableResolver {
      public MavenVersionResolver() {
      private String getMavenVersion(final IProject project) {
        if (project == null) {
          throw new IllegalArgumentException("Missing project"); //$NON-NLS-1$
        String result = ""; //$NON-NLS-1$
        try {
          if (project.hasNature(IMavenConstants.NATURE_ID)) {
            final MavenProjectManager projectManager = MavenPlugin.getDefault()
            final IMavenProjectFacade projectFacade = projectManager.create(
                project, new NullProgressMonitor());
            if (projectFacade != null) {
              final ArtifactKey mavenProject = projectFacade.getArtifactKey();
              if (mavenProject != null) {
                result = mavenProject.getVersion();
                // remove snapshot-indicator
                final int index = result.lastIndexOf("-SNAPSHOT"); //$NON-NLS-1$
                if (index != -1) {
                  result = result.substring(0, index);
        } catch (final CoreException ex) {
        return result;
       * {@inheritDoc}
      protected String resolve(final TemplateContext context) {
        // TODO better way to get the project?!
        return getMavenVersion(((CodeTemplateContext) context).getJavaProject()

    With the MavenProjectManager from m2eclipse we can create a IMavenProjectFacade, this facade returns the ArtifactKey and this key have the version. If the version is a snapshot-version we can cut this trailing string off and the result is the (next) version for our maven-project (for me it doesn’t make sense to add the snapshot-version into a @since comment because the release-version should be documented in the sourcecode).

    Maybe the check for the „m2eclipse“-nature is not necessary:

    if (project.hasNature(IMavenConstants.NATURE_ID)) {....}

    I tried without the nature-check and it works. The project must contain a „pom.xml“ to get a IMavenProjectFacade.

    This was the first part of the solution. The placeholder „pom_version“ will be available for all editor-templates in the „java-context“:


    Waffel described already a solution (a workaround) to use a editor-template-resolver in the code-templates. He registered a IStartup class which copies his own BundleIdResolver/BundleVersionResolver into the (internal) code-template-context-registry of the Eclipse-Java-Plugin. For waffel this was fine because he doesn’t register his resolvers as editor-template-resolvers. I want use my MavenVersionResolver in all java-templates and in the code-templates.

    And i don’t want create a new instance of the resolver, i want reuse the extension-point-configured resolver. So i have only one place to define my resolver (type = ‚pom_version‘, localized name, localized description, class etc.).

    I found a other way to register the resolver

    1. i search my MavenVersionResolver in the registered editor-templates (java-context)
    2. if i found one, i add this reference to the (internal) code-template-registry

     * Currently it's not possible to provide more variables for
     * <tt>java-code-templates</tt>, we can only add more <tt>editor-templates</tt>
     * via extension-point.
     * <p>
     * This {@link IStartup} is a workaround to register our
     * {@link MavenVersionResolver} for <tt>java-code-templates</tt> too.
     * </p>
     * @author hoehmann
     * @since 1.0.0
    public class RegisterResolvers implements IStartup {
      private static final String JAVA_PLUGIN_ID = "org.eclipse.jdt.ui"; //$NON-NLS-1$
       * Add our resolver to each registered code-template-context.
       * @param javaPlugin
       *          must not be <code>null</code>
       * @param mavenVersionResolver
       *          must not be <code>null</code>
      private void addMavenVersionResolver(final JavaPlugin javaPlugin,
          final MavenVersionResolver mavenVersionResolver) {
        final ContextTypeRegistry codeTemplateContextRegistry = javaPlugin
        final Iterator ctIter = codeTemplateContextRegistry.contextTypes();
        while (ctIter.hasNext()) {
          final TemplateContextType contextType = (TemplateContextType) ctIter
       * {@inheritDoc}
      public void earlyStartup() {
        // check if plug-in org.eclipse.jdt.ui is final already active
        final Bundle bundle = Platform.getBundle(JAVA_PLUGIN_ID);
        if (bundle != null && bundle.getState() == Bundle.ACTIVE) {
        } else {
          // register listener to final get informed, when plug-in final becomes
          // active
          final BundleContext bundleContext = Activator.getDefault().getBundle()
          bundleContext.addBundleListener(new BundleListener() {
            public void bundleChanged(final BundleEvent pEvent) {
              final Bundle eventBundle = pEvent.getBundle();
              if (!eventBundle.getSymbolicName().equals(JAVA_PLUGIN_ID)) {
                // ignore other plugins
              if (eventBundle.getState() == Bundle.ACTIVE) {
       * Try to find our {@link MavenVersionResolver} in the java-plugin
       * template-context-registry.
       * @param javaPlugin
       *          must not be <code>null</code>
       * @return
      private MavenVersionResolver getMavenVersionResolver(
          final JavaPlugin javaPlugin) {
        final ContextTypeRegistry contextRegistry = javaPlugin
        final TemplateContextType javaContextType = contextRegistry
        final Iterator<TemplateVariableResolver> resolvers = javaContextType
        MavenVersionResolver mavenVersionResolver = null;
        while (resolvers.hasNext()) {
          final TemplateVariableResolver resolver =;
          if (resolver instanceof MavenVersionResolver) {
            mavenVersionResolver = (MavenVersionResolver) resolver;
        return mavenVersionResolver;
       * First find the maven-version-resolver from the registered resolvers.
      private void registerResolvers() {
        final JavaPlugin javaPlugin = JavaPlugin.getDefault();
        if (javaPlugin == null) {
          throw new IllegalStateException(String.format(
              "Expected plugin '%s' is not available", JAVA_PLUGIN_ID));
        final MavenVersionResolver mavenVersionResolver = getMavenVersionResolver(javaPlugin);
        if (mavenVersionResolver != null) {
          addMavenVersionResolver(javaPlugin, mavenVersionResolver);

    Now its possible to use „pom_version“ in code-templates too:


    Now the final test  …  create a „normal“ java-project, create a new class. The javadoc will not contain a version (the project doesn’t have a maven-nature):


    If the project is a „real“ maven project the version will be available:


    If anyone need the plugin … leave a comment.

  • Andreas Höhmann 18:50 am Wednesday, 22. July 2009 Permalink |
    Tags: EclEmma, , FindBugs, JBoss Tools, , MoreUnit, Plugin, PropEdit, Spring-IDE, , WTP   

    My Eclipse Plugin List 

    Today i updated my Eclipse 3.5 M7 to the final 3.5. Here are my plugin list:


    • PropEdit – nice Propertyeditor which can handle UTF-8 correctly
    • Spring-IDE – Beansearch, Contexteditor with content assistant
    • FindBugs – Check your code for bugs
    • WTP – of course for a web developer 😉
    • Subversive – for SVN integration
    • JBoss Tools – nice XHTML (facelets) editor, web.xml editor, faces-config editor and more
    • m2Eclipse – cool maven integration
    • EclEmma – code coverage
    • TeamCity – continues integration platform
    • MoreUnit – jump from Code to Unittest, create new Test if not exists
    • TestNG – integration for these unittests

    What are your prefered plugins?

  • Andreas Höhmann 11:24 am Friday, 10. July 2009 Permalink |
    Tags: buildnumber-plugin, deploy, , Plugin, tomcat,   

    Deploy maven war-project to tomcat 

    With maven it’s possible to deploy the current version of your webapplication (<packaging>war</packaging>) with one command!

    mvn clean package tomcat:deploy-only

    All we have to to is to define the tomcat-maven-plugin:


    You have to define username/password in your settings.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="" xmlns:xsi=""

    Check the tomcat-user.xml:

    <?xml version='1.0' encoding='utf-8'?>
     <role rolename="manager"/>
     <role rolename="admin"/>
     <user username="admin" password="123geheim" roles="admin,manager"/>

    If you  run the maven command you will see:

    [INFO] [tomcat:deploy-only {execution: default-cli}]
    [INFO] Deploying war to http://server:8080/foobar-1.0.0-SNAPSHOT-B20090710  
    [INFO] OK - Deployed application at context path /foobar-1.0.0-SNAPSHOT-B20090710
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------

    To get the version and a buildnumber in the context-path you must define the finalName and you must use a „buildnumber-plugin“, e.g.  buildnumber-maven-plugin or maven-timestamp-plugin:

  • Andreas Höhmann 11:13 am Monday, 8. June 2009 Permalink |
    Tags: , , Plugin, Repository   

    Nexus Pro verwaltet Eclipse-Repositories 

    Mit Hilfe von Nexus-Pro (Version 1.3.2) ist es möglich Eclipse-Plugin-Repositories zu verwalten.

    Damit wird es möglich für ein Entwicklungsteam eine Liste von Plugin-Repositories zentral zu verwalten. Alle Entwickler stellen in ihrem Eclipse Update Manager nur noch dieses eine Repository (Nexus) ein und fertig 🙂


    • externer Netzwerktraffic wird reduziert
    • Thema Sicherheit, Entwickler müssen nicht unbedingt ins Internet (Proxy etc.)
    • man sieht zentral welche Plugins, in welchen Versionen verwendet werden

    Kurzes Video hier:

  • Andreas Höhmann 22:33 am Sunday, 16. November 2008 Permalink |
    Tags: debug, , , Plugin, sourcecode   

    Hacking maven-eclipse-plugin with eclipse-ide 

    This article show you how you can fix bugs for maven-plugins (eclipse setup for hacking the code, debugging etc.) with a concrete project: maven-eclipse-plugin. Lets start …

    At the moment one of my private todos is to fix a classpath-bug for mavens eclipse-plugin.

    First of all: this maven-plugin is great! If you have a maven-project and you want edit the source inside the eclipse-ide all you have to do is „mvn eclipse:eclipse“ in the base-dir of the project. The plugin will generate all eclipse-files for you, e.g. „.project“, „.classpath“, the „.settings“-directory etc. And there is much more … e.g. pde-development with maven. Have a look at the plugin-homepage.

    Ok. What’s the problem? I have a pom with more than one resources:


    The resources directory contains a lot of resources. For all property-files i want activate filtering, meens maven should replace placeholders in the files before the result is copied into the target-directory.

    If i now start „mvn eclipse:eclipse“ the plugin doesnt handle the different directories/includes/excludes correct. The result is a .classpath like this (i removed uninteresting entries).

     <classpathentry kind="src"

    Wrong buildpath

    The second resource (with disabled filtering and the exlude for *.properties) was not included in the classpath. If the resource-directory contains other „important“ files (e.g. spring-xmls for test or images or whatever) then the eclipse-environment is not complete.

    The problem is now clear 🙂 So lets fix the .classpath-generation-code. The plugin-code is available, maven can be started in debug-mode with „mvnDebug eclipse:eclipse“ but then my first debug-session was not sucessful. I’m searching for the correct place to fix the code but where should i place a breakpoint? Mhhh … no sources for the maven-code … first of all i need a complete debugable maven-environment. To make a long story short … i got it 😀 Here is the todo-list:

    1. Use Eclipse and checkout maven-eclipse-plugin (Its a good idea to use the trunk –
    2. Now install the plugin with „mvn install“. This will install the newest version in the local repository.
    3. Then use „mvn eclipse:eclipse“ to generate all eclipse-files for the maven-eclipse-plugin.
    4. Refresh the maven-eclipse-plugin project in the eclipse-ide. Now you are ready to debug a „mvn eclipse:eclipse“ session. But hold a second! Most of the maven code will not be available in the ide, the debugging is not fun. To handle this you must checkout the maven-code.
    5. Use Eclipse and checkout the maven-sources ( There are many branches and tags available. Look into the pom.xml of the maven-eclipse-plugin to find out the right version. The plugin-api dependency is perfect for this:


      So we have to checkout the 2.0.8 branch (

    6. Now build maven with „mvn install“ and prepare the usage in eclipse with „mvn eclipse:eclipse“.
    7. Create a working-set „maven 2.0.8“ and import all subprojects from the maven-project. With eclipse this is very ease. Use the „Existing Projects into Workspace“ import. Select the base-directory of the maven-project and import all subprojects in the workspace. Important: you must delete the „.project“ file in the maven-project-directory to run the bulk-import successfully!
    8. Now your workspace should look like this:
      Ready to hack maven-eclipse-plugin
    9. Now the last step – call „mvn eclipse:eclipse“ for the maven-eclipse-pluigin project (second time). Then you will have a eclipse-project with project-dependencies to the maven-projects (e.g. maven-plugin-api).

    The „eclipse-test“ project contains the above pom.xml with the two resources.

    To debug the eclipse-plugin i have to

    1. Start „mvnDebug eclipse:eclipse“ in the eclipse-test project
    2. Start a „Remote Java Application“ debug-session (localhost:8000) with additional sources of „maven-eclipse-plugin-trunk“ project


  • Andreas Höhmann 18:33 am Wednesday, 20. August 2008 Permalink
    Tags: Build, Continuous Integration, , Plugin, Site, , xdoc   

    Show TeamCity Buildstatus in Maven Projectsite 

    Today i will show you a little hack for TeamCity and Maven. At the end you will be able to show the last (live!) buildstatus of your artifact on the generate project-site.

    Lets define a new menu-item „status“ in our project-site-descriptor (src/site/site.xml):

      <menu name="Overview" inherit="top">
      <item name="Introduction" href="index.html" />
      <item name="Status" href="status.html" />

    Hint: you can do this in your parent-project, so all subproject will inherit this menu.

    Now we must define the status.xml (src/site/xdoc/status.xml):

    <?xml version="1.0" encoding="UTF-8"?>
        <section name="Status">
          <div id="statuswidget"/>
        <script type="text/javascript">
          // url to the team-city-server
          // define HOST, PORT and BUILDID
          var url = 'http://HOST:PORT/externalStatus.html'
                   + '?buildTypeId=BUILDID'
                   + unescape( '%26' )   // "hide" amp
                   + 'withCss=true';
          var container = document.getElementById('statuswidget');
          var iframe = document.createElement('iframe');
  = '100%';
 = '500px';
 = 'none';
          iframe.doc = null;
            iframe.doc = iframe.contentDocument;
          else if(iframe.contentWindow)
            iframe.doc = iframe.contentWindow.document;
          else if(iframe.document)
            iframe.doc = iframe.document;

    Insert HOST and PORT. The BUILDID is the number of the build-configuration:

    Hint: The width of the iframe should be 100% but you can customize the height – so if you later click on the status-element you can show teamcity directly in you projectsite … cool 😀

    Activate the status-widget for your build-configuration:

    Build the site:

    mvn clean site-deploy

    Now you have a new menu-item, click and you will see the TeamCity status for your artifact.

    The implementation details …

    The „normal“ way to display the build-status (see TeamCity documentation) is shown here:

    <script type="text/javascript" src="<path_to_server>/externalStatus.html?js=1&amp;amp;buildTypeId=BUILDID">

    But it’s not possible to insert this code in maven’s xdoc-format (there is no javascript-tag allowed!).
    So i found a solution to insert the teamcity-url into a dynamic created iframe. The second trick is to encode the „&“ in the url (unescape(‚%26‘)).

    Try it!

  • Andreas Höhmann 12:34 am Wednesday, 16. April 2008 Permalink |
    Tags: , , Plugin,   

    Maven + Eclipse + Spring 

    Today i show how you can easily develop a Mavenproject with Spring-Beans
    in your Eclipse-IDE. You have to add a new plugin to your pom’s

                    <!&#91;CDATA&#91;<?xml version="1.0" encoding="UTF-8"?>
                    <!&#91;CDATA&#91;<?xml version="1.0" encoding="UTF-8"?>

    Then you can run mvn eclipse:clean eclipse:eclipse (eclipse:clean is not required). The eclipse-plugin will create/change the .springBean and the .settings/org.springframework.ide.eclipse.core.prefs. Then you can refresh the eclipse-project (F5) from now the project contains a Spring-Builder which will handle the defined spring-configuration-files services.xml and datasource.xml. If you have more Springfiles you have to change the plugin-configuration.

Neuen Beitrag erstellen
nächster Beitrag/nächster Kommentar
vorheriger Beitrag/vorheriger Kommentar
zeige/verstecke Kommentare
Zum Anfang gehen
zum Login
Zeige/Verberge Hilfe
Shift + ESC