*/
private RepositoryQueryLayerFactory layerFactory;
+ private static final String POM = "pom";
+
public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
processArtifact( artifact, reporter, queryLayer );
- if ( model != null )
+ if ( model != null && POM.equals( artifact.getType() ) )
{
List dependencies = model.getDependencies();
processDependencies( dependencies, reporter, queryLayer, artifact );
{
ArtifactRepository repository = artifact.getRepository();
// TODO! always null currently, need to configure this properly
- if ( artifact.getFile() != null && indexDirectory != null )
+ if ( indexDirectory != null )
{
- RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) );
-
- String checksum = null;
- try
- {
- checksum = digester.calc( artifact.getFile() );
- }
- catch ( DigesterException e )
+ if ( artifact.getFile() != null )
{
- reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
- }
+ RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) );
- if ( checksum != null )
- {
+ String checksum = null;
try
{
- List results = index.search( new LuceneQuery(
- new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
+ checksum = digester.calc( artifact.getFile() );
+ }
+ catch ( DigesterException e )
+ {
+ reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
+ }
- if ( !results.isEmpty() )
+ if ( checksum != null )
+ {
+ try
{
- for ( Iterator i = results.iterator(); i.hasNext(); )
- {
- StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+ List results = index.search( new LuceneQuery(
+ new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
- //make sure it is not the same artifact
- if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
+ if ( !results.isEmpty() )
+ {
+ for ( Iterator i = results.iterator(); i.hasNext(); )
{
- //report only duplicates from the same groupId
- String groupId = artifact.getGroupId();
- if ( groupId.equals( result.getGroupId() ) )
+ StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+
+ //make sure it is not the same artifact
+ if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
{
- reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+ //report only duplicates from the same groupId
+ String groupId = artifact.getGroupId();
+ if ( groupId.equals( result.getGroupId() ) )
+ {
+ reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+ }
}
}
}
}
- }
- catch ( RepositoryIndexSearchException e )
- {
- reporter.addWarning( artifact, "Failed to search in index" + e );
+ catch ( RepositoryIndexSearchException e )
+ {
+ reporter.addWarning( artifact, "Failed to search in index" + e );
+ }
}
}
- }
- else
- {
- reporter.addWarning( artifact, "Artifact file is null" );
+ else
+ {
+ reporter.addWarning( artifact, "Artifact file is null" );
+ }
}
}
}
/**
* This class validates well-formedness of pom xml file.
*
+ * @todo nice to have this a specific, tested report - however it is likely to double up with project building exceptions from IndexerTask. Resolve [!]
* @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="invalid-pom"
*/
public class InvalidPomArtifactReportProcessor
}
}
}
- else
- {
- reporter.addWarning( artifact, "The artifact is not a pom xml file." );
- }
}
}
*/
private MavenProjectBuilder projectBuilder;
+ private static final String POM = "pom";
+
/**
* Check whether the artifact is in its proper location. The location of the artifact
* is validated first against the groupId, artifactId and versionId in the specified model
if ( model != null )
{
- //check if the artifact is located in its proper location based on the info
- //specified in the model object/pom
- Artifact modelArtifact = artifactFactory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
- model.getVersion(), model.getPackaging() );
-
- String modelPath = repository.pathOf( modelArtifact );
- if ( !modelPath.equals( artifactPath ) )
+ // only check if it is a standalone POM, or an artifact other than a POM
+ // ie, don't check the location of the POM for another artifact matches that of the artifact
+ if ( !POM.equals( artifact.getType() ) || POM.equals( model.getPackaging() ) )
{
- reporter.addFailure( artifact,
- "The artifact is out of place. It does not match the specified location in the repository pom." );
+ //check if the artifact is located in its proper location based on the info
+ //specified in the model object/pom
+ Artifact modelArtifact = artifactFactory.createArtifactWithClassifier( model.getGroupId(),
+ model.getArtifactId(),
+ model.getVersion(),
+ artifact.getType(),
+ artifact.getClassifier() );
+
+ String modelPath = repository.pathOf( modelArtifact );
+ if ( !modelPath.equals( artifactPath ) )
+ {
+ reporter.addFailure( artifact,
+ "The artifact is out of place. It does not match the specified location in the repository pom: " +
+ modelPath );
+ }
}
}
}
else
{
- reporter.addFailure( artifact,
- "The artifact is out of place. It does not exist at the specified location in the repository pom." );
+ throw new IllegalStateException( "Couldn't find artifact " + file );
}
}
artifactReportProcessor.processArtifact( artifact, null, reporter );
assertEquals( 0, reporter.getNumFailures() );
- assertEquals( 1, reporter.getNumWarnings() );
+ assertEquals( 0, reporter.getNumWarnings() );
}
}
throws IOException, XmlPullParserException
{
Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
+ Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
- artifactReportProcessor.processArtifact( artifact, null, reporter );
+ Model model = readPom( repository.pathOf( pomArtifact ) );
+ artifactReportProcessor.processArtifact( artifact, model, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact is in the location specified in the
+ * file system pom, but the pom itself is passed in.
+ */
+ public void testLocationArtifactReporterSuccessPom()
+ throws IOException, XmlPullParserException
+ {
+ Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
+
+ Model model = readPom( repository.pathOf( pomArtifact ) );
+ artifactReportProcessor.processArtifact( pomArtifact, model, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact is in the location specified in the
+ * file system pom, with a classifier.
+ */
+ public void testLocationArtifactReporterSuccessClassifier()
+ throws IOException, XmlPullParserException
+ {
+ Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "java-source" );
+ Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
+
+ Model model = readPom( repository.pathOf( pomArtifact ) );
+ artifactReportProcessor.processArtifact( artifact, model, reporter );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
throws IOException, XmlPullParserException
{
Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
+ Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
- artifactReportProcessor.processArtifact( artifact, null, reporter );
- assertEquals( 1, reporter.getNumFailures() );
+ try
+ {
+ Model model = readPom( repository.pathOf( pomArtifact ) );
+ artifactReportProcessor.processArtifact( artifact, model, reporter );
+ fail( "Should not have passed the artifact" );
+ }
+ catch ( IllegalStateException e )
+ {
+ // correct!
+ }
}
/**