From 73e549b231b86b280deaf4fa649280f5294c827f Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 26 Jul 2005 05:54:24 +0000 Subject: [PATCH] o Fixing resolution of LATEST in plugin-versions, when is enabled in plugin-registry.xml, or when --check-plugin-latest is specified on the command line. o Fixing core-library resolution for expression: ${plugin.artifacts} and ${plugin.artifactMap} (latter is keyed by g:a) o Modified maven-core-it-plugin to accept something like "-DartifactToFile=org.apache.maven:maven-artifact"...it'll lookup that artifact in ${plugin.artifactMap}, and touch a file that's a mutation of the abs. path for that artifact. o Added pomArtifact to ResolutionGroup, since the MavenMetadataSource ALWAYS creates a new Artifact for a pom...this allows us to retrieve the resolved Artifact for that pom. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225234 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/ArtifactResolverTest.java | 4 +- .../artifact/metadata/ResolutionGroup.java | 11 +++- .../DefaultArtifactCollectorTest.java | 2 +- maven-core-it-plugin/pom.xml | 10 ++++ .../maven/plugin/coreit/CoreItMojo.java | 31 ++++++++--- .../java/org/apache/maven/cli/MavenCli.java | 36 ++++++------- .../maven/plugin/DefaultPluginManager.java | 5 ++ .../version/DefaultPluginVersionManager.java | 53 +++++++++++-------- .../project/artifact/MavenMetadataSource.java | 2 +- .../maven/project/TestArtifactResolver.java | 2 +- .../settings/DefaultMavenSettingsBuilder.java | 29 ++++++---- 11 files changed, 123 insertions(+), 62 deletions(-) diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index ebbf5191cf..2730153ea5 100644 --- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -115,7 +115,7 @@ public class ArtifactResolverTest } } - return new ResolutionGroup( dependencies, remoteRepositories ); + return new ResolutionGroup( artifact, dependencies, remoteRepositories ); } }; @@ -162,7 +162,7 @@ public class ArtifactResolverTest } } - return new ResolutionGroup( dependencies, remoteRepositories ); + return new ResolutionGroup( artifact, dependencies, remoteRepositories ); } }; diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java index f02da12451..65c69f413d 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java @@ -1,5 +1,7 @@ package org.apache.maven.artifact.metadata; +import org.apache.maven.artifact.Artifact; + import java.util.List; import java.util.Set; @@ -8,13 +10,20 @@ public class ResolutionGroup private final Set artifacts; private final List resolutionRepositories; + private final Artifact pomArtifact; - public ResolutionGroup( Set artifacts, List resolutionRepositories ) + public ResolutionGroup( Artifact pomArtifact, Set artifacts, List resolutionRepositories ) { + this.pomArtifact = pomArtifact; this.artifacts = artifacts; this.resolutionRepositories = resolutionRepositories; } + public Artifact getPomArtifact() + { + return pomArtifact; + } + public Set getArtifacts() { return artifacts; diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java index d146f4010c..b6dda0e622 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java @@ -419,7 +419,7 @@ public class DefaultArtifactCollectorTest ArtifactSpec a = (ArtifactSpec) artifacts.get( key ); try { - return new ResolutionGroup( createArtifacts( artifactFactory, a.dependencies, artifact.getScope(), + return new ResolutionGroup( artifact, createArtifacts( artifactFactory, a.dependencies, artifact.getScope(), artifact.getDependencyFilter() ), Collections.EMPTY_LIST ); } catch ( InvalidVersionSpecificationException e ) diff --git a/maven-core-it-plugin/pom.xml b/maven-core-it-plugin/pom.xml index 5877def47a..c6a7e78aa5 100644 --- a/maven-core-it-plugin/pom.xml +++ b/maven-core-it-plugin/pom.xml @@ -17,5 +17,15 @@ maven-project 2.0-beta-1-SNAPSHOT + + org.apache.maven + maven-artifact + 2.0-beta-1-SNAPSHOT + + + jline + jline + 0.9.1 + diff --git a/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java b/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java index 056c85f86a..1636501913 100644 --- a/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java +++ b/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java @@ -16,14 +16,15 @@ package org.apache.maven.plugin.coreit; * limitations under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import java.io.IOException; import java.io.File; import java.io.FileWriter; -import java.util.List; +import java.io.IOException; +import java.util.Map; /** * @goal touch @@ -47,10 +48,10 @@ public class CoreItMojo private String outputDirectory; /** Test setting of plugin-artifacts on the PluginDescriptor instance. - * @parameter expression="${plugin.artifacts}" + * @parameter expression="${plugin.artifactMap}" * @required */ - private List pluginArtifacts; + private Map pluginArtifacts; /** * @parameter expression="target/test-basedir-alignment" @@ -66,6 +67,11 @@ public class CoreItMojo * @parameter */ private String goalItem = "bar"; + + /** + * @parameter expression="${artifactToFile}" + */ + private String artifactToFile; public void execute() throws MojoExecutionException @@ -81,16 +87,29 @@ public class CoreItMojo } touch( basedirAlignmentDirectory, "touch.txt" ); + + File outDir = new File( outputDirectory ); // Test parameter setting if ( pluginItem != null ) { - touch( new File( outputDirectory ), pluginItem ); + touch( outDir, pluginItem ); } if ( goalItem != null ) { - touch( new File( outputDirectory ), goalItem ); + touch( outDir, goalItem ); + } + + if ( artifactToFile != null ) + { + Artifact artifact = (Artifact) pluginArtifacts.get( artifactToFile ); + + File artifactFile = artifact.getFile(); + + String filename = artifactFile.getAbsolutePath().replace('/', '_').replace(':', '_') + ".txt"; + + touch( outDir, filename ); } project.getBuild().setFinalName( "coreitified" ); diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index 48e40d346f..7674e78629 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -493,17 +493,17 @@ public class MavenCli public static final char ACTIVATE_PROFILES = 'P'; - public static final String FORCE_PLUGIN_UPDATES = "check-plugin-updates"; + public static final String FORCE_PLUGIN_UPDATES = "cpu"; - public static final String FORCE_PLUGIN_UPDATES2 = "update-plugins"; + public static final String FORCE_PLUGIN_UPDATES2 = "up"; - public static final String SUPPRESS_PLUGIN_UPDATES = "no-plugin-updates"; + public static final String SUPPRESS_PLUGIN_UPDATES = "npu"; - public static final String SUPPRESS_PLUGIN_REGISTRY = "no-plugin-registry"; + public static final String SUPPRESS_PLUGIN_REGISTRY = "npr"; - public static final String FORCE_PLUGIN_LATEST_CHECK = "check-plugin-latest"; + public static final String FORCE_PLUGIN_LATEST_CHECK = "cpl"; - public static final String SUPPRESS_PLUGIN_LATEST_CHECK = "no-plugin-latest"; + public static final String SUPPRESS_PLUGIN_LATEST_CHECK = "npl"; public static final char CHECKSUM_FAILURE_POLICY = 'C'; @@ -545,19 +545,19 @@ public class MavenCli options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription( "Run in non-interactive (batch) mode" ).create( BATCH_MODE ) ); - options.addOption( OptionBuilder.withLongOpt( FORCE_PLUGIN_UPDATES ).withDescription( - "Force upToDate check for any relevant registered plugins" ).create( "cpu" ) ); - options.addOption( OptionBuilder.withLongOpt( FORCE_PLUGIN_UPDATES2 ).withDescription( - "Synonym for " + FORCE_PLUGIN_UPDATES ).create( "up" ) ); - options.addOption( OptionBuilder.withLongOpt( SUPPRESS_PLUGIN_UPDATES ).withDescription( - "Suppress upToDate check for any relevant registered plugins" ).create( "npu" ) ); - options.addOption( OptionBuilder.withLongOpt( FORCE_PLUGIN_LATEST_CHECK ).withDescription( - "Force checking of LATEST metadata for plugin versions" ).create( "cpl" ) ); - options.addOption( OptionBuilder.withLongOpt( SUPPRESS_PLUGIN_LATEST_CHECK ).withDescription( - "Suppress checking of LATEST metadata for plugin versions" ).create( "npl" ) ); + options.addOption( OptionBuilder.withLongOpt( "check-plugin-updates" ).withDescription( + "Force upToDate check for any relevant registered plugins" ).create( FORCE_PLUGIN_UPDATES ) ); + options.addOption( OptionBuilder.withLongOpt( "update-plugins" ).withDescription( + "Synonym for " + FORCE_PLUGIN_UPDATES ).create( FORCE_PLUGIN_UPDATES2 ) ); + options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription( + "Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) ); + options.addOption( OptionBuilder.withLongOpt( "check-plugin-latest" ).withDescription( + "Force checking of LATEST metadata for plugin versions" ).create( FORCE_PLUGIN_LATEST_CHECK ) ); + options.addOption( OptionBuilder.withLongOpt( "no-plugin-latest" ).withDescription( + "Suppress checking of LATEST metadata for plugin versions" ).create( SUPPRESS_PLUGIN_LATEST_CHECK ) ); - options.addOption( OptionBuilder.withLongOpt( SUPPRESS_PLUGIN_REGISTRY ).withDescription( - "Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( "npr" ) ); + options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription( + "Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) ); options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription( "Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index b0bdd6937c..c579276893 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -623,6 +623,11 @@ public class DefaultPluginManager else { String artifactPath = resourceUrl.getPath(); + + if ( artifactPath.startsWith( "file:" ) ) + { + artifactPath = artifactPath.substring( "file:".length() ); + } artifactPath = artifactPath.substring( 0, artifactPath.length() - resource.length() ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index 3efd38a36f..17a11b00fa 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -20,8 +20,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.transform.LatestArtifactTransformation; import org.apache.maven.artifact.transform.ReleaseArtifactTransformation; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.RuntimeInformation; @@ -149,7 +149,7 @@ public class DefaultPluginVersionManager Boolean rtCheckLatest = settingsRTInfo.getCheckLatestPluginVersion(); boolean checkLatestMetadata = Boolean.TRUE.equals( rtCheckLatest ) || - ( !Boolean.FALSE.equals( rtCheckLatest ) && Boolean.valueOf( getPluginRegistry( groupId, artifactId).getCheckLatest() ) + ( !Boolean.FALSE.equals( rtCheckLatest ) && Boolean.valueOf( getPluginRegistry( groupId, artifactId ).getCheckLatest() ) .booleanValue() ); // third pass...if we're checking for latest install/deploy, retrieve the version for LATEST metadata and also @@ -622,31 +622,41 @@ public class DefaultPluginVersionManager Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId ); String version = null; + try { - artifactMetadataSource.retrieve( artifact, localRepository, remoteRepositories ); - - MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, - localRepository ); - - boolean pluginValid = true; - - // if we don't have the required Maven version, then ignore an update - if ( project.getPrerequesites() != null && project.getPrerequesites().getMaven() != null ) + ResolutionGroup resolutionGroup = artifactMetadataSource.retrieve( artifact, localRepository, remoteRepositories ); + + // switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom + // artifact. + artifact = resolutionGroup.getPomArtifact(); + + // make sure this artifact was actually resolved to a file in the repo... + if ( artifact.getFile() != null ) { - DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion( - project.getPrerequesites().getMaven() ); - if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 ) + MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, + localRepository ); + + boolean pluginValid = true; + + // if we don't have the required Maven version, then ignore an update + if ( project.getPrerequesites() != null && project.getPrerequesites().getMaven() != null ) { - getLogger().info( "Ignoring available plugin update: " + artifact.getVersion() + - " as it requires Maven version " + requiredVersion ); - pluginValid = false; + DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion( + project.getPrerequesites().getMaven() ); + + if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 ) + { + getLogger().info( "Ignoring available plugin update: " + artifact.getVersion() + + " as it requires Maven version " + requiredVersion ); + pluginValid = false; + } } - } - if ( pluginValid ) - { - version = artifact.getVersion(); + if ( pluginValid ) + { + version = artifact.getVersion(); + } } } catch ( ArtifactMetadataRetrievalException e ) @@ -663,6 +673,7 @@ public class DefaultPluginVersionManager throw new PluginVersionResolutionException( groupId, artifactId, "Unable to determine Maven version for comparison", e ); } + return version; } diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index eccf511b73..96a4a5401c 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -130,7 +130,7 @@ public class MavenMetadataSource Set artifacts = createArtifacts( artifactFactory, p.getDependencies(), artifact.getScope(), artifact.getDependencyFilter() ); - return new ResolutionGroup( artifacts, p.getRemoteArtifactRepositories() ); + return new ResolutionGroup( pomArtifact, artifacts, p.getRemoteArtifactRepositories() ); } catch ( InvalidVersionSpecificationException e ) { diff --git a/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java b/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java index 4d254d5ffa..37c043538a 100644 --- a/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java +++ b/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java @@ -132,7 +132,7 @@ public class TestArtifactResolver throw new ArtifactMetadataRetrievalException( e ); } - return new ResolutionGroup( artifacts, artifactRepositories ); + return new ResolutionGroup( artifact, artifacts, artifactRepositories ); } protected Set createArtifacts( List dependencies, String inheritedScope ) diff --git a/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index 257b47a13c..b5450d9793 100644 --- a/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -52,6 +52,8 @@ public class DefaultMavenSettingsBuilder private File userSettingsFile; private File globalSettingsFile; + + private Settings loadedSettings; // ---------------------------------------------------------------------- // Component Lifecycle @@ -106,20 +108,25 @@ public class DefaultMavenSettingsBuilder public Settings buildSettings() throws IOException, XmlPullParserException { - Settings globalSettings = readSettings( globalSettingsFile ); - Settings userSettings = readSettings( userSettingsFile ); - - if ( userSettings == null ) + if ( loadedSettings == null ) { - userSettings = new Settings(); - userSettings.setRuntimeInfo( new RuntimeInfo( userSettings ) ); + Settings globalSettings = readSettings( globalSettingsFile ); + Settings userSettings = readSettings( userSettingsFile ); + + if ( userSettings == null ) + { + userSettings = new Settings(); + userSettings.setRuntimeInfo( new RuntimeInfo( userSettings ) ); + } + + SettingsUtils.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); + + setLocalRepository( userSettings ); + + loadedSettings = userSettings; } - SettingsUtils.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); - - setLocalRepository( userSettings ); - - return userSettings; + return loadedSettings; } private void setLocalRepository( Settings userSettings )