]> source.dussan.org Git - archiva.git/blob
b9fd36dd7dbbdd5efa1ace1a28ee53fcd75e106a
[archiva.git] /
1 package org.apache.maven.archiva.reporting;
2
3 /*
4  * Copyright 2005-2006 The Apache Software Foundation.
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
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;
28
29 import java.util.Iterator;
30 import java.util.List;
31
32 /**
33  * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="default"
34  */
35 public class DefaultArtifactReportProcessor
36     implements ArtifactReportProcessor
37 {
38     /**
39      * @plexus.requirement
40      */
41     private ArtifactFactory artifactFactory;
42
43     /**
44      * @plexus.requirement
45      */
46     private RepositoryQueryLayerFactory layerFactory;
47
48     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
49                                  ArtifactRepository repository )
50     {
51         RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository );
52         processArtifact( artifact, reporter, queryLayer );
53
54         List dependencies = model.getDependencies();
55         processDependencies( dependencies, reporter, queryLayer );
56     }
57
58     private void processArtifact( Artifact artifact, ArtifactReporter reporter,
59                                   RepositoryQueryLayer repositoryQueryLayer )
60     {
61         if ( repositoryQueryLayer.containsArtifact( artifact ) )
62         {
63             reporter.addSuccess( artifact );
64         }
65         else
66         {
67             reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
68         }
69     }
70
71     private void processDependencies( List dependencies, ArtifactReporter reporter,
72                                       RepositoryQueryLayer repositoryQueryLayer )
73     {
74         if ( dependencies.size() > 0 )
75         {
76             Iterator iterator = dependencies.iterator();
77             while ( iterator.hasNext() )
78             {
79                 Dependency dependency = (Dependency) iterator.next();
80
81                 Artifact artifact = null;
82                 try
83                 {
84                     artifact = createArtifact( dependency );
85
86                     if ( repositoryQueryLayer.containsArtifact( artifact ) )
87                     {
88                         reporter.addSuccess( artifact );
89                     }
90                     else
91                     {
92                         reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
93                     }
94                 }
95                 catch ( InvalidVersionSpecificationException e )
96                 {
97                     reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION );
98                 }
99             }
100         }
101     }
102
103     private Artifact createArtifact( Dependency dependency )
104         throws InvalidVersionSpecificationException
105     {
106         return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
107                                                          VersionRange.createFromVersionSpec( dependency.getVersion() ),
108                                                          dependency.getType(), dependency.getClassifier(),
109                                                          dependency.getScope() );
110     }
111 }