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.FileReader;
28 import java.io.IOException;
29 import java.io.Reader;
32 * This class validates well-formedness of pom xml file.
34 * @todo nice to have this a specific, tested report - however it is likely to double up with project building exceptions from IndexerTask. Resolve [!]
35 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="invalid-pom"
37 public class InvalidPomArtifactReportProcessor
38 implements ArtifactReportProcessor
40 private static final String ROLE_HINT = "invalid-pom";
43 * @param artifact The pom xml file to be validated, passed as an artifact object.
44 * @param reporter The artifact reporter object.
46 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
48 ArtifactRepository repository = artifact.getRepository();
50 if ( !"file".equals( repository.getProtocol() ) )
52 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
53 throw new UnsupportedOperationException(
54 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
57 if ( "pom".equals( artifact.getType().toLowerCase() ) )
59 File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
63 addFailure( reporter, artifact, "pom-missing", "POM not found." );
69 MavenXpp3Reader pomReader = new MavenXpp3Reader();
73 reader = new FileReader( f );
74 pomReader.read( reader );
76 catch ( XmlPullParserException e )
78 addFailure( reporter, artifact, "pom-parse-exception",
79 "The pom xml file is not well-formed. Error while parsing: " + e.getMessage() );
81 catch ( IOException e )
83 addFailure( reporter, artifact, "pom-io-exception",
84 "Error while reading the pom xml file: " + e.getMessage() );
88 IOUtil.close( reader );
94 private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
96 // TODO: reason could be an i18n key derived from the processor and the problem ID and the
97 reporter.addFailure( artifact, ROLE_HINT, problem, reason );