Maven Archetype
  1. Maven Archetype
  2. ARCHETYPE-235

DefaultPomManager.mergePoms ignores ordering of plugins

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-alpha-4
    • Fix Version/s: 2.0-alpha-5
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      when you invoke an archetype with attribute partial=true (<archetype-descriptor partial="true" .... ) the pom of the archetype-resources is merged with the existing pom.
      During the merge of build plugins the DefaultPomManager ignores the ordering of the plugins in the archetype (generatedModel).
      The DefaultPomManager uses the ordering of the map generatedPluginsByIds :

      Map pluginsByIds = model.getBuild().getPluginsAsMap();

      Map generatedPluginsByIds = generatedModel.getBuild().getPluginsAsMap();
      Iterator generatedPluginsIds = generatedPluginsByIds.keySet().iterator();
      while ( generatedPluginsIds.hasNext() )
      {
      String generatedPluginsId = (String) generatedPluginsIds.next();

      if ( !pluginsByIds.containsKey( generatedPluginsId ) )

      { model.getBuild().addPlugin((Plugin) generatedPluginsByIds.get( generatedPluginsId ) ); }

      else

      { getLogger().warn( "Can not override plugin: " + generatedPluginsId ); }

      }

      When the build process depends on the ordering of the plugins it may fail.

      The solution is to iterate over the list of plugins instead of the map

      Map pluginsByIds = model.getBuild().getPluginsAsMap();
      List generatedPlugins = generatedModel.getBuild().getPlugins();

      Iterator generatedPluginsIterator = generatedPlugins.iterator();
      while ( generatedPluginsIterator.hasNext() )
      {
      Plugin plugin = (Plugin)generatedPluginsIterator.next();
      String generatedPluginsId = plugin.getKey();

      if ( !pluginsByIds.containsKey( generatedPluginsId ) )

      { model.getBuild().addPlugin(plugin); }

      else

      { getLogger().warn( "Can not override plugin: " + generatedPluginsId ); }

      }

        Activity

        Hide
        Kai Reichert added a comment -

        At our company we had the same problem with merging of multiple partial archetypes.

        So we decided to try out the above mentioned solution. It works perfectly, but only sorts the plugins.
        There are more elements to merge inside a pom.xml than just plugins. We also need profiles, properties, etc.

        To cut a long story short we created a patch which implements many of the missing use cases while merging pom.xml's. It can be applied to the 2.0-alpha-4 version of the archetype module.

        It would be great if more people test the patch and that someone will intergrate it into maven.

        Show
        Kai Reichert added a comment - At our company we had the same problem with merging of multiple partial archetypes. So we decided to try out the above mentioned solution. It works perfectly, but only sorts the plugins. There are more elements to merge inside a pom.xml than just plugins. We also need profiles, properties, etc. To cut a long story short we created a patch which implements many of the missing use cases while merging pom.xml's. It can be applied to the 2.0-alpha-4 version of the archetype module. It would be great if more people test the patch and that someone will intergrate it into maven.
        Hide
        Kai Reichert added a comment -

        this patch file has unix line endings. transform it to DOS newline endings if you want to use it under DOS/Windows.

        Show
        Kai Reichert added a comment - this patch file has unix line endings. transform it to DOS newline endings if you want to use it under DOS/Windows.
        Hide
        Christian Bauer added a comment -

        Example of installing the patch under windows.

        Edit the patch (for example with jedit) to transform the newlines to DOS format and save the file as maven-archetype-2.0-alpha-4-patch-19032009.windows.patch

        Run the following script:

        REM go to the directory of this script
        cd %~dp0
        %~d0
        echo on
        REM if the patch command is not installed on your system, you can download it from
        REM http://gnuwin32.sourceforge.net/packages/patch.htm

        REM Enter the path to the bin Directory of patch command like
        REM C:\Programme\GnuWin32\bin
        SET /P PATCHPATH=

        REM you need the svnkit subversion client, because otherwise you get problems with the length of the filenames
        REM is the snvkit installed
        REM Enter the path to the svnkit like
        REM C:\Christian\Programme\svnkit-1.2.3.5521
        SET /P SVNKITPATH=

        REM check out
        call %SVNKITPATH%\jsvn.bat co https://svn.apache.org/repos/asf/maven/archetype/tags/maven-archetype-2.0-alpha-4/
        echo on
        cd maven-archetype-2.0-alpha-4

        call %PATCHPATH%\patch -p0 <..\maven-archetype-2.0-alpha-4-patch-19032009.windows.patch
        echo on
        pause

        call mvn install

        cd %~dp0
        echo on

        rem deleting the archetype dir
        pause
        rem the name is too long so it is renamed before
        rename maven-archetype-2.0-alpha-4 a
        rmdir /s /q a

        Show
        Christian Bauer added a comment - Example of installing the patch under windows. Edit the patch (for example with jedit) to transform the newlines to DOS format and save the file as maven-archetype-2.0-alpha-4-patch-19032009.windows.patch Run the following script: REM go to the directory of this script cd %~dp0 %~d0 echo on REM if the patch command is not installed on your system, you can download it from REM http://gnuwin32.sourceforge.net/packages/patch.htm REM Enter the path to the bin Directory of patch command like REM C:\Programme\GnuWin32\bin SET /P PATCHPATH= REM you need the svnkit subversion client, because otherwise you get problems with the length of the filenames REM is the snvkit installed REM Enter the path to the svnkit like REM C:\Christian\Programme\svnkit-1.2.3.5521 SET /P SVNKITPATH= REM check out call %SVNKITPATH%\jsvn.bat co https://svn.apache.org/repos/asf/maven/archetype/tags/maven-archetype-2.0-alpha-4/ echo on cd maven-archetype-2.0-alpha-4 call %PATCHPATH%\patch -p0 <..\maven-archetype-2.0-alpha-4-patch-19032009.windows.patch echo on pause call mvn install cd %~dp0 echo on rem deleting the archetype dir pause rem the name is too long so it is renamed before rename maven-archetype-2.0-alpha-4 a rmdir /s /q a
        Hide
        Raphaël Piéroni added a comment -

        Patche applied since revision 764258

        Show
        Raphaël Piéroni added a comment - Patche applied since revision 764258

          People

          • Assignee:
            Unassigned
            Reporter:
            Christian Bauer
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: