You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2006/09/12 07:46:12 UTC
svn commit: r442459 - in /maven/archiva/trunk/archiva-reports-standard/src:
main/java/org/apache/maven/archiva/reporting/
test/java/org/apache/maven/archiva/reporting/
test/resources/org/apache/maven/archiva/reporting/
Author: brett
Date: Mon Sep 11 22:46:12 2006
New Revision: 442459
URL: http://svn.apache.org/viewvc?view=rev&rev=442459
Log:
[MRM-60] add a basic "old artifact" report
Added:
maven/archiva/trunk/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessor.java (with props)
maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.java (with props)
maven/archiva/trunk/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.xml (with props)
Modified:
maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java
Added: maven/archiva/trunk/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessor.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessor.java?view=auto&rev=442459
==============================================================================
--- maven/archiva/trunk/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessor.java (added)
+++ maven/archiva/trunk/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessor.java Mon Sep 11 22:46:12 2006
@@ -0,0 +1,88 @@
+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.artifact.Artifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+
+import java.io.File;
+
+/**
+ * Find artifacts in the repository that are considered old.
+ *
+ * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="old-artifact"
+ */
+public class OldArtifactReportProcessor
+ implements ArtifactReportProcessor
+{
+ private static final String ROLE_HINT = "old-artifact";
+
+ /**
+ * The maximum age of an artifact before it is reported old, specified in seconds. The default is 1 year.
+ *
+ * @plexus.configuration default-value="31536000"
+ */
+ private int maxAge;
+
+ public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
+ {
+ ArtifactRepository repository = artifact.getRepository();
+
+ if ( !"file".equals( repository.getProtocol() ) )
+ {
+ // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
+ throw new UnsupportedOperationException(
+ "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
+ }
+
+ adjustDistributionArtifactHandler( artifact );
+
+ String artifactPath = repository.pathOf( artifact );
+
+ //get the location of the artifact itself
+ File file = new File( repository.getBasedir(), artifactPath );
+
+ if ( file.exists() )
+ {
+ if ( System.currentTimeMillis() - file.lastModified() > maxAge * 1000 )
+ {
+ // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+ reporter.addNotice( artifact, ROLE_HINT, "old-artifact",
+ "The artifact is older than the maximum age of " + maxAge + " seconds." );
+ }
+ }
+ else
+ {
+ throw new IllegalStateException( "Couldn't find artifact " + file );
+ }
+ }
+
+ private static void adjustDistributionArtifactHandler( Artifact artifact )
+ {
+ // need to tweak these as they aren't currently in the known type converters. TODO - add them in Maven
+ if ( "distribution-zip".equals( artifact.getType() ) )
+ {
+ artifact.setArtifactHandler( new DefaultArtifactHandler( "zip" ) );
+ }
+ else if ( "distribution-tgz".equals( artifact.getType() ) )
+ {
+ artifact.setArtifactHandler( new DefaultArtifactHandler( "tar.gz" ) );
+ }
+ }
+}
Propchange: maven/archiva/trunk/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java?view=diff&rev=442459&r1=442458&r2=442459
==============================================================================
--- maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java (original)
+++ maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java Mon Sep 11 22:46:12 2006
@@ -38,18 +38,35 @@
private ArtifactFactory artifactFactory;
+ private ArtifactRepositoryFactory factory;
+
+ private ArtifactRepositoryLayout layout;
+
protected void setUp()
throws Exception
{
super.setUp();
+
File repositoryDirectory = getTestFile( "src/test/repository" );
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
- ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+ factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
repository = factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout,
null, null );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ }
+
+ protected Artifact createArtifactFromRepository( File repository, String groupId, String artifactId,
+ String version )
+ throws Exception
+ {
+ Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
+
+ artifact.setRepository(
+ factory.createArtifactRepository( "repository", repository.toURL().toString(), layout, null, null ) );
+
+ return artifact;
}
protected Artifact createArtifact( String groupId, String artifactId, String version )
Added: maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.java?view=auto&rev=442459
==============================================================================
--- maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.java (added)
+++ maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.java Mon Sep 11 22:46:12 2006
@@ -0,0 +1,96 @@
+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.reporting.model.ArtifactResults;
+import org.apache.maven.archiva.reporting.model.Result;
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.Iterator;
+
+/**
+ * This class tests the OldArtifactReportProcessor.
+ */
+public class OldArtifactReportProcessorTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private ArtifactReportProcessor artifactReportProcessor;
+
+ private ReportingDatabase reportDatabase;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "old-artifact" );
+
+ ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "old-artifact" );
+ reportDatabase = new ReportingDatabase( reportGroup );
+ }
+
+ public void testOldArtifact()
+ {
+ Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" );
+
+ artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
+ assertEquals( 0, reportDatabase.getNumFailures() );
+ assertEquals( 0, reportDatabase.getNumWarnings() );
+ assertEquals( "Check notices", 1, reportDatabase.getNumNotices() );
+ ArtifactResults results = (ArtifactResults) reportDatabase.getArtifactIterator().next();
+ assertEquals( artifact.getArtifactId(), results.getArtifactId() );
+ assertEquals( artifact.getGroupId(), results.getGroupId() );
+ assertEquals( artifact.getVersion(), results.getVersion() );
+ assertEquals( 1, results.getNotices().size() );
+ Iterator i = results.getNotices().iterator();
+ Result result = (Result) i.next();
+ assertEquals( "old-artifact", result.getProcessor() );
+ }
+
+ public void testNewArtifact()
+ throws Exception
+ {
+ File repository = getTestFile( "target/test-repository" );
+
+ FileUtils.copyDirectoryStructure( getTestFile( "src/test/repository/groupId" ),
+ new File( repository, "groupId" ) );
+
+ Artifact artifact = createArtifactFromRepository( repository, "groupId", "artifactId", "1.0-alpha-1" );
+
+ artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
+ assertEquals( 0, reportDatabase.getNumFailures() );
+ assertEquals( 0, reportDatabase.getNumWarnings() );
+ assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
+ }
+
+ public void testMissingArtifact()
+ throws Exception
+ {
+ Artifact artifact = createArtifact( "foo", "bar", "XP" );
+
+ try
+ {
+ artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
+ fail( "Should not have passed" );
+ }
+ catch ( IllegalStateException e )
+ {
+ assertTrue( true );
+ }
+ }
+}
Propchange: maven/archiva/trunk/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/archiva/trunk/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.xml?view=auto&rev=442459
==============================================================================
--- maven/archiva/trunk/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.xml (added)
+++ maven/archiva/trunk/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.xml Mon Sep 11 22:46:12 2006
@@ -0,0 +1,28 @@
+<!--
+ ~ 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.
+ -->
+
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.archiva.reporting.ArtifactReportProcessor</role>
+ <role-hint>old-artifact</role-hint>
+ <implementation>org.apache.maven.archiva.reporting.OldArtifactReportProcessor</implementation>
+ <configuration>
+ <maxAge>10</maxAge>
+ </configuration>
+ </component>
+ </components>
+</component-set>
\ No newline at end of file
Propchange: maven/archiva/trunk/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/OldArtifactReportProcessorTest.xml
------------------------------------------------------------------------------
svn:eol-style = native