2011-01-28 16:12:57 +00:00
|
|
|
From c804249cb3355df3ac10b4a83fffa2a4c84bd69b Mon Sep 17 00:00:00 2001
|
2010-12-21 14:25:37 +00:00
|
|
|
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
|
2011-01-28 16:12:57 +00:00
|
|
|
Date: Tue, 18 Jan 2011 11:09:32 +0100
|
2011-01-11 15:40:20 +00:00
|
|
|
Subject: [PATCH 2/2] Use custom resolver
|
2010-12-21 14:25:37 +00:00
|
|
|
|
2011-01-11 15:40:20 +00:00
|
|
|
WorkspaceReader is used to resolve main dependencies, but we had to
|
|
|
|
add this resolve to ProjectModelResolver and DefaultModelResolver as
|
|
|
|
well because these are instantiated early and used to build model of
|
|
|
|
project when WorkspaceReader is not available yet.
|
2010-12-21 14:25:37 +00:00
|
|
|
---
|
2011-01-11 15:40:20 +00:00
|
|
|
.../repository/internal/DefaultModelResolver.java | 9 +++++++++
|
|
|
|
.../org/apache/maven/artifact/ArtifactUtils.java | 10 ++++++++--
|
|
|
|
.../main/java/org/apache/maven/DefaultMaven.java | 7 +++++++
|
2011-01-28 16:12:57 +00:00
|
|
|
.../main/java/org/apache/maven/ReactorReader.java | 4 ++--
|
2011-01-11 15:40:20 +00:00
|
|
|
.../apache/maven/plugin/MavenPluginValidator.java | 5 ++++-
|
|
|
|
.../internal/DefaultPluginVersionResolver.java | 9 +++++++++
|
|
|
|
.../apache/maven/project/ProjectModelResolver.java | 9 +++++++++
|
2011-01-12 15:57:07 +00:00
|
|
|
.../project/artifact/MavenMetadataSource.java | 9 +++++++++
|
2011-01-11 15:40:20 +00:00
|
|
|
.../model/validation/DefaultModelValidator.java | 16 +++++++++++++---
|
2011-01-28 16:12:57 +00:00
|
|
|
9 files changed, 70 insertions(+), 8 deletions(-)
|
2010-12-21 14:25:37 +00:00
|
|
|
|
2011-01-11 15:40:20 +00:00
|
|
|
diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
|
|
|
|
index cae3735..2d11d64 100644
|
|
|
|
--- a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
|
|
|
|
+++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
|
|
|
|
@@ -39,6 +39,7 @@ import org.sonatype.aether.repository.RemoteRepository;
|
|
|
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
|
|
|
import org.sonatype.aether.resolution.ArtifactResolutionException;
|
|
|
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
|
|
|
+import org.apache.maven.artifact.resolver.JavadirWorkspaceReader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A model resolver to assist building of dependency POMs. This resolver gives priority to those repositories that have
|
|
|
|
@@ -108,6 +109,14 @@ class DefaultModelResolver
|
|
|
|
throws UnresolvableModelException
|
|
|
|
{
|
|
|
|
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if ( System.getProperty("maven.local.mode") != null) {
|
2011-01-11 15:40:20 +00:00
|
|
|
+ JavadirWorkspaceReader wReader = new JavadirWorkspaceReader();
|
|
|
|
+ File pomFile = wReader.findArtifact(pomArtifact);
|
|
|
|
+ // if pom file does not exist continue resolving using different
|
|
|
|
+ // resolvers (maybe they will have more luck)
|
|
|
|
+ if ( pomFile != null )
|
|
|
|
+ return new FileModelSource( pomFile );
|
|
|
|
+ }
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-12-21 14:25:37 +00:00
|
|
|
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
|
2011-01-11 15:40:20 +00:00
|
|
|
index 1f37d4f..d60dab8 100644
|
2010-12-21 14:25:37 +00:00
|
|
|
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
|
|
|
|
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -99,12 +99,18 @@ public final class ArtifactUtils
|
2010-12-21 14:25:37 +00:00
|
|
|
{
|
|
|
|
throw new NullPointerException( "artifactId is null" );
|
|
|
|
}
|
|
|
|
- if ( version == null )
|
2011-02-10 10:57:07 +00:00
|
|
|
+ // in local mode we ignore versions because these would only cause
|
2011-01-11 15:40:20 +00:00
|
|
|
+ // problems
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if ( version == null && System.getProperty("maven.local.mode") == null )
|
2010-12-21 14:25:37 +00:00
|
|
|
{
|
|
|
|
throw new NullPointerException( "version is null" );
|
|
|
|
}
|
|
|
|
|
|
|
|
- return groupId + ":" + artifactId + ":" + version;
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if( System.getProperty("maven.local.mode") == null ) {
|
2010-12-21 14:25:37 +00:00
|
|
|
+ return groupId + ":" + artifactId + ":" + version;
|
|
|
|
+ } else {
|
|
|
|
+ return versionlessKey(groupId, artifactId);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
|
|
|
|
diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
|
2011-01-11 15:40:20 +00:00
|
|
|
index e892ee9..0222b01 100644
|
2010-12-21 14:25:37 +00:00
|
|
|
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
|
|
|
|
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
|
|
|
|
@@ -55,6 +55,7 @@ import org.apache.maven.project.ProjectBuildingException;
|
|
|
|
import org.apache.maven.project.ProjectBuildingRequest;
|
|
|
|
import org.apache.maven.project.ProjectBuildingResult;
|
|
|
|
import org.apache.maven.project.ProjectSorter;
|
|
|
|
+import org.apache.maven.artifact.resolver.JavadirWorkspaceReader;
|
|
|
|
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
|
|
|
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
|
|
|
|
import org.apache.maven.settings.Mirror;
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -361,6 +362,12 @@ public class DefaultMaven
|
2010-12-21 14:25:37 +00:00
|
|
|
session.setWorkspaceReader( workspaceRepository );
|
|
|
|
}
|
|
|
|
|
2011-01-11 15:40:20 +00:00
|
|
|
+ // Set our own workspace reader to resolve from /usr/share/java
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if ( System.getProperty("maven.local.mode") != null)
|
2010-12-21 14:25:37 +00:00
|
|
|
+ {
|
|
|
|
+ session.setWorkspaceReader(new JavadirWorkspaceReader());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
|
|
|
|
decrypt.setProxies( request.getProxies() );
|
|
|
|
decrypt.setServers( request.getServers() );
|
2011-01-28 16:12:57 +00:00
|
|
|
diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
|
|
|
|
index 62e181a..3d08c65 100644
|
|
|
|
--- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java
|
|
|
|
+++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
|
|
|
|
@@ -216,7 +216,7 @@ class ReactorReader
|
|
|
|
|
|
|
|
public File findArtifact( Artifact artifact )
|
|
|
|
{
|
|
|
|
- String projectKey = artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getVersion();
|
|
|
|
+ String projectKey = ArtifactUtils.key( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
|
|
|
|
|
|
|
|
MavenProject project = projectsByGAV.get( projectKey );
|
|
|
|
|
|
|
|
@@ -230,7 +230,7 @@ class ReactorReader
|
|
|
|
|
|
|
|
public List<String> findVersions( Artifact artifact )
|
|
|
|
{
|
|
|
|
- String key = artifact.getGroupId() + ':' + artifact.getArtifactId();
|
|
|
|
+ String key = ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
|
|
|
|
|
|
|
|
List<MavenProject> projects = projectsByGA.get( key );
|
|
|
|
if ( projects == null || projects.isEmpty() )
|
2010-12-21 14:25:37 +00:00
|
|
|
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
|
2011-01-11 15:40:20 +00:00
|
|
|
index 009635b..7d03748 100644
|
2010-12-21 14:25:37 +00:00
|
|
|
--- a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
|
|
|
|
+++ b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -60,7 +60,10 @@ public class MavenPluginValidator
|
2010-12-21 14:25:37 +00:00
|
|
|
errors.add( "Plugin's descriptor contains the wrong artifact ID: " + pluginDescriptor.getArtifactId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
- if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) )
|
2011-02-10 10:57:07 +00:00
|
|
|
+ // ignore incorrect version in local mode (we can have different
|
2011-01-11 15:40:20 +00:00
|
|
|
+ // versions in /usr/share/java
|
2010-12-21 14:25:37 +00:00
|
|
|
+ if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() )
|
2011-02-10 10:57:07 +00:00
|
|
|
+ && System.getProperty("maven.local.mode") == null)
|
2010-12-21 14:25:37 +00:00
|
|
|
{
|
|
|
|
errors.add( "Plugin's descriptor contains the wrong version: " + pluginDescriptor.getVersion() );
|
|
|
|
}
|
|
|
|
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java
|
2011-01-11 15:40:20 +00:00
|
|
|
index fb074fb..bf2e703 100644
|
2010-12-21 14:25:37 +00:00
|
|
|
--- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java
|
|
|
|
+++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -75,6 +75,15 @@ public class DefaultPluginVersionResolver
|
2010-12-21 14:25:37 +00:00
|
|
|
throws PluginVersionResolutionException
|
|
|
|
{
|
|
|
|
logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() );
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if (System.getProperty("maven.local.mode") != null) {
|
|
|
|
+ // in local mode we always use "latest" as a resolved version
|
2011-01-11 15:40:20 +00:00
|
|
|
+ // (we ignore it anyway)
|
2010-12-21 14:25:37 +00:00
|
|
|
+ DefaultPluginVersionResult result = new DefaultPluginVersionResult("latest");
|
|
|
|
+ result.setRepository(request.getRepositorySession().getWorkspaceReader().getRepository());
|
|
|
|
+ logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
|
|
|
|
+ + " to latest from repository " + result.getRepository());
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
PluginVersionResult result = resolveFromProject( request );
|
|
|
|
|
2011-01-11 15:40:20 +00:00
|
|
|
diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
|
|
|
|
index 403351a..2351620 100644
|
|
|
|
--- a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
|
|
|
|
+++ b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
|
|
|
|
@@ -41,6 +41,7 @@ import org.sonatype.aether.repository.RepositoryPolicy;
|
|
|
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
|
|
|
import org.sonatype.aether.resolution.ArtifactResolutionException;
|
|
|
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
|
|
|
+import org.apache.maven.artifact.resolver.JavadirWorkspaceReader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A model resolver to assist building of projects. This resolver gives priority to those repositories that have been
|
|
|
|
@@ -172,6 +173,14 @@ class ProjectModelResolver
|
|
|
|
if ( pomFile == null )
|
|
|
|
{
|
|
|
|
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if ( System.getProperty("maven.local.mode") != null) {
|
2011-01-11 15:40:20 +00:00
|
|
|
+ JavadirWorkspaceReader wReader = new JavadirWorkspaceReader();
|
|
|
|
+ pomFile = wReader.findArtifact(pomArtifact);
|
|
|
|
+ // if pom file does not exist continue resolving using different resolvers
|
|
|
|
+ // (maybe they will have more luck)
|
|
|
|
+ if ( pomFile != null)
|
|
|
|
+ return new FileModelSource( pomFile );
|
|
|
|
+ }
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-01-12 15:57:07 +00:00
|
|
|
diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
|
|
|
|
index 066fbf3..a7cbf40 100644
|
|
|
|
--- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
|
|
|
|
+++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
|
|
|
|
@@ -326,6 +326,15 @@ public class MavenMetadataSource
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // this is a workaround for 669034
|
|
|
|
+ // Seems like plexus-container-default has some quirks that
|
|
|
|
+ // cause it to lose version. Needs more looking into and fix it
|
|
|
|
+ // properly
|
2011-02-10 10:57:07 +00:00
|
|
|
+ if (dependency.getVersion() == null && System.getProperty("maven.local.mode") != null)
|
2011-01-12 15:57:07 +00:00
|
|
|
+ {
|
|
|
|
+ System.out.println("FIXING NULL VERSION:" + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion());
|
|
|
|
+ dependency.setVersion("1.0.0");
|
|
|
|
+ }
|
|
|
|
VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
|
|
|
|
|
|
|
|
Artifact dependencyArtifact =
|
2010-12-21 14:25:37 +00:00
|
|
|
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
|
2011-01-11 15:40:20 +00:00
|
|
|
index 033211a..eec6caf 100644
|
2010-12-21 14:25:37 +00:00
|
|
|
--- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
|
|
|
|
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -405,7 +405,11 @@ public class DefaultModelValidator
|
2010-12-21 14:25:37 +00:00
|
|
|
|
|
|
|
if ( !management )
|
|
|
|
{
|
|
|
|
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
|
2011-02-10 10:57:07 +00:00
|
|
|
+ // in local mode set version to "latest" and validate
|
|
|
|
+ if(System.getProperty("maven.local.mode") != null && d.getVersion() == null)
|
2010-12-21 14:25:37 +00:00
|
|
|
+ d.setVersion("latest");
|
|
|
|
+ else
|
|
|
|
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: Extensions like Flex Mojos use custom scopes like "merged", "internal", "external", etc.
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -433,7 +437,11 @@ public class DefaultModelValidator
|
2010-12-21 14:25:37 +00:00
|
|
|
{
|
|
|
|
validateEffectiveDependency( problems, d, false, prefix, request );
|
|
|
|
|
|
|
|
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
|
2011-02-10 10:57:07 +00:00
|
|
|
+ // in local mode set version to "latest" and validate
|
|
|
|
+ if(System.getProperty("maven.local.mode") != null && d.getVersion() == null)
|
2010-12-21 14:25:37 +00:00
|
|
|
+ d.setVersion("latest");
|
|
|
|
+ else
|
|
|
|
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
|
|
|
|
|
|
|
|
validateEnum( prefix + "scope", problems, errOn30, d.getScope(), d.getManagementKey(), d, "compile",
|
|
|
|
"runtime", "system" );
|
2011-01-11 15:40:20 +00:00
|
|
|
@@ -452,7 +460,9 @@ public class DefaultModelValidator
|
2010-12-21 14:25:37 +00:00
|
|
|
{
|
|
|
|
validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d );
|
|
|
|
|
|
|
|
- validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
|
2011-02-10 10:57:07 +00:00
|
|
|
+ // in local mode ignore missing version completely
|
|
|
|
+ if(System.getProperty("maven.local.mode") == null)
|
2010-12-21 14:25:37 +00:00
|
|
|
+ validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
|
|
|
|
d );
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2011-01-11 15:40:20 +00:00
|
|
|
1.7.3.4
|
2010-12-21 14:25:37 +00:00
|
|
|
|