diff options
author | Brett Porter <brett@apache.org> | 2006-09-08 05:16:51 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2006-09-08 05:16:51 +0000 |
commit | 90f0dddc4363000f1b854f4fd8f9f3282433f21d (patch) | |
tree | 864a65b55815fb4b2aa9738d92fe4cafc8299195 /archiva-core | |
parent | 2ae0f74fec8ef399c913b584cbba87b7bf8df053 (diff) | |
download | archiva-90f0dddc4363000f1b854f4fd8f9f3282433f21d.tar.gz archiva-90f0dddc4363000f1b854f4fd8f9f3282433f21d.zip |
[MRM-161] introduce a model for storing reports in the repository, and wire them up on the back of the indexer.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441377 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-core')
-rw-r--r-- | archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java | 20 | ||||
-rw-r--r-- | archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java | 149 |
2 files changed, 163 insertions, 6 deletions
diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java b/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java index 271f97a09..c37e6b608 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java @@ -6,7 +6,9 @@ import org.apache.maven.archiva.discoverer.ArtifactDiscoverer; import org.apache.maven.archiva.discoverer.DiscovererException; import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter; import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter; -import org.apache.maven.archiva.reporting.ArtifactReporter; +import org.apache.maven.archiva.reporting.ReportingDatabase; +import org.apache.maven.archiva.reporting.ReportingStore; +import org.apache.maven.archiva.reporting.ReportingStoreException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; @@ -51,7 +53,7 @@ public class DefaultRepositoryManager /** * @plexus.requirement */ - private ArtifactReporter reporter; + private ReportingStore reportingStore; public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, boolean includeSnapshots ) @@ -80,6 +82,18 @@ public class DefaultRepositoryManager includeSnapshots ? new AcceptAllArtifactFilter() : (ArtifactFilter) new SnapshotArtifactFilter(); List legacyArtifacts = artifactDiscoverer.discoverArtifacts( legacyRepository, null, filter ); - repositoryConverter.convert( legacyArtifacts, repository, reporter ); + ReportingDatabase reporter; + try + { + reporter = reportingStore.getReportsFromStore( repository ); + + repositoryConverter.convert( legacyArtifacts, repository, reporter ); + + reportingStore.storeReports( reporter, repository ); + } + catch ( ReportingStoreException e ) + { + throw new RepositoryConversionException( "Error convering legacy repository.", e ); + } } } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java index c15f3f4c6..94d4aba38 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java @@ -23,15 +23,26 @@ import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory; import org.apache.maven.archiva.configuration.RepositoryConfiguration; 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.SnapshotArtifactFilter; import org.apache.maven.archiva.indexer.RepositoryArtifactIndex; import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory; import org.apache.maven.archiva.indexer.RepositoryIndexException; import org.apache.maven.archiva.indexer.record.IndexRecordExistsArtifactFilter; import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory; +import org.apache.maven.archiva.reporting.ArtifactReportProcessor; +import org.apache.maven.archiva.reporting.ReportingDatabase; +import org.apache.maven.archiva.reporting.ReportingStore; +import org.apache.maven.archiva.reporting.ReportingStoreException; import org.apache.maven.archiva.scheduler.TaskExecutionException; +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.resolver.filter.AndArtifactFilter; +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; @@ -75,10 +86,37 @@ public class IndexerTask private Map artifactDiscoverers; /** + * @plexus.requirement role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" + */ + private List artifactReports; + + /** + * @plexus.requirement role="org.apache.maven.archiva.discoverer.MetadataDiscoverer" + */ + private Map metadataDiscoverers; + + /** + * @plexus.requirement role="org.apache.maven.archiva.reporting.MetadataReportProcessor" + */ + private List metadataReports; + + /** * @plexus.requirement role-hint="standard" */ private RepositoryIndexRecordFactory recordFactory; + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + private static final int ARTIFACT_BUFFER_SIZE = 1000; + + /** + * @plexus.requirement + */ + private ReportingStore reportingStore; + public void execute() throws TaskExecutionException { @@ -136,6 +174,11 @@ public class IndexerTask ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration ); + getLogger().debug( + "Reading previous report database from repository " + repositoryConfiguration.getName() ); + ReportingDatabase reporter = reportingStore.getReportsFromStore( repository ); + + // Discovery process String layoutProperty = repositoryConfiguration.getLayout(); ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty ); AndArtifactFilter filter = new AndArtifactFilter(); @@ -151,13 +194,37 @@ public class IndexerTask getLogger().info( "Searching repository " + repositoryConfiguration.getName() ); List artifacts = discoverer.discoverArtifacts( repository, blacklistedPatterns, filter ); + if ( !artifacts.isEmpty() ) { - // TODO! reporting + getLogger().info( "Discovered " + artifacts.size() + " unindexed artifacts" ); + + // Work through these in batches, then flush the project cache. + for ( int j = 0; j < artifacts.size(); j += ARTIFACT_BUFFER_SIZE ) + { + int end = j + ARTIFACT_BUFFER_SIZE; + List currentArtifacts = + artifacts.subList( j, end > artifacts.size() ? artifacts.size() : end ); - getLogger().info( "Indexing " + artifacts.size() + " new artifacts" ); - index.indexArtifacts( artifacts, recordFactory ); + // run the reports + runArtifactReports( currentArtifacts, reporter ); + + index.indexArtifacts( currentArtifacts, recordFactory ); + } + + // MNG-142 - the project builder retains a lot of objects in its inflexible cache. This is a hack + // around that. TODO: remove when it is configurable + flushProjectBuilderCacheHack(); } + + // TODO! use reporting manager as a filter + MetadataDiscoverer metadataDiscoverer = + (MetadataDiscoverer) metadataDiscoverers.get( layoutProperty ); + metadataDiscoverer.discoverMetadata( repository, blacklistedPatterns ); + + //TODO! metadata reporting + + reportingStore.storeReports( reporter, repository ); } } } @@ -169,11 +236,53 @@ public class IndexerTask { throw new TaskExecutionException( e.getMessage(), e ); } + catch ( ReportingStoreException e ) + { + throw new TaskExecutionException( e.getMessage(), e ); + } time = System.currentTimeMillis() - time; getLogger().info( "Finished repository indexing process in " + time + "ms" ); } + private void runArtifactReports( List artifacts, ReportingDatabase reporter ) + { + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + ArtifactRepository repository = artifact.getRepository(); + + 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 ); + } + runArtifactReports( artifact, model, reporter ); + } + } + + 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 ); + } + } + public void executeNowIfNeeded() throws TaskExecutionException { @@ -202,4 +311,38 @@ public class IndexerTask throw new TaskExecutionException( e.getMessage(), e ); } } + + /** + * @todo remove when no longer needed (MNG-142) + * @plexus.requirement + */ + private MavenProjectBuilder projectBuilder; + + private void flushProjectBuilderCacheHack() + { + try + { + if ( projectBuilder != null ) + { + java.lang.reflect.Field f = projectBuilder.getClass().getDeclaredField( "rawProjectCache" ); + f.setAccessible( true ); + Map cache = (Map) f.get( projectBuilder ); + cache.clear(); + + f = projectBuilder.getClass().getDeclaredField( "processedProjectCache" ); + f.setAccessible( true ); + cache = (Map) f.get( projectBuilder ); + cache.clear(); + } + } + catch ( NoSuchFieldException e ) + { + throw new RuntimeException( e ); + } + catch ( IllegalAccessException e ) + { + throw new RuntimeException( e ); + } + } + } |