[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
This commit is contained in:
Brett Porter 2006-06-08 05:21:14 +00:00
parent bda451364b
commit 8532c8ed0a
2 changed files with 34 additions and 40 deletions

View File

@ -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;
}
}

View File

@ -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();