]> source.dussan.org Git - archiva.git/blob
851bbd9021ceb8a25c3e23fc40cfaefdd814e6d7
[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.versioning.InvalidVersionSpecificationException;
24 import org.apache.maven.artifact.versioning.VersionRange;
25 import org.apache.maven.model.Dependency;
26 import org.apache.maven.model.Model;
27
28 import java.text.MessageFormat;
29 import java.util.Iterator;
30 import java.util.List;
31
32 /**
33  * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="dependency"
34  */
35 public class DependencyArtifactReportProcessor
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( Artifact artifact, Model model, ReportingDatabase reporter )
49     {
50         RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
51         processArtifact( artifact, reporter, queryLayer );
52
53         if ( model != null )
54         {
55             List dependencies = model.getDependencies();
56             processDependencies( dependencies, reporter, queryLayer, artifact );
57         }
58     }
59
60     private void processArtifact( Artifact artifact, ReportingDatabase reporter,
61                                   RepositoryQueryLayer repositoryQueryLayer )
62     {
63         if ( !repositoryQueryLayer.containsArtifact( artifact ) )
64         {
65             reporter.addFailure( artifact, "Artifact does not exist in the repository" );
66         }
67     }
68
69     private void processDependencies( List dependencies, ReportingDatabase reporter,
70                                       RepositoryQueryLayer repositoryQueryLayer, Artifact sourceArtifact )
71     {
72         if ( dependencies.size() > 0 )
73         {
74             Iterator iterator = dependencies.iterator();
75             while ( iterator.hasNext() )
76             {
77                 Dependency dependency = (Dependency) iterator.next();
78
79                 try
80                 {
81                     Artifact artifact = createArtifact( dependency );
82
83                     if ( !repositoryQueryLayer.containsArtifact( artifact ) )
84                     {
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 );
89                     }
90                 }
91                 catch ( InvalidVersionSpecificationException e )
92                 {
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 );
97                 }
98             }
99         }
100     }
101
102     private Artifact createArtifact( Dependency dependency )
103         throws InvalidVersionSpecificationException
104     {
105         return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
106                                                          VersionRange.createFromVersionSpec( dependency.getVersion() ),
107                                                          dependency.getType(), dependency.getClassifier(),
108                                                          dependency.getScope() );
109     }
110 }