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.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.model.Dependency;
23 import org.apache.maven.model.Model;
25 import java.util.Iterator;
26 import java.util.List;
29 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="default"
31 public class DefaultArtifactReportProcessor
32 implements ArtifactReportProcessor
34 private static final String EMPTY_STRING = "";
37 private ArtifactFactory artifactFactory;
39 private RepositoryQueryLayer repositoryQueryLayer;
41 public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
42 ArtifactRepository repository )
44 if ( artifact == null )
46 reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT );
50 processArtifact( artifact, reporter );
55 reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL );
59 List dependencies = model.getDependencies();
60 processDependencies( dependencies, reporter );
64 private void processArtifact( Artifact artifact, ArtifactReporter reporter )
66 boolean hasFailed = false;
67 if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null )
69 reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID );
72 if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null )
74 reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID );
77 if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null )
79 reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION );
84 if ( repositoryQueryLayer.containsArtifact( artifact ) )
86 reporter.addSuccess( artifact );
90 reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
95 private void processDependencies( List dependencies, ArtifactReporter reporter )
97 if ( dependencies.size() > 0 )
99 Iterator iterator = dependencies.iterator();
100 while ( iterator.hasNext() )
102 boolean hasFailed = false;
103 Dependency dependency = (Dependency) iterator.next();
104 Artifact artifact = createArtifact( dependency );
105 if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null )
107 reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID );
110 if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null )
112 reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID );
115 if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null )
117 reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION );
122 if ( repositoryQueryLayer.containsArtifact( artifact ) )
124 reporter.addSuccess( artifact );
128 reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
137 * Only used for passing a mock object when unit testing
139 * @param repositoryQueryLayer
141 protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer )
143 this.repositoryQueryLayer = repositoryQueryLayer;
147 * Only used for passing a mock object when unit testing
149 * @param artifactFactory
151 protected void setArtifactFactory( ArtifactFactory artifactFactory )
153 this.artifactFactory = artifactFactory;
156 private Artifact createArtifact( Dependency dependency )
158 return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(),
159 dependency.getVersion(), "pom" );