* under the License.
*/
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;
-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;
-
/**
* @plexus.component role="org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager" role-hint="default"
*/
*/
private MetadataRepository metadataRepository;
- /**
- * @plexus.requirement
- */
- private RepositoryContentFactory repositoryContentFactory;
-
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
public RepositoryStatistics getLastStatistics( String repositoryId )
}
}
- private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns,
- ManagedRepositoryContent repositoryContent )
+ private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns )
{
for ( String namespace : metadataRepository.getNamespaces( repositoryId, ns ) )
{
- walkRepository( stats, repositoryId, ns + "." + namespace, repositoryContent );
+ walkRepository( stats, repositoryId, ns + "." + namespace );
}
Collection<String> projects = metadataRepository.getProjects( repositoryId, ns );
stats.setTotalArtifactCount( stats.getTotalArtifactCount() + 1 );
stats.setTotalArtifactFileSize( stats.getTotalArtifactFileSize() + artifact.getSize() );
- // TODO: need a maven2 metadata repository API equivalent
- try
+ MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID );
+ if ( facet != null )
{
- String type = repositoryContent.toArtifactReference(
- ns.replace( '.', '/' ) + "/" + project + "/" + version + "/" +
- artifact.getId() ).getType();
+ String type = facet.getType();
stats.setTotalCountForType( type, stats.getTotalCountForType( type ) + 1 );
}
- catch ( LayoutException e )
- {
- // ignore
- }
}
}
}
// it on the fly
for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) )
{
- ManagedRepositoryContent content;
- try
- {
- content = repositoryContentFactory.getManagedRepositoryContent( repositoryId );
- }
- catch ( RepositoryException e )
- {
- throw new RuntimeException( e );
- }
- walkRepository( repositoryStatistics, repositoryId, ns, content );
+ walkRepository( repositoryStatistics, repositoryId, ns );
}
log.info( "Repository walk for statistics executed in " + ( System.currentTimeMillis() - startWalk ) + "ms" );
{
this.metadataRepository = metadataRepository;
}
-
- public void setRepositoryContentFactory( RepositoryContentFactory repositoryContentFactory )
- {
- this.repositoryContentFactory = repositoryContentFactory;
- }
}
* under the License.
*/
+import junit.framework.TestCase;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.easymock.MockControl;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Map;
import java.util.TimeZone;
-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
{
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()