brett       2004/11/04 07:09:59

  Modified:    src/java/org/apache/maven/plugin Tag: MAVEN-1_0-BRANCH
                        PluginManager.java
               xdocs    Tag: MAVEN-1_0-BRANCH changes.xml
  Log:
  PR: MAVEN-1427

  make sure only one plugin per artifact ID is installed at a time with plugin 
dependencies
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.70.4.55 +77 -33    maven/src/java/org/apache/maven/plugin/PluginManager.java
  
  Index: PluginManager.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/PluginManager.java,v
  retrieving revision 1.70.4.54
  retrieving revision 1.70.4.55
  diff -u -r1.70.4.54 -r1.70.4.55
  --- PluginManager.java        24 Sep 2004 10:38:43 -0000      1.70.4.54
  +++ PluginManager.java        4 Nov 2004 15:09:58 -0000       1.70.4.55
  @@ -24,7 +24,6 @@
   import com.werken.werkz.Session;
   import com.werken.werkz.WerkzProject;
   import com.werken.werkz.jelly.JellySession;
  -
   import org.apache.commons.io.FileUtils;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.expression.Expression;
  @@ -147,6 +146,7 @@
   
       /** The current goal attainment base context. */
       private MavenJellyContext baseContext;
  +    private static final String PLUGIN_TEMP_MAP = "PluginManager.PLUGIN_TEMP_MAP";
   
       /**
        * Default constructor.
  @@ -657,6 +657,7 @@
           {
               cleanupAttainGoal( pluginSet );
               delayedPops = oldDelayedPops;
  +            reinstallPlugins( project.getContext() );
               project.popContext();
               baseContext = prevBaseContext;
           }
  @@ -673,6 +674,8 @@
           {
               JellyScriptHousing housing = ( JellyScriptHousing ) j.next();
   
  +            reinstallPlugins( housing.getProject().getContext() );
  +
               housing.getProject().popContext();
           }
           delayedPops.clear();
  @@ -804,23 +807,13 @@
       }
   
       /**
  -     */
  -    public void installPlugin( File file, Project parentProject ) throws 
MavenException
  -    {
  -        // By default, don't copy to the unpacked plugins directory - only use this 
dependency for this project
  -        installPlugin( file, parentProject, false );
  -        // TODO:  we should unload the plugin after the project is done in this 
case - we really need
  -        // to define the lifecycle of plugins
  -    }
  -
  -    /**
        * Load and install a plugin.
        *
        * @param file          the file to install. Must be a plugin jar
        * @param parentProject the project to load the installed plugin into
        * @todo remove any old one
        */
  -    public void installPlugin( File file, Project parentProject, boolean cache )
  +    public void installPlugin( File file, Project parentProject )
           throws MavenException
       {
           log.debug( "Using plugin file: " + file );
  @@ -829,38 +822,89 @@
               String pluginName = file.getCanonicalFile().getName();
               pluginName = pluginName.substring( 0, pluginName.indexOf( ".jar" ) );
       
  -            if ( !isLoaded( pluginName ) )
  -            {    
  -                // expand it
  -                File unpackedPluginDir = unpackPlugin( pluginName, file );
  -                if ( unpackedPluginDir != null ) 
  +            if ( isLoaded( pluginName ) )
  +            {
  +                // already installed this version
  +                return;
  +            }
  +
  +            // expand it
  +            File unpackedPluginDir = unpackPlugin( pluginName, file );
  +            if ( unpackedPluginDir != null )
  +            {
  +                JellyScriptHousing housing = createLazyPluginHousing( 
unpackedPluginDir );
  +                if ( housing != null )
                   {
  -                    JellyScriptHousing housing = createPluginHousing( 
unpackedPluginDir );
  -                    if ( housing == null )
  +                    String artifactId = housing.getProject().getArtifactId();
  +                    if ( artifactIdToHousingMap.containsKey( artifactId ) )
                       {
  -                        throw new MavenException( "Not a valid plugin file: " + 
file );
  +                        // old version
  +                        JellyScriptHousing oldHousing = (JellyScriptHousing) 
artifactIdToHousingMap.get( artifactId );
  +                        log.debug( "Temporarily uninstalling: " + oldHousing );
  +                        addPluginToReinstall( parentProject.getContext(), 
artifactId, oldHousing );
  +                        pluginHousings.remove( oldHousing.getName() );
  +                        mapper.invalidatePlugin( oldHousing );
  +                        transientMapper.invalidatePlugin( oldHousing );
                       }
   
  -                    // By default, not caching the plugin - its a per execution 
installation
  -                    housing.parse( transientMapper );
  -                    // Should only be putting in the transientMapper - but it is 
not consistent with isLoaded
  -                    housing.parse( mapper );
  -                    if ( cache )
  -                    {
  -                        cacheManager.registerPlugin( pluginName, housing );
  -                        housing.parse( cacheManager );
  -                        cacheManager.saveCache( unpackedPluginsDir );
  -                    }
  +                    mapArtifactIdToPluginHousing( artifactId, housing );
                   }
  -                else 
  +                else
                   {
  -                    throw new MavenException( "Not a valid JAR file: " + file );
  +                    throw new MavenException( "Not a valid plugin file: " + file );
                   }
  +
  +                log.debug( "Installing plugin: " + housing );
  +                // By default, not caching the plugin - its a per execution 
installation
  +                housing.parse( transientMapper );
  +                // Should only be putting in the transientMapper - but it is not 
consistent with isLoaded
  +                housing.parse( mapper );
  +            }
  +            else
  +            {
  +                throw new MavenException( "Not a valid JAR file: " + file );
               }
           }
           catch ( IOException e )
           {
               throw new MavenException( "Error installing plugin", e );
  +        }
  +    }
  +
  +    /**
  +     * @todo can this be removed and simplified if transient mapper contains the 
plugin mapping only?
  +     */
  +    private void addPluginToReinstall( MavenJellyContext context, String 
artifactId, JellyScriptHousing housing )
  +    {
  +        Map m = (Map) context.getVariables().get( PLUGIN_TEMP_MAP );
  +        if ( m == null )
  +        {
  +            m = new HashMap();
  +            context.setVariable( PLUGIN_TEMP_MAP, m );
  +        }
  +        m.put( artifactId, housing );
  +    }
  +
  +    /**
  +     * @todo can this be removed and simplified if transient mapper contains the 
plugin mapping only?
  +     */
  +    private void reinstallPlugins( MavenJellyContext context ) throws MavenException
  +    {
  +        Map m = (Map) context.getVariables().get( PLUGIN_TEMP_MAP );
  +        if ( m != null )
  +        {
  +            for ( Iterator i = m.keySet().iterator(); i.hasNext(); )
  +            {
  +                String artifactId = (String) i.next();
  +                JellyScriptHousing housing = (JellyScriptHousing) m.get( artifactId 
);
  +                pluginHousings.remove( housing.getName() );
  +                mapper.invalidatePlugin( housing );
  +                transientMapper.invalidatePlugin( housing );
  +                housing = (JellyScriptHousing) m.get( artifactId );
  +                log.debug( "Reinstalling: " + housing );
  +                housing.parse( transientMapper );
  +                housing.parse( mapper );
  +             }
           }
       }
   
  
  
  
  No                   revision
  No                   revision
  1.14.4.47 +2 -0      maven/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/maven/xdocs/changes.xml,v
  retrieving revision 1.14.4.46
  retrieving revision 1.14.4.47
  diff -u -r1.14.4.46 -r1.14.4.47
  --- changes.xml       4 Nov 2004 11:08:56 -0000       1.14.4.46
  +++ changes.xml       4 Nov 2004 15:09:59 -0000       1.14.4.47
  @@ -25,6 +25,8 @@
     </properties>
     <body>
       <release version="1.0.1-SNAPSHOT" date="in CVS MAVEN-1_0-BRANCH">
  +      <action dev="brett" type="fix" issue="MAVEN-1427">Improve plugin dependency 
handling by removing old plugins before using a different version</action>
  +      <action dev="brett" type="fix" issue="MAVEN-1422" due-to="Eric Lapierre">Fix 
inheritence inside the reactor over multiple levels</action>
         <action dev="brett" type="fix" issue="MAVEN-1405" due-to="Philipp Kohl">Use 
preemptive authentication when there are some credentials, so the first 403 is really 
forbidden.</action>
         <action dev="brett" type="fix" issue="MAVEN-1457">Don't display the password 
on the console when a remote repository uses basic authentication.</action>
         <action dev="brett" type="fix" issue="MAVEN-1471">Prevent 
NullPointerException in a case that has been encountered, and display a warning 
instead.</action>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to