aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-reports-standard
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-09-08 16:56:58 +0000
committerBrett Porter <brett@apache.org>2006-09-08 16:56:58 +0000
commit1f481e2126f96fbc72666fd1913f7ed22057e79f (patch)
tree74cfc385d4853b3d2483e94294395a761db75da6 /archiva-reports-standard
parent0ea31038c852340ffbd8266759a2a1c66bcf3d6c (diff)
downloadarchiva-1f481e2126f96fbc72666fd1913f7ed22057e79f.tar.gz
archiva-1f481e2126f96fbc72666fd1913f7ed22057e79f.zip
[MRM-77] ability to regenerate the report
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441573 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-reports-standard')
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java223
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java5
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java74
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java1
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java7
5 files changed, 310 insertions, 0 deletions
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java
new file mode 100644
index 000000000..4e73d58b5
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java
@@ -0,0 +1,223 @@
+package org.apache.maven.archiva.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
+import org.apache.maven.archiva.discoverer.DiscovererException;
+import org.apache.maven.archiva.discoverer.MetadataDiscoverer;
+import org.apache.maven.archiva.discoverer.filter.AcceptAllMetadataFilter;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.model.Model;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Report executor implementation.
+ *
+ * @plexus.component
+ */
+public class DefaultReportExecutor
+ extends AbstractLogEnabled
+ implements ReportExecutor
+{
+ /**
+ * @plexus.requirement
+ */
+ private MavenProjectBuilder projectBuilder;
+
+ /**
+ * @plexus.requirement
+ */
+ private ReportingStore reportingStore;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @todo replace with a ReportGroup that is identified as "health" and has requirements on the specific health reports
+ * @plexus.requirement role="org.apache.maven.archiva.reporting.ArtifactReportProcessor"
+ */
+ private List artifactReports;
+
+ /**
+ * @plexus.requirement role="org.apache.maven.archiva.reporting.MetadataReportProcessor"
+ */
+ private List metadataReports;
+
+ /**
+ * @plexus.requirement role="org.apache.maven.archiva.discoverer.ArtifactDiscoverer"
+ */
+ private Map artifactDiscoverers;
+
+ /**
+ * @plexus.requirement role="org.apache.maven.archiva.discoverer.MetadataDiscoverer"
+ */
+ private Map metadataDiscoverers;
+
+ public void runMetadataReports( List metadata, ArtifactRepository repository )
+ throws ReportingStoreException
+ {
+ ReportingDatabase reporter = getReportDatabase( repository );
+
+ for ( Iterator i = metadata.iterator(); i.hasNext(); )
+ {
+ RepositoryMetadata repositoryMetadata = (RepositoryMetadata) i.next();
+
+ File file =
+ new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
+ reporter.cleanMetadata( repositoryMetadata, file.lastModified() );
+
+ // TODO: should the report set be limitable by configuration?
+ runMetadataReports( repositoryMetadata, repository, reporter );
+ }
+
+ reportingStore.storeReports( reporter, repository );
+ }
+
+ private void runMetadataReports( RepositoryMetadata repositoryMetadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
+ {
+ for ( Iterator i = metadataReports.iterator(); i.hasNext(); )
+ {
+ MetadataReportProcessor report = (MetadataReportProcessor) i.next();
+
+ report.processMetadata( repositoryMetadata, repository, reporter );
+ }
+ }
+
+ public void runArtifactReports( List artifacts, ArtifactRepository repository )
+ throws ReportingStoreException
+ {
+ ReportingDatabase reporter = getReportDatabase( repository );
+
+ for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+ {
+ Artifact artifact = (Artifact) i.next();
+
+ Model model = null;
+ try
+ {
+ Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion() );
+ MavenProject project =
+ projectBuilder.buildFromRepository( pomArtifact, Collections.EMPTY_LIST, repository );
+
+ model = project.getModel();
+ }
+ catch ( ProjectBuildingException e )
+ {
+ reporter.addWarning( artifact, "Error reading project model: " + e );
+ }
+
+ reporter.removeArtifact( artifact );
+
+ runArtifactReports( artifact, model, reporter );
+ }
+
+ reportingStore.storeReports( reporter, repository );
+ }
+
+ public ReportingDatabase getReportDatabase( ArtifactRepository repository )
+ throws ReportingStoreException
+ {
+ getLogger().debug( "Reading previous report database from repository " + repository.getId() );
+ return reportingStore.getReportsFromStore( repository );
+ }
+
+ public void runReports( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
+ throws DiscovererException, ReportingStoreException
+ {
+ // Flush (as in toilet, not store) the report database
+ reportingStore.removeReportDatabase( repository );
+
+ // Discovery process
+ String layoutProperty = getRepositoryLayout( repository.getLayout() );
+ ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty );
+
+ // Save some memory by not tracking paths we won't use
+ // TODO: Plexus CDC should be able to inject this configuration
+ discoverer.setTrackOmittedPaths( false );
+
+ List artifacts = discoverer.discoverArtifacts( repository, blacklistedPatterns, filter );
+
+ if ( !artifacts.isEmpty() )
+ {
+ getLogger().info( "Discovered " + artifacts.size() + " artifacts" );
+
+ // run the reports
+ runArtifactReports( artifacts, repository );
+ }
+
+ MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers.get( layoutProperty );
+ List metadata =
+ metadataDiscoverer.discoverMetadata( repository, blacklistedPatterns, new AcceptAllMetadataFilter() );
+
+ if ( !metadata.isEmpty() )
+ {
+ getLogger().info( "Discovered " + metadata.size() + " metadata files" );
+
+ // run the reports
+ runMetadataReports( metadata, repository );
+ }
+ }
+
+ private String getRepositoryLayout( ArtifactRepositoryLayout layout )
+ {
+ // gross limitation that there is no reverse lookup of the hint for the layout.
+ if ( layout.getClass().equals( DefaultRepositoryLayout.class ) )
+ {
+ return "default";
+ }
+ else if ( layout.getClass().equals( LegacyRepositoryLayout.class ) )
+ {
+ return "legacy";
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Unknown layout: " + layout );
+ }
+ }
+
+ private void runArtifactReports( Artifact artifact, Model model, ReportingDatabase reporter )
+ {
+ // TODO: should the report set be limitable by configuration?
+ for ( Iterator i = artifactReports.iterator(); i.hasNext(); )
+ {
+ ArtifactReportProcessor report = (ArtifactReportProcessor) i.next();
+
+ report.processArtifact( artifact, model, reporter );
+ }
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java
index 65d920506..b61b12277 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java
@@ -120,4 +120,9 @@ public class DefaultReportingStore
IOUtil.close( fileWriter );
}
}
+
+ public void removeReportDatabase( ArtifactRepository repository )
+ {
+ reports.remove( repository );
+ }
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java
new file mode 100644
index 000000000..c20c10c8c
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java
@@ -0,0 +1,74 @@
+package org.apache.maven.archiva.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.archiva.discoverer.DiscovererException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
+import java.util.List;
+
+/**
+ * Executes a report or report group.
+ */
+public interface ReportExecutor
+{
+ /**
+ * Plexus component role name.
+ */
+ String ROLE = ReportExecutor.class.getName();
+
+ /**
+ * Run reports on a set of metadata.
+ *
+ * @param metadata the RepositoryMetadata objects to report on
+ * @param repository the repository that they come from
+ * @throws ReportingStoreException if there is a problem reading/writing the report database
+ */
+ public void runMetadataReports( List metadata, ArtifactRepository repository )
+ throws ReportingStoreException;
+
+ /**
+ * Run reports on a set of artifacts.
+ *
+ * @param artifacts the Artifact objects to report on
+ * @param repository the repository that they come from
+ * @throws ReportingStoreException if there is a problem reading/writing the report database
+ */
+ public void runArtifactReports( List artifacts, ArtifactRepository repository )
+ throws ReportingStoreException;
+
+ /**
+ * Get the report database in use for a given repository.
+ *
+ * @param repository the repository
+ * @return the report database
+ * @throws ReportingStoreException if there is a problem reading the report database
+ */
+ ReportingDatabase getReportDatabase( ArtifactRepository repository )
+ throws ReportingStoreException;
+
+ /**
+ * Run the artifact and metadata reports for the repository. The artifacts and metadata will be discovered.
+ *
+ * @param repository the repository to run from
+ * @param blacklistedPatterns the patterns to exclude during discovery
+ * @param filter the filter to use during discovery to get a consistent list of artifacts
+ */
+ public void runReports( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
+ throws DiscovererException, ReportingStoreException;
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java
index 823bbe7ef..de6aebf7d 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java
@@ -278,4 +278,5 @@ public class ReportingDatabase
{
return repository;
}
+
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java
index 2f9e71225..f37c41e7c 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java
@@ -50,4 +50,11 @@ public interface ReportingStore
*/
void storeReports( ReportingDatabase database, ArtifactRepository repository )
throws ReportingStoreException;
+
+ /**
+ * Remove the report database from the memory cache.
+ *
+ * @param repository the repository of the database to remove
+ */
+ void removeReportDatabase( ArtifactRepository repository );
}