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 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
50 RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
51 processArtifact( artifact, reporter, queryLayer );
55 List dependencies = model.getDependencies();
56 processDependencies( dependencies, reporter, queryLayer, artifact );
60 private void processArtifact( Artifact artifact, ReportingDatabase reporter,
61 RepositoryQueryLayer repositoryQueryLayer )
63 if ( !repositoryQueryLayer.containsArtifact( artifact ) )
65 reporter.addFailure( artifact, "Artifact does not exist in the repository" );
69 private void processDependencies( List dependencies, ReportingDatabase reporter,
70 RepositoryQueryLayer repositoryQueryLayer, Artifact sourceArtifact )
72 if ( dependencies.size() > 0 )
74 Iterator iterator = dependencies.iterator();
75 while ( iterator.hasNext() )
77 Dependency dependency = (Dependency) iterator.next();
81 Artifact artifact = createArtifact( dependency );
83 if ( !repositoryQueryLayer.containsArtifact( artifact ) )
85 String reason = MessageFormat.format(
86 "Artifact''s dependency {0} does not exist in the repository",
87 new String[]{dependency.toString()} );
88 reporter.addFailure( sourceArtifact, reason );
91 catch ( InvalidVersionSpecificationException e )
93 String reason = MessageFormat.format( "Artifact''s dependency {0} contains an invalid version {1}",
94 new String[]{dependency.toString(),
95 dependency.getVersion()} );
96 reporter.addFailure( sourceArtifact, reason );
102 private Artifact createArtifact( Dependency dependency )
103 throws InvalidVersionSpecificationException
105 return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
106 VersionRange.createFromVersionSpec( dependency.getVersion() ),
107 dependency.getType(), dependency.getClassifier(),
108 dependency.getScope() );