Fixing dependencies and adapting to new lib versions

This commit is contained in:
Martin Stockhammer 2018-10-28 13:04:30 +01:00
parent 24ee701d1d
commit d39977c413
31 changed files with 431 additions and 87 deletions

View File

@ -67,5 +67,8 @@
<requiredProperty key="httpcoreVersion">
<defaultValue>${httpclient.core.version}</defaultValue>
</requiredProperty>
<requiredProperty key="asmVersion">
<defaultValue>${asm.version}</defaultValue>
</requiredProperty>
</requiredProperties>
</archetype-descriptor>

View File

@ -40,6 +40,7 @@
<mockito.version>${mockitoVersion}</mockito.version>
<httpclient.version>${httpclientVersion}</httpclient.version>
<httpclient.core.version>${httpcoreVersion}</httpclient.core.version>
<asm.version>${asmVersion}</asm.version>
</properties>
<dependencies>
<dependency>
@ -208,6 +209,12 @@
<version>${springockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- match up with those used by Archiva -->
@ -233,6 +240,11 @@
<artifactId>httpcore</artifactId>
<version>${httpclient.core.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -30,4 +30,5 @@ redbackRegistryVersion=${redback.registry.version}
springockitoVersion=${springockito.version}
mockitoVersion=${mockito.version}
httpclientVersion=${httpclient.version}
httpcoreVersion=${httpclient.core.version}
httpcoreVersion=${httpclient.core.version}
asmVersion=${asm.version}

View File

@ -179,6 +179,12 @@
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View File

@ -141,6 +141,12 @@
<artifactId>archiva-maven2-indexer</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -41,6 +41,35 @@
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-model-converter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.0</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-api</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-impl</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-util</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-checksum</artifactId>
@ -103,7 +132,7 @@
<scope>test</scope>
</dependency>
<!-- Needed for JDK >= 9 -->
<!-- START Needed for JDK >= 9 -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
@ -115,6 +144,13 @@
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
<!-- STOP Needed for JDK >= 9 -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -23,10 +23,12 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.component.annotations.Component;
/**
* @author jdcasey
*/
@Component( role = ArtifactRepositoryLayout.class, hint = "legacy")
public class LegacyRepositoryLayout
implements ArtifactRepositoryLayout
{

View File

@ -30,6 +30,7 @@ import org.apache.archiva.repository.scanner.RepositoryScanner;
import org.apache.archiva.repository.scanner.RepositoryScannerException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.springframework.stereotype.Service;
@ -53,7 +54,7 @@ public class DefaultLegacyRepositoryConverter
/**
*
*/
private ArtifactRepositoryFactory artifactRepositoryFactory;
// private ArtifactRepositoryFactory artifactRepositoryFactory;
/**
*
@ -77,7 +78,7 @@ public class DefaultLegacyRepositoryConverter
public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge )
throws PlexusSisuBridgeException
{
artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
// artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
}
@ -95,8 +96,8 @@ public class DefaultLegacyRepositoryConverter
legacyRepository.setLayout( "legacy" );
ArtifactRepository repository =
artifactRepositoryFactory.createArtifactRepository( "default", defaultRepositoryUrl, defaultLayout,
null, null );
new MavenArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null);
legacyConverterConsumer.setExcludes( fileExclusionPatterns );
legacyConverterConsumer.setDestinationRepository( repository );

View File

@ -22,11 +22,13 @@ package org.apache.archiva.converter;
import junit.framework.TestCase;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.converter.artifact.LegacyRepositoryLayout;
import org.apache.archiva.converter.legacy.LegacyRepositoryConverter;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.junit.Before;
import org.junit.Test;
@ -73,14 +75,14 @@ public class RepositoryConverterTest
{
super.setUp();
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
// ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
//(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
ArtifactRepositoryLayout layout = new LegacyRepositoryLayout();
//(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
Path sourceBase = Paths.get( "src/test/source-repository" );
sourceRepository = factory.createArtifactRepository( "source", sourceBase.toUri().toURL().toString(), layout, null,
sourceRepository = new MavenArtifactRepository( "source", sourceBase.toUri().toURL().toString(), layout, null,
null );
layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );

View File

@ -27,7 +27,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
@ -82,13 +82,13 @@ public class LegacyToDefaultConverterTest
{
super.setUp();
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
// ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
ArtifactRepositoryLayout layout = new LegacyRepositoryLayout();
Path sourceBase = getTestFile( "src/test/source-repository" );
sourceRepository =
factory.createArtifactRepository( "source", sourceBase.toUri().toURL().toString(), layout, null, null );
new MavenArtifactRepository( "source", sourceBase.toUri().toURL().toString(), layout, null, null );
layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
@ -96,7 +96,7 @@ public class LegacyToDefaultConverterTest
copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase );
targetRepository =
factory.createArtifactRepository( "target", targetBase.toUri().toURL().toString(), layout, null, null );
new MavenArtifactRepository( "target", targetBase.toUri().toURL().toString(), layout, null, null );
artifactConverter =
applicationContext.getBean( "artifactConverter#legacy-to-default", ArtifactConverter.class );
@ -919,10 +919,9 @@ public class LegacyToDefaultConverterTest
{
// test that it fails if the same
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
sourceRepository =
factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository.getLayout(), null,
new MavenArtifactRepository( "source", targetRepository.getUrl(), targetRepository.getLayout(), null,
null );
Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" );
@ -1043,12 +1042,10 @@ public class LegacyToDefaultConverterTest
private void createModernSourceRepository()
throws Exception
{
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
Path sourceBase = getTestFile( "src/test/source-modern-repository" );
sourceRepository =
factory.createArtifactRepository( "source", sourceBase.toUri().toURL().toString(), layout, null, null );
new MavenArtifactRepository( "source", sourceBase.toUri().toURL().toString(), layout, null, null );
}
}

View File

@ -242,6 +242,12 @@
<artifactId>log4j-jcl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -60,6 +60,16 @@
<artifactId>indexer-core</artifactId>
<classifier>shaded-lucene</classifier>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.codehaus.plexus</groupId>

View File

@ -19,6 +19,8 @@ package org.apache.archiva.common.plexusbridge;
* under the License.
*/
import com.google.inject.AbstractModule;
import org.apache.maven.bridge.MavenRepositorySystem;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
@ -26,11 +28,13 @@ import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.sisu.inject.TypeArguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
@ -48,6 +52,8 @@ import java.util.Map;
public class PlexusSisuBridge
{
private MavenRepositorySystem mavenRepositorySystem = new MavenRepositorySystem();
private Logger log = LoggerFactory.getLogger( getClass() );
private boolean containerAutoWiring = true;
@ -62,6 +68,16 @@ public class PlexusSisuBridge
private DefaultPlexusContainer plexusContainer;
class InternalBinder extends AbstractModule {
@Override
protected void configure( )
{
bind( MavenRepositorySystem.class ).toInstance( mavenRepositorySystem );
// bind(TypeArguments.implicitKey( MavenRepositorySystem.class )).to(MavenRepositorySystem.class);
}
}
@PostConstruct
public void initialize()
throws PlexusSisuBridgeException
@ -88,6 +104,7 @@ public class PlexusSisuBridge
for ( URL url : urls )
{
containerRealm.addURL( url );
log.debug("Added url {}", url);
}
}
@ -100,11 +117,16 @@ public class PlexusSisuBridge
try
{
Thread.currentThread().setContextClassLoader( containerRealm );
plexusContainer = new DefaultPlexusContainer( conf );
InternalBinder binder = new InternalBinder( );
plexusContainer = new DefaultPlexusContainer( conf, binder );
}
catch ( PlexusContainerException e )
{
throw new PlexusSisuBridgeException( e.getMessage(), e );
} catch (Throwable ex) {
log.error("PlexusSisuBridge initialization failed {}", ex.getMessage(), ex);
throw new PlexusSisuBridgeException( ex.getMessage(), ex );
}
finally
{

View File

@ -28,11 +28,11 @@
default-lazy-init="true">
<context:annotation-config/>
<context:component-scan base-package="org.apache.archiva.common.plexusbridge
org.apache.maven.index"/>
<context:component-scan base-package="org.apache.archiva.common.plexusbridge, org.apache.maven.*"/>
<!--
<bean id="indexer" class="org.apache.maven.index.DefaultIndexer"/>
<bean id="indexer" class="org.apache.maven.bridge.MavenRepositorySystem.apache.maven.index.DefaultIndexer"/>
<bean id="scanner" class="org.apache.maven.index.DefaultScanner"/>
<bean id="indexerEngine" class="org.apache.maven.index.DefaultIndexerEngine"/>
<bean id="searchEngine" class="org.apache.maven.index.DefaultSearchEngine"/>

View File

@ -76,7 +76,12 @@
<artifactId>archiva-test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -223,7 +223,7 @@
<scope>test</scope>
</dependency>
<!-- Needed for JDK >= 9 -->
<!-- START Needed for JDK >= 9 -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
@ -235,6 +235,14 @@
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
<!-- END Needed for JDK >= 9 -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -260,6 +260,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -137,7 +137,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -115,6 +115,12 @@
<artifactId>xercesImpl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -202,6 +202,12 @@
<artifactId>archiva-maven2-indexer</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -403,6 +403,14 @@
<artifactId>jaxb-runtime</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -31,7 +31,8 @@
<properties>
<webappDirectory>${project.build.directory}/container/webapps/archiva</webappDirectory>
<container.propertiesPortFilePath>${project.build.directory}/container-port.properties</container.propertiesPortFilePath>
<container.propertiesPortFilePath>${project.build.directory}/container-port.properties
</container.propertiesPortFilePath>
<maxWaitTimeInMs>10000</maxWaitTimeInMs>
<selenium-server.version>3.4.0</selenium-server.version>
<fluentlenium.version>3.2.0</fluentlenium.version>
@ -50,20 +51,20 @@
<artifactId>archiva-webapp</artifactId>
<type>war</type>
</dependency>
<!-- <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-slf4j-logging</artifactId>
<exclusions>
<exclusion>
<artifactId>plexus-component-api</artifactId>
<!-- <dependency>
<groupId>org.codehaus.plexus</groupId>
</exclusion>
</exclusions>
</dependency>-->
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-slf4j-logging</artifactId>
<exclusions>
<exclusion>
<artifactId>plexus-component-api</artifactId>
<groupId>org.codehaus.plexus</groupId>
</exclusion>
</exclusions>
</dependency>-->
<!--
jcr-oak currently needs guava 15.0 and selenium webdriver needs 22.0
@ -174,7 +175,6 @@
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
@ -341,8 +341,26 @@
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-slf4j-logging</artifactId>
<version>1.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
@ -811,7 +829,7 @@
<configuration>
<failOnError>false</failOnError>
<target>
<delete file="${user.home}/.m2/archiva.xml" />
<delete file="${user.home}/.m2/archiva.xml"/>
</target>
</configuration>
</execution>

View File

@ -793,6 +793,26 @@
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-slf4j-logging</artifactId>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>

View File

@ -258,7 +258,7 @@
<scope>test</scope>
</dependency>
<!-- Needed for JDK >= 9 -->
<!-- START Needed for JDK >= 9 -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
@ -270,6 +270,13 @@
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
<!-- END Needed for JDK >= 9 -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -99,8 +99,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.3.9</version>
<artifactId>maven-resolver-provider</artifactId>
</dependency>
<!--
@ -124,13 +123,11 @@
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>0.9.0.M2</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>0.9.0.M2</version>
</dependency>
<dependency>
@ -225,6 +222,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -256,6 +256,7 @@ public class Maven3DependencyTreeBuilder
}
}
private RepositorySystem newRepositorySystem()

View File

@ -75,6 +75,7 @@ import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.impl.VersionRangeResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
@ -291,7 +292,7 @@ public class Maven2RepositoryStorage
// MRM-1411
req.setModelResolver(
new RepositoryModelResolver( managedRepository, pathTranslator, wagonFactory, remoteRepositories,
networkProxies, managedRepository ) );
networkProxies, managedRepository ));
Model model;
try

View File

@ -21,6 +21,8 @@ package org.apache.archiva.metadata.repository.storage.maven2;
import org.apache.archiva.admin.model.beans.NetworkProxy;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.dependency.tree.maven2.ArchivaRepositoryConnectorFactory;
import org.apache.archiva.indexer.UnsupportedBaseContextException;
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
@ -34,6 +36,7 @@ import org.apache.archiva.repository.RepositoryCredentials;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.lang.StringUtils;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
@ -42,6 +45,10 @@ import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.resolution.InvalidRepositoryException;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
import org.apache.maven.repository.internal.DefaultVersionResolver;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
@ -50,6 +57,26 @@ import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.DependencySelector;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.impl.VersionRangeResolver;
import org.eclipse.aether.impl.VersionResolver;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager;
import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResolutionException;
import org.eclipse.aether.resolution.VersionRangeResult;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.util.graph.selector.AndDependencySelector;
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -63,6 +90,10 @@ import java.util.Map;
public class RepositoryModelResolver
implements ModelResolver
{
private RepositorySystemSession session;
private VersionRangeResolver versionRangeResolver;
private Path basedir;
private RepositoryPathTranslator pathTranslator;
@ -77,6 +108,8 @@ public class RepositoryModelResolver
private static final String METADATA_FILENAME = "maven-metadata.xml";
private DefaultServiceLocator locator;
// key/value: remote repo ID/network proxy
Map<String, NetworkProxy> networkProxyMap;
@ -91,7 +124,7 @@ public class RepositoryModelResolver
public RepositoryModelResolver( ManagedRepository managedRepository, RepositoryPathTranslator pathTranslator,
WagonFactory wagonFactory, List<RemoteRepository> remoteRepositories,
Map<String, NetworkProxy> networkProxiesMap, ManagedRepository targetRepository )
Map<String, NetworkProxy> networkProxiesMap, ManagedRepository targetRepository)
{
this( Paths.get( managedRepository.getLocation() ), pathTranslator );
@ -104,6 +137,45 @@ public class RepositoryModelResolver
this.networkProxyMap = networkProxiesMap;
this.targetRepository = targetRepository;
this.locator = MavenRepositorySystemUtils.newServiceLocator( );
locator.addService( RepositoryConnectorFactory.class,
ArchivaRepositoryConnectorFactory.class );// FileRepositoryConnectorFactory.class );
locator.addService( VersionResolver.class, DefaultVersionResolver.class );
locator.addService( VersionRangeResolver.class, DefaultVersionRangeResolver.class );
locator.addService( ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class );
this.session = newRepositorySystemSession( newRepositorySystem(), managedRepository.getLocalPath().toString() );
this.versionRangeResolver = locator.getService(VersionRangeResolver.class);
}
private RepositorySystem newRepositorySystem()
{
return locator.getService( RepositorySystem.class );
}
private RepositorySystemSession newRepositorySystemSession( RepositorySystem system, String localRepoDir )
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession( );
LocalRepository repo = new LocalRepository( localRepoDir );
DependencySelector depFilter = new AndDependencySelector( new ExclusionDependencySelector() );
session.setDependencySelector( depFilter );
SimpleLocalRepositoryManagerFactory repFactory = new SimpleLocalRepositoryManagerFactory( );
try
{
LocalRepositoryManager manager = repFactory.newInstance( session, repo );
session.setLocalRepositoryManager(manager);
}
catch ( NoLocalRepositoryManagerException e )
{
e.printStackTrace( );
}
return session;
}
@Override
@ -163,18 +235,41 @@ public class RepositoryModelResolver
return new FileModelSource( model.toFile() );
}
// TODO: v3.0.0 Implement this method
@Override
public ModelSource resolveModel( Parent parent ) throws UnresolvableModelException
{
return null;
public ModelSource resolveModel(Parent parent) throws UnresolvableModelException {
try {
Artifact artifact = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "", "pom", parent.getVersion());
VersionRangeRequest versionRangeRequest;
versionRangeRequest = new VersionRangeRequest(artifact, null, null);
VersionRangeResult versionRangeResult = this.versionRangeResolver.resolveVersionRange(this.session, versionRangeRequest);
if (versionRangeResult.getHighestVersion() == null) {
throw new UnresolvableModelException(String.format("No versions matched the requested parent version range '%s'", parent.getVersion()), parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
} else if (versionRangeResult.getVersionConstraint() != null && versionRangeResult.getVersionConstraint().getRange() != null && versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null) {
throw new UnresolvableModelException(String.format("The requested parent version range '%s' does not specify an upper bound", parent.getVersion()), parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
} else {
parent.setVersion(versionRangeResult.getHighestVersion().toString());
return this.resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
}
} catch ( VersionRangeResolutionException var5) {
throw new UnresolvableModelException(var5.getMessage(), parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), var5);
}
}
// TODO: v3.0.0 Implement this method
@Override
public ModelSource resolveModel( Dependency dependency ) throws UnresolvableModelException
{
return null;
public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException {
try {
Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "", "pom", dependency.getVersion());
VersionRangeRequest versionRangeRequest = new VersionRangeRequest(artifact, null, null);
VersionRangeResult versionRangeResult = this.versionRangeResolver.resolveVersionRange(this.session, versionRangeRequest);
if (versionRangeResult.getHighestVersion() == null) {
throw new UnresolvableModelException(String.format("No versions matched the requested dependency version range '%s'", dependency.getVersion()), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
} else if (versionRangeResult.getVersionConstraint() != null && versionRangeResult.getVersionConstraint().getRange() != null && versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null) {
throw new UnresolvableModelException(String.format("The requested dependency version range '%s' does not specify an upper bound", dependency.getVersion()), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
} else {
dependency.setVersion(versionRangeResult.getHighestVersion().toString());
return this.resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
}
} catch (VersionRangeResolutionException var5) {
throw new UnresolvableModelException(var5.getMessage(), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), var5);
}
}
protected Path findTimeStampedSnapshotPom( String groupId, String artifactId, String version,
@ -237,7 +332,7 @@ public class RepositoryModelResolver
public ModelResolver newCopy()
{
return new RepositoryModelResolver( managedRepository, pathTranslator, wagonFactory, remoteRepositories,
networkProxyMap, targetRepository );
networkProxyMap, targetRepository);
}
// FIXME: we need to do some refactoring, we cannot re-use the proxy components of archiva-proxy in maven2-repository

View File

@ -179,7 +179,14 @@
<artifactId>metrics-core</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>

View File

@ -118,6 +118,13 @@
<artifactId>xercesImpl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

86
pom.xml
View File

@ -55,8 +55,9 @@
<commons-lang.version>2.6</commons-lang.version>
<maven3x.version>3.5.4</maven3x.version>
<maven.version>2.0.8</maven.version>
<aether.version>1.13.1</aether.version>
<maven.artifact-manager.version>2.2.1</maven.artifact-manager.version>
<sonatype.aether.version>1.13.1</sonatype.aether.version>
<eclipse.aether.version>0.9.0.M2</eclipse.aether.version>
<maven-model-converter.version>2.1</maven-model-converter.version>
<maven.indexer.version>6.0.0</maven.indexer.version>
@ -89,9 +90,12 @@
<guava.version>15.0</guava.version>
<openjpaVersion>2.4.1</openjpaVersion>
<asm.version>5.0.4</asm.version>
<!-- restore when we will be able to use a derby in memory database -->
<redbackTestJdbcUrl>jdbc:derby:memory:users-test;create=true</redbackTestJdbcUrl>
<redbackTestJdbcDriver>org.apache.derby.jdbc.EmbeddedDriver</redbackTestJdbcDriver>
<sisu-inject-plexus.version>0.3.3</sisu-inject-plexus.version>
<plexus-digest.version>1.1</plexus-digest.version>
<plexus-expression-evaluator.version>2.1</plexus-expression-evaluator.version>
@ -818,6 +822,9 @@
<artifactId>mail</artifactId>
<version>${javaxMailVersion}</version>
</dependency>
<!-- Maven related dependencies -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
@ -844,12 +851,12 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
<version>${maven3x.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>${maven.version}</version>
<version>${maven.artifact-manager.version}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
@ -858,32 +865,54 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>${maven3x.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>${maven3x.version}</version>
</dependency>
<!-- Eclipse aether -->
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${eclipse.aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>${eclipse.aether.version}</version>
</dependency>
<!-- Sonatype aether -->
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${sonatype.aether.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${sonatype.aether.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${sonatype.aether.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>${sonatype.aether.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.codehaus.plexus</groupId>
@ -1561,6 +1590,15 @@
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
</dependencies>
</dependencyManagement>