maven/0002-Use-custom-resolver.patch

225 lines
12 KiB
Diff
Raw Normal View History

2012-01-31 13:11:08 +00:00
From 46e6dbc205065a670fa3b6e7c41e02e30b2fdb7a Mon Sep 17 00:00:00 2001
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
2012-01-31 13:11:08 +00:00
Date: Tue, 18 Jan 2011 11:09:32 +0100
Subject: [PATCH 2/5] Use custom resolver
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.
---
.../repository/internal/DefaultModelResolver.java | 9 +++++++++
.../org/apache/maven/artifact/ArtifactUtils.java | 10 ++++++++--
.../main/java/org/apache/maven/DefaultMaven.java | 7 +++++++
.../apache/maven/plugin/MavenPluginValidator.java | 5 ++++-
.../internal/DefaultPluginVersionResolver.java | 9 +++++++++
.../apache/maven/project/ProjectModelResolver.java | 9 +++++++++
.../project/artifact/MavenMetadataSource.java | 9 +++++++++
.../model/validation/DefaultModelValidator.java | 16 +++++++++++++---
8 files changed, 68 insertions(+), 6 deletions(-)
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
2012-01-31 13:11:08 +00:00
index 96b9fc3..f30bf94 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
@@ -40,6 +40,7 @@ import org.sonatype.aether.repository.RemoteRepository;
2012-01-31 13:11:08 +00:00
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;
2012-01-31 13:11:08 +00:00
/**
* A model resolver to assist building of dependency POMs. This resolver gives priority to those repositories that have
@@ -114,6 +115,14 @@ class DefaultModelResolver
2012-01-31 13:11:08 +00:00
throws UnresolvableModelException
{
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
+ if ( System.getProperty("maven.local.mode") != null) {
+ 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 );
+ }
2012-01-31 13:11:08 +00:00
try
{
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
2012-01-31 13:11:08 +00:00
index 8efc45c..df7d4e9 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
@@ -99,12 +99,18 @@ public final class ArtifactUtils
2012-01-31 13:11:08 +00:00
{
throw new NullPointerException( "artifactId is null" );
}
- if ( version == null )
+ // in local mode we ignore versions because these would only cause
+ // problems
+ if ( version == null && System.getProperty("maven.local.mode") == null )
2012-01-31 13:11:08 +00:00
{
throw new NullPointerException( "version is null" );
}
- return groupId + ":" + artifactId + ":" + version;
+ if( System.getProperty("maven.local.mode") == null ) {
+ return groupId + ":" + artifactId + ":" + version;
+ } else {
+ return versionlessKey(groupId, artifactId);
+ }
2012-01-31 13:11:08 +00:00
}
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
2012-01-31 13:11:08 +00:00
index cd944a8..7bff4a0 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -56,6 +56,7 @@ import org.apache.maven.project.ProjectBuildingException;
2012-01-31 13:11:08 +00:00
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;
2012-01-31 13:11:08 +00:00
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
import org.apache.maven.settings.Mirror;
@@ -375,6 +376,12 @@ public class DefaultMaven
session.setWorkspaceReader( workspaceRepository );
}
+ // Set our own workspace reader to resolve from /usr/share/java
+ if ( System.getProperty("maven.local.mode") != null)
+ {
+ session.setWorkspaceReader(new JavadirWorkspaceReader());
+ }
+
2012-01-31 13:11:08 +00:00
DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
decrypt.setProxies( request.getProxies() );
decrypt.setServers( request.getServers() );
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
2012-01-31 13:11:08 +00:00
index 2eb2738..28fcdd9 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
@@ -60,7 +60,10 @@ public class MavenPluginValidator
2012-01-31 13:11:08 +00:00
errors.add( "Plugin's descriptor contains the wrong artifact ID: " + pluginDescriptor.getArtifactId() );
}
- if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) )
+ // ignore incorrect version in local mode (we can have different
+ // versions in /usr/share/java
+ if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() )
+ && System.getProperty("maven.local.mode") == null)
2012-01-31 13:11:08 +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
2012-01-31 13:11:08 +00:00
index a215d28..754406a 100644
--- 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
@@ -89,6 +89,15 @@ public class DefaultPluginVersionResolver
2012-01-31 13:11:08 +00:00
throws PluginVersionResolutionException
{
logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() );
+ if (System.getProperty("maven.local.mode") != null) {
+ // in local mode we always use "latest" as a resolved version
+ // (we ignore it anyway)
+ 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;
+ }
2012-01-31 13:11:08 +00:00
PluginVersionResult result = resolveFromProject( request );
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
2012-01-31 13:11:08 +00:00
index e6cc411..bab7885 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
@@ -42,6 +42,7 @@ import org.sonatype.aether.repository.RemoteRepository;
2012-01-31 13:11:08 +00:00
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;
2012-01-31 13:11:08 +00:00
/**
* A model resolver to assist building of projects. This resolver gives priority to those repositories that have been
@@ -147,6 +148,14 @@ class ProjectModelResolver
2012-01-31 13:11:08 +00:00
if ( pomFile == null )
{
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
+ if ( System.getProperty("maven.local.mode") != null) {
+ 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 );
+ }
2012-01-31 13:11:08 +00:00
try
{
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
2012-01-31 13:11:08 +00:00
index 919f0ee..68a509d 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
@@ -325,6 +325,15 @@ public class MavenMetadataSource
2012-01-31 13:11:08 +00:00
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
+ if (dependency.getVersion() == null && System.getProperty("maven.local.mode") != null)
+ {
+ System.out.println("FIXING NULL VERSION:" + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion());
+ dependency.setVersion("1.0.0");
+ }
2012-01-31 13:11:08 +00:00
VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
Artifact dependencyArtifact =
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
2012-01-31 13:11:08 +00:00
index d7a6ac9..6c76173 100644
--- 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
2012-01-31 13:11:08 +00:00
@@ -433,7 +433,11 @@ public class DefaultModelValidator
if ( !management )
{
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
+ // in local mode set version to "latest" and validate
+ if(System.getProperty("maven.local.mode") != null && d.getVersion() == null)
+ d.setVersion("latest");
+ else
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
2012-01-31 13:11:08 +00:00
/*
* TODO: Extensions like Flex Mojos use custom scopes like "merged", "internal", "external", etc.
@@ -461,7 +465,11 @@ public class DefaultModelValidator
{
validateEffectiveDependency( problems, d, false, prefix, request );
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
+ // in local mode set version to "latest" and validate
+ if(System.getProperty("maven.local.mode") != null && d.getVersion() == null)
+ d.setVersion("latest");
+ else
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
2012-01-31 13:11:08 +00:00
validateEnum( prefix + "scope", problems, errOn30, d.getScope(), d.getManagementKey(), d, "compile",
"runtime", "system" );
@@ -480,7 +488,9 @@ public class DefaultModelValidator
{
validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d );
- validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
+ // in local mode ignore missing version completely
+ if(System.getProperty("maven.local.mode") == null)
+ validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
2012-01-31 13:11:08 +00:00
d );
}
--
2012-01-31 13:11:08 +00:00
1.7.7.6