From 0f4bec30498077a096182f0c085a2d2b116e3751 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 16 Dec 2009 00:38:50 +0000 Subject: [PATCH] [MRM-1301] add back problem reporting for invalid / missing POM git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@891084 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaMetadataCreationConsumer.java | 11 +- .../repository/TestMetadataRepository.java | 2 +- .../memory/TestMetadataRepository.java | 2 +- .../repository/TestMetadataRepository.java | 2 +- .../repository/MetadataRepository.java | 4 +- .../plugins/maven2-repository/pom.xml | 4 + .../Maven2RepositoryMetadataResolver.java | 42 ++++++- .../repository/TestMetadataRepository.java | 107 ++++++++++++++++++ .../repository/TestMetadataResolver.java | 14 +-- .../Maven2RepositoryMetadataResolverTest.java | 35 ++++-- .../Maven2RepositoryMetadataResolverTest.xml | 4 + .../file/FileMetadataRepository.java | 8 +- .../file/FileMetadataRepositoryTest.java | 18 ++- .../reports/RepositoryProblemFacet.java | 14 ++- .../consumers/DuplicateArtifactsConsumer.java | 2 +- .../DefaultRepositoryStatisticsManager.java | 2 +- .../RepositoryStatisticsManagerTest.java | 8 +- 17 files changed, 226 insertions(+), 53 deletions(-) create mode 100644 archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index 762d3adf7..3275405d4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -161,13 +161,14 @@ public class ArchivaMetadataCreationConsumer project.setNamespace( artifact.getGroupId() ); project.setId( artifact.getArtifactId() ); + String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() ); // TODO: maybe not too efficient since it may have already been read and stored for this artifact ProjectVersionMetadata versionMetadata; try { versionMetadata = storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), - VersionUtil.getBaseVersion( artifact.getVersion() ) ); + projectVersion ); } catch ( MetadataResolverException e ) { @@ -176,7 +177,9 @@ public class ArchivaMetadataCreationConsumer if ( versionMetadata == null ) { - throw new ConsumerException( "Unable to read metadata for artifact: " + artifact ); + log.warn( "Missing POM for artifact: " + artifact + "; creating empty metadata" ); + versionMetadata = new ProjectVersionMetadata(); + versionMetadata.setId( projectVersion ); } ArtifactMetadata artifactMeta = new ArtifactMetadata(); @@ -209,8 +212,8 @@ public class ArchivaMetadataCreationConsumer // TODO: transaction // read the metadata and update it if it is newer or doesn't exist - metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), - versionMetadata.getId(), artifactMeta ); + metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), projectVersion, + artifactMeta ); metadataRepository.updateProjectVersion( repository.getId(), project.getNamespace(), project.getId(), versionMetadata ); metadataRepository.updateProject( repository.getId(), project ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index d5f899471..c42488105 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -116,7 +116,7 @@ public class TestMetadataRepository return null; //To change body of implemented methods use File | Settings | File Templates. } - public void addMetadataFacet( String repositoryId, String facetId, MetadataFacet metadataFacet ) + public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) { //To change body of implemented methods use File | Settings | File Templates. } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java index cebad9b3e..45d9106e6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java @@ -156,7 +156,7 @@ public class TestMetadataRepository throw new UnsupportedOperationException(); } - public void addMetadataFacet( String repositoryId, String facetId, MetadataFacet metadataFacet ) + public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) { throw new UnsupportedOperationException(); } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index d5f899471..c42488105 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -116,7 +116,7 @@ public class TestMetadataRepository return null; //To change body of implemented methods use File | Settings | File Templates. } - public void addMetadataFacet( String repositoryId, String facetId, MetadataFacet metadataFacet ) + public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) { //To change body of implemented methods use File | Settings | File Templates. } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 44993ea87..e02e2edd1 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -51,11 +51,11 @@ public interface MetadataRepository void updateNamespace( String repoId, String namespace ); - List getMetadataFacets( String repodId, String facetId ); + List getMetadataFacets( String repoId, String facetId ); MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ); - void addMetadataFacet( String repositoryId, String facetId, MetadataFacet metadataFacet ); + void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ); void removeMetadataFacets( String repositoryId, String facetId ); diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml index 89d00adb5..6a696c690 100644 --- a/archiva-modules/plugins/maven2-repository/pom.xml +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -28,6 +28,10 @@ maven2-repository Maven 2.x Repository Support + + org.apache.archiva + problem-reports + org.apache.archiva metadata-model 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 b69063efe..02bf6af68 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 @@ -35,11 +35,13 @@ import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ProjectMetadata; 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.MetadataResolverException; import org.apache.archiva.metadata.repository.filter.AllFilter; import org.apache.archiva.metadata.repository.filter.Filter; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; +import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -80,6 +82,11 @@ public class Maven2RepositoryMetadataResolver */ private RepositoryPathTranslator pathTranslator; + /** + * @plexus.requirement + */ + private MetadataRepository metadataRepository; + private final static Logger log = LoggerFactory.getLogger( Maven2RepositoryMetadataResolver.class ); private static final String METADATA_FILENAME = "maven-metadata.xml"; @@ -127,11 +134,22 @@ public class Maven2RepositoryMetadataResolver } } - File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, - projectId + "-" + artifactVersion + ".pom" ); + String id = projectId + "-" + artifactVersion + ".pom"; + File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, id ); if ( !file.exists() ) { + // TODO: an event mechanism would remove coupling to the problem reporting plugin + RepositoryProblemFacet problem = new RepositoryProblemFacet(); + problem.setProblem( "missing-pom" ); + problem.setMessage( "The artifact's POM file '" + file + "' was missing" ); + problem.setProject( projectId ); + problem.setNamespace( namespace ); + problem.setRepositoryId( repoId ); + problem.setVersion( projectVersion ); + + metadataRepository.addMetadataFacet( repoId, problem ); + // metadata could not be resolved return null; } @@ -149,8 +167,19 @@ public class Maven2RepositoryMetadataResolver } catch ( ModelBuildingException e ) { - throw new MetadataResolverException( "Unable to build Maven POM to derive metadata from: " + e.getMessage(), - e ); + // TODO: an event mechanism would remove coupling to the problem reporting plugin + RepositoryProblemFacet problem = new RepositoryProblemFacet(); + problem.setProblem( "invalid-pom" ); + problem.setMessage( "The artifact's POM file '" + file + "' was invalid: " + e.getMessage() ); + problem.setProject( projectId ); + problem.setNamespace( namespace ); + problem.setRepositoryId( repoId ); + problem.setVersion( projectVersion ); + + metadataRepository.addMetadataFacet( repoId, problem ); + + // metadata could not be resolved + return null; } ProjectVersionMetadata metadata = new ProjectVersionMetadata(); @@ -531,6 +560,11 @@ public class Maven2RepositoryMetadataResolver return metadata; } + public void setConfiguration( ArchivaConfiguration configuration ) + { + this.archivaConfiguration = configuration; + } + private static class DirectoryFilter implements FilenameFilter { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java new file mode 100644 index 000000000..6b21379cf --- /dev/null +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -0,0 +1,107 @@ +package org.apache.archiva.metadata.repository; + +/* + * 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 java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.model.MetadataFacet; +import org.apache.archiva.metadata.model.ProjectMetadata; +import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.model.ProjectVersionReference; + +public class TestMetadataRepository + extends TestMetadataResolver + implements MetadataRepository +{ + private Map facets = new HashMap(); + + public void updateProject( String repoId, ProjectMetadata project ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion, + ArtifactMetadata artifactMeta ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void updateProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion, + ProjectVersionReference reference ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void updateNamespace( String repoId, String namespace ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public List getMetadataFacets( String repoId, String facetId ) + { + return new ArrayList( facets.keySet() ); + } + + public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ) + { + return facets.get( name ); + } + + public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) + { + facets.put( metadataFacet.getName(), metadataFacet ); + } + + public void removeMetadataFacets( String repositoryId, String facetId ) + { + facets.clear(); + } + + public void removeMetadataFacet( String repoId, String facetId, String name ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public List getArtifactsByDateRange( String repoId, Date startTime, Date endTime ) + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public Collection getRepositories() + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public List getArtifactsByChecksum( String repoId, String checksum ) + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java index f18d9c20a..43aefdd8b 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java @@ -1,12 +1,5 @@ package org.apache.archiva.metadata.repository; -import java.util.Collection; - -import org.apache.archiva.metadata.model.ArtifactMetadata; -import org.apache.archiva.metadata.model.ProjectMetadata; -import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.metadata.model.ProjectVersionReference; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -26,6 +19,13 @@ import org.apache.archiva.metadata.model.ProjectVersionReference; * under the License. */ +import java.util.Collection; + +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.model.ProjectMetadata; +import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.model.ProjectVersionReference; + public class TestMetadataResolver implements MetadataResolver { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index 94fd22638..167e51cf9 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -30,9 +30,11 @@ import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.License; import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.filter.ExcludesFilter; import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; +import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -55,6 +57,8 @@ public class Maven2RepositoryMetadataResolverTest private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; + private MetadataRepository metadataRepository; + public void setUp() throws Exception { @@ -69,6 +73,8 @@ public class Maven2RepositoryMetadataResolverTest configuration.save( c ); resolver = (Maven2RepositoryMetadataResolver) lookup( StorageMetadataResolver.class, "maven2" ); + metadataRepository = (MetadataRepository) lookup( MetadataRepository.class ); + metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ); } public void testGetProjectVersionMetadata() @@ -204,27 +210,36 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForInvalidPom() + throws MetadataResolverException { - try - { - ProjectVersionMetadata metadata = - resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ); + assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); - fail( "Expected failure, but received metadata: " + metadata ); - } - catch ( MetadataResolverException e ) - { - assertTrue( true ); - } + ProjectVersionMetadata metadata = + resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ); + assertNull( metadata ); + + assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); + RepositoryProblemFacet facet = + (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID, + "com.example.test/invalid-pom/1.0" ); + assertEquals( "invalid-pom", facet.getProblem() ); } public void testGetProjectVersionMetadataForMissingPom() throws MetadataResolverException { + assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); + ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ); assertNull( metadata ); + assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); + RepositoryProblemFacet facet = + (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID, + "com.example.test/missing-pom/1.0" ); + assertEquals( "missing-pom", facet.getProblem() ); + } public void testGetRootNamespaces() diff --git a/archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml b/archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml index d8ea35f56..8ccfa682b 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml +++ b/archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml @@ -23,5 +23,9 @@ org.apache.maven.archiva.configuration.ArchivaConfiguration org.apache.archiva.configuration.TestConfiguration + + org.apache.archiva.metadata.repository.MetadataRepository + org.apache.archiva.metadata.repository.TestMetadataRepository + \ No newline at end of file diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index cb27a3afb..2406bebac 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -303,16 +303,16 @@ public class FileMetadataRepository return metadataFacet; } - public void addMetadataFacet( String repositoryId, String facetId, MetadataFacet metadataFacet ) + public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) { Properties properties = new Properties(); properties.putAll( metadataFacet.toProperties() ); try { - writeProperties( properties, - new File( getMetadataDirectory( repositoryId, facetId ), metadataFacet.getName() ), - METADATA_KEY ); + File directory = + new File( getMetadataDirectory( repositoryId, metadataFacet.getFacetId() ), metadataFacet.getName() ); + writeProperties( properties, directory, METADATA_KEY ); } catch ( IOException e ) { diff --git a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java index f8d22d5f7..932c64f75 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java @@ -125,7 +125,7 @@ public class FileMetadataRepositoryTest public void testGetMetadataFacet() { - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, new TestMetadataFacet( TEST_VALUE ) ); + repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); assertEquals( new TestMetadataFacet( TEST_VALUE ), repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); @@ -138,14 +138,14 @@ public class FileMetadataRepositoryTest public void testGetMetadataFacetWhenUnknownName() { - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, new TestMetadataFacet( TEST_VALUE ) ); + repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) ); } public void testGetMetadataFacetWhenDefaultValue() { - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, new TestMetadataFacet( null ) ); + repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) ); assertEquals( new TestMetadataFacet( "test-metadata" ), repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); @@ -153,14 +153,12 @@ public class FileMetadataRepositoryTest public void testGetMetadataFacetWhenUnknownFacetId() { - repository.addMetadataFacet( TEST_REPO_ID, UNKNOWN, new TestMetadataFacet( TEST_VALUE ) ); - assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) ); } public void testGetMetadataFacets() { - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, new TestMetadataFacet( TEST_VALUE ) ); + repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); assertEquals( Collections.singletonList( TEST_NAME ), repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) ); @@ -174,7 +172,7 @@ public class FileMetadataRepositoryTest public void testRemoveFacets() { - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, new TestMetadataFacet( TEST_VALUE ) ); + repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertFalse( facets.isEmpty() ); @@ -204,7 +202,7 @@ public class FileMetadataRepositoryTest public void testRemoveFacet() { TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE ); - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, metadataFacet ); + repository.addMetadataFacet( TEST_REPO_ID, metadataFacet ); assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); @@ -280,8 +278,8 @@ public class FileMetadataRepositoryTest public void testRepositories() { - repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, new TestMetadataFacet( TEST_VALUE ) ); - repository.addMetadataFacet( OTHER_REPO, TEST_FACET_ID, new TestMetadataFacet( TEST_VALUE ) ); + repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); + repository.addMetadataFacet( OTHER_REPO, new TestMetadataFacet( TEST_VALUE ) ); assertEquals( Arrays.asList( OTHER_REPO, TEST_REPO_ID ), repository.getRepositories() ); } diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacet.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacet.java index 33694c032..328ccf833 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacet.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemFacet.java @@ -60,7 +60,10 @@ public class RepositoryProblemFacet map.put( "namespace", namespace ); map.put( "project", project ); map.put( "version", version ); - map.put( "id", id ); + if ( id != null ) + { + map.put( "id", id ); + } map.put( "message", message ); map.put( "problem", problem ); return map; @@ -147,8 +150,13 @@ public class RepositoryProblemFacet return problem; } - static String createName( String namespace, String project, String projectVersion, String id ) + public static String createName( String namespace, String project, String projectVersion, String id ) { - return namespace + "/" + project + "/" + projectVersion + "/" + id; + String name = namespace + "/" + project + "/" + projectVersion; + if ( id != null ) + { + name = name + "/" + id; + } + return name; } } 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 c6c5d837f..a9b365eee 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 @@ -209,7 +209,7 @@ public class DuplicateArtifactsConsumer "/" + dupArtifact.getProject() + "/" + dupArtifact.getVersion() + "/" + dupArtifact.getId() ); problem.setProblem( "duplicate-artifact" ); - metadataRepository.addMetadataFacet( repoId, RepositoryProblemFacet.FACET_ID, problem ); + metadataRepository.addMetadataFacet( repoId, problem ); } } } diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index 561cf3c8c..5d877951a 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -77,7 +77,7 @@ public class DefaultRepositoryStatisticsManager // populate total project count from content repository // repositoryStatistics.setTotalProjectCount( ); - metadataRepository.addMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID, repositoryStatistics ); + metadataRepository.addMetadataFacet( repositoryId, repositoryStatistics ); } public void deleteStatistics( String repositoryId ) diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java index d75e68330..f806291c8 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java @@ -120,7 +120,7 @@ public class RepositoryStatisticsManagerTest RepositoryStatistics stats = createTestStats( startTime, current ); - metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), Arrays.asList( stats.getName() ) ); @@ -152,11 +152,11 @@ public class RepositoryStatisticsManagerTest Date startTime1 = new Date( current.getTime() - 12345 ); RepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) ); - metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats1 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, stats1 ); Date startTime2 = new Date( current.getTime() - 3000 ); RepositoryStatistics stats2 = createTestStats( startTime2, current ); - metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, stats2 ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), @@ -391,7 +391,7 @@ public class RepositoryStatisticsManagerTest private void addStats( Date startTime, Date endTime ) { RepositoryStatistics stats = createTestStats( startTime, endTime ); - metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); statsCreated.put( stats.getName(), stats ); } -- 2.39.5