*/
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;
* 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
//@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
{
throw new ReportProcessorException( "Unable to create RepositoryIndex instance", e );
}
- if ( searchLayer == null )
- {
- searchLayer = new RepositoryIndexSearchLayer( index, artifactFactory );
- }
-
String checksum;
try
{
try
{
- List results = searchLayer.searchAdvanced( query );
+ List results = searchLayer.searchAdvanced( query, index );
if ( results.isEmpty() )
{
reporter.addWarning( artifact, "Artifact file is null" );
}
}
-
- public ArtifactFactory getArtifactFactory()
- {
- return artifactFactory;
- }
-
- public void setArtifactFactory( ArtifactFactory artifactFactory )
- {
- this.artifactFactory = artifactFactory;
- }
}
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;
private Model model;
- private DuplicateArtifactFileReportProcessor processor;
+ private ArtifactReportProcessor processor;
private ArtifactFactory artifactFactory;
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();