1 package org.apache.maven.archiva.consumers;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.common.consumers.GenericArtifactConsumer;
23 import org.apache.maven.archiva.common.utils.BaseFile;
24 import org.apache.maven.archiva.reporting.database.ArtifactResultsDatabase;
25 import org.apache.maven.archiva.reporting.group.ReportGroup;
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.InvalidArtifactRTException;
28 import org.apache.maven.model.Model;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.project.MavenProjectBuilder;
31 import org.apache.maven.project.ProjectBuildingException;
33 import java.util.Collections;
36 * ArtifactHealthConsumer
38 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
41 * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumer"
42 * role-hint="artifact-health"
43 * instantiation-strategy="per-lookup"
45 public class ArtifactHealthConsumer
46 extends GenericArtifactConsumer
51 private ArtifactResultsDatabase database;
54 * @plexus.requirement role-hint="health"
56 private ReportGroup health;
61 private MavenProjectBuilder projectBuilder;
63 public void processArtifact( Artifact artifact, BaseFile file )
68 Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact
69 .getArtifactId(), artifact.getVersion() );
70 MavenProject project = projectBuilder.buildFromRepository( pomArtifact, Collections.EMPTY_LIST, repository );
72 model = project.getModel();
74 catch ( InvalidArtifactRTException e )
76 database.addWarning( artifact, "health", "invalid", "Invalid artifact [" + artifact + "] : " + e );
78 catch ( ProjectBuildingException e )
80 database.addWarning( artifact, "health", "project-build", "Error reading project model: " + e );
83 database.remove( artifact );
84 health.processArtifact( artifact, model );
87 public void processFileProblem( BaseFile path, String message )
89 /* do nothing here (yet) */
90 // TODO: store build failure into database?
93 public String getName()
95 return "Artifact Health Consumer";