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.repository.ArtifactRepository;
24 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
25 import org.apache.maven.artifact.versioning.VersionRange;
26 import org.apache.maven.model.Dependency;
27 import org.apache.maven.model.Model;
29 import java.util.Iterator;
30 import java.util.List;
33 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="default"
35 public class DefaultArtifactReportProcessor
36 implements ArtifactReportProcessor
41 private ArtifactFactory artifactFactory;
46 private RepositoryQueryLayerFactory layerFactory;
48 public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
49 ArtifactRepository repository )
51 RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository );
52 processArtifact( artifact, reporter, queryLayer );
54 List dependencies = model.getDependencies();
55 processDependencies( dependencies, reporter, queryLayer );
58 private void processArtifact( Artifact artifact, ArtifactReporter reporter,
59 RepositoryQueryLayer repositoryQueryLayer )
61 if ( repositoryQueryLayer.containsArtifact( artifact ) )
63 reporter.addSuccess( artifact );
67 reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
71 private void processDependencies( List dependencies, ArtifactReporter reporter,
72 RepositoryQueryLayer repositoryQueryLayer )
74 if ( dependencies.size() > 0 )
76 Iterator iterator = dependencies.iterator();
77 while ( iterator.hasNext() )
79 Dependency dependency = (Dependency) iterator.next();
81 Artifact artifact = null;
84 artifact = createArtifact( dependency );
86 if ( repositoryQueryLayer.containsArtifact( artifact ) )
88 reporter.addSuccess( artifact );
92 reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
95 catch ( InvalidVersionSpecificationException e )
97 reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION );
103 private Artifact createArtifact( Dependency dependency )
104 throws InvalidVersionSpecificationException
106 return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
107 VersionRange.createFromVersionSpec( dependency.getVersion() ),
108 dependency.getType(), dependency.getClassifier(),
109 dependency.getScope() );