working on MercuryRepositorySystem - oprimized Adapter

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@762576 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Gusakov 2009-04-07 00:18:23 +00:00
parent 7b079e3b04
commit 847aecea98
5 changed files with 118 additions and 18 deletions

View File

@ -67,9 +67,13 @@ END SNIPPET: ant-bootstrap -->
<property name="maven.repo.central" value="http://repository.sonatype.org/content/groups/public"/> <property name="maven.repo.central" value="http://repository.sonatype.org/content/groups/public"/>
<!-- <!--
<property name="maven.repo.central" value="http://repo1.maven.org/maven2"/> <property name="maven.repo.central" value="http://repo1.maven.org/maven2"/>
<property name="maven.repo.update.policy" value="daily"/>
<property name="maven.repo.update.policy" value="always"/>
--> -->
<property name="maven.repo.update.policy" value="daily"/> <property name="maven.repo.update.policy" value="daily"/>
<property name="maven.repo.system" value="don.t"/>
<condition property="do.not.clean.local.repo"> <condition property="do.not.clean.local.repo">
<not> <not>
<isset property="clean.local.repo"/> <isset property="clean.local.repo"/>
@ -89,6 +93,52 @@ END SNIPPET: ant-bootstrap -->
<mkdir dir="${maven.repo.local}"/> <mkdir dir="${maven.repo.local}"/>
</target> </target>
<target name="flip-default-repository" unless="do.not.flip.repository">
<replace dir="${basedir}/maven-repository/src/main/java">
<include name="**/LegacyRepositorySystem.java"/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "default" )'
value='@Component( role = RepositorySystem.class, hint = "${legacy-hint}" )'/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "legacy" )'
value='@Component( role = RepositorySystem.class, hint = "${legacy-hint}" )'/>
</replace>
<replace dir="${basedir}/maven-repository-mercury/src/main/java">
<include name="**/MercuryRepositorySystem.java"/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "mercury" )'
value='@Component( role = RepositorySystem.class, hint = "${mercury-hint}" )'/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "default" )'
value='@Component( role = RepositorySystem.class, hint = "${mercury-hint}" )'/>
</replace>
<echo>maven.repo.system is ${maven.repo.system}, flip: legacy-hint=${legacy-hint}, mercury-hint=${mercury-hint}</echo>
</target>
<target name="flip-default-repository-system" description="flips repository system impl">
<condition property="legacy-hint" value="default">
<equals arg1="${maven.repo.system}" arg2="legacy"/>
</condition>
<condition property="mercury-hint" value="mercury">
<equals arg1="${maven.repo.system}" arg2="legacy"/>
</condition>
<condition property="legacy-hint" value="legacy">
<equals arg1="${maven.repo.system}" arg2="mercury"/>
</condition>
<condition property="mercury-hint" value="default">
<equals arg1="${maven.repo.system}" arg2="mercury"/>
</condition>
<condition property="do.not.flip.repository" value="default">
<equals arg1="${maven.repo.system}" arg2="don.t"/>
</condition>
<antcall target="flip-default-repository"/>
</target>
<target name="pull" depends="init,clean-local-repo" unless="skip.pull"> <target name="pull" depends="init,clean-local-repo" unless="skip.pull">
<property name="verbose" value="false"/> <property name="verbose" value="false"/>
<!-- Pull the dependencies that Maven needs to build --> <!-- Pull the dependencies that Maven needs to build -->
@ -219,7 +269,7 @@ END SNIPPET: ant-bootstrap -->
<modello file="maven-compat/src/main/mdo/metadata.mdo"/> <modello file="maven-compat/src/main/mdo/metadata.mdo"/>
</target> </target>
<target name="compile-boot" depends="generate-sources" description="compiles the bootstrap sources"> <target name="compile-boot" depends="generate-sources,flip-default-repository-system" description="compiles the bootstrap sources">
<path id="sources"> <path id="sources">
<dirset dir="."> <dirset dir=".">
@ -253,6 +303,12 @@ END SNIPPET: ant-bootstrap -->
<arg value="install"/> <arg value="install"/>
<arg value="-Dmaven.repo.local=${maven.repo.local}"/> <arg value="-Dmaven.repo.local=${maven.repo.local}"/>
<arg value="-Dsurefire.useFile=${surefire.useFile}"/> <arg value="-Dsurefire.useFile=${surefire.useFile}"/>
<!-- <debug-the-bootstrap> -->
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=NONE"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"/>
<!-- </debug-the-bootstrap> -->
</java> </java>
</target> </target>

View File

@ -21,9 +21,14 @@ package org.apache.maven.repository.mercury;
import java.io.File; import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
@ -46,9 +51,13 @@ import org.apache.maven.repository.MetadataGraphNode;
*/ */
public class MercuryAdaptor public class MercuryAdaptor
{ {
private static Map<String, Repository> _repos = Collections.synchronizedMap( new HashMap<String, Repository>() );
public static List<Repository> toMercuryRepos( ArtifactRepository localRepository, public static List<Repository> toMercuryRepos( ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, List<ArtifactRepository> remoteRepositories,
DependencyProcessor dependencyProcessor ) DependencyProcessor dependencyProcessor
)
{ {
if ( localRepository == null && Util.isEmpty( remoteRepositories ) ) if ( localRepository == null && Util.isEmpty( remoteRepositories ) )
return null; return null;
@ -60,9 +69,25 @@ public class MercuryAdaptor
if ( localRepository != null ) if ( localRepository != null )
{ {
LocalRepositoryM2 lr = String url = localRepository.getUrl();
new LocalRepositoryM2( localRepository.getId(), new File( localRepository.getUrl() ),
dependencyProcessor ); LocalRepositoryM2 lr = (LocalRepositoryM2) _repos.get( url );
if( lr == null )
try
{
URI rootURI = new URI( url );
File localRepoDir = new File( rootURI );
lr = new LocalRepositoryM2( localRepository.getId(), localRepoDir, dependencyProcessor );
_repos.put( url, lr );
}
catch ( URISyntaxException e )
{
throw new IllegalArgumentException( e );
}
res.add( lr ); res.add( lr );
} }
@ -70,16 +95,24 @@ public class MercuryAdaptor
{ {
for ( ArtifactRepository ar : remoteRepositories ) for ( ArtifactRepository ar : remoteRepositories )
{ {
Server server; String url = ar.getUrl();
try
RemoteRepositoryM2 rr = (RemoteRepositoryM2) _repos.get( url );
if( rr == null )
{ {
server = new Server( ar.getId(), new URL( ar.getUrl() ) ); Server server;
try
{
server = new Server( ar.getId(), new URL( url ) );
}
catch ( MalformedURLException e )
{
throw new IllegalArgumentException( e );
}
rr = new RemoteRepositoryM2( server, dependencyProcessor );
_repos.put( url, rr );
} }
catch ( MalformedURLException e )
{
throw new IllegalArgumentException( e );
}
RemoteRepositoryM2 rr = new RemoteRepositoryM2( server, dependencyProcessor );
res.add( rr ); res.add( rr );
} }

View File

@ -25,6 +25,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.mercury.artifact.Artifact;
import org.apache.maven.mercury.artifact.ArtifactMetadata; import org.apache.maven.mercury.artifact.ArtifactMetadata;
import org.apache.maven.mercury.artifact.ArtifactQueryList; import org.apache.maven.mercury.artifact.ArtifactQueryList;
import org.apache.maven.mercury.artifact.ArtifactScopeEnum; import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
@ -48,7 +49,7 @@ import org.codehaus.plexus.lang.Language;
* @author Oleg Gusakov * @author Oleg Gusakov
* @version $Id$ * @version $Id$
*/ */
@Component( role = RepositorySystem.class, hint = "mercury" ) @Component( role = RepositorySystem.class, hint = "default" )
public class MercuryRepositorySystem public class MercuryRepositorySystem
extends LegacyRepositorySystem extends LegacyRepositorySystem
implements RepositorySystem implements RepositorySystem
@ -83,15 +84,25 @@ public class MercuryRepositorySystem
try try
{ {
List<ArtifactMetadata> mercuryMetadataList = org.apache.maven.artifact.Artifact mavenRootArtifact = request.getArtifact();
_mercury.resolve( repos, null, MercuryAdaptor.toMercuryMetadata( request.getArtifact() ) );
ArtifactMetadata rootMd = MercuryAdaptor.toMercuryMetadata( mavenRootArtifact );
List<ArtifactMetadata> mercuryMetadataList = _mercury.resolve( repos, null, rootMd );
List<org.apache.maven.mercury.artifact.Artifact> mercuryArtifactList = List<org.apache.maven.mercury.artifact.Artifact> mercuryArtifactList =
_mercury.read( repos, mercuryMetadataList ); _mercury.read( repos, mercuryMetadataList );
if ( !Util.isEmpty( mercuryArtifactList ) ) if ( !Util.isEmpty( mercuryArtifactList ) )
{
for ( org.apache.maven.mercury.artifact.Artifact a : mercuryArtifactList ) for ( org.apache.maven.mercury.artifact.Artifact a : mercuryArtifactList )
result.addArtifact( MercuryAdaptor.toMavenArtifact( _artifactFactory, a ) ); result.addArtifact( MercuryAdaptor.toMavenArtifact( _artifactFactory, a ) );
// maven likes the original artifact instance - fill it in
Artifact mercuryRootArtifact = mercuryArtifactList.get( 0 );
mavenRootArtifact.setFile( mercuryRootArtifact.getFile() );
}
} }
catch ( RepositoryException e ) catch ( RepositoryException e )
{ {

View File

@ -59,7 +59,7 @@ import org.codehaus.plexus.util.StringUtils;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
*/ */
@Component( role = RepositorySystem.class, hint = "default" ) @Component( role = RepositorySystem.class, hint = "legacy" )
public class LegacyRepositorySystem public class LegacyRepositorySystem
implements RepositorySystem implements RepositorySystem
{ {