From a309c4022d4f5b11a756c5275afae2fd774e5c77 Mon Sep 17 00:00:00 2001 From: Oleg Gusakov Date: Wed, 8 Apr 2009 22:40:24 +0000 Subject: [PATCH] switched to mercury-alpha-7-SN dependency to enable managed version maps, the lifecycle UTs pass git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@763438 13f79535-47bb-0310-9956-ffa450edef68 --- README.bootstrap.mercury.txt | 48 ++++++ build-mercury.xml | 12 +- .../maven/plugin/DefaultPluginManager.java | 4 +- maven-repository-mercury/pom.xml | 2 +- .../repository/mercury/MercuryAdaptor.java | 140 ++++++++++++++---- .../mercury/MercuryRepositorySystem.java | 104 +++++++++++-- .../repository/LegacyRepositorySystem.java | 11 +- pom.xml | 2 +- 8 files changed, 267 insertions(+), 56 deletions(-) create mode 100644 README.bootstrap.mercury.txt diff --git a/README.bootstrap.mercury.txt b/README.bootstrap.mercury.txt new file mode 100644 index 0000000000..dcb96dd0f4 --- /dev/null +++ b/README.bootstrap.mercury.txt @@ -0,0 +1,48 @@ +BOOTSTRAPPING BASICS +----------------------- + +You'll need: + +- Java 1.5 +- Ant 1.6.5 or later + +First, give Ant a location into which the completed Maven distro should be installed: + + export M2_HOME=$HOME/apps/maven/apache-maven-3.0-SNAPSHOT + +Then, run Ant: + + ant -f build-mercury.xml + +You can use additiona options on ant command line: + +-Dmaven.repo.update.policy={never|always|daily} +-Dmaven.repo.system={mercury|legacy} +-Dmaven.home=$HOME/apps/maven/apache-maven-3.0-SNAPSHOT + +if you'd like to debug the bootstrap from Eclipse, issue the following command: + +export ANT_OPTS='-Dmercury.log.level=info -Dmercury.dump.tree=../forest' +export ANT_OPTS=$ANT_OPTS' -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000' + +the additional options: +-Dmercury.log.level={info|warn|error|debug} - defines mercury verbocity +-Dmercury.dump.tree=../forest - tells mercury to spit all the resolved trees into files ../forest-xxx.xml, where xxx is a timestamp + +Then connect Eclipse debugging session to local port 8000 + +for example: + +For the first time - run the following, it will update the local repo + +export ANT_OPTS='-Dmercury.log.level=info -Dmercury.dump.tree=../forest' +export ANT_OPTS=$ANT_OPTS' -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000' +ant -f build-mercury.xml -Dmaven.repo.update.policy=always + +then you can run + +ant -f build-mercury.xml -Dmaven.repo.update.policy=never -Dmaven.repo.system=mercury + +to debug the bootstrap + + \ No newline at end of file diff --git a/build-mercury.xml b/build-mercury.xml index fa7a532ebe..1f866ce02b 100644 --- a/build-mercury.xml +++ b/build-mercury.xml @@ -173,10 +173,10 @@ END SNIPPET: ant-bootstrap --> mercury.classpath=${mc} ======================================================================== - + @@ -297,18 +297,20 @@ END SNIPPET: ant-bootstrap --> - + - + 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 f9a3ca58d2..dcb51bbdc4 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 @@ -426,10 +426,8 @@ public class DefaultPluginManager Set resolved = new LinkedHashSet(); - for ( Iterator it = result.getArtifacts().iterator(); it.hasNext(); ) + for ( Artifact artifact : result.getArtifacts() ) { - Artifact artifact = it.next(); - if ( !artifact.equals( pluginArtifact ) ) { artifact = project.replaceWithActiveArtifact( artifact ); diff --git a/maven-repository-mercury/pom.xml b/maven-repository-mercury/pom.xml index 0b3cf1f20b..2aa9a6aa1c 100644 --- a/maven-repository-mercury/pom.xml +++ b/maven-repository-mercury/pom.xml @@ -31,7 +31,7 @@ under the License. Mercury implementation for the Maven Repository System - 1.0-alpha-6-SNAPSHOT + 1.0-alpha-7-SNAPSHOT diff --git a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java index 4946c7a5c2..9599f06cb6 100644 --- a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java +++ b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java @@ -36,6 +36,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; +import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.mercury.artifact.ArtifactMetadata; import org.apache.maven.mercury.artifact.ArtifactScopeEnum; @@ -60,7 +62,7 @@ public class MercuryAdaptor private static Map _repos = Collections.synchronizedMap( new HashMap() ); public static List toMercuryRepos( ArtifactRepository localRepository, - List remoteRepositories, + List remoteRepositories, DependencyProcessor dependencyProcessor ) { @@ -99,9 +101,25 @@ public class MercuryAdaptor if ( !Util.isEmpty( remoteRepositories ) ) { - for ( ArtifactRepository ar : remoteRepositories ) + for ( Object o : remoteRepositories ) { - String url = ar.getUrl(); + String url; + String id; + + if( ArtifactRepository.class.isAssignableFrom( o.getClass() )) + { + ArtifactRepository ar = (ArtifactRepository) o; + url = ar.getUrl(); + id = ar.getId(); + } + else if( org.apache.maven.model.Repository.class.isAssignableFrom( o.getClass() )) + { + org.apache.maven.model.Repository ar = (org.apache.maven.model.Repository) o; + url = ar.getUrl(); + id = ar.getId(); + } + else + throw new IllegalArgumentException( "found illegal class in the remote repository list - " + o.getClass().getName() ); RemoteRepositoryM2 rr = (RemoteRepositoryM2) _repos.get( url ); @@ -110,7 +128,7 @@ public class MercuryAdaptor Server server; try { - server = new Server( ar.getId(), new URL( url ) ); + server = new Server( id, new URL( url ) ); } catch ( MalformedURLException e ) { @@ -134,18 +152,22 @@ public class MercuryAdaptor return res; } - public static ArtifactMetadata toMercuryBasicMetadata( Artifact a ) + private static void setInExClusion( ArtifactMetadata md, List patterns, boolean inc ) { - ArtifactMetadata md = new ArtifactMetadata(); - md.setGroupId( a.getGroupId() ); - md.setArtifactId( a.getArtifactId() ); - md.setVersion( a.getVersion() ); - md.setType( a.getType() ); - md.setScope( a.getScope() ); - - return md; + if( Util.isEmpty( patterns ) ) + return; + + List lusions = new ArrayList( patterns.size() ); + + for( String pattern : patterns ) + lusions.add( new ArtifactMetadata(pattern) ); + + if( inc ) + md.setInclusions( lusions ); + else + md.setExclusions( lusions ); } - + public static ArtifactMetadata toMercuryMetadata( Artifact a ) { ArtifactMetadata md = new ArtifactMetadata(); @@ -154,21 +176,46 @@ public class MercuryAdaptor md.setVersion( a.getVersion() ); md.setType( a.getType() ); md.setScope( a.getScope() ); - + + if( "test-jar".equals( a.getType() ) ) + { + md.setType( "jar" ); + md.setClassifier( "tests" ); + } + + ArtifactFilter af = a.getDependencyFilter(); + + if( af != null ) + { + if( ExcludesArtifactFilter.class.isAssignableFrom( af.getClass() ) ) + { + setInExClusion( md, ((ExcludesArtifactFilter)af).getPatterns(), false ); + } + else if( IncludesArtifactFilter.class.isAssignableFrom( af.getClass() ) ) + { + setInExClusion( md, ((IncludesArtifactFilter)af).getPatterns(), true ); + } + } return md; } public static Artifact toMavenArtifact( ArtifactFactory af, org.apache.maven.mercury.artifact.Artifact a ) { - Artifact ma = a.getClassifier() == null - ? af.createArtifact( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getScope(), a.getType() ) - : af.createArtifactWithClassifier( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getType(), a.getClassifier() ) + boolean isTestJar = "test-jar".equals( a.getType() ); + + String type = isTestJar ? "jar" : a.getType(); + + String classifier = isTestJar ? "tests" : a.getType(); + + Artifact ma = classifier == null + ? af.createArtifact( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getScope(), type ) + : af.createArtifactWithClassifier( a.getGroupId(), a.getArtifactId(), a.getVersion(), type, classifier ) ; ma.setScope( a.getScope() ); ma.setFile( a.getFile() ); - ma.setResolved( true ); + ma.setResolved( a.getFile() != null ); ma.setResolvedVersion( a.getVersion() ); @@ -177,9 +224,15 @@ public class MercuryAdaptor public static Artifact toMavenArtifact( ArtifactFactory af, org.apache.maven.mercury.artifact.ArtifactMetadata a ) { - Artifact ma = a.getClassifier() == null - ? af.createArtifact( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getScope(), a.getType() ) - : af.createArtifactWithClassifier( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getType(), a.getClassifier() ) + boolean isTestJar = "test-jar".equals( a.getType() ); + + String type = isTestJar ? "jar" : a.getType(); + + String classifier = isTestJar ? "tests" : a.getType(); + + Artifact ma = classifier == null + ? af.createArtifact( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getScope(), type ) + : af.createArtifactWithClassifier( a.getGroupId(), a.getArtifactId(), a.getVersion(), type, classifier ) ; ma.setScope( a.getScope() ); @@ -199,6 +252,12 @@ public class MercuryAdaptor mmd.setVersion( md.getVersion() ); mmd.setClassifier( md.getClassifier() ); mmd.setType( md.getType() ); + + if( "test-jar".equals( md.getType() ) ) + { + mmd.setType( "jar" ); + mmd.setClassifier( "tests" ); + } return mmd; } @@ -211,6 +270,12 @@ public class MercuryAdaptor mmd.setVersion( md.getVersion() ); mmd.setClassifier( md.getClassifier() ); mmd.setType( md.getType() ); + + if( "test-jar".equals( md.getType() ) ) + { + mmd.setType( "jar" ); + mmd.setClassifier( "tests" ); + } return mmd; } @@ -223,6 +288,12 @@ public class MercuryAdaptor mmd.setVersion( md.getVersion() ); mmd.setClassifier( md.getClassifier() ); mmd.setType( md.getType() ); + + if( "test-jar".equals( md.getType() ) ) + { + mmd.setType( "jar" ); + mmd.setClassifier( "tests" ); + } return mmd; } @@ -278,10 +349,10 @@ public class MercuryAdaptor scopeStr = ((ScopeArtifactFilter)filter).getScope(); } - if( "org.apache.maven.plugins:maven-remote-resources-plugin".equals( - reqArtifact.getGroupId()+":"+reqArtifact.getArtifactId() - ) - ) scopeStr = null; +// if( "org.apache.maven.plugins:maven-remote-resources-plugin".equals( +// reqArtifact.getGroupId()+":"+reqArtifact.getArtifactId() +// ) +// ) scopeStr = null; // else if( isPlugin ) // scopeStr = org.apache.maven.mercury.artifact.Artifact.SCOPE_RUNTIME; @@ -296,11 +367,28 @@ public class MercuryAdaptor return ArtifactScopeEnum.provided; else if( org.apache.maven.mercury.artifact.Artifact.SCOPE_RUNTIME.equals( scopeStr ) ) return ArtifactScopeEnum.runtime; + else if( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( scopeStr ) ) + return ArtifactScopeEnum.runtime; else if( org.apache.maven.mercury.artifact.Artifact.SCOPE_SYSTEM.equals( scopeStr ) ) return ArtifactScopeEnum.system; } return null; } + + public static Map toMercuryVersionMap(Map map ) + { + if( Util.isEmpty( map ) ) + return null; + + Map res = new HashMap( map.size() ); + + for( Entry e : map.entrySet() ) + { + res.put( e.getKey(), toMercuryMetadata( e.getValue() ) ); + } + + return res; + } } diff --git a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java index b42b65e98c..bd7f8bd322 100644 --- a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java +++ b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java @@ -19,9 +19,14 @@ under the License. package org.apache.maven.repository.mercury; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; @@ -77,6 +82,8 @@ System.out.println("mercury: request for "+request.getArtifact() if ( request.getArtifact() == null ) throw new IllegalArgumentException( LANG.getMessage( "null.request.artifact" ) ); + + Map versionMap = MercuryAdaptor.toMercuryVersionMap( (Map)request.getManagedVersionMap() ); ArtifactResolutionResult result = new ArtifactResolutionResult(); @@ -89,31 +96,90 @@ System.out.println("mercury: request for "+request.getArtifact() try { long start = System.currentTimeMillis(); - org.apache.maven.artifact.Artifact mavenRootArtifact = request.getArtifact(); - org.apache.maven.artifact.Artifact mavenPluginArtifact = mavenRootArtifact; + + org.apache.maven.artifact.Artifact rootArtifact = request.getArtifact(); - boolean isPlugin = "maven-plugin".equals( mavenRootArtifact.getType() ); + org.apache.maven.artifact.Artifact mavenPluginArtifact = rootArtifact; - ArtifactScopeEnum scope = MercuryAdaptor.extractScope( mavenRootArtifact, isPlugin, request.getFilter() ); + Set artifacts = request.getArtifactDependencies(); + + boolean isPlugin = "maven-plugin".equals( rootArtifact.getType() ); + + ArtifactScopeEnum scope = MercuryAdaptor.extractScope( rootArtifact, isPlugin, request.getFilter() ); if( isPlugin ) - mavenRootArtifact = createArtifact( mavenRootArtifact.getGroupId() - , mavenRootArtifact.getArtifactId() - , mavenRootArtifact.getVersion() - , mavenRootArtifact.getScope() + rootArtifact = createArtifact( rootArtifact.getGroupId() + , rootArtifact.getArtifactId() + , rootArtifact.getVersion() + , rootArtifact.getScope() , "jar" ); - ArtifactMetadata rootMd = MercuryAdaptor.toMercuryMetadata( mavenRootArtifact ); + ArtifactMetadata rootMd = MercuryAdaptor.toMercuryMetadata( rootArtifact ); + + org.apache.maven.artifact.Artifact root = null; + + // copied from artifact resolver + if ( request.isResolveRoot() && rootArtifact.getFile() == null && Util.isEmpty( artifacts ) ) + { + try + { + List mercuryMetadataList = new ArrayList(1); + + mercuryMetadataList.add( rootMd ); + + List mercuryArtifactList = + _mercury.read( repos, mercuryMetadataList ); + + if( Util.isEmpty( mercuryArtifactList ) ) + { + result.addErrorArtifactException( new ArtifactResolutionException( "scope="+scope, rootArtifact) ); + return result; + } + + root = isPlugin ? mavenPluginArtifact : rootArtifact; + + org.apache.maven.mercury.artifact.Artifact a = mercuryArtifactList.get( 0 ); + + root.setFile( a.getFile() ); + root.setResolved( true ); + root.setResolvedVersion( a.getVersion() ); + + result.addArtifact( rootArtifact ); + result.addRequestedArtifact( rootArtifact ); + } + catch ( Exception e ) + { + result.addMissingArtifact( request.getArtifact() ); + return result; + } + } + + if ( Util.isEmpty( artifacts ) ) + { + return result; + } - List mercuryMetadataList = _mercury.resolve( repos, scope, rootMd ); + List mercuryMetadataList = null; + + if ( Util.isEmpty( artifacts ) ) + mercuryMetadataList = _mercury.resolve( repos, scope, rootMd ); + else + { + List query = new ArrayList( artifacts.size() + 1 ); + + query.add( rootMd ); + + for( Artifact a : artifacts ) + query.add( MercuryAdaptor.toMercuryMetadata( a ) ); + + mercuryMetadataList = _mercury.resolve( repos, scope, new ArtifactQueryList(query), null, null, versionMap ); + } List mercuryArtifactList = _mercury.read( repos, mercuryMetadataList ); long diff = System.currentTimeMillis() - start; - - org.apache.maven.artifact.Artifact root = null; if ( !Util.isEmpty( mercuryArtifactList ) ) { @@ -121,26 +187,32 @@ long diff = System.currentTimeMillis() - start; { if( a.getGroupId().equals( rootMd.getGroupId() ) && a.getArtifactId().equals( rootMd.getArtifactId() ) ) { // root artifact processing - root = isPlugin ? mavenPluginArtifact : mavenRootArtifact; + root = isPlugin ? mavenPluginArtifact : rootArtifact; root.setFile( a.getFile() ); root.setResolved( true ); root.setResolvedVersion( a.getVersion() ); result.addArtifact( root ); + result.addRequestedArtifact( root ); } else { - result.addArtifact( MercuryAdaptor.toMavenArtifact( _artifactFactory, a ) ); + Artifact ma = MercuryAdaptor.toMavenArtifact( _artifactFactory, a ); + + result.addArtifact( ma ); + result.addRequestedArtifact( ma ); } } System.out.println("mercury: resolved("+diff+") "+root+"("+scope+") as file "+root.getFile() ); +//for( Artifact a: result.getArtifacts() ) +//System.out.println("mercury dependency: "+a+" as file "+a.getFile() ); } else { - result.addMissingArtifact( mavenRootArtifact ); -System.out.println("mercury: missing artifact("+diff+") "+mavenRootArtifact+"("+scope+")" ); + result.addMissingArtifact( rootArtifact ); +System.out.println("mercury: missing artifact("+diff+") "+rootArtifact+"("+scope+")" ); } } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index 249a753ce1..f1eea5e685 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -373,11 +373,14 @@ public class LegacyRepositorySystem } public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) - { - -//System.out.println("legacy: request with "+request.getRemoteRepostories().size()+" repos" ); + { + +if(request.getRemoteRepostories() != null && request.getRemoteRepostories().size() > 10 ) +{ + System.out.println("legacy: request with "+request.getRemoteRepostories().size()+" remote repositories" ); +} ArtifactResolutionResult res = artifactResolver.resolve( request ); -//System.out.println( "legacy resolved: "+request.getArtifact() ); + return res; } diff --git a/pom.xml b/pom.xml index eb21839315..22f8cad7dd 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ under the License. 1.0 1.0-beta-5 1.8 - 1.0-alpha-6-SNAPSHOT + 1.0-alpha-7-SNAPSHOT 1.0-alpha-1 1.2 3.2.6