From 24ee701d1daee202e799b5ca17f9dff19d398c6e Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 26 Oct 2018 22:23:45 +0200 Subject: [PATCH] Changing aether dependencies from sonatype to eclipse. Compile OK. --- .../artifact/LegacyToDefaultConverter.java | 5 +- .../common/plexusbridge/DigesterUtils.java | 79 ------------------- .../transaction/AbstractTransactionEvent.java | 4 - .../archiva/transaction/CreateFileEvent.java | 3 +- .../archiva/transaction/FileTransaction.java | 1 - .../plugins/maven2-repository/pom.xml | 22 +++++- .../ArchivaRepositoryConnectorFactory.java | 32 +++++--- .../tree/maven2/DependencyTreeBuilder.java | 2 +- .../maven2/Maven3DependencyTreeBuilder.java | 77 ++++++++++-------- .../maven2/TreeDependencyNodeVisitor.java | 7 +- .../maven2/RepositoryModelResolver.java | 22 ++++++ 11 files changed, 113 insertions(+), 141 deletions(-) delete mode 100644 archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/DigesterUtils.java diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java index 1404b0ca4..b7f152cf6 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java @@ -22,7 +22,6 @@ package org.apache.archiva.converter.artifact; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksumValidationException; import org.apache.archiva.checksum.ChecksummedFile; -import org.apache.archiva.common.plexusbridge.DigesterUtils; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; import org.apache.archiva.transaction.FileTransaction; @@ -46,8 +45,6 @@ import org.apache.maven.model.Relocation; import org.apache.maven.model.converter.ModelConverter; import org.apache.maven.model.converter.PomTranslationException; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.codehaus.plexus.digest.Digester; -import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.springframework.stereotype.Service; @@ -77,7 +74,7 @@ public class LegacyToDefaultConverter implements ArtifactConverter { /** - * {@link List}<{@link Digester} + * */ private List digesters; diff --git a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/DigesterUtils.java b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/DigesterUtils.java deleted file mode 100644 index befd7decb..000000000 --- a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/DigesterUtils.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.apache.archiva.common.plexusbridge; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.codehaus.plexus.digest.Digester; -import org.codehaus.plexus.digest.Md5Digester; -import org.codehaus.plexus.digest.Sha1Digester; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import java.util.Arrays; -import java.util.List; - -/** - * @author Olivier Lamy - * @since 1.4-M1 - */ -@Service( "digesterUtils" ) -public class DigesterUtils -{ - - private Logger log = LoggerFactory.getLogger( getClass() ); - - private List allDigesters; - - @Inject - public DigesterUtils( PlexusSisuBridge plexusSisuBridge ) - throws PlexusSisuBridgeException - { - this.allDigesters = plexusSisuBridge.lookupList( Digester.class ); - - if ( allDigesters == null || allDigesters.isEmpty() ) - { - // olamy when the TCL is not a URLClassLoader lookupList fail ! - // when using tomcat maven plugin so adding a simple hack - log.warn( "using lookupList from sisu plexus failed so build plexus Digesters manually" ); - - allDigesters = Arrays.asList( new Sha1Digester(), new Md5Digester() ); - - } - - if ( allDigesters == null || allDigesters.isEmpty() ) - { - throw new PlexusSisuBridgeException( "no way to initiliaze IndexCreator" ); - } - - log.debug( "allIndexCreators {}", allDigesters ); - - } - - public List getAllDigesters() - { - return allDigesters; - } - - public void setAllDigesters( List allDigesters ) - { - this.allDigesters = allDigesters; - } -} diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java index 0082517d8..d9c717140 100644 --- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java +++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java @@ -22,7 +22,6 @@ package org.apache.archiva.transaction; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.commons.io.FileUtils; -import org.codehaus.plexus.digest.Digester; import java.io.IOException; import java.nio.charset.Charset; @@ -51,9 +50,6 @@ public abstract class AbstractTransactionEvent private List createdFiles = new ArrayList<>(); - /** - * {@link List}<{@link Digester}> - */ private List checksumAlgorithms; protected AbstractTransactionEvent() diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java index 2be970657..038501f40 100644 --- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java +++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java @@ -20,7 +20,6 @@ package org.apache.archiva.transaction; */ import org.apache.archiva.checksum.ChecksumAlgorithm; -import org.codehaus.plexus.digest.Digester; import java.io.IOException; import java.nio.file.Files; @@ -43,7 +42,7 @@ public class CreateFileEvent * * @param content * @param destination - * @param checksumAlgorithms {@link List}<{@link Digester}> digesters to use for checksumming + * @param checksumAlgorithms digesters to use for checksumming */ public CreateFileEvent( String content, Path destination, List checksumAlgorithms ) { diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java index 1c93667ac..083318a4a 100644 --- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java +++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java @@ -20,7 +20,6 @@ package org.apache.archiva.transaction; */ import org.apache.archiva.checksum.ChecksumAlgorithm; -import org.codehaus.plexus.digest.Digester; import java.io.IOException; import java.nio.file.Path; diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml index d79a11494..a1fc76686 100644 --- a/archiva-modules/plugins/maven2-repository/pom.xml +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -100,9 +100,10 @@ org.apache.maven maven-aether-provider - ${maven3x.version} + 3.3.9 + + + org.eclipse.aether + aether-api + 0.9.0.M2 + + + + org.eclipse.aether + aether-connector-file + 0.9.0.M2 + + + + org.apache.maven.resolver + maven-resolver-impl + 1.0.3 + org.apache.archiva @@ -205,6 +224,7 @@ jaxb-api test + diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/ArchivaRepositoryConnectorFactory.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/ArchivaRepositoryConnectorFactory.java index bc08156c6..612ed5d07 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/ArchivaRepositoryConnectorFactory.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/ArchivaRepositoryConnectorFactory.java @@ -18,17 +18,18 @@ package org.apache.archiva.dependency.tree.maven2; * under the License. */ +import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.connector.file.FileRepositoryConnectorFactory; -import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.spi.connector.ArtifactDownload; -import org.sonatype.aether.spi.connector.ArtifactUpload; -import org.sonatype.aether.spi.connector.MetadataDownload; -import org.sonatype.aether.spi.connector.MetadataUpload; -import org.sonatype.aether.spi.connector.RepositoryConnector; -import org.sonatype.aether.transfer.NoRepositoryConnectorException; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.connector.file.FileRepositoryConnectorFactory; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.spi.connector.ArtifactDownload; +import org.eclipse.aether.spi.connector.ArtifactUpload; +import org.eclipse.aether.spi.connector.MetadataDownload; +import org.eclipse.aether.spi.connector.MetadataUpload; +import org.eclipse.aether.spi.connector.RepositoryConnector; +import org.eclipse.aether.transfer.NoRepositoryConnectorException; import java.util.Collection; @@ -37,8 +38,11 @@ import java.util.Collection; * @since 1.4-M3 */ public class ArchivaRepositoryConnectorFactory - extends FileRepositoryConnectorFactory + implements RepositoryConnectorFactory { + + private FileRepositoryConnectorFactory delegate = new FileRepositoryConnectorFactory(); + public ArchivaRepositoryConnectorFactory() { // no op but empty constructor needed by aether @@ -50,7 +54,7 @@ public class ArchivaRepositoryConnectorFactory { try { - return super.newInstance( session, repository ); + return delegate.newInstance( session, repository ); } catch ( NoRepositoryConnectorException e ) { @@ -83,4 +87,10 @@ public class ArchivaRepositoryConnectorFactory } }; } + + @Override + public float getPriority( ) + { + return 0; + } } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilder.java index 1c6ad5329..9f3bb7f9a 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilder.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilder.java @@ -19,7 +19,7 @@ package org.apache.archiva.dependency.tree.maven2; */ import org.apache.archiva.maven2.model.TreeEntry; -import org.sonatype.aether.graph.DependencyVisitor; +import org.eclipse.aether.graph.DependencyVisitor; import java.util.List; diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java index a6624286d..f9e441454 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java @@ -35,37 +35,39 @@ import org.apache.archiva.maven2.metadata.MavenMetadataReader; import org.apache.archiva.maven2.model.TreeEntry; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.model.ArchivaRepositoryMetadata; -import org.apache.archiva.proxy.common.WagonFactory; import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.xml.XMLException; import org.apache.commons.lang.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.model.building.DefaultModelBuilderFactory; -import org.apache.maven.model.building.ModelBuilder; 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.MavenRepositorySystemSession; +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.impl.DefaultServiceLocator; +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.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonatype.aether.RepositorySystem; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.collection.CollectRequest; -import org.sonatype.aether.collection.CollectResult; -import org.sonatype.aether.collection.DependencyCollectionException; -import org.sonatype.aether.collection.DependencySelector; -import org.sonatype.aether.graph.Dependency; -import org.sonatype.aether.graph.DependencyVisitor; -import org.sonatype.aether.impl.ArtifactDescriptorReader; -import org.sonatype.aether.impl.VersionRangeResolver; -import org.sonatype.aether.impl.VersionResolver; -import org.sonatype.aether.impl.internal.DefaultServiceLocator; -import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager; -import org.sonatype.aether.spi.connector.RepositoryConnectorFactory; -import org.sonatype.aether.util.artifact.DefaultArtifact; -import org.sonatype.aether.util.graph.selector.AndDependencySelector; -import org.sonatype.aether.util.graph.selector.ExclusionDependencySelector; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.collection.CollectResult; +import org.eclipse.aether.collection.DependencyCollectionException; +import org.eclipse.aether.collection.DependencySelector; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.DependencyVisitor; +import org.eclipse.aether.impl.ArtifactDescriptorReader; +import org.eclipse.aether.impl.VersionRangeResolver; +import org.eclipse.aether.impl.VersionResolver; +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.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -96,9 +98,6 @@ public class Maven3DependencyTreeBuilder @Named( "repositoryPathTranslator#maven2" ) private RepositoryPathTranslator pathTranslator; - @Inject - private WagonFactory wagonFactory; - @Inject private ManagedRepositoryAdmin managedRepositoryAdmin; @@ -113,7 +112,6 @@ public class Maven3DependencyTreeBuilder private ArtifactFactory factory; - private ModelBuilder builder; @PostConstruct public void initialize() @@ -122,10 +120,11 @@ public class Maven3DependencyTreeBuilder factory = plexusSisuBridge.lookup( ArtifactFactory.class, "default" ); DefaultModelBuilderFactory defaultModelBuilderFactory = new DefaultModelBuilderFactory(); - builder = defaultModelBuilderFactory.newInstance(); + defaultModelBuilderFactory.newInstance(); } - @Override + + public void buildDependencyTree( List repositoryIds, String groupId, String artifactId, String version, DependencyVisitor dependencyVisitor ) throws DependencyTreeBuilderException @@ -229,7 +228,7 @@ public class Maven3DependencyTreeBuilder RepositorySystemSession session = newRepositorySystemSession( system, resolveRequest.localRepoDir ); - org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact( + org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact( resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version ); CollectRequest collectRequest = new CollectRequest(); @@ -238,9 +237,8 @@ public class Maven3DependencyTreeBuilder // add remote repositories for ( RemoteRepository remoteRepository : resolveRequest.remoteRepositories ) { - collectRequest.addRepository( - new org.sonatype.aether.repository.RemoteRepository( remoteRepository.getId(), "default", - remoteRepository.getUrl() ) ); + org.eclipse.aether.repository.RemoteRepository repo = new org.eclipse.aether.repository.RemoteRepository.Builder( remoteRepository.getId( ), "default", remoteRepository.getUrl( ) ).build( ); + collectRequest.addRepository(repo); } collectRequest.setRequestContext( "project" ); @@ -262,7 +260,7 @@ public class Maven3DependencyTreeBuilder private RepositorySystem newRepositorySystem() { - DefaultServiceLocator locator = new DefaultServiceLocator(); + DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator( ); locator.addService( RepositoryConnectorFactory.class, ArchivaRepositoryConnectorFactory.class );// FileRepositoryConnectorFactory.class ); locator.addService( VersionResolver.class, DefaultVersionResolver.class ); @@ -276,13 +274,22 @@ public class Maven3DependencyTreeBuilder private RepositorySystemSession newRepositorySystemSession( RepositorySystem system, String localRepoDir ) { - MavenRepositorySystemSession session = new MavenRepositorySystemSession(); + DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession( ); + + LocalRepository repo = new LocalRepository( localRepoDir ); DependencySelector depFilter = new AndDependencySelector( new ExclusionDependencySelector() ); session.setDependencySelector( depFilter ); - - session.setLocalRepositoryManager( - new SimpleLocalRepositoryManager( localRepoDir ) ); + SimpleLocalRepositoryManagerFactory repFactory = new SimpleLocalRepositoryManagerFactory( ); + try + { + LocalRepositoryManager manager = repFactory.newInstance( session, repo ); + session.setLocalRepositoryManager(manager); + } + catch ( NoLocalRepositoryManagerException e ) + { + e.printStackTrace( ); + } return session; } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java index 7dda3972d..a53ee670c 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java @@ -20,10 +20,11 @@ package org.apache.archiva.dependency.tree.maven2; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.maven2.model.TreeEntry; +import org.eclipse.aether.graph.DependencyVisitor; import org.modelmapper.ModelMapper; import org.modelmapper.convention.MatchingStrategies; -import org.sonatype.aether.graph.DependencyNode; -import org.sonatype.aether.graph.DependencyVisitor; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.graph.DependencyVisitor; import java.util.List; @@ -39,7 +40,7 @@ public class TreeDependencyNodeVisitor private TreeEntry currentEntry; - private org.sonatype.aether.graph.DependencyNode firstDependencyNode; + private org.eclipse.aether.graph.DependencyNode firstDependencyNode; public TreeDependencyNodeVisitor( List treeEntries ) { diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java index f72c22b5b..b2fd1220f 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java @@ -34,6 +34,8 @@ 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.model.Dependency; +import org.apache.maven.model.Parent; import org.apache.maven.model.Repository; import org.apache.maven.model.building.FileModelSource; import org.apache.maven.model.building.ModelSource; @@ -161,6 +163,20 @@ 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; + } + + // TODO: v3.0.0 Implement this method + @Override + public ModelSource resolveModel( Dependency dependency ) throws UnresolvableModelException + { + return null; + } + protected Path findTimeStampedSnapshotPom( String groupId, String artifactId, String version, String parentDirectory ) { @@ -211,6 +227,12 @@ public class RepositoryModelResolver // ID since they will rarely match } + @Override + public void addRepository( Repository repository, boolean b ) throws InvalidRepositoryException + { + + } + @Override public ModelResolver newCopy() {