From 664eea9e415707c40571bfc5462a6cb9af5fd7f4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 4 Aug 2012 06:56:52 +0000 Subject: [PATCH] dependency tree with aether move beans to a separate new module to be able to reuse beans git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1369269 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-base/archiva-maven2-model/pom.xml | 64 ++++ .../archiva/maven2}/model/Artifact.java | 203 ++++++++++- .../archiva/maven2}/model/TreeEntry.java | 30 +- archiva-modules/archiva-base/pom.xml | 1 + .../archiva-rest/archiva-rest-api/pom.xml | 5 + .../api/model/ArtifactTransferRequest.java | 2 + .../rest/api/services/BrowseService.java | 4 +- .../api/services/RepositoriesService.java | 2 +- .../rest/api/services/SearchService.java | 2 +- .../archiva-rest-services/pom.xml | 6 + .../rest/services/AbstractRestService.java | 2 +- .../rest/services/DefaultBrowseService.java | 25 +- .../services/DefaultRepositoriesService.java | 2 +- .../rest/services/DefaultSearchService.java | 2 +- .../utils/ArtifactDownloadInfoBuilder.java | 2 +- .../rest/services/BrowseServiceTest.java | 2 +- .../services/RepositoriesServiceTest.java | 2 +- .../rest/services/SearchServiceTest.java | 2 +- .../web/action/DeleteArtifactAction.java | 2 +- .../web/action/ShowArtifactAction.java | 2 +- .../archiva/DownloadMergedIndexTest.java | 2 +- .../web/action/ShowArtifactActionTest.java | 2 +- .../plugins/maven2-repository/pom.xml | 33 +- .../maven2/Maven3DependencyTreeBuilder.java | 15 +- .../maven2}/TreeDependencyNodeVisitor.java | 44 +-- .../maven2/DependencyTreeBuilderTest.java | 2 + .../DependencyTreeBuilderTestMaven3.java | 338 ++---------------- pom.xml | 5 + 28 files changed, 399 insertions(+), 404 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-maven2-model/pom.xml rename archiva-modules/{archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api => archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2}/model/Artifact.java (58%) rename archiva-modules/{archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api => archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2}/model/TreeEntry.java (76%) rename archiva-modules/{archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils => plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2}/TreeDependencyNodeVisitor.java (56%) diff --git a/archiva-modules/archiva-base/archiva-maven2-model/pom.xml b/archiva-modules/archiva-base/archiva-maven2-model/pom.xml new file mode 100644 index 000000000..aa24b0b04 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-maven2-model/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.archiva + archiva-base + 1.4-M3-SNAPSHOT + + + archiva-maven2-model + 1.4-M3-SNAPSHOT + bundle + + Archiva Base :: Maven 2 Model + + + + org.codehaus.jackson + jackson-core-asl + + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.archiva.maven2.model + ${project.version} + + javax.xml.bind.annotation, + org.codehaus.jackson.annotate, + + + org.apache.archiva.maven2.model*;version=${project.version} + + + + + + + + diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java b/archiva-modules/archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2/model/Artifact.java similarity index 58% rename from archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java rename to archiva-modules/archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2/model/Artifact.java index 3baa0ce0a..cf010b309 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java +++ b/archiva-modules/archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2/model/Artifact.java @@ -1,4 +1,4 @@ -package org.apache.archiva.rest.api.model; +package org.apache.archiva.maven2.model; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -136,6 +136,7 @@ public class Artifact /** * human readable size : not available for all services + * * @since 1.4-M3 */ private String size; @@ -153,10 +154,16 @@ public class Artifact /** * concat of artifactId+'-'+version+'.'+type + * * @since 1.4-M3 */ private String id; + /** + * @since 1.4-M3 + */ + private String scope; + public Artifact() { @@ -170,6 +177,25 @@ public class Artifact this.version = version; } + /** + * @since 1.4-M3 + */ + public Artifact( String groupId, String artifactId, String version, String scope ) + { + this( groupId, artifactId, version ); + this.scope = scope; + } + + /** + * @since 1.4-M3 + */ + public Artifact( String groupId, String artifactId, String version, String scope, String classifier ) + { + this( groupId, artifactId, version ); + this.scope = scope; + this.classifier = classifier; + } + public String getGroupId() { return groupId; @@ -421,6 +447,16 @@ public class Artifact this.id = id; } + public String getScope() + { + return scope; + } + + public void setScope( String scope ) + { + this.scope = scope; + } + @Override public String toString() { @@ -455,4 +491,169 @@ public class Artifact return sb.toString(); } + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( !( o instanceof Artifact ) ) + { + return false; + } + + Artifact artifact = (Artifact) o; + + if ( !artifactId.equals( artifact.artifactId ) ) + { + return false; + } + if ( bundleDescription != null + ? !bundleDescription.equals( artifact.bundleDescription ) + : artifact.bundleDescription != null ) + { + return false; + } + if ( bundleDocUrl != null ? !bundleDocUrl.equals( artifact.bundleDocUrl ) : artifact.bundleDocUrl != null ) + { + return false; + } + if ( bundleExportPackage != null + ? !bundleExportPackage.equals( artifact.bundleExportPackage ) + : artifact.bundleExportPackage != null ) + { + return false; + } + if ( bundleExportService != null + ? !bundleExportService.equals( artifact.bundleExportService ) + : artifact.bundleExportService != null ) + { + return false; + } + if ( bundleImportPackage != null + ? !bundleImportPackage.equals( artifact.bundleImportPackage ) + : artifact.bundleImportPackage != null ) + { + return false; + } + if ( bundleLicense != null ? !bundleLicense.equals( artifact.bundleLicense ) : artifact.bundleLicense != null ) + { + return false; + } + if ( bundleName != null ? !bundleName.equals( artifact.bundleName ) : artifact.bundleName != null ) + { + return false; + } + if ( bundleRequireBundle != null + ? !bundleRequireBundle.equals( artifact.bundleRequireBundle ) + : artifact.bundleRequireBundle != null ) + { + return false; + } + if ( bundleSymbolicName != null + ? !bundleSymbolicName.equals( artifact.bundleSymbolicName ) + : artifact.bundleSymbolicName != null ) + { + return false; + } + if ( bundleVersion != null ? !bundleVersion.equals( artifact.bundleVersion ) : artifact.bundleVersion != null ) + { + return false; + } + if ( classifier != null ? !classifier.equals( artifact.classifier ) : artifact.classifier != null ) + { + return false; + } + if ( context != null ? !context.equals( artifact.context ) : artifact.context != null ) + { + return false; + } + if ( fileExtension != null ? !fileExtension.equals( artifact.fileExtension ) : artifact.fileExtension != null ) + { + return false; + } + if ( goals != null ? !goals.equals( artifact.goals ) : artifact.goals != null ) + { + return false; + } + if ( !groupId.equals( artifact.groupId ) ) + { + return false; + } + if ( id != null ? !id.equals( artifact.id ) : artifact.id != null ) + { + return false; + } + if ( packaging != null ? !packaging.equals( artifact.packaging ) : artifact.packaging != null ) + { + return false; + } + if ( path != null ? !path.equals( artifact.path ) : artifact.path != null ) + { + return false; + } + if ( prefix != null ? !prefix.equals( artifact.prefix ) : artifact.prefix != null ) + { + return false; + } + if ( repositoryId != null ? !repositoryId.equals( artifact.repositoryId ) : artifact.repositoryId != null ) + { + return false; + } + if ( scope != null ? !scope.equals( artifact.scope ) : artifact.scope != null ) + { + return false; + } + if ( size != null ? !size.equals( artifact.size ) : artifact.size != null ) + { + return false; + } + if ( type != null ? !type.equals( artifact.type ) : artifact.type != null ) + { + return false; + } + if ( url != null ? !url.equals( artifact.url ) : artifact.url != null ) + { + return false; + } + if ( !version.equals( artifact.version ) ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = context != null ? context.hashCode() : 0; + result = 31 * result + ( url != null ? url.hashCode() : 0 ); + result = 31 * result + groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); + result = 31 * result + ( repositoryId != null ? repositoryId.hashCode() : 0 ); + result = 31 * result + version.hashCode(); + result = 31 * result + ( prefix != null ? prefix.hashCode() : 0 ); + result = 31 * result + ( goals != null ? goals.hashCode() : 0 ); + result = 31 * result + ( bundleVersion != null ? bundleVersion.hashCode() : 0 ); + result = 31 * result + ( bundleSymbolicName != null ? bundleSymbolicName.hashCode() : 0 ); + result = 31 * result + ( bundleExportPackage != null ? bundleExportPackage.hashCode() : 0 ); + result = 31 * result + ( bundleExportService != null ? bundleExportService.hashCode() : 0 ); + result = 31 * result + ( bundleDescription != null ? bundleDescription.hashCode() : 0 ); + result = 31 * result + ( bundleName != null ? bundleName.hashCode() : 0 ); + result = 31 * result + ( bundleLicense != null ? bundleLicense.hashCode() : 0 ); + result = 31 * result + ( bundleDocUrl != null ? bundleDocUrl.hashCode() : 0 ); + result = 31 * result + ( bundleImportPackage != null ? bundleImportPackage.hashCode() : 0 ); + result = 31 * result + ( bundleRequireBundle != null ? bundleRequireBundle.hashCode() : 0 ); + result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); + result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 ); + result = 31 * result + ( fileExtension != null ? fileExtension.hashCode() : 0 ); + result = 31 * result + ( size != null ? size.hashCode() : 0 ); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + result = 31 * result + ( path != null ? path.hashCode() : 0 ); + result = 31 * result + ( id != null ? id.hashCode() : 0 ); + result = 31 * result + ( scope != null ? scope.hashCode() : 0 ); + return result; + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java b/archiva-modules/archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2/model/TreeEntry.java similarity index 76% rename from archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java rename to archiva-modules/archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2/model/TreeEntry.java index 0ac2713af..9cf4d9a06 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java +++ b/archiva-modules/archiva-base/archiva-maven2-model/src/main/java/org/apache/archiva/maven2/model/TreeEntry.java @@ -1,4 +1,4 @@ -package org.apache.archiva.rest.api.model; +package org.apache.archiva.maven2.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -82,4 +82,32 @@ public class TreeEntry { this.parent = parent; } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( !( o instanceof TreeEntry ) ) + { + return false; + } + + TreeEntry treeEntry = (TreeEntry) o; + + if ( artifact != null ? !artifact.equals( treeEntry.artifact ) : treeEntry.artifact != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + return artifact != null ? artifact.hashCode() : 0; + } } diff --git a/archiva-modules/archiva-base/pom.xml b/archiva-modules/archiva-base/pom.xml index 364bb0132..230f97828 100644 --- a/archiva-modules/archiva-base/pom.xml +++ b/archiva-modules/archiva-base/pom.xml @@ -49,5 +49,6 @@ archiva-repository-admin archiva-security-common archiva-maven2-metadata + archiva-maven2-model \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml index fc0d99471..405c90107 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml @@ -50,6 +50,11 @@ metadata-model + + org.apache.archiva + archiva-maven2-model + + org.apache.archiva archiva-repository-scanner diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactTransferRequest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactTransferRequest.java index 4bb367f46..6385cba4e 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactTransferRequest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactTransferRequest.java @@ -18,6 +18,8 @@ package org.apache.archiva.rest.api.model; * under the License. */ +import org.apache.archiva.maven2.model.Artifact; + import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java index 539a4f135..d5584ff15 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java @@ -21,12 +21,12 @@ package org.apache.archiva.rest.api.services; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.redback.authorization.RedbackAuthorization; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactContent; import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.Entry; -import org.apache.archiva.rest.api.model.TreeEntry; +import org.apache.archiva.maven2.model.TreeEntry; import org.apache.archiva.rest.api.model.VersionsList; import javax.ws.rs.DELETE; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java index 406322e3a..a35ec80c6 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java @@ -21,7 +21,7 @@ package org.apache.archiva.rest.api.services; import org.apache.archiva.redback.authorization.RedbackAuthorization; import org.apache.archiva.repository.scanner.RepositoryScanStatistics; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactTransferRequest; import org.apache.archiva.security.common.ArchivaRoleConstants; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java index c17448f3b..d48002949 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java @@ -20,7 +20,7 @@ package org.apache.archiva.rest.api.services; */ -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.GroupIdList; import org.apache.archiva.rest.api.model.SearchRequest; import org.apache.archiva.rest.api.model.StringList; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml index 9d054b565..d584e4fb2 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml @@ -85,6 +85,12 @@ org.apache.archiva archiva-repository-scanner + + + org.apache.archiva + archiva-maven2-model + + org.apache.archiva.redback redback-authorization-api diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index 0a031ed95..38858ec0c 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -30,7 +30,7 @@ import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal import org.apache.archiva.redback.rest.services.RedbackRequestInformation; import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.UserManager; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.security.AccessDeniedException; import org.apache.archiva.security.ArchivaSecurityException; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 061f8e87f..ff075ee2e 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -22,6 +22,8 @@ import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder; import org.apache.archiva.dependency.tree.maven2.Maven3DependencyTreeBuilder; +import org.apache.archiva.maven2.model.Artifact; +import org.apache.archiva.maven2.model.TreeEntry; import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.MetadataFacet; @@ -39,19 +41,16 @@ import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; -import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactContent; import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.BrowseResultEntry; import org.apache.archiva.rest.api.model.Entry; -import org.apache.archiva.rest.api.model.TreeEntry; import org.apache.archiva.rest.api.model.VersionsList; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.BrowseService; import org.apache.archiva.rest.services.utils.ArtifactContentEntryComparator; import org.apache.archiva.rest.services.utils.ArtifactDownloadInfoBuilder; -import org.apache.archiva.rest.services.utils.TreeDependencyNodeVisitor; import org.apache.archiva.security.ArchivaSecurityException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; @@ -427,25 +426,10 @@ public class DefaultBrowseService { List selectedRepos = getSelectedRepos( repositoryId ); - List treeEntries = new ArrayList(); - TreeDependencyNodeVisitor treeDependencyNodeVisitor = new TreeDependencyNodeVisitor( treeEntries ); - /* - try - { - dependencyTreeBuilder.buildDependencyTree( selectedRepos, groupId, artifactId, version, - treeDependencyNodeVisitor ); - } - catch ( DependencyTreeBuilderException e ) - { - throw new ArchivaRestServiceException( e.getMessage(), - Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); - } - */ try { - maven3DependencyTreeBuilder.buildDependencyTree( selectedRepos, groupId, artifactId, version, - treeDependencyNodeVisitor ); + return maven3DependencyTreeBuilder.buildDependencyTree( selectedRepos, groupId, artifactId, version ); } catch ( Exception e ) @@ -453,8 +437,7 @@ public class DefaultBrowseService log.error( e.getMessage(), e ); } - log.debug( "treeEntrie: {}", treeEntries ); - return treeEntries; + return Collections.emptyList(); } public List getUserRepositories() diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index 333912f1d..99dc202b9 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -61,7 +61,7 @@ import org.apache.archiva.repository.metadata.RepositoryMetadataWriter; import org.apache.archiva.repository.scanner.RepositoryScanStatistics; import org.apache.archiva.repository.scanner.RepositoryScanner; import org.apache.archiva.repository.scanner.RepositoryScannerException; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactTransferRequest; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.RepositoriesService; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index d33985117..ee2ce4cc3 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -26,7 +26,7 @@ import org.apache.archiva.indexer.search.SearchFields; import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResults; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.Dependency; import org.apache.archiva.rest.api.model.GroupIdList; import org.apache.archiva.rest.api.model.SearchRequest; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java index b569ac8e0..8e29e1d2a 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java @@ -22,7 +22,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.commons.io.FilenameUtils; import java.io.File; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java index 4f9c68ab5..825856f52 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java @@ -19,7 +19,7 @@ package org.apache.archiva.rest.services; */ import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.BrowseResultEntry; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java index 5198d6376..b784b29f4 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java @@ -21,7 +21,7 @@ package org.apache.archiva.rest.services; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.FileUtil; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.BrowseResultEntry; import org.apache.archiva.rest.api.model.VersionsList; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java index c3a9cbc01..241d6900d 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java @@ -19,7 +19,7 @@ package org.apache.archiva.rest.services; */ import org.apache.archiva.admin.model.beans.UiConfiguration; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.SearchRequest; import org.apache.archiva.rest.api.services.SearchService; import org.fest.assertions.api.Assertions; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java index e836727b8..cdf446c52 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java @@ -25,7 +25,7 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.audit.Auditable; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.common.utils.VersionUtil; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.RepositoriesService; import org.apache.archiva.security.AccessDeniedException; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/ShowArtifactAction.java index 5e09669e9..bbc6bf2fb 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/ShowArtifactAction.java @@ -37,7 +37,7 @@ import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.services.utils.ArtifactDownloadInfoBuilder; import org.apache.commons.lang.StringUtils; import org.springframework.context.annotation.Scope; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java index 234df6903..118ff0dc8 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java @@ -22,7 +22,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.beans.RepositoryGroup; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.SearchRequest; import org.apache.archiva.rest.api.services.ManagedRepositoriesService; import org.apache.archiva.rest.api.services.ProxyConnectorService; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/ShowArtifactActionTest.java index a2368ccb0..584e198c6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/ShowArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/ShowArtifactActionTest.java @@ -29,7 +29,7 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.rest.api.model.Artifact; +import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.webtest.memory.TestMetadataResolver; import org.apache.archiva.webtest.memory.TestRepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml index 9409084a9..3046a3ecd 100644 --- a/archiva-modules/plugins/maven2-repository/pom.xml +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -123,10 +123,28 @@ org.apache.archiva archiva-configuration + + org.apache.archiva + archiva-maven2-model + org.apache.maven.wagon wagon-provider-api + + net.sf.beanlib + beanlib + + + cglib + cglib + + + aopalliance + aopalliance + + + org.apache.maven.wagon wagon-http @@ -164,20 +182,11 @@ test - net.sf.beanlib - beanlib + org.easytesting + fest-assert-core test - - - cglib - cglib - - - aopalliance - aopalliance - - + 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 023fe50ba..1e03b7dfb 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 @@ -30,6 +30,7 @@ import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; +import org.apache.archiva.maven2.model.TreeEntry; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.proxy.common.WagonFactory; import org.apache.maven.artifact.Artifact; @@ -67,6 +68,7 @@ import javax.inject.Inject; import javax.inject.Named; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -120,8 +122,8 @@ public class Maven3DependencyTreeBuilder builder = defaultModelBuilderFactory.newInstance(); } - public void buildDependencyTree( List repositoryIds, String groupId, String artifactId, String version, - DependencyVisitor dependencyVisitor ) + public List buildDependencyTree( List repositoryIds, String groupId, String artifactId, + String version ) throws Exception { Artifact projectArtifact = factory.createProjectArtifact( groupId, artifactId, version ); @@ -139,7 +141,7 @@ public class Maven3DependencyTreeBuilder if ( repository == null ) { // metadata could not be resolved - return; + return Collections.emptyList(); } // MRM-1411 @@ -166,9 +168,14 @@ public class Maven3DependencyTreeBuilder } } + List treeEntries = new ArrayList(); + TreeDependencyNodeVisitor treeDependencyNodeVisitor = new TreeDependencyNodeVisitor( treeEntries ); + // FIXME take care of relative path - resolve( repository.getLocation(), groupId, artifactId, version, dependencyVisitor ); + resolve( repository.getLocation(), groupId, artifactId, version, treeDependencyNodeVisitor ); + log.debug( "treeEntrie: {}", treeEntries ); + return treeEntries; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java similarity index 56% rename from archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java rename to archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java index 22e4b0af2..49edbe5b2 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java @@ -1,4 +1,4 @@ -package org.apache.archiva.rest.services.utils; +package org.apache.archiva.dependency.tree.maven2; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,10 +19,9 @@ package org.apache.archiva.rest.services.utils; */ import net.sf.beanlib.provider.replicator.BeanReplicator; -import org.apache.archiva.rest.api.model.Artifact; -import org.apache.archiva.rest.api.model.TreeEntry; -import org.apache.maven.shared.dependency.tree.DependencyNode; -import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; +import org.apache.archiva.maven2.model.Artifact; +import org.apache.archiva.maven2.model.TreeEntry; +import org.sonatype.aether.graph.DependencyNode; import org.sonatype.aether.graph.DependencyVisitor; import java.util.List; @@ -32,15 +31,13 @@ import java.util.List; * @since 1.4-M3 */ public class TreeDependencyNodeVisitor - implements DependencyNodeVisitor, DependencyVisitor + implements DependencyVisitor { final List treeEntries; private TreeEntry currentEntry; - private DependencyNode firstNode; - private org.sonatype.aether.graph.DependencyNode firstDependencyNode; public TreeDependencyNodeVisitor( List treeEntries ) @@ -48,33 +45,12 @@ public class TreeDependencyNodeVisitor this.treeEntries = treeEntries; } - public boolean visit( DependencyNode node ) - { - TreeEntry entry = new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) ); - entry.setParent( currentEntry ); - currentEntry = entry; - - if ( firstNode == null ) - { - firstNode = node; - treeEntries.add( currentEntry ); - } - else - { - currentEntry.getParent().getChilds().add( currentEntry ); - } - return true; - } - - public boolean endVisit( DependencyNode node ) - { - currentEntry = currentEntry.getParent(); - return true; - } - public boolean visitEnter( org.sonatype.aether.graph.DependencyNode dependencyNode ) + public boolean visitEnter( DependencyNode dependencyNode ) { - TreeEntry entry = new TreeEntry( new BeanReplicator().replicateBean( dependencyNode.getDependency().getArtifact(), Artifact.class ) ); + TreeEntry entry = new TreeEntry( + new BeanReplicator().replicateBean( dependencyNode.getDependency().getArtifact(), Artifact.class ) ); + entry.getArtifact().setScope( dependencyNode.getDependency().getScope() ); entry.setParent( currentEntry ); currentEntry = entry; @@ -90,7 +66,7 @@ public class TreeDependencyNodeVisitor return true; } - public boolean visitLeave( org.sonatype.aether.graph.DependencyNode dependencyNode ) + public boolean visitLeave( DependencyNode dependencyNode ) { currentEntry = currentEntry.getParent(); return true; diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java index 8669f3c41..948dab0f6 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTest.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.maven2.model.TreeEntry; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.versioning.VersionRange; @@ -279,4 +280,5 @@ public class DependencyTreeBuilderTest control.verify(); } + } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java index 8af4ca7ce..edb3ca793 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java @@ -24,27 +24,20 @@ import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.maven2.model.Artifact; +import org.apache.archiva.maven2.model.TreeEntry; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; -import org.easymock.MockControl; +import org.fest.assertions.api.Assertions; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.sonatype.aether.RepositorySystem; -import org.sonatype.aether.artifact.Artifact; -import org.sonatype.aether.graph.Dependency; -import org.sonatype.aether.graph.DependencyNode; -import org.sonatype.aether.graph.DependencyVisitor; -import org.sonatype.aether.impl.internal.DefaultRepositorySystem; -import org.sonatype.aether.util.artifact.DefaultArtifact; -import org.sonatype.aether.util.graph.DefaultDependencyNode; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; import java.io.File; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.List; @RunWith( ArchivaSpringJUnit4ClassRunner.class ) @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) @@ -66,10 +59,6 @@ public class DependencyTreeBuilderTestMaven3 private static final String TEST_GROUP_ID = "org.apache.archiva"; - private DefaultRepositorySystem defaultRepositorySystem; - - - final Map nodes = new HashMap(); @Inject @Named( value = "archivaConfiguration#test" ) @@ -81,8 +70,6 @@ public class DependencyTreeBuilderTestMaven3 { super.setUp(); - defaultRepositorySystem = (DefaultRepositorySystem) plexusSisuBridge.lookup( RepositorySystem.class ); - Configuration configuration = new Configuration(); ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( TEST_REPO_ID ); @@ -96,7 +83,7 @@ public class DependencyTreeBuilderTestMaven3 private Artifact createArtifact( String groupId, String artifactId, String version ) { - return new DefaultArtifact( groupId, artifactId, "jar", version ); + return new Artifact( groupId, artifactId, version ); } private String getId( Artifact artifact ) @@ -109,321 +96,40 @@ public class DependencyTreeBuilderTestMaven3 throws Exception { - DependencyNode springContext = new DefaultDependencyNode( - new Dependency( createArtifact( "org.springframework", "spring-context", "2.5.6" ), "compile" ) ); - - //springContext.setPremanagedVersion( "2.5.5" ); - - nodes.put( getId( springContext.getDependency().getArtifact() ), springContext ); - - DependencyNode springTest = new DefaultDependencyNode( - new Dependency( createArtifact( "org.springframework", "spring-test", "2.5.5" ), "test" ) ); - - nodes.put( getId( springTest.getDependency().getArtifact() ), springTest ); - - DependencyNode plexusUtils = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus", "plexus-utils", "1.4.5" ), "compile" ) ); - - //plexusUtils.setPremanagedVersion( "1.5.1" ); - - nodes.put( getId( plexusUtils.getDependency().getArtifact() ), plexusUtils ); - - DependencyNode slf4jLog4j12 = new DefaultDependencyNode( - new Dependency( createArtifact( "org.slf4j", "slf4j-log4j12", "1.5.0" ), "runtime" ) ); - - //slf4jLog4j12.setPremanagedScope( "test" ); - - nodes.put( getId( slf4jLog4j12.getDependency().getArtifact() ), slf4jLog4j12 ); - - DependencyNode plexusLog4j = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus", "plexus-log4j-logging", "1.1-alpha-3" ), "test" ) ); - - nodes.put( getId( plexusLog4j.getDependency().getArtifact() ), plexusLog4j ); - - DependencyNode log4j = - new DefaultDependencyNode( new Dependency( createArtifact( "log4j", "log4j", "1.2.14" ), "test" ) ); - - nodes.put( getId( log4j.getDependency().getArtifact() ), log4j ); - - DependencyNode mavenArtifact = new DefaultDependencyNode( - new Dependency( createArtifact( "org.apache.maven", "maven-artifact", "2.0.8" ), "test" ) ); - - nodes.put( getId( mavenArtifact.getDependency().getArtifact() ), mavenArtifact ); - - DependencyNode mavenProject = new DefaultDependencyNode( - new Dependency( createArtifact( "org.apache.maven", "maven-project", "2.0.8" ), "test" ) ); - - nodes.put( getId( mavenProject.getDependency().getArtifact() ), mavenProject ); - - DependencyNode mavenCore = new DefaultDependencyNode( - new Dependency( createArtifact( "org.apache.maven", "maven-core", "2.0.8" ), "test" ) ); - - nodes.put( getId( mavenCore.getDependency().getArtifact() ), mavenCore ); - - DependencyNode mavenSettings = new DefaultDependencyNode( - new Dependency( createArtifact( "org.apache.maven", "maven-settings", "2.0.8" ), "test" ) ); - - nodes.put( getId( mavenSettings.getDependency().getArtifact() ), mavenSettings ); - - DependencyNode mavenModel = new DefaultDependencyNode( - new Dependency( createArtifact( "org.apache.maven", "maven-model", "2.0.8" ), "test" ) ); - - nodes.put( getId( mavenModel.getDependency().getArtifact() ), mavenModel ); - - DependencyNode plexusCommandLine = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus", "plexus-command-line", "1.0-alpha-2" ), "test" ) ); - - nodes.put( getId( plexusCommandLine.getDependency().getArtifact() ), plexusCommandLine ); - - DependencyNode plexusRegistryCommons = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus.registry", "plexus-registry-commons", "1.0-alpha-2" ), - "test" ) ); - - nodes.put( getId( plexusRegistryCommons.getDependency().getArtifact() ), plexusRegistryCommons ); - - //plexusRegistryCommons.setPremanagedVersion( "1.0-alpha-3" ); - - DependencyNode plexusRegistryApi = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus.registry", "plexus-registry-api", "1.0-alpha-2" ), - "test" ) ); - - nodes.put( getId( plexusRegistryApi.getDependency().getArtifact() ), plexusRegistryApi ); - - //plexusRegistryApi.setPremanagedVersion( "1.0-alpha-3" ); - - DependencyNode plexusSpring = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2" ), "test" ) ); - - nodes.put( getId( plexusSpring.getDependency().getArtifact() ), plexusSpring ); - - plexusSpring.getChildren().add( springContext ); - plexusSpring.getChildren().add( springTest ); - plexusSpring.getChildren().add( plexusUtils ); - plexusSpring.getChildren().add( slf4jLog4j12 ); - plexusSpring.getChildren().add( plexusLog4j ); - plexusSpring.getChildren().add( log4j ); - plexusSpring.getChildren().add( mavenArtifact ); - plexusSpring.getChildren().add( mavenProject ); - plexusSpring.getChildren().add( mavenCore ); - plexusSpring.getChildren().add( mavenSettings ); - plexusSpring.getChildren().add( mavenModel ); - plexusSpring.getChildren().add( plexusCommandLine ); - plexusSpring.getChildren().add( plexusRegistryCommons ); - plexusSpring.getChildren().add( plexusRegistryApi ); - - DependencyNode commonsLang = new DefaultDependencyNode( - new Dependency( createArtifact( "commons-lang", "commons-lang", "2.2" ), "compile" ) ); - - nodes.put( getId( commonsLang.getDependency().getArtifact() ), commonsLang ); - - DependencyNode commonsIO = new DefaultDependencyNode( - new Dependency( createArtifact( "commons-io", "commons-io", "1.4" ), "compile" ) ); - - nodes.put( getId( commonsIO.getDependency().getArtifact() ), commonsIO ); - - DependencyNode slf4j = new DefaultDependencyNode( - new Dependency( createArtifact( "org.slf4j", "slf4j-api", "1.5.0" ), "compile" ) ); - - nodes.put( getId( slf4j.getDependency().getArtifact() ), slf4j ); - - DependencyNode plexusAPI = new DefaultDependencyNode( - new Dependency( createArtifact( "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" ), - "compile" ) ); - - nodes.put( getId( plexusAPI.getDependency().getArtifact() ), plexusAPI ); - - DependencyNode xalan = - new DefaultDependencyNode( new Dependency( createArtifact( "xalan", "xalan", "2.7.0" ), "compile" ) ); - - nodes.put( getId( xalan.getDependency().getArtifact() ), xalan ); - - DependencyNode dom4j = - new TestDefaultDependencyNode( new Dependency( createArtifact( "dom4j", "dom4j", "1.6.1" ), "test" ) ); + List treeEntries = + builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID, + TEST_VERSION ); - nodes.put( getId( dom4j.getDependency().getArtifact() ), dom4j ); - - //dom4j.setFailedUpdateScope("compile"); - - DependencyNode junit = - new TestDefaultDependencyNode( new Dependency( createArtifact( "junit", "junit", "3.8.1" ), "test" ) ); - - nodes.put( getId( junit.getDependency().getArtifact() ), junit ); - - DependencyNode easymock = new TestDefaultDependencyNode( - new Dependency( createArtifact( "easymock", "easymock", "1.2_Java1.3" ), "test" ) ); - - nodes.put( getId( easymock.getDependency().getArtifact() ), easymock ); - - DependencyNode easymockExt = new TestDefaultDependencyNode( - new Dependency( createArtifact( "easymock", "easymockclassextension", "1.2" ), "test" ) ); - - nodes.put( getId( easymockExt.getDependency().getArtifact() ), easymockExt ); - - DependencyNode mainNode = new TestDefaultDependencyNode( - new Dependency( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ), "" ) ); - - nodes.put( getId( mainNode.getDependency().getArtifact() ), mainNode ); - - mainNode.getChildren().add( commonsLang ); - mainNode.getChildren().add( commonsIO ); - mainNode.getChildren().add( slf4j ); - mainNode.getChildren().add( plexusAPI ); - mainNode.getChildren().add( plexusSpring ); - mainNode.getChildren().add( xalan ); - mainNode.getChildren().add( dom4j ); - mainNode.getChildren().add( junit ); - mainNode.getChildren().add( easymock ); - mainNode.getChildren().add( easymockExt ); - - /*defaultRepositorySystem.setDependencyCollector( new DependencyCollector() - { - - public CollectResult collectDependencies( RepositorySystemSession session, CollectRequest request ) - throws DependencyCollectionException - { - CollectResult collectResult = new CollectResult( request ); - collectResult.setRoot( new DefaultDependencyNode() ); - for ( Dependency dependency : request.getDependencies() ) - { - DependencyNode node = nodes.get( getId( dependency.getArtifact() ) ); - if ( node != null ) - { - collectResult.getRoot().getChildren().add( node ); - } - } - return collectResult; - } - } ); - */ - - MockControl control = MockControl.createStrictControl( DependencyVisitor.class ); - DependencyVisitor visitor = (DependencyVisitor) control.getMock(); - - control.expectAndReturn( visitor.visitEnter( mainNode ), true ); - - control.expectAndReturn( visitor.visitEnter( commonsLang ), true ); - control.expectAndReturn( visitor.visitLeave( commonsLang ), true ); - - control.expectAndReturn( visitor.visitEnter( commonsIO ), true ); - control.expectAndReturn( visitor.visitLeave( commonsIO ), true ); - - control.expectAndReturn( visitor.visitEnter( slf4j ), true ); - control.expectAndReturn( visitor.visitLeave( slf4j ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusAPI ), true ); - control.expectAndReturn( visitor.visitLeave( plexusAPI ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusSpring ), true ); - - control.expectAndReturn( visitor.visitEnter( springContext ), true ); - control.expectAndReturn( visitor.visitLeave( springContext ), true ); - - control.expectAndReturn( visitor.visitEnter( springTest ), true ); - control.expectAndReturn( visitor.visitLeave( springTest ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusUtils ), true ); - control.expectAndReturn( visitor.visitLeave( plexusUtils ), true ); - - control.expectAndReturn( visitor.visitEnter( slf4jLog4j12 ), true ); - control.expectAndReturn( visitor.visitLeave( slf4jLog4j12 ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusLog4j ), true ); - control.expectAndReturn( visitor.visitLeave( plexusLog4j ), true ); - - control.expectAndReturn( visitor.visitEnter( log4j ), true ); - control.expectAndReturn( visitor.visitLeave( log4j ), true ); - - control.expectAndReturn( visitor.visitEnter( mavenArtifact ), true ); - control.expectAndReturn( visitor.visitLeave( mavenArtifact ), true ); - - control.expectAndReturn( visitor.visitEnter( mavenProject ), true ); - control.expectAndReturn( visitor.visitLeave( mavenProject ), true ); - - control.expectAndReturn( visitor.visitEnter( mavenCore ), true ); - control.expectAndReturn( visitor.visitLeave( mavenCore ), true ); - - control.expectAndReturn( visitor.visitEnter( mavenSettings ), true ); - control.expectAndReturn( visitor.visitLeave( mavenSettings ), true ); - - control.expectAndReturn( visitor.visitEnter( mavenModel ), true ); - control.expectAndReturn( visitor.visitLeave( mavenModel ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusCommandLine ), true ); - control.expectAndReturn( visitor.visitLeave( plexusCommandLine ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusRegistryCommons ), true ); - control.expectAndReturn( visitor.visitLeave( plexusRegistryCommons ), true ); - - control.expectAndReturn( visitor.visitEnter( plexusRegistryApi ), true ); - control.expectAndReturn( visitor.visitLeave( plexusRegistryApi ), true ); - - control.expectAndReturn( visitor.visitLeave( plexusSpring ), true ); - - control.expectAndReturn( visitor.visitEnter( xalan ), true ); - control.expectAndReturn( visitor.visitLeave( xalan ), true ); - - control.expectAndReturn( visitor.visitEnter( dom4j ), true ); - control.expectAndReturn( visitor.visitLeave( dom4j ), true ); - - control.expectAndReturn( visitor.visitEnter( junit ), true ); - control.expectAndReturn( visitor.visitLeave( junit ), true ); - - control.expectAndReturn( visitor.visitEnter( easymock ), true ); - control.expectAndReturn( visitor.visitLeave( easymock ), true ); - - control.expectAndReturn( visitor.visitEnter( easymockExt ), true ); - control.expectAndReturn( visitor.visitLeave( easymockExt ), true ); - - control.expectAndReturn( visitor.visitLeave( mainNode ), true ); - - control.replay(); - - visitor = new DependencyVisitor() - { - public boolean visitEnter( DependencyNode dependencyNode ) - { - return true; - } - - public boolean visitLeave( DependencyNode dependencyNode ) - { - return true; - } - }; - - builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID, - TEST_VERSION, visitor ); - - control.verify(); + Assertions.assertThat( treeEntries ).isNotNull().isNotEmpty().contains( + new TreeEntry( new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" ) ) ); + Assertions.assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains( + new TreeEntry( new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" ) ) ); } - public static class TestDefaultDependencyNode - extends DefaultDependencyNode + + public static class TestTreeEntry + extends TreeEntry { + Artifact a; - private TestDefaultDependencyNode( Dependency dependency ) + public TestTreeEntry( Artifact a ) { - super( dependency ); + this.a = a; } @Override public int hashCode() { - return super.hashCode(); + return this.a.hashCode(); } @Override public boolean equals( Object o ) { - DependencyNode node = (DependencyNode) o; - boolean equals = this.getDependency().getArtifact().getGroupId().equals( - node.getDependency().getArtifact().getGroupId() ) && - this.getDependency().getArtifact().getArtifactId().equals( - node.getDependency().getArtifact().getArtifactId() ) && - this.getDependency().getArtifact().getVersion().equals( - node.getDependency().getArtifact().getVersion() ); - return equals; + Artifact artifact = ( (TreeEntry) o ).getArtifact(); + return artifact.equals( this.a ); } } + } diff --git a/pom.xml b/pom.xml index 4bdb298ee..6fe773519 100644 --- a/pom.xml +++ b/pom.xml @@ -163,6 +163,11 @@ archiva-maven2-metadata ${project.version} + + org.apache.archiva + archiva-maven2-model + ${project.version} + org.apache.archiva archiva-repository-admin-api -- 2.39.5