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.repository.ArtifactRepository;
21 import org.apache.maven.model.Model;
22 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
23 import org.codehaus.plexus.util.IOUtil;
24 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
27 import java.io.FileNotFoundException;
28 import java.io.FileReader;
29 import java.io.IOException;
30 import java.io.Reader;
33 * This class validates well-formedness of pom xml file.
35 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="invalid-pom"
37 public class InvalidPomArtifactReportProcessor
38 implements ArtifactReportProcessor
42 * @param artifact The pom xml file to be validated, passed as an artifact object.
43 * @param reporter The artifact reporter object.
44 * @param repository the repository where the artifact is located.
46 public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
47 ArtifactRepository repository )
49 if ( !"file".equals( repository.getProtocol() ) )
51 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
52 throw new UnsupportedOperationException(
53 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
56 if ( "pom".equals( artifact.getType().toLowerCase() ) )
58 File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
62 reporter.addFailure( artifact, "Artifact not found." );
68 MavenXpp3Reader pomReader = new MavenXpp3Reader();
72 reader = new FileReader( f );
73 pomReader.read( reader );
74 reporter.addSuccess( artifact );
76 catch ( XmlPullParserException e )
78 reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " +
81 catch ( FileNotFoundException e )
83 reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
85 catch ( IOException e )
87 reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
91 IOUtil.close( reader );
97 reporter.addWarning( artifact, "The artifact is not a pom xml file." );