You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/02/14 14:44:11 UTC

svn commit: r744497 - in /maven/components/branches/maven-2.1.x: maven-artifact/src/main/java/org/apache/maven/artifact/ maven-core/src/main/java/org/apache/maven/plugin/

Author: bentmann
Date: Sat Feb 14 13:44:10 2009
New Revision: 744497

URL: http://svn.apache.org/viewvc?rev=744497&view=rev
Log:
[MNG-3284] Cached plugins are used, even when the specifically declared 

o Extended both plugin manager and collector to include the plugin version in the lookup keys as inspired by r591391 and r615004

Added:
    maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java   (with props)
Modified:
    maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
    maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
    maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java

Modified: maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java?rev=744497&r1=744496&r2=744497&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java Sat Feb 14 13:44:10 2009
@@ -20,7 +20,6 @@
  */
 
 import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.artifact.handler.ArtifactHandler;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -28,6 +27,7 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
 
 public final class ArtifactUtils
 {
@@ -43,6 +43,19 @@
                 .matches() );
     }
 
+    public static String toSnapshotVersion( String version )
+    {
+        Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
+        if ( m.matches() )
+        {
+            return m.group( 1 ) + '-' + Artifact.SNAPSHOT_VERSION;
+        }
+        else
+        {
+            return version;
+        }
+    }
+
     public static String versionlessKey( Artifact artifact )
     {
         return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );

Modified: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=744497&r1=744496&r2=744497&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Sat Feb 14 13:44:10 2009
@@ -202,7 +202,9 @@
 
             artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository );
 
-            PlexusContainer pluginContainer = container.getChildContainer( plugin.getKey() );
+            String pluginKey = PluginUtils.constructVersionedKey( plugin );
+
+            PlexusContainer pluginContainer = container.getChildContainer( pluginKey );
 
             File pluginFile = pluginArtifact.getFile();
 
@@ -213,7 +215,7 @@
             else if ( pluginFile.lastModified() > pluginContainer.getCreationDate().getTime() )
             {
                 getLogger().info(
-                    "Reloading plugin container for: " + plugin.getKey() + ". The plugin artifact has changed." );
+                    "Reloading plugin container for: " + pluginKey + ". The plugin artifact has changed." );
 
                 pluginContainer.dispose();
 
@@ -292,7 +294,7 @@
 
         try
         {
-            child = container.createChildContainer( plugin.getKey(),
+            child = container.createChildContainer( PluginUtils.constructVersionedKey( plugin ).intern(),
                                                     Collections.singletonList( pluginArtifact.getFile() ),
                                                     Collections.EMPTY_MAP,
                                                     Collections.singletonList( pluginCollector ) );
@@ -580,7 +582,7 @@
     private PlexusContainer getPluginContainer( PluginDescriptor pluginDescriptor )
         throws PluginManagerException
     {
-        String pluginKey = pluginDescriptor.getPluginLookupKey();
+        String pluginKey = PluginUtils.constructVersionedKey( pluginDescriptor );
 
         PlexusContainer pluginContainer = container.getChildContainer( pluginKey );
 

Modified: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java?rev=744497&r1=744496&r2=744497&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java (original)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java Sat Feb 14 13:44:10 2009
@@ -54,8 +54,7 @@
         {
             PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
             
-            // TODO: see comment in getPluginDescriptor
-            String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
+            String key = PluginUtils.constructVersionedKey( pluginDescriptor );
             
             if ( !pluginsInProcess.contains( key ) )
             {
@@ -75,16 +74,14 @@
 
     public PluginDescriptor getPluginDescriptor( Plugin plugin )
     {
-        // TODO: include version, but can't do this in the plugin manager as it is not resolved to the right version
-        // at that point. Instead, move the duplication check to the artifact container, or store it locally based on
-        // the unresolved version?
-        return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() );
+        String key = PluginUtils.constructVersionedKey( plugin );
+        return (PluginDescriptor) pluginDescriptors.get( key );
     }
 
     public boolean isPluginInstalled( Plugin plugin )
     {
-        // TODO: see comment in getPluginDescriptor
-        return pluginDescriptors.containsKey( plugin.getKey() );
+        String key = PluginUtils.constructVersionedKey( plugin );
+        return pluginDescriptors.containsKey( key );
     }
 
     public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
@@ -94,14 +91,15 @@
 
     public void flushPluginDescriptor( Plugin plugin )
     {
-        pluginsInProcess.remove( plugin.getKey() );
-        pluginDescriptors.remove( plugin.getKey() );
+        String key = PluginUtils.constructVersionedKey( plugin );
+        pluginsInProcess.remove( key );
+        pluginDescriptors.remove( key );
         
         for ( Iterator it = pluginIdsByPrefix.entrySet().iterator(); it.hasNext(); )
         {
             Map.Entry entry = (Map.Entry) it.next();
             
-            if ( plugin.getKey().equals( entry.getValue() ) )
+            if ( key.equals( PluginUtils.constructVersionedKey( (PluginDescriptor) entry.getValue() ) ) )
             {
                 it.remove();
             }

Added: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java?rev=744497&view=auto
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java (added)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java Sat Feb 14 13:44:10 2009
@@ -0,0 +1,79 @@
+package org.apache.maven.plugin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Provides utility methods for plugin management.
+ * 
+ * @author Benjamin Bentmann
+ */
+class PluginUtils
+{
+
+    /**
+     * Creates a lookup key for the specified plugin.
+     * 
+     * @param plugin The plugin, must not be <code>null</code>.
+     * @return The lookup key for the plugin in the form groupId:artifactId:baseVersion, never <code>null</code>.
+     */
+    public static String constructVersionedKey( Plugin plugin )
+    {
+        return constructVersionedKey( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
+    }
+
+    /**
+     * Creates a lookup key for the specified plugin.
+     * 
+     * @param plugin The plugin's descriptor, must not be <code>null</code>.
+     * @return The lookup key for the plugin in the form groupId:artifactId:baseVersion, never <code>null</code>.
+     */
+    public static String constructVersionedKey( PluginDescriptor plugin )
+    {
+        return constructVersionedKey( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
+    }
+
+    /**
+     * Creates a lookup key from the specified plugin coordinates.
+     * 
+     * @param groupId The group id of the plugin, must not be <code>null</code> or empty.
+     * @param artifactId The artifact id of the plugin, must not be <code>null</code> or empty.
+     * @param version The (possibly) timestamped version of the plugin, must not be <code>null</code> or empty.
+     * @return The lookup key for the plugin in the form groupId:artifactId:baseVersion, never <code>null</code>.
+     */
+    private static String constructVersionedKey( String groupId, String artifactId, String version )
+    {
+        if ( StringUtils.isEmpty( version ) )
+        {
+            throw new IllegalStateException( "version for plugin " + groupId + ":" + artifactId + " is not set" );
+        }
+
+        String baseVersion = ArtifactUtils.toSnapshotVersion( version );
+
+        StringBuffer key = new StringBuffer( 128 );
+        key.append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( baseVersion );
+        return key.toString();
+    }
+
+}

Propchange: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/plugin/PluginUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision