From 8532c8ed0adc8db9738301da1dcda1271a3513c1 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 8 Jun 2006 05:21:14 +0000 Subject: [PATCH] [MRM-118] update recently added duplicate processor git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412664 13f79535-47bb-0310-9956-ffa450edef68 --- .../DuplicateArtifactFileReportProcessor.java | 45 +++++-------------- ...licateArtifactFileReportProcessorTest.java | 29 +++++++++--- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java index 598531fbd..076e3b81a 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java @@ -17,12 +17,9 @@ package org.apache.maven.repository.reporting; */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Model; -import org.apache.maven.repository.digest.DefaultDigester; import org.apache.maven.repository.digest.Digester; -import org.apache.maven.repository.indexing.DefaultRepositoryIndexingFactory; import org.apache.maven.repository.indexing.RepositoryIndex; import org.apache.maven.repository.indexing.RepositoryIndexException; import org.apache.maven.repository.indexing.RepositoryIndexSearchException; @@ -42,22 +39,29 @@ import java.util.List; * Validates an artifact file for duplicates within the same groupId based from what's available in a RepositoryIndex * * @author Edwin Punzalan + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="duplicate" */ public class DuplicateArtifactFileReportProcessor implements ArtifactReportProcessor { + /** + * @plexus.requirement + */ private Digester digester; + /** + * @plexus.requirement + */ private RepositoryIndexingFactory indexFactory; //@todo configurable? private String algorithm = RepositoryIndex.FLD_MD5; + /** + * @plexus.requirement + */ private RepositoryIndexSearchLayer searchLayer; - //@todo must be injected - private ArtifactFactory artifactFactory; - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository ) throws ReportProcessorException @@ -67,18 +71,6 @@ public class DuplicateArtifactFileReportProcessor //@todo remove hard-coded value; current value enables tests to pass String indexPath = new File( "target/.index" ).getAbsolutePath(); - //@todo may be injected? - if ( digester == null ) - { - digester = new DefaultDigester(); - } - - //@todo may be injected? - if ( indexFactory == null ) - { - indexFactory = new DefaultRepositoryIndexingFactory(); - } - RepositoryIndex index; try { @@ -89,11 +81,6 @@ public class DuplicateArtifactFileReportProcessor throw new ReportProcessorException( "Unable to create RepositoryIndex instance", e ); } - if ( searchLayer == null ) - { - searchLayer = new RepositoryIndexSearchLayer( index, artifactFactory ); - } - String checksum; try { @@ -112,7 +99,7 @@ public class DuplicateArtifactFileReportProcessor try { - List results = searchLayer.searchAdvanced( query ); + List results = searchLayer.searchAdvanced( query, index ); if ( results.isEmpty() ) { @@ -157,14 +144,4 @@ public class DuplicateArtifactFileReportProcessor reporter.addWarning( artifact, "Artifact file is null" ); } } - - public ArtifactFactory getArtifactFactory() - { - return artifactFactory; - } - - public void setArtifactFactory( ArtifactFactory artifactFactory ) - { - this.artifactFactory = artifactFactory; - } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java index 70d617263..5f97f05ea 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java @@ -1,9 +1,25 @@ package org.apache.maven.repository.reporting; +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.model.Model; -import org.apache.maven.repository.digest.DefaultDigester; +import org.apache.maven.repository.digest.Digester; import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; import org.codehaus.plexus.util.FileUtils; @@ -21,7 +37,7 @@ public class DuplicateArtifactFileReportProcessorTest private Model model; - private DuplicateArtifactFileReportProcessor processor; + private ArtifactReportProcessor processor; private ArtifactFactory artifactFactory; @@ -31,14 +47,15 @@ public class DuplicateArtifactFileReportProcessorTest throws Exception { super.setUp(); - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class.getName() ); + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + Digester digester = (Digester) lookup( Digester.ROLE ); + reporter = new MockArtifactReporter(); artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" ); model = new Model(); - processor = new DuplicateArtifactFileReportProcessor(); - processor.setArtifactFactory( artifactFactory ); + processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" ); - ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexPath, repository, new DefaultDigester() ); + ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexPath, repository, digester ); index.indexArtifact( artifact ); index.optimize(); index.close(); -- 2.39.5