1 package org.apache.maven.archiva.reporting;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.archiva.layer.RepositoryQueryLayer;
20 import org.apache.maven.archiva.layer.RepositoryQueryLayerFactory;
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.factory.ArtifactFactory;
23 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
24 import org.apache.maven.artifact.versioning.VersionRange;
25 import org.apache.maven.model.Dependency;
26 import org.apache.maven.model.Model;
28 import java.text.MessageFormat;
29 import java.util.Iterator;
30 import java.util.List;
33 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="dependency"
35 public class DependencyArtifactReportProcessor
36 implements ArtifactReportProcessor
41 private ArtifactFactory artifactFactory;
46 private RepositoryQueryLayerFactory layerFactory;
48 private static final String POM = "pom";
50 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
52 RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
53 processArtifact( artifact, reporter, queryLayer );
55 if ( model != null && POM.equals( artifact.getType() ) )
57 List dependencies = model.getDependencies();
58 processDependencies( dependencies, reporter, queryLayer, artifact );
62 private void processArtifact( Artifact artifact, ReportingDatabase reporter,
63 RepositoryQueryLayer repositoryQueryLayer )
65 if ( !repositoryQueryLayer.containsArtifact( artifact ) )
67 reporter.addFailure( artifact, "Artifact does not exist in the repository" );
71 private void processDependencies( List dependencies, ReportingDatabase reporter,
72 RepositoryQueryLayer repositoryQueryLayer, Artifact sourceArtifact )
74 if ( dependencies.size() > 0 )
76 Iterator iterator = dependencies.iterator();
77 while ( iterator.hasNext() )
79 Dependency dependency = (Dependency) iterator.next();
83 Artifact artifact = createArtifact( dependency );
85 if ( !repositoryQueryLayer.containsArtifact( artifact ) )
87 String reason = MessageFormat.format(
88 "Artifact''s dependency {0} does not exist in the repository",
89 new String[]{getDependencyString( dependency )} );
90 reporter.addFailure( sourceArtifact, reason );
93 catch ( InvalidVersionSpecificationException e )
95 String reason = MessageFormat.format( "Artifact''s dependency {0} contains an invalid version {1}",
96 new String[]{getDependencyString( dependency ),
97 dependency.getVersion()} );
98 reporter.addFailure( sourceArtifact, reason );
104 static String getDependencyString( Dependency dependency )
106 String str = "(group=" + dependency.getGroupId();
107 str += ", artifact=" + dependency.getArtifactId();
108 str += ", version=" + dependency.getVersion();
109 str += ", type=" + dependency.getType();
110 if ( dependency.getClassifier() != null )
112 str += ", classifier=" + dependency.getClassifier();
118 private Artifact createArtifact( Dependency dependency )
119 throws InvalidVersionSpecificationException
121 return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
122 VersionRange.createFromVersionSpec( dependency.getVersion() ),
123 dependency.getType(), dependency.getClassifier(),
124 dependency.getScope() );