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.archiva.discoverer.ArtifactDiscoverer;
20 import org.apache.maven.archiva.discoverer.DiscovererException;
21 import org.apache.maven.archiva.discoverer.MetadataDiscoverer;
22 import org.apache.maven.archiva.discoverer.filter.AcceptAllMetadataFilter;
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.artifact.factory.ArtifactFactory;
25 import org.apache.maven.artifact.repository.ArtifactRepository;
26 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
27 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
28 import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
29 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
30 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
31 import org.apache.maven.model.Model;
32 import org.apache.maven.project.MavenProject;
33 import org.apache.maven.project.MavenProjectBuilder;
34 import org.apache.maven.project.ProjectBuildingException;
35 import org.codehaus.plexus.logging.AbstractLogEnabled;
38 import java.util.Collections;
39 import java.util.Iterator;
40 import java.util.List;
44 * Report executor implementation.
48 public class DefaultReportExecutor
49 extends AbstractLogEnabled
50 implements ReportExecutor
55 private MavenProjectBuilder projectBuilder;
60 private ReportingStore reportingStore;
65 private ArtifactFactory artifactFactory;
68 * @todo replace with a ReportGroup that is identified as "health" and has requirements on the specific health reports
69 * @plexus.requirement role="org.apache.maven.archiva.reporting.ArtifactReportProcessor"
71 private List artifactReports;
74 * @plexus.requirement role="org.apache.maven.archiva.reporting.MetadataReportProcessor"
76 private List metadataReports;
79 * @plexus.requirement role="org.apache.maven.archiva.discoverer.ArtifactDiscoverer"
81 private Map artifactDiscoverers;
84 * @plexus.requirement role="org.apache.maven.archiva.discoverer.MetadataDiscoverer"
86 private Map metadataDiscoverers;
88 public void runMetadataReports( List metadata, ArtifactRepository repository )
89 throws ReportingStoreException
91 ReportingDatabase reporter = getReportDatabase( repository );
93 for ( Iterator i = metadata.iterator(); i.hasNext(); )
95 RepositoryMetadata repositoryMetadata = (RepositoryMetadata) i.next();
98 new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
99 reporter.cleanMetadata( repositoryMetadata, file.lastModified() );
101 // TODO: should the report set be limitable by configuration?
102 runMetadataReports( repositoryMetadata, repository, reporter );
105 reportingStore.storeReports( reporter, repository );
108 private void runMetadataReports( RepositoryMetadata repositoryMetadata, ArtifactRepository repository,
109 ReportingDatabase reporter )
111 for ( Iterator i = metadataReports.iterator(); i.hasNext(); )
113 MetadataReportProcessor report = (MetadataReportProcessor) i.next();
115 report.processMetadata( repositoryMetadata, repository, reporter );
119 public void runArtifactReports( List artifacts, ArtifactRepository repository )
120 throws ReportingStoreException
122 ReportingDatabase reporter = getReportDatabase( repository );
124 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
126 Artifact artifact = (Artifact) i.next();
131 Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
132 artifact.getArtifactId(),
133 artifact.getVersion() );
134 MavenProject project =
135 projectBuilder.buildFromRepository( pomArtifact, Collections.EMPTY_LIST, repository );
137 model = project.getModel();
139 catch ( ProjectBuildingException e )
141 reporter.addWarning( artifact, "Error reading project model: " + e );
144 reporter.removeArtifact( artifact );
146 runArtifactReports( artifact, model, reporter );
149 reportingStore.storeReports( reporter, repository );
152 public ReportingDatabase getReportDatabase( ArtifactRepository repository )
153 throws ReportingStoreException
155 getLogger().debug( "Reading previous report database from repository " + repository.getId() );
156 return reportingStore.getReportsFromStore( repository );
159 public void runReports( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
160 throws DiscovererException, ReportingStoreException
162 // Flush (as in toilet, not store) the report database
163 reportingStore.removeReportDatabase( repository );
166 String layoutProperty = getRepositoryLayout( repository.getLayout() );
167 ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty );
169 // Save some memory by not tracking paths we won't use
170 // TODO: Plexus CDC should be able to inject this configuration
171 discoverer.setTrackOmittedPaths( false );
173 List artifacts = discoverer.discoverArtifacts( repository, blacklistedPatterns, filter );
175 if ( !artifacts.isEmpty() )
177 getLogger().info( "Discovered " + artifacts.size() + " artifacts" );
180 runArtifactReports( artifacts, repository );
183 MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers.get( layoutProperty );
185 metadataDiscoverer.discoverMetadata( repository, blacklistedPatterns, new AcceptAllMetadataFilter() );
187 if ( !metadata.isEmpty() )
189 getLogger().info( "Discovered " + metadata.size() + " metadata files" );
192 runMetadataReports( metadata, repository );
196 private String getRepositoryLayout( ArtifactRepositoryLayout layout )
198 // gross limitation that there is no reverse lookup of the hint for the layout.
199 if ( layout.getClass().equals( DefaultRepositoryLayout.class ) )
203 else if ( layout.getClass().equals( LegacyRepositoryLayout.class ) )
209 throw new IllegalArgumentException( "Unknown layout: " + layout );
213 private void runArtifactReports( Artifact artifact, Model model, ReportingDatabase reporter )
215 // TODO: should the report set be limitable by configuration?
216 for ( Iterator i = artifactReports.iterator(); i.hasNext(); )
218 ArtifactReportProcessor report = (ArtifactReportProcessor) i.next();
220 report.processArtifact( artifact, model, reporter );