1 package org.apache.maven.repository.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.xml.pull.XmlPullParserException;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
30 import java.io.Reader;
31 import java.net.MalformedURLException;
35 * This class validates well-formedness of pom xml file.
37 public class InvalidPomArtifactReportProcessor
38 implements ArtifactReportProcessor
43 * @param artifact The pom xml file to be validated, passed as an artifact object.
44 * @param reporter The artifact reporter object.
45 * @param repository the repository where the artifact is located.
47 public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
48 ArtifactRepository repository )
50 InputStream is = null;
52 if ( "pom".equals( artifact.getType().toLowerCase() ) )
55 if ( "file".equals( repository.getProtocol() ) )
59 is = new FileInputStream( repository.getBasedir() + artifact.getGroupId() + "/" +
60 artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/" + artifact.getArtifactId() +
61 "-" + artifact.getBaseVersion() + "." + artifact.getType() );
63 catch ( FileNotFoundException fe )
65 reporter.addFailure( artifact, "Artifact not found." );
72 URL url = new URL( repository.getUrl() + artifact.getGroupId() + "/" + artifact.getArtifactId() +
73 "/" + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" +
74 artifact.getBaseVersion() + "." + artifact.getType() );
75 is = url.openStream();
78 catch ( MalformedURLException me )
80 reporter.addFailure( artifact, "Error retrieving artifact from remote repository." );
82 catch ( IOException ie )
84 reporter.addFailure( artifact, "Error retrieving artifact from remote repository." );
88 Reader reader = new InputStreamReader( is );
89 MavenXpp3Reader pomReader = new MavenXpp3Reader();
93 Model pomModel = pomReader.read( reader );
94 reporter.addSuccess( artifact );
96 catch ( XmlPullParserException xe )
98 reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing." );
100 catch ( IOException oe )
102 reporter.addFailure( artifact, "Error while reading the pom xml file." );
108 reporter.addWarning( artifact, "The artifact is not a pom xml file." );