From af2a929978a21ddd615ab84e3b1bb4ebe3c7f3b7 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Tue, 9 Mar 2010 04:24:32 +0000 Subject: [PATCH] [MNG-1301] remove the problem reports dependency on the repository layer, start to migrate path parsing into metadata API git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@920649 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-core-consumers/pom.xml | 11 +- .../repository/AbstractRepositoryPurge.java | 15 +- ...eanupReleasedSnapshotsRepositoryPurge.java | 16 +- .../repository/DaysOldRepositoryPurge.java | 20 +- .../repository/RepositoryPurgeConsumer.java | 14 +- .../RetentionCountRepositoryPurge.java | 14 +- .../AbstractRepositoryPurgeTest.java | 8 +- ...pReleasedSnapshotsRepositoryPurgeTest.java | 8 +- .../archiva-repository-layer/pom.xml | 10 + .../repository/content/DefaultPathParser.java | 190 ++++++---------- .../ManagedDefaultRepositoryContent.java | 14 +- .../content/DefaultPathParserTest.java | 13 ++ .../RepositoryListenerFactoryBean.java | 7 +- .../web/action/DeleteArtifactAction.java | 26 +-- .../webapp/WEB-INF/applicationContext.xml | 2 +- .../services/AdministrationServiceImpl.java | 10 +- .../AdministrationServiceImplTest.java | 14 +- .../storage/RepositoryPathTranslator.java | 7 + .../repository/events/RepositoryListener.java | 2 +- archiva-modules/metadata/pom.xml | 3 +- .../metadata/test-repository/pom.xml | 13 ++ .../com/example/invalid-artifact.txt | 1 + .../1.0-SNAPSHOT/maven-metadata.xml | 13 ++ .../1.0-SNAPSHOT/maven-metadata.xml.md5 | 1 + .../1.0-SNAPSHOT/maven-metadata.xml.sha1 | 1 + .../test-artifact-1.0-20100308.230825-1.jar | Bin 0 -> 2367 bytes ...est-artifact-1.0-20100308.230825-1.jar.md5 | 1 + ...st-artifact-1.0-20100308.230825-1.jar.sha1 | 1 + .../test-artifact-1.0-20100308.230825-1.pom | 24 ++ ...est-artifact-1.0-20100308.230825-1.pom.md5 | 1 + ...st-artifact-1.0-20100308.230825-1.pom.sha1 | 1 + .../test/test-artifact/maven-metadata.xml | 12 + .../test/test-artifact/maven-metadata.xml.md5 | 1 + .../test-artifact/maven-metadata.xml.sha1 | 1 + .../Maven2RepositoryMetadataResolver.java | 75 +++--- .../Maven2RepositoryPathTranslator.java | 147 +++++++++++- .../plugins/problem-reports/pom.xml | 55 ++++- .../RepositoryProblemEventListener.java | 4 +- .../consumers/DuplicateArtifactsConsumer.java | 90 ++++---- .../DuplicateArtifactsConsumerTest.java | 215 ++++++++++++++++++ .../reports/consumers/MockitoFactory.java | 51 +++++ .../resources/META-INF/spring-context.xml | 32 +++ pom.xml | 17 +- 43 files changed, 829 insertions(+), 332 deletions(-) rename archiva-modules/{archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events => archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/spring}/RepositoryListenerFactoryBean.java (94%) rename archiva-modules/{archiva-base/archiva-repository-layer/src/main/java/org/apache/maven => metadata/metadata-repository-api/src/main/java/org/apache}/archiva/repository/events/RepositoryListener.java (95%) create mode 100644 archiva-modules/metadata/test-repository/pom.xml create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/invalid-artifact.txt create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.md5 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.sha1 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.md5 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.sha1 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.md5 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.sha1 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.md5 create mode 100644 archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.sha1 create mode 100644 archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java create mode 100644 archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/MockitoFactory.java create mode 100644 archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml index 8984cc707..c3c302f93 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml @@ -18,7 +18,8 @@ ~ under the License. --> - + 4.0.0 org.apache.archiva @@ -42,17 +43,21 @@ org.apache.archiva archiva-repository-layer + + org.apache.archiva + metadata-repository-api + org.codehaus.plexus plexus-digest + + org.codehaus.plexus plexus-spring test - - org.slf4j slf4j-simple diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java index f0ae08c2d..9ec6c8e5a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -19,18 +19,18 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.archiva.repository.audit.AuditEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.FilenameFilter; import java.util.List; import java.util.Set; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.repository.ManagedRepositoryContent; -import org.apache.maven.archiva.repository.audit.AuditEvent; -import org.apache.maven.archiva.repository.events.RepositoryListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * Base class for all repository purge tasks. * @@ -67,6 +67,7 @@ public abstract class AbstractRepositoryPurge { File artifactFile = repository.toFile( reference ); + // TODO: looks incomplete, might not delete related metadata? for ( RepositoryListener listener : listeners ) { listener.deleteArtifact( repository.getId(), reference.getGroupId(), reference.getArtifactId(), diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index 44ca8caa1..a242e2e8c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -19,12 +19,7 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -38,11 +33,16 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** *

* This will look in a single managed repository, and purge any snapshots that are present @@ -174,7 +174,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge versionRef.setVersion( version ); repository.deleteVersion( versionRef ); - // TODO: looks incomplete, might not delete related artifacts? + // TODO: looks incomplete, might not delete related metadata? for ( RepositoryListener listener : listeners ) { listener.deleteArtifact( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java index bdca2646e..7f15d5912 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java @@ -19,6 +19,16 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.commons.lang.time.DateUtils; +import org.apache.maven.archiva.common.utils.VersionComparator; +import org.apache.maven.archiva.common.utils.VersionUtil; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.maven.archiva.repository.ContentNotFoundException; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.archiva.repository.layout.LayoutException; + import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -30,16 +40,6 @@ import java.util.List; import java.util.Set; import java.util.regex.Matcher; -import org.apache.commons.lang.time.DateUtils; -import org.apache.maven.archiva.common.utils.VersionComparator; -import org.apache.maven.archiva.common.utils.VersionUtil; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.VersionedReference; -import org.apache.maven.archiva.repository.ContentNotFoundException; -import org.apache.maven.archiva.repository.ManagedRepositoryContent; -import org.apache.maven.archiva.repository.events.RepositoryListener; -import org.apache.maven.archiva.repository.layout.LayoutException; - /** * Purge from repository all snapshots older than the specified days in the repository configuration. * diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java index c71de5ca2..bcdc5c5fa 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java @@ -19,11 +19,7 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.FileTypes; @@ -35,13 +31,17 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + /** * Consumer for removing old snapshots in the repository based on the criteria * specified by the user. @@ -94,7 +94,7 @@ public class RepositoryPurgeConsumer private boolean deleteReleasedSnapshots; - /** @plexus.requirement role="org.apache.maven.archiva.repository.events.RepositoryListener" */ + /** @plexus.requirement role="org.apache.archiva.repository.events.RepositoryListener" */ private List listeners = Collections.emptyList(); public String getId() diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java index 9ff3d44ce..d7798758c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java @@ -19,21 +19,21 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.layout.LayoutException; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + /** * Purge the repository by retention count. Retain only the specified number of snapshots. * diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index e59ee05ea..6ef310fbc 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -19,17 +19,17 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import java.io.File; -import java.io.IOException; - +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.repository.ManagedRepositoryContent; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; +import java.io.File; +import java.io.IOException; + /** */ public abstract class AbstractRepositoryPurgeTest diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index fb04112cf..01b771d46 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -19,18 +19,18 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ -import java.io.File; -import java.util.Collections; - +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.repository.RepositoryContentFactory; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.custommonkey.xmlunit.XMLAssert; import org.easymock.MockControl; +import java.io.File; +import java.util.Collections; + /** */ diff --git a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml index 041f1e919..bfc9dc68a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml +++ b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml @@ -71,6 +71,16 @@ org.apache.archiva metadata-model + + org.apache.archiva + maven2-repository + + + org.apache.archiva + problem-reports + + + diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java index 42ca3c1f9..b9e6c674a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java @@ -19,6 +19,9 @@ package org.apache.maven.archiva.repository.content; * under the License. */ +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; +import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.model.ArtifactReference; @@ -27,12 +30,16 @@ import org.apache.maven.archiva.repository.layout.LayoutException; /** * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference. * + * TODO: remove in favour of path translator, this is just delegating for the most part + * * @version $Id$ */ public class DefaultPathParser implements PathParser { private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: "; + private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(); + /** * {@inheritDoc} * @see org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String) @@ -45,133 +52,78 @@ public class DefaultPathParser implements PathParser throw new LayoutException( "Unable to convert blank path." ); } - ArtifactReference artifact = new ArtifactReference(); - - String normalizedPath = StringUtils.replace( path, "\\", "/" ); - String pathParts[] = StringUtils.split( normalizedPath, '/' ); - - /* Minimum parts. - * - * path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar" - * path[0] = "commons-lang"; // The Group ID - * path[1] = "commons-lang"; // The Artifact ID - * path[2] = "2.1"; // The Version - * path[3] = "commons-lang-2.1.jar" // The filename. - */ - - if ( pathParts.length < 4 ) + ArtifactMetadata metadata; + try { - // Illegal Path Parts Length. - throw new LayoutException( "Not enough parts to the path [" + path - + "] to construct an ArchivaArtifact from. (Requires at least 4 parts)" ); + metadata = pathTranslator.getArtifactForPath( null, path ); + } + catch ( IllegalArgumentException e ) + { + throw new LayoutException( e.getMessage(), e ); } - // Maven 2.x path. - int partCount = pathParts.length; - int filenamePos = partCount - 1; - int baseVersionPos = partCount - 2; - int artifactIdPos = partCount - 3; - int groupIdPos = partCount - 4; + ArtifactReference artifact = new ArtifactReference(); + artifact.setGroupId( metadata.getNamespace() ); + artifact.setArtifactId( metadata.getProject() ); + artifact.setVersion( metadata.getVersion() ); - // Second to last is the baseVersion (the directory version) - String baseVersion = pathParts[baseVersionPos]; - - // Third to last is the artifact Id. - artifact.setArtifactId( pathParts[artifactIdPos] ); - - // Remaining pieces are the groupId. - for ( int i = 0; i <= groupIdPos; i++ ) + // TODO: use Maven facet instead + String filename = metadata.getId(); + FilenameParser parser = new FilenameParser( filename ); + artifact.setArtifactId( parser.expect( artifact.getArtifactId() ) ); + if ( artifact.getArtifactId() == null ) { - if ( i == 0 ) + throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, " + + "should start with artifactId as stated in path." ); + } + String baseVersion = VersionUtil.getBaseVersion( metadata.getVersion() ); + artifact.setVersion( parser.expect( baseVersion ) ); + if ( artifact.getVersion() == null ) + { + // We working with a snapshot? + if ( VersionUtil.isSnapshot( baseVersion ) ) { - artifact.setGroupId( pathParts[i] ); + artifact.setVersion( parser.nextVersion() ); + if ( !VersionUtil.isUniqueSnapshot( artifact.getVersion() ) ) + { + throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid," + + "expected timestamp format in filename." ); + } } else - { - artifact.setGroupId( artifact.getGroupId() + "." + pathParts[i] ); - } - } - - try - { - // Last part is the filename - String filename = pathParts[filenamePos]; - - // Now we need to parse the filename to get the artifact version Id. - if ( StringUtils.isBlank( filename ) ) - { - throw new IllegalArgumentException( INVALID_ARTIFACT_PATH + "Unable to split blank filename." ); - } - - FilenameParser parser = new FilenameParser( filename ); - - // Expect the filename to start with the artifactId. - artifact.setArtifactId( parser.expect( artifact.getArtifactId() ) ); - - if ( artifact.getArtifactId() == null ) { throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, " - + "should start with artifactId as stated in path." ); - } - - // Process the version. - artifact.setVersion( parser.expect( baseVersion ) ); - - if ( artifact.getVersion() == null ) - { - // We working with a snapshot? - if ( VersionUtil.isSnapshot( baseVersion ) ) - { - artifact.setVersion( parser.nextVersion() ); - if ( !VersionUtil.isUniqueSnapshot( artifact.getVersion() ) ) - { - throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid," - + "expected timestamp format in filename." ); - } - } - else - { - throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, " - + "expected version as stated in path." ); - } - } - - // Do we have a classifier? - switch(parser.seperator()) - { - case '-': - // Definately a classifier. - artifact.setClassifier( parser.remaining() ); - - // Set the type. - artifact.setType( ArtifactExtensionMapping.mapExtensionAndClassifierToType( artifact.getClassifier(), parser.getExtension() ) ); - break; - case '.': - // We have an dual extension possibility. - String extension = parser.remaining() + '.' + parser.getExtension(); - artifact.setType( extension ); - break; - case 0: - // End of the filename, only a simple extension left. - Set the type. - String type = ArtifactExtensionMapping.mapExtensionToType( parser.getExtension() ); - if ( type == null ) - { - throw new LayoutException( "Invalid artifact: no type was specified" ); - } - artifact.setType( type ); - break; - } - - // Special case for maven plugins - if ( StringUtils.equals( "jar", artifact.getType() ) && - ArtifactExtensionMapping.isMavenPlugin( artifact.getArtifactId() ) ) - { - artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); + + "expected version as stated in path." ); } } - catch ( LayoutException e ) + switch(parser.seperator()) { - throw e; + case '-': + // Definately a classifier. + artifact.setClassifier( parser.remaining() ); + + // Set the type. + artifact.setType( ArtifactExtensionMapping.mapExtensionAndClassifierToType( artifact.getClassifier(), parser.getExtension() ) ); + break; + case '.': + // We have an dual extension possibility. + String extension = parser.remaining() + '.' + parser.getExtension(); + artifact.setType( extension ); + break; + case 0: + // End of the filename, only a simple extension left. - Set the type. + String type = ArtifactExtensionMapping.mapExtensionToType( parser.getExtension() ); + if ( type == null ) + { + throw new LayoutException( "Invalid artifact: no type was specified" ); + } + artifact.setType( type ); + break; + } + if ( StringUtils.equals( "jar", artifact.getType() ) && + ArtifactExtensionMapping.isMavenPlugin( artifact.getArtifactId() ) ) + { + artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); } // Sanity Checks. @@ -187,16 +139,6 @@ public class DefaultPathParser implements PathParser + filenameBaseVersion ); } } - else - { - // Non SNAPSHOT rules. - // Do we pass the simple test? - if ( !StringUtils.equals( baseVersion, artifact.getVersion() ) ) - { - throw new LayoutException( "Invalid artifact: version declared in directory path does" - + " not match what was found in the artifact filename." ); - } - } return artifact; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java index 54f9b44aa..a000748a1 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java @@ -19,11 +19,6 @@ package org.apache.maven.archiva.repository.content; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.configuration.FileTypes; @@ -36,6 +31,11 @@ import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.layout.LayoutException; +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + /** * ManagedDefaultRepositoryContent * @@ -332,9 +332,9 @@ public class ManagedDefaultRepositoryContent public ArtifactReference toArtifactReference( String path ) throws LayoutException { - if ( ( path != null ) && path.startsWith( repository.getLocation() ) ) + if ( ( path != null ) && path.startsWith( repository.getLocation() ) && repository.getLocation().length() > 0 ) { - return super.toArtifactReference( path.substring( repository.getLocation().length() ) ); + return super.toArtifactReference( path.substring( repository.getLocation().length() + 1 ) ); } return super.toArtifactReference( path ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java index e3b6d5c98..bb8fcbd38 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java @@ -195,6 +195,19 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + public void testWindowsPathSeparator() + throws LayoutException + { + String groupId = "commons-lang"; + String artifactId = "commons-lang"; + String version = "2.1"; + String classifier = null; + String type = "jar"; + String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.jar"; + + assertLayout( path, groupId, artifactId, version, classifier, type ); + } + /** * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected" */ diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events/RepositoryListenerFactoryBean.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/spring/RepositoryListenerFactoryBean.java similarity index 94% rename from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events/RepositoryListenerFactoryBean.java rename to archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/spring/RepositoryListenerFactoryBean.java index cfd48c317..582290284 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events/RepositoryListenerFactoryBean.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/spring/RepositoryListenerFactoryBean.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.repository.events; +package org.apache.archiva.web.spring; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,13 +19,14 @@ package org.apache.maven.archiva.repository.events; * under the License. */ -import java.util.List; - +import org.apache.archiva.repository.events.RepositoryListener; import org.springframework.beans.BeansException; import org.springframework.beans.factory.FactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import java.util.List; + /** * @todo though we will eventually remove this altogether, an interim cleanup would be to genericise this * and replace the calls in RepositoryContentConsumers with calls to the same thing diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java index caecd1e37..aae9ac692 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java @@ -19,23 +19,13 @@ package org.apache.maven.archiva.web.action; * under the License. */ -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -49,7 +39,6 @@ import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.audit.Auditable; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader; @@ -59,6 +48,17 @@ import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.UserRepositories; +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + /** * Delete an artifact. Metadata will be updated if one exists, otherwise it would be created. * @@ -109,7 +109,7 @@ public class DeleteArtifactAction private RepositoryContentFactory repositoryFactory; /** - * @plexus.requirement role="org.apache.maven.archiva.repository.events.RepositoryListener" + * @plexus.requirement role="org.apache.archiva.repository.events.RepositoryListener" */ private List listeners; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml index 3973bb8ac..217d366ca 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -55,7 +55,7 @@ - + diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index 9a2f51fa2..379288c11 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -19,12 +19,9 @@ package org.apache.archiva.web.xmlrpc.services; * under the License. */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; @@ -45,11 +42,14 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.codehaus.plexus.registry.RegistryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + /** * AdministrationServiceImpl * diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index 310225772..d0a3e9377 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -19,14 +19,9 @@ package org.apache.archiva.web.xmlrpc.services; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; @@ -47,12 +42,17 @@ import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent; import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent; import org.apache.maven.archiva.repository.content.PathParser; -import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.layout.LayoutException; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; import org.easymock.classextension.MockClassControl; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * AdministrationServiceImplTest * diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java index c877ec8ec..ee9358219 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java @@ -19,6 +19,8 @@ package org.apache.archiva.metadata.repository.storage; * under the License. */ +import org.apache.archiva.metadata.model.ArtifactMetadata; + import java.io.File; public interface RepositoryPathTranslator @@ -32,4 +34,9 @@ public interface RepositoryPathTranslator File toFile( File basedir, String namespace ); File toFile( File basedir, String namespace, String projectId, String projectVersion ); + + ArtifactMetadata getArtifactForPath( String repoId, String relativePath ); + + ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion, + String id ); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events/RepositoryListener.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java similarity index 95% rename from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events/RepositoryListener.java rename to archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java index 838a30985..2978d1a9b 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/events/RepositoryListener.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.repository.events; +package org.apache.archiva.repository.events; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/archiva-modules/metadata/pom.xml b/archiva-modules/metadata/pom.xml index 646612a45..fc3c88642 100644 --- a/archiva-modules/metadata/pom.xml +++ b/archiva-modules/metadata/pom.xml @@ -29,5 +29,6 @@ metadata-model metadata-repository-api + test-repository - + \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/pom.xml b/archiva-modules/metadata/test-repository/pom.xml new file mode 100644 index 000000000..2755b31ec --- /dev/null +++ b/archiva-modules/metadata/test-repository/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + metadata + org.apache.archiva + 1.4-SNAPSHOT + + test-repository + Archiva Repository for Testing + diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/invalid-artifact.txt b/archiva-modules/metadata/test-repository/src/main/resources/com/example/invalid-artifact.txt new file mode 100644 index 000000000..acfe11318 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/invalid-artifact.txt @@ -0,0 +1 @@ +invalid path diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..89f58d525 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,13 @@ + + + com.example.test + test-artifact + 1.0-SNAPSHOT + + + 20100308.230825 + 1 + + 20100308230825 + + diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.md5 new file mode 100644 index 000000000..d774a5365 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.md5 @@ -0,0 +1 @@ +7210867ac16cd955db89cfca699e7c96 \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.sha1 new file mode 100644 index 000000000..0e44079af --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +271faeb2039d026ee6a3c937375b5ff7d4b1d605 \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar new file mode 100644 index 0000000000000000000000000000000000000000..dab36c0bb0c66f497de834aa43e0c797233ad445 GIT binary patch literal 2367 zcmWIWW@h1H00G{>OdBu*N^k;cU)K;vT~9wZ{Q#&k4h9~evdJ?#wbFpnH9#zatjyQZ z&(qB{I7H9a?X&Nh(>~t1dKY=Ub+yi&Ilno`;EM5sr$stm=T7K&>pF3;KUoqsMNIpE zO2y7O-9f_MLBS<+wbqKra0^W~4ic>qJ{|NKDC1>Z>~-Lgr|U{pRe?s4*!5F#CcI3m zV*A*(Y){Od7zUWT7#P^loX-MuS8{$X+~t@mc%Uj$D-v@Ha#HcA6hu>5l3H8>SIz;p zx@Nlj-Y`Z624yA&1}SXH9SaKdl5-M^i*o}{dNDhStT|`ay}0w{9n+5@taBH)cPKPf zNQ878Xl zY_rs^<*Z3Qd|+9lZri1mJWK47Pn7fh;%V*v5NI&PRHo$< zNe#XnS>`Kq4Uagnu5S42|8_ap! z|26BnnV3mJjPxnt59#x+m$}?Js68>@Fw6hr7VoDWVszYkr~S8psnyrVWh|O5TtBTf z?#`3j&CD?`A#93f;Hl{*elCp*7Pg*Yl)TXPfIB%fM6zs2XQsC|+w@rv1e06WF87~h zIPYlsDh@d>@36mjEV-KRzP?=ceNUzG4ym0Fw>0b*mPtDq^z>sduRxBcwwEK5f1^6j z7S>}I!r6O*=6j!87AR}Wbya(r;oKLGsvG4l)Ce8EXeGGmv{S+NyE_jCTQA;K?h~}E zH>v&7zAn?JCe2JcUfveMjV#xIKai{hK)B_3xM%f3B;hX6fN0dq$Jd|0E)kYqWpqXVB$zE z4leUQ>#gghAz*C1`7V(y}#uUEs4xLu8%MoDb8E zz0ijlu%yunn|62=fb3;##TCLCCxF!nJkVf;7t9fu1&{*F1>lJKim4eR3F31Ks5pZF zP>2`<3netCV3>xQpb=(sFkma*V5To=tS8xQXkmwJ1t=uZb0ESBdsb4NkD4C?yjj^m Orf~zI0?@gfU>*Py!O#H! literal 0 HcmV?d00001 diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.md5 new file mode 100644 index 000000000..e98bc51e4 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.md5 @@ -0,0 +1 @@ +cc2236dd70af3667080a786c7dcb4a9b \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.sha1 new file mode 100644 index 000000000..2d7e3840f --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar.sha1 @@ -0,0 +1 @@ +edf5938e646956f445c6ecb719d44579cdeed974 \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom new file mode 100644 index 000000000..69a7d1689 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom @@ -0,0 +1,24 @@ + + 4.0.0 + com.example.test + test-artifact + jar + 1.0-SNAPSHOT + test-artifact + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + + test-repo + file:${basedir}/repository + + + diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.md5 new file mode 100644 index 000000000..531fc330c --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.md5 @@ -0,0 +1 @@ +ce7eeb9586dc4992dc961d9f3a28006b \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.sha1 new file mode 100644 index 000000000..c0edca2a1 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom.sha1 @@ -0,0 +1 @@ +be040c8462fd31d4e03749e3586afbb21f43594e \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml new file mode 100644 index 000000000..2678fa1dc --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml @@ -0,0 +1,12 @@ + + + com.example.test + test-artifact + 1.0-SNAPSHOT + + + 1.0-SNAPSHOT + + 20100308230825 + + diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.md5 new file mode 100644 index 000000000..3dff69b48 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.md5 @@ -0,0 +1 @@ +93afaac7340faadc7efd097952d79fa4 \ No newline at end of file diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.sha1 new file mode 100644 index 000000000..1ff7fb544 --- /dev/null +++ b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +d59d588343d61fd7d838984a0daa4aaa2546bf9d \ No newline at end of file diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java index 168e3b1b5..39dc81441 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java @@ -60,8 +60,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * @plexus.component role="org.apache.archiva.metadata.repository.storage.StorageMetadataResolver" role-hint="maven2" @@ -114,6 +112,7 @@ public class Maven2RepositoryMetadataResolver String projectVersion ) throws MetadataResolutionException { + // Remove problems associated with this version, since we'll be re-adding any that still exist // TODO: an event mechanism would remove coupling to the problem reporting plugin // TODO: this removes all problems - do we need something that just removes the problems created by this resolver? String name = RepositoryProblemFacet.createName( namespace, projectId, projectVersion, null ); @@ -490,54 +489,42 @@ public class Maven2RepositoryMetadataResolver { for ( File file : files ) { - ArtifactMetadata metadata = new ArtifactMetadata(); - metadata.setId( file.getName() ); - metadata.setProject( projectId ); - metadata.setNamespace( namespace ); - metadata.setRepositoryId( repoId ); - metadata.setWhenGathered( new Date() ); - metadata.setFileLastModified( file.lastModified() ); - ChecksummedFile checksummedFile = new ChecksummedFile( file ); - try - { - metadata.setMd5( checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 ) ); - } - catch ( IOException e ) - { - log.error( "Unable to checksum file " + file + ": " + e.getMessage() ); - } - try - { - metadata.setSha1( checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 ) ); - } - catch ( IOException e ) - { - log.error( "Unable to checksum file " + file + ": " + e.getMessage() ); - } - metadata.setSize( file.length() ); - - // TODO: very crude, migrate the functionality from the repository-layer here - if ( VersionUtil.isGenericSnapshot( projectVersion ) ) - { - String mainVersion = projectVersion.substring( 0, projectVersion.length() - - 8 ); // 8 is length of "SNAPSHOT" - Matcher m = Pattern.compile( - projectId + "-" + mainVersion + "([0-9]{8}.[0-9]{6}-[0-9]+).*" ).matcher( file.getName() ); - m.matches(); - String version = mainVersion + m.group( 1 ); - - metadata.setVersion( version ); - } - else - { - metadata.setVersion( projectVersion ); - } + ArtifactMetadata metadata = getArtifactFromFile( repoId, namespace, projectId, projectVersion, file ); artifacts.add( metadata ); } } return artifacts; } + private ArtifactMetadata getArtifactFromFile( String repoId, String namespace, String projectId, + String projectVersion, File file ) + { + ArtifactMetadata metadata = pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion, file.getName() ); + + metadata.setWhenGathered( new Date() ); + metadata.setFileLastModified( file.lastModified() ); + ChecksummedFile checksummedFile = new ChecksummedFile( file ); + try + { + metadata.setMd5( checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 ) ); + } + catch ( IOException e ) + { + log.error( "Unable to checksum file " + file + ": " + e.getMessage() ); + } + try + { + metadata.setSha1( checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 ) ); + } + catch ( IOException e ) + { + log.error( "Unable to checksum file " + file + ": " + e.getMessage() ); + } + metadata.setSize( file.length() ); + + return metadata; + } + private boolean isProject( File dir, Filter filter ) { // scan directories for a valid project version subdirectory, meaning this must be a project directory diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java index b92debbe4..acec739cf 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java @@ -1,8 +1,14 @@ package org.apache.archiva.metadata.repository.storage.maven2; -import java.io.File; - +import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.common.utils.VersionUtil; + +import java.io.File; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -113,4 +119,141 @@ public class Maven2RepositoryPathTranslator { return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); } + + private static String parseTimestampedVersionFromId( String projectId, String projectVersion, String id ) + { + String mainVersion = projectVersion.substring( 0, projectVersion.length() - 8 ); // 8 is length of "SNAPSHOT" + if ( mainVersion.length() == 0 ) + { + throw new IllegalArgumentException( + "Timestamped snapshots must contain the main version, filename was '" + id + "'" ); + } + Matcher m = Pattern.compile( projectId + "-" + mainVersion + "([0-9]{8}.[0-9]{6}-[0-9]+).*" ).matcher( id ); + m.matches(); + return mainVersion + m.group( 1 ); + } + + public ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion, + String id ) + { + ArtifactMetadata metadata = new ArtifactMetadata(); + metadata.setId( id ); + metadata.setProject( projectId ); + metadata.setNamespace( namespace ); + metadata.setRepositoryId( repoId ); + + if ( VersionUtil.isGenericSnapshot( projectVersion ) ) + { + String version = parseTimestampedVersionFromId( projectId, projectVersion, id ); + + metadata.setVersion( version ); + } + else + { + metadata.setVersion( projectVersion ); + } + return metadata; + } + + public ArtifactMetadata getArtifactForPath( String repoId, String relativePath ) + { + String[] parts = relativePath.replace( '\\', '/' ).split( "/" ); + + int len = parts.length; + if ( len < 4 ) + { + throw new IllegalArgumentException( + "Not a valid artifact path in a Maven 2 repository, not enough directories: " + relativePath ); + } + + String id = parts[--len]; + String baseVersion = parts[--len]; + String artifactId = parts[--len]; + String groupId = StringUtils.join( Arrays.copyOfRange( parts, 0, len ), '.' ); + + if ( !id.startsWith( artifactId + "-" ) ) + { + throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id + + "' doesn't start with artifact ID '" + artifactId + "'" ); + } + + int index = artifactId.length() + 1; + String version; + if ( id.substring( index ).startsWith( baseVersion ) && !VersionUtil.isUniqueSnapshot( baseVersion ) ) + { + // non-snapshot versions, or non-timestamped snapshot versions + version = baseVersion; + } + else if ( VersionUtil.isGenericSnapshot( baseVersion ) ) + { + // timestamped snapshots + try + { + version = parseTimestampedVersionFromId( artifactId, baseVersion, id ); + } + catch ( IllegalStateException e ) + { + throw new IllegalArgumentException( + "Not a valid artifact path in a Maven 2 repository, filename '" + id + + "' doesn't contain a timestamped version matching snapshot '" + baseVersion + "'" ); + } + } + else + { + // invalid + throw new IllegalArgumentException( + "Not a valid artifact path in a Maven 2 repository, filename '" + id + "' doesn't contain version '" + + baseVersion + "'" ); + } + + String classifier; + String ext; + index += version.length(); + if ( index == id.length() ) + { + // no classifier or extension + classifier = null; + ext = null; + } + else + { + char c = id.charAt( index ); + if ( c == '-' ) + { + // classifier up until last '.' + int extIndex = id.lastIndexOf( '.' ); + if ( extIndex > index ) + { + classifier = id.substring( index + 1, extIndex ); + ext = id.substring( extIndex + 1 ); + } + else + { + classifier = id.substring( index + 1 ); + ext = null; + } + } + else if ( c == '.' ) + { + // rest is the extension + classifier = null; + ext = id.substring( index + 1 ); + } + else + { + throw new IllegalArgumentException( + "Not a valid artifact path in a Maven 2 repository, filename '" + id + + "' expected classifier or extension but got '" + id.substring( index ) + "'" ); + } + } + + ArtifactMetadata metadata = new ArtifactMetadata(); + metadata.setId( id ); + metadata.setNamespace( groupId ); + metadata.setProject( artifactId ); + metadata.setRepositoryId( repoId ); + metadata.setVersion( version ); + // TODO: set classifier and extension on Maven facet + return metadata; + } } diff --git a/archiva-modules/plugins/problem-reports/pom.xml b/archiva-modules/plugins/problem-reports/pom.xml index 5d98090a5..c1f39808d 100644 --- a/archiva-modules/plugins/problem-reports/pom.xml +++ b/archiva-modules/plugins/problem-reports/pom.xml @@ -32,14 +32,59 @@ org.apache.archiva metadata-repository-api - - - org.apache.archiva - archiva-repository-layer - org.apache.archiva archiva-checksum + + org.apache.archiva + archiva-model + + + org.apache.archiva + archiva-consumer-api + + + org.codehaus.plexus + plexus-spring + test + + + org.slf4j + slf4j-simple + test + + + org.mockito + mockito-all + 1.8.3 + test + + + org.apache.archiva + test-repository + test + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + test-repository + generate-test-resources + + unpack-dependencies + + + test-repository + target/test-repository + + + + + + diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java index c0a03c326..cec2b0861 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java @@ -20,12 +20,12 @@ package org.apache.archiva.reports; */ import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.maven.archiva.repository.events.RepositoryListener; +import org.apache.archiva.repository.events.RepositoryListener; /** * Process repository management events and respond appropriately. * - * @plexus.component role="org.apache.maven.archiva.repository.events.RepositoryListener" role-hint="problem-reports" + * @plexus.component role="org.apache.archiva.repository.events.RepositoryListener" role-hint="problem-reports" */ public class RepositoryProblemEventListener implements RepositoryListener diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java index a9b365eee..9c3135a92 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java @@ -19,17 +19,11 @@ package org.apache.archiva.reports.consumers; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.commons.collections.CollectionUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -39,11 +33,6 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.repository.ManagedRepositoryContent; -import org.apache.maven.archiva.repository.RepositoryContentFactory; -import org.apache.maven.archiva.repository.RepositoryException; -import org.apache.maven.archiva.repository.layout.LayoutException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.registry.Registry; @@ -51,6 +40,13 @@ import org.codehaus.plexus.registry.RegistryListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + /** * Search the database of known SHA1 Checksums for potential duplicate artifacts. * @@ -87,24 +83,23 @@ public class DuplicateArtifactsConsumer */ private FileTypes filetypes; - /** - * @plexus.requirement - */ - private RepositoryContentFactory repositoryFactory; - private List includes = new ArrayList(); private File repositoryDir; private String repoId; - private ManagedRepositoryContent repository; - /** * @plexus.requirement */ private MetadataRepository metadataRepository; + /** + * FIXME: needs to be selected based on the repository in question + * @plexus.requirement role-hint="maven2" + */ + private RepositoryPathTranslator pathTranslator; + public String getId() { return id; @@ -133,16 +128,8 @@ public class DuplicateArtifactsConsumer public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered ) throws ConsumerException { - try - { - repoId = repo.getId(); - repository = repositoryFactory.getManagedRepositoryContent( repoId ); - this.repositoryDir = new File( repository.getRepoRoot() ); - } - catch ( RepositoryException e ) - { - throw new ConsumerException( e.getMessage(), e ); - } + repoId = repo.getId(); + this.repositoryDir = new File( repo.getLocation() ); } public void processFile( String path ) @@ -152,6 +139,8 @@ public class DuplicateArtifactsConsumer // TODO: would be quicker to somehow make sure it ran after the update database consumer, or as a part of that // perhaps could use an artifact context that is retained for all consumers? First in can set the SHA-1 + // alternatively this could come straight from the storage resolver, which could populate the artifact metadata + // in the later parse call with the desired checksum and use that String checksumSha1; ChecksummedFile checksummedFile = new ChecksummedFile( artifactFile ); try @@ -167,46 +156,45 @@ public class DuplicateArtifactsConsumer if ( CollectionUtils.isNotEmpty( results ) ) { - if ( results.size() <= 1 ) - { - // No duplicates detected. - log.debug( "Found no duplicate artifact results on: " + path + " (repository " + repoId + ")" ); - return; - } - - ArtifactReference artifactReference; + ArtifactMetadata originalArtifact; try { - artifactReference = repository.toArtifactReference( path ); + originalArtifact = pathTranslator.getArtifactForPath( repoId, path ); } - catch ( LayoutException e ) + catch ( Exception e ) { - log.warn( "Unable to report problem for path: " + path ); + log.warn( "Not reporting problem for invalid artifact in checksum check: " + e.getMessage() ); return; } for ( ArtifactMetadata dupArtifact : results ) { String id = path.substring( path.lastIndexOf( "/" ) + 1 ); - if ( dupArtifact.getId().equals( id ) && - dupArtifact.getNamespace().equals( artifactReference.getGroupId() ) && - dupArtifact.getProject().equals( artifactReference.getArtifactId() ) && - dupArtifact.getVersion().equals( artifactReference.getVersion() ) ) + if ( dupArtifact.getId().equals( id ) && dupArtifact.getNamespace().equals( + originalArtifact.getNamespace() ) && dupArtifact.getProject().equals( + originalArtifact.getProject() ) && dupArtifact.getVersion().equals( + originalArtifact.getVersion() ) ) { // Skip reference to itself. + if ( log.isDebugEnabled() ) + { + log.debug( "Not counting duplicate for artifact " + dupArtifact + " for path " + path ); + } continue; } RepositoryProblemFacet problem = new RepositoryProblemFacet(); problem.setRepositoryId( repoId ); - problem.setNamespace( artifactReference.getGroupId() ); - problem.setProject( artifactReference.getArtifactId() ); - problem.setVersion( artifactReference.getVersion() ); + problem.setNamespace( originalArtifact.getNamespace() ); + problem.setProject( originalArtifact.getProject() ); + problem.setVersion( originalArtifact.getVersion() ); problem.setId( id ); - // TODO: proper path conversion for new metadata - problem.setMessage( - "Duplicate Artifact Detected: " + path + " <--> " + dupArtifact.getNamespace().replace( '.', '/' ) + - "/" + dupArtifact.getProject() + "/" + dupArtifact.getVersion() + "/" + dupArtifact.getId() ); + // TODO: need to get the right storage resolver for the repository the dupe artifact is in, it might be + // a different type + // TODO: we need the project version here, not the artifact version + problem.setMessage( "Duplicate Artifact Detected: " + path + " <--> " + pathTranslator.toPath( + dupArtifact.getNamespace(), dupArtifact.getProject(), dupArtifact.getVersion(), + dupArtifact.getId() ) ); problem.setProblem( "duplicate-artifact" ); metadataRepository.addMetadataFacet( repoId, problem ); diff --git a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java new file mode 100644 index 000000000..1a870c965 --- /dev/null +++ b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java @@ -0,0 +1,215 @@ +package org.apache.archiva.reports.consumers; + +/* + * 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.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.model.MetadataFacet; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; +import org.apache.archiva.reports.RepositoryProblemFacet; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.mockito.ArgumentCaptor; +import org.mockito.Matchers; + +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Date; + +import static org.mockito.Mockito.*; + +@SuppressWarnings( {"ThrowableInstanceNeverThrown"} ) +public class DuplicateArtifactsConsumerTest + extends PlexusInSpringTestCase +{ + private DuplicateArtifactsConsumer consumer; + + private ManagedRepositoryConfiguration config; + + private MetadataRepository metadataRepository; + + private static final String TEST_REPO = "test-repo"; + + private static final String TEST_CHECKSUM = "edf5938e646956f445c6ecb719d44579cdeed974"; + + private static final String TEST_PROJECT = "test-artifact"; + + private static final String TEST_NAMESPACE = "com.example.test"; + + private static final String TEST_FILE = + "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar"; + + private static final String TEST_VERSION = "1.0-20100308.230825-1"; + + private static final ArtifactMetadata TEST_METADATA = createMetadata( TEST_VERSION ); + + private RepositoryPathTranslator pathTranslator; + + public void setUp() + throws Exception + { + super.setUp(); + + consumer = (DuplicateArtifactsConsumer) lookup( KnownRepositoryContentConsumer.class, "duplicate-artifacts" ); + assertNotNull( consumer ); + + config = new ManagedRepositoryConfiguration(); + config.setId( TEST_REPO ); + config.setLocation( getTestFile( "target/test-repository" ).getAbsolutePath() ); + + metadataRepository = (MetadataRepository) lookup( MetadataRepository.class ); + + pathTranslator = (RepositoryPathTranslator) lookup( RepositoryPathTranslator.class, "maven2" ); + when( pathTranslator.getArtifactForPath( TEST_REPO, TEST_FILE ) ).thenReturn( TEST_METADATA ); + } + + public void testConsumerArtifactNotDuplicated() + throws ConsumerException + { + when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( + TEST_METADATA ) ); + + consumer.beginScan( config, new Date() ); + consumer.processFile( TEST_FILE ); + consumer.completeScan(); + + verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.anyObject() ); + } + + // TODO: Doesn't currently work +// public void testConsumerArtifactNotDuplicatedForOtherSnapshots() +// throws ConsumerException +// { +// when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( +// TEST_METADATA, createMetadata( "1.0-20100309.002023-2" ) ) ); +// +// consumer.beginScan( config, new Date() ); +// consumer.processFile( TEST_FILE ); +// consumer.completeScan(); +// +// verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.anyObject() ); +// } + + public void testConsumerArtifactDuplicated() + throws ConsumerException + { + when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( + TEST_METADATA, createMetadata( "1.0" ) ) ); + + consumer.beginScan( config, new Date() ); + consumer.processFile( TEST_FILE ); + consumer.completeScan(); + + ArgumentCaptor argument = ArgumentCaptor.forClass( RepositoryProblemFacet.class ); + verify( metadataRepository ).addMetadataFacet( eq( TEST_REPO ), argument.capture() ); + RepositoryProblemFacet problem = argument.getValue(); + assertProblem( problem ); + } + + public void testConsumerArtifactDuplicatedButSelfNotInMetadataRepository() + throws ConsumerException + { + when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( + createMetadata( "1.0" ) ) ); + + consumer.beginScan( config, new Date() ); + consumer.processFile( TEST_FILE ); + consumer.completeScan(); + + ArgumentCaptor argument = ArgumentCaptor.forClass( RepositoryProblemFacet.class ); + verify( metadataRepository ).addMetadataFacet( eq( TEST_REPO ), argument.capture() ); + RepositoryProblemFacet problem = argument.getValue(); + assertProblem( problem ); + } + + public void testConsumerArtifactFileNotExist() + throws ConsumerException + { + consumer.beginScan( config, new Date() ); + try + { + consumer.processFile( "com/example/test/test-artifact/2.0/test-artifact-2.0.jar" ); + fail( "Should have failed to find file" ); + } + catch ( ConsumerException e ) + { + assertTrue( e.getCause() instanceof FileNotFoundException ); + } + finally + { + consumer.completeScan(); + } + + verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.anyObject() ); + } + + public void testConsumerArtifactNotAnArtifactPathNoResults() + throws ConsumerException + { + consumer.beginScan( config, new Date() ); + // No exception unnecessarily for something we can't report on + consumer.processFile( "com/example/invalid-artifact.txt" ); + consumer.completeScan(); + + verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.anyObject() ); + } + + public void testConsumerArtifactNotAnArtifactPathResults() + throws ConsumerException + { + when( metadataRepository.getArtifactsByChecksum( eq( TEST_REPO ), anyString() ) ).thenReturn( Arrays.asList( + TEST_METADATA, createMetadata( "1.0" ) ) ); + + // override, this feels a little overspecified though + when( pathTranslator.getArtifactForPath( TEST_REPO, "com/example/invalid-artifact.txt" ) ).thenThrow( + new IllegalArgumentException() ); + + consumer.beginScan( config, new Date() ); + // No exception unnecessarily for something we can't report on + consumer.processFile( "com/example/invalid-artifact.txt" ); + consumer.completeScan(); + + verify( metadataRepository, never() ).addMetadataFacet( eq( TEST_REPO ), Matchers.anyObject() ); + } + + private static void assertProblem( RepositoryProblemFacet problem ) + { + assertEquals( TEST_REPO, problem.getRepositoryId() ); + assertEquals( TEST_NAMESPACE, problem.getNamespace() ); + assertEquals( TEST_PROJECT, problem.getProject() ); + assertEquals( TEST_VERSION, problem.getVersion() ); + assertEquals( TEST_PROJECT + "-" + TEST_VERSION + ".jar", problem.getId() ); + assertNotNull( problem.getMessage() ); + assertEquals( "duplicate-artifact", problem.getProblem() ); + } + + private static ArtifactMetadata createMetadata( String version ) + { + ArtifactMetadata artifact = new ArtifactMetadata(); + artifact.setId( TEST_PROJECT + "-" + version + ".jar" ); + artifact.setNamespace( TEST_NAMESPACE ); + artifact.setProject( TEST_PROJECT ); + artifact.setVersion( version ); + artifact.setRepositoryId( TEST_REPO ); + return artifact; + } +} diff --git a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/MockitoFactory.java b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/MockitoFactory.java new file mode 100644 index 000000000..e298e905b --- /dev/null +++ b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/MockitoFactory.java @@ -0,0 +1,51 @@ +package org.apache.archiva.reports.consumers; + +/* + * 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.springframework.beans.factory.FactoryBean; + +import static org.mockito.Mockito.mock; + +public class MockitoFactory + implements FactoryBean +{ + private final Class type; + + public MockitoFactory( Class type ) + { + this.type = type; + } + + public Object getObject() + throws Exception + { + return mock( type ); + } + + public Class getObjectType() + { + return type; + } + + public boolean isSingleton() + { + return true; + } +} diff --git a/archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml b/archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml new file mode 100644 index 000000000..0aafa2680 --- /dev/null +++ b/archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 735a38244..851b5a9ce 100644 --- a/pom.xml +++ b/pom.xml @@ -329,11 +329,6 @@ archiva-artifact-converter 1.4-SNAPSHOT - - org.apache.archiva - archiva-artifact-reports - 1.4-SNAPSHOT - org.apache.archiva archiva-checksum @@ -359,11 +354,6 @@ archiva-converter 1.4-SNAPSHOT - - org.apache.archiva - archiva-dependency-graph - 1.4-SNAPSHOT - org.apache.archiva archiva-core-consumers @@ -376,12 +366,7 @@ org.apache.archiva - archiva-database - 1.4-SNAPSHOT - - - org.apache.archiva - archiva-database-consumers + test-repository 1.4-SNAPSHOT