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