From: Brett Porter Date: Sat, 9 Sep 2006 08:08:37 +0000 (+0000) Subject: [MRM-77] run report in the background X-Git-Tag: archiva-0.9-alpha-1~572 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2906f4b296596d76041c3cd739bc5c257bc9bc7a;p=archiva.git [MRM-77] run report in the background git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441757 13f79535-47bb-0310-9956-ffa450edef68 --- 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 75280b3ea..b556e15b5 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 @@ -182,6 +182,8 @@ public class IndexerTask List currentArtifacts = artifacts.subList( j, end > artifacts.size() ? artifacts.size() : end ); + // TODO: proper queueing of this in case it was triggered externally (not harmful to do so at present, but not optimal) + // run the reports. Done intermittently to avoid losing track of what is indexed since // that is what the filter is based on. reportExecutor.runArtifactReports( currentArtifacts, repository ); 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 index 4e73d58b5..08a5e89bf 100644 --- 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 @@ -85,6 +85,8 @@ public class DefaultReportExecutor */ private Map metadataDiscoverers; + private static final int ARTIFACT_BUFFER_SIZE = 1000; + public void runMetadataReports( List metadata, ArtifactRepository repository ) throws ReportingStoreException { @@ -160,7 +162,8 @@ public class DefaultReportExecutor throws DiscovererException, ReportingStoreException { // Flush (as in toilet, not store) the report database - reportingStore.removeReportDatabase( repository ); + ReportingDatabase database = getReportDatabase( repository ); + database.clear(); // Discovery process String layoutProperty = getRepositoryLayout( repository.getLayout() ); @@ -176,8 +179,21 @@ public class DefaultReportExecutor { getLogger().info( "Discovered " + artifacts.size() + " artifacts" ); - // run the reports - runArtifactReports( artifacts, repository ); + // 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 ); + + // TODO: proper queueing of this in case it was triggered externally (not harmful to do so at present, but not optimal) + + // run the reports. + runArtifactReports( currentArtifacts, repository ); + } + + // 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(); } MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers.get( layoutProperty ); @@ -220,4 +236,31 @@ public class DefaultReportExecutor report.processArtifact( artifact, model, reporter ); } } + + 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 ); + } + } } 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 b61b12277..8d033e2e0 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 @@ -121,8 +121,4 @@ public class DefaultReportingStore } } - 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 index c20c10c8c..39aedd8d1 100644 --- 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 @@ -68,6 +68,9 @@ public interface ReportExecutor * @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 + * @throws ReportingStoreException if there is a problem reading/writing the report database + * @throws org.apache.maven.archiva.discoverer.DiscovererException + * if there is a problem finding the artifacts and metadata to report on */ 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 de6aebf7d..ba6ad5bf8 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 @@ -45,6 +45,8 @@ public class ReportingDatabase private ArtifactRepository repository; + private boolean inProgress; + public ReportingDatabase() { this( new Reporting(), null ); @@ -279,4 +281,26 @@ public class ReportingDatabase return repository; } + public boolean isInProgress() + { + return inProgress; + } + + public void setInProgress( boolean inProgress ) + { + this.inProgress = inProgress; + } + + public void clear() + { + // clear the values rather than destroy the instance so that the "inProgress" indicator is in tact. + numWarnings = 0; + numFailures = 0; + + artifactMap.clear(); + metadataMap.clear(); + + reporting.getArtifacts().clear(); + reporting.getMetadata().clear(); + } } 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 f37c41e7c..00d9b7c14 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 @@ -51,10 +51,4 @@ 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 ); } diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java index c4a77f365..79f84a085 100644 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java @@ -95,6 +95,14 @@ public class ReportsAction RepositoryConfiguration repositoryConfiguration = configuration.getRepositoryById( repositoryId ); ArtifactRepository repository = factory.createRepository( repositoryConfiguration ); + ReportingDatabase database = executor.getReportDatabase( repository ); + if ( database.isInProgress() ) + { + return SUCCESS; + } + + database.setInProgress( true ); + List blacklistedPatterns = new ArrayList(); if ( repositoryConfiguration.getBlackListPatterns() != null ) { @@ -115,9 +123,16 @@ public class ReportsAction filter = new SnapshotArtifactFilter(); } - executor.runReports( repository, blacklistedPatterns, filter ); + try + { + executor.runReports( repository, blacklistedPatterns, filter ); + } + finally + { + database.setInProgress( false ); + } - return execute(); + return SUCCESS; } public String getRepositoryId() diff --git a/archiva-webapp/src/main/resources/xwork.xml b/archiva-webapp/src/main/resources/xwork.xml index 61def7a32..ea61ccb86 100644 --- a/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-webapp/src/main/resources/xwork.xml @@ -111,6 +111,13 @@ /WEB-INF/jsp/reports/reports.jsp + + + + reports + reports + + /WEB-INF/jsp/showArtifact.jsp diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp index 9bc3713b0..523f05b96 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp @@ -30,6 +30,8 @@
+ +
@@ -38,12 +40,21 @@ Repair all | --%> - - - - - - Regenerate Report + + + + + + + + Regenerate Report + + + + Report in progress + +

Repository: ${database.repository.name}

@@ -55,8 +66,9 @@ ${database.numWarnings}

+ <%-- TODO need to protect iterations against concurrent modification exceptions by cloning the lists synchronously --%> <%-- TODO! factor out common parts, especially artifact rendering tag --%> - <%-- TODO! paginate --%> + <%-- TODO! paginate (displaytag?) --%>

Artifacts