diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
index ccc067f2e..c01f02fda 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
@@ -298,8 +298,8 @@ public class GenerateReportAction
}
input = new StringBuffer(
- "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count," +
- "Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" );
+ "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes," +
+ "Jars,Wars\n" );
// multiple repos
for ( String repo : selectedRepositories )
@@ -322,14 +322,11 @@ public class GenerateReportAction
input.append( repositoryStats.getTotalArtifactFileSize() ).append( "," );
input.append( repositoryStats.getTotalArtifactCount() ).append( "," );
input.append( repositoryStats.getTotalGroupCount() ).append( "," );
- input.append( repositoryStats.getTotalProjectCount() );//.append( "," );
- // TODO
-// input.append( repositoryStats.getPluginCount() ).append( "," );
-// input.append( repositoryStats.getArchetypeCount() ).append( "," );
-// input.append( repositoryStats.getJarCount() ).append( "," );
-// input.append( repositoryStats.getWarCount() ).append( "," );
-// input.append( repositoryStats.getDeploymentCount() ).append( "," );
-// input.append( repositoryStats.getDownloadCount() ).append( "\n" );
+ input.append( repositoryStats.getTotalProjectCount() ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "maven-plugin" ) ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "maven-archetype" ) ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "jar" ) ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "war" ) );
input.append( "\n" );
}
}
@@ -356,8 +353,8 @@ public class GenerateReportAction
}
input = new StringBuffer(
- "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count," +
- "Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" );
+ "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins," +
+ "Archetypes,Jars,Wars\n" );
for ( RepositoryStatistics repositoryStats : stats )
{
@@ -366,14 +363,11 @@ public class GenerateReportAction
input.append( repositoryStats.getTotalArtifactFileSize() ).append( "," );
input.append( repositoryStats.getTotalArtifactCount() ).append( "," );
input.append( repositoryStats.getTotalGroupCount() ).append( "," );
- input.append( repositoryStats.getTotalProjectCount() );//.append( "," );
- // TODO
-// input.append( repositoryStats.getPluginCount() ).append( "," );
-// input.append( repositoryStats.getArchetypeCount() ).append( "," );
-// input.append( repositoryStats.getJarCount() ).append( "," );
-// input.append( repositoryStats.getWarCount() ).append( "," );
-// input.append( repositoryStats.getDeploymentCount() ).append( "," );
-// input.append( repositoryStats.getDownloadCount() );
+ input.append( repositoryStats.getTotalProjectCount() ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "maven-plugin" ) ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "maven-archetype" ) ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "jar" ) ).append( "," );
+ input.append( repositoryStats.getTotalCountForType( "war" ) );
input.append( "\n" );
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp
index 71405670b..990b5833e 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp
@@ -150,14 +150,10 @@
Artifact Count |
Group Count |
Project Count |
- <%-- TODO
Plugins |
Archetypes |
Jars |
Wars |
- Deployments |
- Downloads |
- --%>
@@ -168,15 +164,11 @@
${stats.totalArtifactCount} |
${stats.totalGroupCount} |
${stats.totalProjectCount} |
- <%-- TODO
- ${stats.pluginCount} |
- ${stats.archetypeCount} |
- ${stats.jarCount} |
- ${stats.warCount} |
- ${stats.deploymentCount} |
- ${stats.downloadCount} |
- --%>
-
+ ${stats.totalCountForType['maven-plugin']} |
+ ${stats.totalCountForType['maven-archetype']} |
+ ${stats.totalCountForType['jar']} |
+ ${stats.totalCountForType['war']} |
+
@@ -191,15 +183,11 @@
Artifact Count |
Group Count |
Project Count |
- <%-- TODO
Plugins |
Archetypes |
Jars |
Wars |
- Deployments |
- Downloads |
- --%>
-
+
@@ -209,14 +197,10 @@
${stats.totalArtifactCount} |
${stats.totalGroupCount} |
${stats.totalProjectCount} |
- <%-- TODO
- ${stats.pluginCount} |
- ${stats.archetypeCount} |
- ${stats.jarCount} |
- ${stats.warCount} |
- ${stats.deploymentCount} |
- ${stats.downloadCount} |
- --%>
+ ${stats.totalCountForType['maven-plugin']} |
+ ${stats.totalCountForType['maven-archetype']} |
+ ${stats.totalCountForType['jar']} |
+ ${stats.totalCountForType['war']} |
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java
index 62b4a3ed0..be7a07c4a 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java
@@ -262,12 +262,9 @@ public class GenerateReportActionTest
assertFalse( action.hasActionErrors() );
assertFalse( action.hasFieldErrors() );
-// assertEquals(
-// "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" +
-// date + ",0,0,0,0,0,1,0,1,1,0,0\n", IOUtils.toString( action.getInputStream() ) );
assertEquals(
- "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" +
- date + ",0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
+ "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n" +
+ date + ",0,0,0,0,0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
repositoryStatisticsManagerControl.verify();
}
@@ -581,12 +578,10 @@ public class GenerateReportActionTest
private void assertMultiRepoCsvResult()
throws IOException
{
-// assertEquals(
-// "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" +
-// "snapshots,0,0,0,0,0,1,0,1,1,0,0\n" + "internal,0,0,0,0,0,1,0,1,1,0,0\n",
assertEquals(
- "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" +
- "snapshots,0,0,0,0,0\n" + "internal,0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
+ "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n" +
+ "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n",
+ IOUtils.toString( action.getInputStream() ) );
}
private RepositoryProblemFacet createProblem( String groupId, String artifactId, String repoId )
diff --git a/archiva-modules/plugins/repository-statistics/pom.xml b/archiva-modules/plugins/repository-statistics/pom.xml
index e294ac20e..83a2df5d7 100644
--- a/archiva-modules/plugins/repository-statistics/pom.xml
+++ b/archiva-modules/plugins/repository-statistics/pom.xml
@@ -51,5 +51,9 @@
jcl-over-slf4j
test
+
+ org.apache.archiva
+ archiva-repository-layer
+
diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
index 506f593d9..80d50359e 100644
--- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
+++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
@@ -28,6 +28,10 @@ import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.layout.LayoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,6 +48,11 @@ public class DefaultRepositoryStatisticsManager
*/
private MetadataRepository metadataRepository;
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryContentFactory repositoryContentFactory;
+
public RepositoryStatistics getLastStatistics( String repositoryId )
{
// TODO: consider a more efficient implementation that directly gets the last one from the content repository
@@ -61,11 +70,12 @@ public class DefaultRepositoryStatisticsManager
}
}
- private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns )
+ private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns,
+ ManagedRepositoryContent repositoryContent )
{
for ( String namespace : metadataRepository.getNamespaces( repositoryId, ns ) )
{
- walkRepository( stats, repositoryId, ns + "." + namespace );
+ walkRepository( stats, repositoryId, ns + "." + namespace, repositoryContent );
}
Collection projects = metadataRepository.getProjects( repositoryId, ns );
@@ -84,7 +94,18 @@ public class DefaultRepositoryStatisticsManager
stats.setTotalArtifactCount( stats.getTotalArtifactCount() + 1 );
stats.setTotalArtifactFileSize( stats.getTotalArtifactFileSize() + artifact.getSize() );
- // TODO: add by type
+ // TODO: need a maven2 metadata repository API equivalent
+ try
+ {
+ String type = repositoryContent.toArtifactReference(
+ ns.replace( '.', '/' ) + "/" + project + "/" + version + "/" +
+ artifact.getId() ).getType();
+ stats.setTotalCountForType( type, stats.getTotalCountForType( type ) + 1 );
+ }
+ catch ( LayoutException e )
+ {
+ // ignore
+ }
}
}
}
@@ -92,7 +113,8 @@ public class DefaultRepositoryStatisticsManager
}
- public void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles )
+ public void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles,
+ long newFiles )
{
RepositoryStatistics repositoryStatistics = new RepositoryStatistics();
repositoryStatistics.setScanStartTime( startTime );
@@ -112,7 +134,16 @@ public class DefaultRepositoryStatisticsManager
// it on the fly
for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) )
{
- walkRepository( repositoryStatistics, repositoryId, ns );
+ ManagedRepositoryContent content;
+ try
+ {
+ content = repositoryContentFactory.getManagedRepositoryContent( repositoryId );
+ }
+ catch ( RepositoryException e )
+ {
+ throw new RuntimeException( e );
+ }
+ walkRepository( repositoryStatistics, repositoryId, ns, content );
}
log.info( "Repository walk for statistics executed in " + ( System.currentTimeMillis() - startWalk ) + "ms" );
@@ -157,4 +188,9 @@ public class DefaultRepositoryStatisticsManager
{
this.metadataRepository = metadataRepository;
}
+
+ public void setRepositoryContentFactory( RepositoryContentFactory repositoryContentFactory )
+ {
+ this.repositoryContentFactory = repositoryContentFactory;
+ }
}
diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
index 6b8020054..735818ce5 100644
--- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
+++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
@@ -50,6 +50,8 @@ public class RepositoryStatistics
static final DateFormat SCAN_TIMESTAMP = new SimpleDateFormat( "yyyyMMdd.HHmmss.SSS" );
+ private Map totalCountForType = new HashMap();
+
public Date getScanEndTime()
{
return scanEndTime;
@@ -156,6 +158,10 @@ public class RepositoryStatistics
properties.put( "totalGroupCount", String.valueOf( totalGroupCount ) );
properties.put( "totalProjectCount", String.valueOf( totalProjectCount ) );
properties.put( "newFileCount", String.valueOf( newFileCount ) );
+ for ( Map.Entry entry : totalCountForType.entrySet() )
+ {
+ properties.put( "count-" + entry.getKey(), String.valueOf( entry.getValue() ) );
+ }
return properties;
}
@@ -169,15 +175,14 @@ public class RepositoryStatistics
totalGroupCount = Long.valueOf( properties.get( "totalGroupCount" ) );
totalProjectCount = Long.valueOf( properties.get( "totalProjectCount" ) );
newFileCount = Long.valueOf( properties.get( "newFileCount" ) );
- }
-
- @Override
- public String toString()
- {
- return "RepositoryStatistics{" + "scanEndTime=" + scanEndTime + ", scanStartTime=" + scanStartTime +
- ", totalArtifactCount=" + totalArtifactCount + ", totalArtifactFileSize=" + totalArtifactFileSize +
- ", totalFileCount=" + totalFileCount + ", totalGroupCount=" + totalGroupCount + ", totalProjectCount=" +
- totalProjectCount + ", newFileCount=" + newFileCount + '}';
+ totalCountForType.clear();
+ for ( Map.Entry entry : properties.entrySet() )
+ {
+ if ( entry.getKey().startsWith( "count-" ) )
+ {
+ totalCountForType.put( entry.getKey().substring( 6 ), Long.valueOf( entry.getValue() ) );
+ }
+ }
}
@Override
@@ -226,6 +231,10 @@ public class RepositoryStatistics
{
return false;
}
+ if ( !totalCountForType.equals( that.totalCountForType ) )
+ {
+ return false;
+ }
return true;
}
@@ -241,6 +250,32 @@ public class RepositoryStatistics
result = 31 * result + (int) ( totalGroupCount ^ ( totalGroupCount >>> 32 ) );
result = 31 * result + (int) ( totalProjectCount ^ ( totalProjectCount >>> 32 ) );
result = 31 * result + (int) ( newFileCount ^ ( newFileCount >>> 32 ) );
+ result = 31 * result + totalCountForType.hashCode();
return result;
}
+
+ @Override
+ public String toString()
+ {
+ return "RepositoryStatistics{" + "scanEndTime=" + scanEndTime + ", scanStartTime=" + scanStartTime +
+ ", totalArtifactCount=" + totalArtifactCount + ", totalArtifactFileSize=" + totalArtifactFileSize +
+ ", totalFileCount=" + totalFileCount + ", totalGroupCount=" + totalGroupCount + ", totalProjectCount=" +
+ totalProjectCount + ", newFileCount=" + newFileCount + ", totalCountForType=" + totalCountForType + '}';
+ }
+
+ public Map getTotalCountForType()
+ {
+ return totalCountForType;
+ }
+
+ public long getTotalCountForType( String type )
+ {
+ Long value = totalCountForType.get( type );
+ return value != null ? value : 0;
+ }
+
+ public void setTotalCountForType( String type, long count )
+ {
+ totalCountForType.put( type, count );
+ }
}
diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
index 289a33820..bb050b503 100644
--- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
+++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
@@ -31,7 +31,11 @@ import java.util.Map;
import junit.framework.TestCase;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
import org.easymock.MockControl;
+import org.easymock.classextension.MockClassControl;
public class RepositoryStatisticsManagerTest
extends TestCase
@@ -61,6 +65,18 @@ public class RepositoryStatisticsManagerTest
metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
repositoryStatisticsManager.setMetadataRepository( metadataRepository );
+
+ ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
+ repository.setId( TEST_REPO_ID );
+ repository.setLocation( "" );
+ ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent();
+ content.setRepository( repository );
+ MockControl control = MockClassControl.createControl( RepositoryContentFactory.class );
+ RepositoryContentFactory contentFactory = (RepositoryContentFactory) control.getMock();
+ contentFactory.getManagedRepositoryContent( TEST_REPO_ID );
+ control.setDefaultReturnValue( content );
+ control.replay();
+ repositoryStatisticsManager.setRepositoryContentFactory( contentFactory );
}
public void testGetLatestStats()