1 package org.apache.maven.archiva.reporting.processor;
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.apache.maven.archiva.reporting.processor.ArtifactReportProcessor;
24 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
25 import org.apache.commons.io.IOUtils;
26 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
29 import java.io.FileReader;
30 import java.io.IOException;
31 import java.io.Reader;
34 * This class validates well-formedness of pom xml file.
36 * @todo nice to have this a specific, tested report - however it is likely to double up with project building exceptions from IndexerTask. Resolve [!]
37 * @plexus.component role="org.apache.maven.archiva.reporting.processor.ArtifactReportProcessor" role-hint="invalid-pom"
39 public class InvalidPomArtifactReportProcessor
40 implements ArtifactReportProcessor
42 private static final String ROLE_HINT = "invalid-pom";
45 * @param artifact The pom xml file to be validated, passed as an artifact object.
46 * @param reporter The artifact reporter object.
48 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
50 ArtifactRepository repository = artifact.getRepository();
52 if ( !"file".equals( repository.getProtocol() ) )
54 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
55 throw new UnsupportedOperationException(
56 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
59 if ( "pom".equals( artifact.getType().toLowerCase() ) )
61 File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
65 addFailure( reporter, artifact, "pom-missing", "POM not found." );
71 MavenXpp3Reader pomReader = new MavenXpp3Reader();
75 reader = new FileReader( f );
76 pomReader.read( reader );
78 catch ( XmlPullParserException e )
80 addFailure( reporter, artifact, "pom-parse-exception",
81 "The pom xml file is not well-formed. Error while parsing: " + e.getMessage() );
83 catch ( IOException e )
85 addFailure( reporter, artifact, "pom-io-exception",
86 "Error while reading the pom xml file: " + e.getMessage() );
90 IOUtils.closeQuietly( reader );
96 private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
98 // TODO: reason could be an i18n key derived from the processor and the problem ID and the
99 reporter.addFailure( artifact, ROLE_HINT, problem, reason );