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.artifact.Artifact;
21 import org.apache.maven.artifact.factory.ArtifactFactory;
22 import org.apache.maven.artifact.repository.ArtifactRepository;
23 import org.apache.maven.model.Dependency;
24 import org.apache.maven.model.Model;
26 import java.util.Iterator;
27 import java.util.List;
30 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="default"
32 public class DefaultArtifactReportProcessor
33 implements ArtifactReportProcessor
35 private static final String EMPTY_STRING = "";
38 private ArtifactFactory artifactFactory;
40 private RepositoryQueryLayer repositoryQueryLayer;
42 public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
43 ArtifactRepository repository )
45 if ( artifact == null )
47 reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT );
51 processArtifact( artifact, reporter );
56 reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL );
60 List dependencies = model.getDependencies();
61 processDependencies( dependencies, reporter );
65 private void processArtifact( Artifact artifact, ArtifactReporter reporter )
67 boolean hasFailed = false;
68 if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null )
70 reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID );
73 if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null )
75 reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID );
78 if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null )
80 reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION );
85 if ( repositoryQueryLayer.containsArtifact( artifact ) )
87 reporter.addSuccess( artifact );
91 reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
96 private void processDependencies( List dependencies, ArtifactReporter reporter )
98 if ( dependencies.size() > 0 )
100 Iterator iterator = dependencies.iterator();
101 while ( iterator.hasNext() )
103 boolean hasFailed = false;
104 Dependency dependency = (Dependency) iterator.next();
105 Artifact artifact = createArtifact( dependency );
106 if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null )
108 reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID );
111 if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null )
113 reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID );
116 if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null )
118 reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION );
123 if ( repositoryQueryLayer.containsArtifact( artifact ) )
125 reporter.addSuccess( artifact );
129 reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
138 * Only used for passing a mock object when unit testing
140 * @param repositoryQueryLayer
142 protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer )
144 this.repositoryQueryLayer = repositoryQueryLayer;
148 * Only used for passing a mock object when unit testing
150 * @param artifactFactory
152 protected void setArtifactFactory( ArtifactFactory artifactFactory )
154 this.artifactFactory = artifactFactory;
157 private Artifact createArtifact( Dependency dependency )
159 return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(),
160 dependency.getVersion(), "pom" );