mirror of https://github.com/apache/archiva.git
[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:
parent
bda451364b
commit
8532c8ed0a
|
@ -17,12 +17,9 @@ package org.apache.maven.repository.reporting;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.model.Model;
|
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.digest.Digester;
|
||||||
import org.apache.maven.repository.indexing.DefaultRepositoryIndexingFactory;
|
|
||||||
import org.apache.maven.repository.indexing.RepositoryIndex;
|
import org.apache.maven.repository.indexing.RepositoryIndex;
|
||||||
import org.apache.maven.repository.indexing.RepositoryIndexException;
|
import org.apache.maven.repository.indexing.RepositoryIndexException;
|
||||||
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
|
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
|
* Validates an artifact file for duplicates within the same groupId based from what's available in a RepositoryIndex
|
||||||
*
|
*
|
||||||
* @author Edwin Punzalan
|
* @author Edwin Punzalan
|
||||||
|
* @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="duplicate"
|
||||||
*/
|
*/
|
||||||
public class DuplicateArtifactFileReportProcessor
|
public class DuplicateArtifactFileReportProcessor
|
||||||
implements ArtifactReportProcessor
|
implements ArtifactReportProcessor
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @plexus.requirement
|
||||||
|
*/
|
||||||
private Digester digester;
|
private Digester digester;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.requirement
|
||||||
|
*/
|
||||||
private RepositoryIndexingFactory indexFactory;
|
private RepositoryIndexingFactory indexFactory;
|
||||||
|
|
||||||
//@todo configurable?
|
//@todo configurable?
|
||||||
private String algorithm = RepositoryIndex.FLD_MD5;
|
private String algorithm = RepositoryIndex.FLD_MD5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.requirement
|
||||||
|
*/
|
||||||
private RepositoryIndexSearchLayer searchLayer;
|
private RepositoryIndexSearchLayer searchLayer;
|
||||||
|
|
||||||
//@todo must be injected
|
|
||||||
private ArtifactFactory artifactFactory;
|
|
||||||
|
|
||||||
public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
|
public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
|
||||||
ArtifactRepository repository )
|
ArtifactRepository repository )
|
||||||
throws ReportProcessorException
|
throws ReportProcessorException
|
||||||
|
@ -67,18 +71,6 @@ public class DuplicateArtifactFileReportProcessor
|
||||||
//@todo remove hard-coded value; current value enables tests to pass
|
//@todo remove hard-coded value; current value enables tests to pass
|
||||||
String indexPath = new File( "target/.index" ).getAbsolutePath();
|
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;
|
RepositoryIndex index;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -89,11 +81,6 @@ public class DuplicateArtifactFileReportProcessor
|
||||||
throw new ReportProcessorException( "Unable to create RepositoryIndex instance", e );
|
throw new ReportProcessorException( "Unable to create RepositoryIndex instance", e );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( searchLayer == null )
|
|
||||||
{
|
|
||||||
searchLayer = new RepositoryIndexSearchLayer( index, artifactFactory );
|
|
||||||
}
|
|
||||||
|
|
||||||
String checksum;
|
String checksum;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -112,7 +99,7 @@ public class DuplicateArtifactFileReportProcessor
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List results = searchLayer.searchAdvanced( query );
|
List results = searchLayer.searchAdvanced( query, index );
|
||||||
|
|
||||||
if ( results.isEmpty() )
|
if ( results.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -157,14 +144,4 @@ public class DuplicateArtifactFileReportProcessor
|
||||||
reporter.addWarning( artifact, "Artifact file is null" );
|
reporter.addWarning( artifact, "Artifact file is null" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactFactory getArtifactFactory()
|
|
||||||
{
|
|
||||||
return artifactFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArtifactFactory( ArtifactFactory artifactFactory )
|
|
||||||
{
|
|
||||||
this.artifactFactory = artifactFactory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,25 @@
|
||||||
package org.apache.maven.repository.reporting;
|
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.Artifact;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.model.Model;
|
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.apache.maven.repository.indexing.ArtifactRepositoryIndex;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
|
@ -21,7 +37,7 @@ public class DuplicateArtifactFileReportProcessorTest
|
||||||
|
|
||||||
private Model model;
|
private Model model;
|
||||||
|
|
||||||
private DuplicateArtifactFileReportProcessor processor;
|
private ArtifactReportProcessor processor;
|
||||||
|
|
||||||
private ArtifactFactory artifactFactory;
|
private ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
|
@ -31,14 +47,15 @@ public class DuplicateArtifactFileReportProcessorTest
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class.getName() );
|
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||||
|
Digester digester = (Digester) lookup( Digester.ROLE );
|
||||||
|
|
||||||
reporter = new MockArtifactReporter();
|
reporter = new MockArtifactReporter();
|
||||||
artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
|
artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
|
||||||
model = new Model();
|
model = new Model();
|
||||||
processor = new DuplicateArtifactFileReportProcessor();
|
processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
|
||||||
processor.setArtifactFactory( artifactFactory );
|
|
||||||
|
|
||||||
ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexPath, repository, new DefaultDigester() );
|
ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexPath, repository, digester );
|
||||||
index.indexArtifact( artifact );
|
index.indexArtifact( artifact );
|
||||||
index.optimize();
|
index.optimize();
|
||||||
index.close();
|
index.close();
|
||||||
|
|
Loading…
Reference in New Issue