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
41 * @param artifact The pom xml file to be validated, passed as an artifact object.
42 * @param reporter The artifact reporter object.
44 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
46 ArtifactRepository repository = artifact.getRepository();
48 if ( !"file".equals( repository.getProtocol() ) )
50 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
51 throw new UnsupportedOperationException(
52 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
55 if ( "pom".equals( artifact.getType().toLowerCase() ) )
57 File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
61 reporter.addFailure( artifact, "Artifact not found." );
67 MavenXpp3Reader pomReader = new MavenXpp3Reader();
71 reader = new FileReader( f );
72 pomReader.read( reader );
74 catch ( XmlPullParserException e )
76 reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " +
79 catch ( FileNotFoundException e )
81 reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
83 catch ( IOException e )
85 reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
89 IOUtil.close( reader );
95 reporter.addWarning( artifact, "The artifact is not a pom xml file." );