diff options
Diffstat (limited to 'archiva-modules/archiva-base')
18 files changed, 520 insertions, 300 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml index a0edd975f..ce7c1409d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml @@ -78,5 +78,10 @@ <artifactId>xmlunit</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java index 7f0abf5ce..41f56b512 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -20,6 +20,8 @@ package org.apache.maven.archiva.consumers.core.repository; */ import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.ManagedRepositoryContent; @@ -41,15 +43,19 @@ public abstract class AbstractRepositoryPurge protected final ManagedRepositoryContent repository; + protected final RepositorySession repositorySession; + protected final List<RepositoryListener> listeners; private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); private static final char DELIM = ' '; - public AbstractRepositoryPurge( ManagedRepositoryContent repository, List<RepositoryListener> listeners ) + public AbstractRepositoryPurge( ManagedRepositoryContent repository, RepositorySession repositorySession, + List<RepositoryListener> listeners ) { this.repository = repository; + this.repositorySession = repositorySession; this.listeners = listeners; } @@ -62,6 +68,7 @@ public abstract class AbstractRepositoryPurge { if ( references != null && !references.isEmpty() ) { + MetadataRepository metadataRepository = repositorySession.getRepository(); for ( ArtifactReference reference : references ) { File artifactFile = repository.toFile( reference ); @@ -69,12 +76,15 @@ public abstract class AbstractRepositoryPurge // FIXME: looks incomplete, might not delete related metadata? for ( RepositoryListener listener : listeners ) { - listener.deleteArtifact( repository.getId(), reference.getGroupId(), reference.getArtifactId(), - reference.getVersion(), artifactFile.getName() ); + listener.deleteArtifact( metadataRepository, repository.getId(), reference.getGroupId(), + reference.getArtifactId(), reference.getVersion(), + artifactFile.getName() ); } // TODO: this needs to be logged artifactFile.delete(); + repositorySession.save(); + triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), AuditEvent.PURGE_ARTIFACT ); purgeSupportFiles( artifactFile ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index e6f218ff6..9179dfcc3 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; @@ -79,9 +81,10 @@ public class CleanupReleasedSnapshotsRepositoryPurge public CleanupReleasedSnapshotsRepositoryPurge( ManagedRepositoryContent repository, MetadataTools metadataTools, ArchivaConfiguration archivaConfig, RepositoryContentFactory repoContentFactory, + RepositorySession repositorySession, List<RepositoryListener> listeners ) { - super( repository, listeners ); + super( repository, repositorySession, listeners ); this.metadataTools = metadataTools; this.archivaConfig = archivaConfig; this.repoContentFactory = repoContentFactory; @@ -168,6 +171,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge artifactRef.getVersion(), artifactRef.getClassifier(), artifactRef.getType(), repository.getId() ); + MetadataRepository metadataRepository = repositorySession.getRepository(); for ( String version : snapshotVersions ) { if ( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) ) @@ -178,8 +182,9 @@ public class CleanupReleasedSnapshotsRepositoryPurge // FIXME: looks incomplete, might not delete related metadata? for ( RepositoryListener listener : listeners ) { - listener.deleteArtifact( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifactFile.getName() ); + listener.deleteArtifact( metadataRepository, repository.getId(), artifact.getGroupId(), + artifact.getArtifactId(), artifact.getVersion(), + artifactFile.getName() ); } needsMetadataUpdate = true; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java index 42eee8103..3c8c65708 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.commons.lang.time.DateUtils; import org.apache.maven.archiva.common.utils.VersionComparator; @@ -42,7 +43,6 @@ import java.util.regex.Matcher; /** * Purge from repository all snapshots older than the specified days in the repository configuration. - * */ public class DaysOldRepositoryPurge extends AbstractRepositoryPurge @@ -53,10 +53,10 @@ public class DaysOldRepositoryPurge private int retentionCount; - public DaysOldRepositoryPurge( ManagedRepositoryContent repository, int daysOlder, - int retentionCount, List<RepositoryListener> listeners ) + public DaysOldRepositoryPurge( ManagedRepositoryContent repository, int daysOlder, int retentionCount, + RepositorySession repositorySession, List<RepositoryListener> listeners ) { - super( repository, listeners ); + super( repository, repositorySession, listeners ); this.daysOlder = daysOlder; this.retentionCount = retentionCount; timestampParser = new SimpleDateFormat( "yyyyMMdd.HHmmss" ); @@ -105,8 +105,8 @@ public class DaysOldRepositoryPurge break; } - ArtifactReference newArtifactReference = - repository.toArtifactReference( artifactFile.getAbsolutePath() ); + ArtifactReference newArtifactReference = repository.toArtifactReference( + artifactFile.getAbsolutePath() ); newArtifactReference.setVersion( version ); File newArtifactFile = repository.toFile( newArtifactReference ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java index ecc845991..e27b261f5 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; @@ -46,11 +48,9 @@ import java.util.List; * Consumer for removing old snapshots in the repository based on the criteria * specified by the user. * - * - * @plexus.component - * role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" - * role-hint="repository-purge" - * instantiation-strategy="per-lookup" + * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" + * role-hint="repository-purge" + * instantiation-strategy="per-lookup" */ public class RepositoryPurgeConsumer extends AbstractMonitoredConsumer @@ -94,9 +94,20 @@ public class RepositoryPurgeConsumer private boolean deleteReleasedSnapshots; - /** @plexus.requirement role="org.apache.archiva.repository.events.RepositoryListener" */ + /** + * @plexus.requirement role="org.apache.archiva.repository.events.RepositoryListener" + */ private List<RepositoryListener> listeners = Collections.emptyList(); - + + /** + * TODO: this could be multiple implementations and needs to be configured. + * + * @plexus.requirement + */ + private RepositorySessionFactory repositorySessionFactory; + + private RepositorySession repositorySession; + public String getId() { return this.id; @@ -125,27 +136,10 @@ public class RepositoryPurgeConsumer public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) throws ConsumerException { + ManagedRepositoryContent repositoryContent; try { - ManagedRepositoryContent repositoryContent = repositoryFactory.getManagedRepositoryContent( repository - .getId() ); - - if ( repository.getDaysOlder() != 0 ) - { - repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder(), - repository.getRetentionCount(), listeners ); - } - else - { - repoPurge = new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), - listeners ); - } - - cleanUp = - new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, configuration, - repositoryFactory, listeners ); - - deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots(); + repositoryContent = repositoryFactory.getManagedRepositoryContent( repository.getId() ); } catch ( RepositoryNotFoundException e ) { @@ -155,6 +149,24 @@ public class RepositoryPurgeConsumer { throw new ConsumerException( "Can't run repository purge: " + e.getMessage(), e ); } + + repositorySession = repositorySessionFactory.createSession(); + + if ( repository.getDaysOlder() != 0 ) + { + repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder(), + repository.getRetentionCount(), repositorySession, listeners ); + } + else + { + repoPurge = new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), + repositorySession, listeners ); + } + + cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, configuration, + repositoryFactory, repositorySession, listeners ); + + deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots(); } public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo ) @@ -189,7 +201,7 @@ public class RepositoryPurgeConsumer public void completeScan() { - /* do nothing */ + repositorySession.close(); } public void completeScan( boolean executeOnEntireRepo ) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java index d7798758c..63a362c76 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; @@ -36,17 +37,16 @@ import java.util.Set; /** * Purge the repository by retention count. Retain only the specified number of snapshots. - * */ public class RetentionCountRepositoryPurge extends AbstractRepositoryPurge { private int retentionCount; - public RetentionCountRepositoryPurge( ManagedRepositoryContent repository, - int retentionCount, List<RepositoryListener> listeners ) + public RetentionCountRepositoryPurge( ManagedRepositoryContent repository, int retentionCount, + RepositorySession repositorySession, List<RepositoryListener> listeners ) { - super( repository, listeners ); + super( repository, repositorySession, listeners ); this.retentionCount = retentionCount; } @@ -61,7 +61,7 @@ public class RetentionCountRepositoryPurge { return; } - + ArtifactReference artifact = repository.toArtifactReference( path ); if ( VersionUtil.isSnapshot( artifact.getVersion() ) ) @@ -114,7 +114,7 @@ public class RetentionCountRepositoryPurge artifact.setVersion( version ); artifact.setClassifier( reference.getClassifier() ); artifact.setType( reference.getType() ); - + try { Set<ArtifactReference> related = repository.getRelatedArtifacts( artifact ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java new file mode 100644 index 000000000..3a96aaa92 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java @@ -0,0 +1,43 @@ +package org.apache.archiva.metadata.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +public class TestRepositorySessionFactory + implements RepositorySessionFactory +{ + private MetadataRepository repository; + + private MetadataResolver resolver; + + public RepositorySession createSession() + { + return new RepositorySession( repository, resolver ); + } + + public void setRepository( MetadataRepository repository ) + { + this.repository = repository; + } + + public void setResolver( MetadataResolver resolver ) + { + this.resolver = resolver; + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index 6ef310fbc..a7a49faf5 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -19,10 +19,11 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; @@ -30,6 +31,9 @@ import org.easymock.MockControl; import java.io.File; import java.io.IOException; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** */ public abstract class AbstractRepositoryPurgeTest @@ -43,15 +47,20 @@ public abstract class AbstractRepositoryPurgeTest public static final int TEST_DAYS_OLDER = 30; - public static final String PATH_TO_BY_DAYS_OLD_ARTIFACT = "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar"; + public static final String PATH_TO_BY_DAYS_OLD_ARTIFACT = + "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar"; - public static final String PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT = "org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar"; + public static final String PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT = + "org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar"; - public static final String PATH_TO_BY_RETENTION_COUNT_ARTIFACT = "org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar"; + public static final String PATH_TO_BY_RETENTION_COUNT_ARTIFACT = + "org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar"; - public static final String PATH_TO_BY_RETENTION_COUNT_POM = "org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT/castor-anttasks-1.1.2-20070506.163513-2.pom"; + public static final String PATH_TO_BY_RETENTION_COUNT_POM = + "org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT/castor-anttasks-1.1.2-20070506.163513-2.pom"; - public static final String PATH_TO_TEST_ORDER_OF_DELETION = "org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar"; + public static final String PATH_TO_TEST_ORDER_OF_DELETION = + "org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar"; protected static final String RELEASES_TEST_REPO_ID = "releases-test-repo-one"; @@ -67,17 +76,25 @@ public abstract class AbstractRepositoryPurgeTest protected RepositoryListener listener; + protected RepositorySession repositorySession; + + protected MetadataRepository metadataRepository; + @Override protected void setUp() throws Exception { super.setUp(); - + listenerControl = MockControl.createControl( RepositoryListener.class ); listener = (RepositoryListener) listenerControl.getMock(); + + repositorySession = mock( RepositorySession.class ); + metadataRepository = mock( MetadataRepository.class ); + when( repositorySession.getRepository() ).thenReturn( metadataRepository ); } - + @Override protected void tearDown() throws Exception @@ -98,7 +115,7 @@ public abstract class AbstractRepositoryPurgeTest config.setSnapshots( true ); config.setDeleteReleasedSnapshots( true ); config.setRetentionCount( TEST_RETENTION_COUNT ); - + return config; } @@ -107,7 +124,7 @@ public abstract class AbstractRepositoryPurgeTest { if ( repo == null ) { - repo = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); + repo = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); repo.setRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); } @@ -123,7 +140,7 @@ public abstract class AbstractRepositoryPurgeTest { assertTrue( "File should exist: " + path, new File( path ).exists() ); } - + protected File getTestRepoRoot() { return getTestFile( "target/test-" + getName() + "/" + TEST_REPO_ID ); @@ -135,16 +152,11 @@ public abstract class AbstractRepositoryPurgeTest File testDir = getTestRepoRoot(); FileUtils.deleteDirectory( testDir ); FileUtils.copyDirectory( getTestFile( "target/test-classes/" + TEST_REPO_ID ), testDir ); - + File releasesTestDir = getTestFile( "target/test-" + getName() + "/" + RELEASES_TEST_REPO_ID ); FileUtils.deleteDirectory( releasesTestDir ); FileUtils.copyDirectory( getTestFile( "target/test-classes/" + RELEASES_TEST_REPO_ID ), releasesTestDir ); - - return testDir.getAbsolutePath(); - } - protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String type ) - { - return new ArchivaArtifact( groupId, artifactId, version, null, type, TEST_REPO_ID ); + return testDir.getAbsolutePath(); } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index f5282e23c..e2dbd9121 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -30,6 +30,7 @@ import org.easymock.MockControl; import java.io.File; import java.util.Collections; +import java.util.List; /** @@ -43,29 +44,32 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public static final String PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO = "org/apache/archiva/released-artifact-in-diff-repo/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar"; - - public static final String PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO = "org/apache/maven/plugins/maven-source-plugin/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar"; - public static final String PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO = "org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar"; - + public static final String PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO = + "org/apache/maven/plugins/maven-source-plugin/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar"; + + public static final String PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO = + "org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar"; + @Override protected void setUp() throws Exception { super.setUp(); - + MetadataTools metadataTools = (MetadataTools) lookup( MetadataTools.class ); - RepositoryContentFactory factory = (RepositoryContentFactory) lookup( RepositoryContentFactory.class, "cleanup-released-snapshots"); - - archivaConfiguration = - (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "cleanup-released-snapshots" ); + RepositoryContentFactory factory = (RepositoryContentFactory) lookup( RepositoryContentFactory.class, + "cleanup-released-snapshots" ); + + archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, + "cleanup-released-snapshots" ); listenerControl = MockControl.createControl( RepositoryListener.class ); - + listener = (RepositoryListener) listenerControl.getMock(); - repoPurge = - new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, archivaConfiguration, factory, - Collections.singletonList( listener ) ); + List<RepositoryListener> listeners = Collections.singletonList( listener ); + repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, archivaConfiguration, + factory, repositorySession, listeners ); } public void testReleasedSnapshotsExistsInSameRepo() @@ -74,20 +78,20 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest Configuration config = archivaConfiguration.getConfiguration(); config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - - String repoRoot = prepareTestRepos(); + + String repoRoot = prepareTestRepos(); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-plugin-plugin", - "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar" ); listenerControl.replay(); - + repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); - + listenerControl.verify(); String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; - + // check if the snapshot was removed assertDeleted( projectRoot + "/2.3-SNAPSHOT" ); assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); @@ -111,19 +115,19 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest // check if metadata file was updated File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); - + String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); - - String expectedVersions = "<expected><versions><version>2.2</version>" + - "<version>2.3</version></versions></expected>"; - + + String expectedVersions = + "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>"; + XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/release", metadataXml ); XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml ); XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml ); XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); } - + public void testNonArtifactFile() throws Exception { @@ -149,25 +153,26 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public void testReleasedSnapshotsExistsInDifferentRepo() throws Exception - { + { Configuration config = archivaConfiguration.getConfiguration(); config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); config.addManagedRepository( getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ) ); - - String repoRoot = prepareTestRepos(); + + String repoRoot = prepareTestRepos(); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.apache.archiva", "released-artifact-in-diff-repo", - "1.0-SNAPSHOT", "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.archiva", + "released-artifact-in-diff-repo", "1.0-SNAPSHOT", + "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); listenerControl.replay(); - + repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO ); listenerControl.verify(); - + String projectRoot = repoRoot + "/org/apache/archiva/released-artifact-in-diff-repo"; - + // check if the snapshot was removed assertDeleted( projectRoot + "/1.0-SNAPSHOT" ); assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); @@ -177,38 +182,38 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.md5" ); assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.sha1" ); - String releasesProjectRoot = - getTestFile( "target/test-" + getName() + "/releases-test-repo-one" ).getAbsolutePath() + - "/org/apache/archiva/released-artifact-in-diff-repo"; - + String releasesProjectRoot = getTestFile( + "target/test-" + getName() + "/releases-test-repo-one" ).getAbsolutePath() + + "/org/apache/archiva/released-artifact-in-diff-repo"; + // check if the released version was not removed - assertExists( releasesProjectRoot + "/1.0" ); + assertExists( releasesProjectRoot + "/1.0" ); assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar" ); assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.md5" ); assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.sha1" ); assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom" ); assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.md5" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.sha1" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.sha1" ); } public void testHigherSnapshotExistsInSameRepo() throws Exception - { + { Configuration config = archivaConfiguration.getConfiguration(); config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - + String repoRoot = prepareTestRepos(); // test listeners for the correct artifacts - no deletions listenerControl.replay(); - + repoPurge.process( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO ); listenerControl.verify(); - + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin"; - + // check if the snapshot was not removed assertExists( projectRoot + "/2.0.3-SNAPSHOT" ); assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar" ); @@ -231,10 +236,10 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); - + String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" + - "<version>2.0.4-SNAPSHOT</version></versions></expected>"; - + "<version>2.0.4-SNAPSHOT</version></versions></expected>"; + XMLAssert.assertXpathEvaluatesTo( "2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml ); XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java index 6db918d6a..b1ef22183 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java @@ -19,12 +19,15 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.repository.events.RepositoryListener; import org.apache.commons.lang.time.DateUtils; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import java.io.File; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Collections; +import java.util.List; /** */ @@ -46,11 +49,10 @@ public class DaysOldRepositoryPurgeTest public void testByLastModified() throws Exception { - repoPurge = - new DaysOldRepositoryPurge( getRepository(), - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(), - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(), - Collections.singletonList( listener ) ); + ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), + repoConfiguration.getRetentionCount(), repositorySession, + Collections.singletonList( listener ) ); String repoRoot = prepareTestRepos(); @@ -59,14 +61,16 @@ public class DaysOldRepositoryPurgeTest setLastModified( projectRoot + "/2.2-SNAPSHOT/", OLD_TIMESTAMP ); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", - "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", - "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" ); - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", - "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", - "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.pom" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-20061118.060401-2", + "maven-install-plugin-2.2-20061118.060401-2.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-20061118.060401-2", + "maven-install-plugin-2.2-20061118.060401-2.pom" ); listenerControl.replay(); repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT ); @@ -106,10 +110,10 @@ public class DaysOldRepositoryPurgeTest public void testOrderOfDeletion() throws Exception { - repoPurge = - new DaysOldRepositoryPurge( getRepository(), getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(), - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(), - Collections.singletonList( listener ) ); + ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + List<RepositoryListener> listeners = Collections.singletonList( listener ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), + repoConfiguration.getRetentionCount(), repositorySession, listeners ); String repoRoot = prepareTestRepos(); @@ -118,10 +122,12 @@ public class DaysOldRepositoryPurgeTest setLastModified( projectRoot + "/1.1.2-SNAPSHOT/", OLD_TIMESTAMP ); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", - "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", - "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); listenerControl.replay(); repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); @@ -154,11 +160,10 @@ public class DaysOldRepositoryPurgeTest public void testMetadataDrivenSnapshots() throws Exception { - repoPurge = - new DaysOldRepositoryPurge( getRepository(), - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(), - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(), - Collections.singletonList( listener ) ); + ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + List<RepositoryListener> listeners = Collections.singletonList( listener ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), + repoConfiguration.getRetentionCount(), repositorySession, listeners ); String repoRoot = prepareTestRepos(); @@ -185,9 +190,9 @@ public class DaysOldRepositoryPurgeTest } // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.codehaus.plexus", "plexus-utils", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.codehaus.plexus", "plexus-utils", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.pom" ); listenerControl.replay(); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java index 4dbf95da6..5fd83812b 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.consumers.core.repository; * under the License. */ +import org.apache.archiva.metadata.repository.RepositorySessionFactory; +import org.apache.archiva.metadata.repository.TestRepositorySessionFactory; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.common.utils.BaseFile; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -62,13 +64,12 @@ public class RepositoryPurgeConsumerTest FileTypes fileTypes = (FileTypes) lookup( FileTypes.class ); fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null ); - KnownRepositoryContentConsumer repoPurgeConsumer = - (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, "repository-purge" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repository-purge" ); File repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" ); - File localFile = - new File( repoLocation, path ); + File localFile = new File( repoLocation, path ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); BaseFile baseFile = new BaseFile( repoLocation, localFile ); @@ -83,16 +84,15 @@ public class RepositoryPurgeConsumerTest File[] contents = dir.listFiles(); for ( int i = 0; i < contents.length; i++ ) { - contents[i].setLastModified( 1179382029 ); + contents[i].setLastModified( 1179382029 ); } } public void testConsumerByRetentionCount() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = - (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, - "repo-purge-consumer-by-retention-count" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" ); ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute. @@ -141,8 +141,8 @@ public class RepositoryPurgeConsumerTest private void addRepoToConfiguration( String configHint, ManagedRepositoryConfiguration repoConfiguration ) throws Exception { - ArchivaConfiguration archivaConfiguration = - (ArchivaConfiguration) lookup( ArchivaConfiguration.class, configHint ); + ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, + configHint ); Configuration configuration = archivaConfiguration.getConfiguration(); configuration.removeManagedRepository( configuration.findManagedRepositoryById( repoConfiguration.getId() ) ); configuration.addManagedRepository( repoConfiguration ); @@ -151,9 +151,8 @@ public class RepositoryPurgeConsumerTest public void testConsumerByDaysOld() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = - (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, - "repo-purge-consumer-by-days-old" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" ); ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); repoConfiguration.setDaysOlder( TEST_DAYS_OLDER ); @@ -182,7 +181,7 @@ public class RepositoryPurgeConsumerTest assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" ); assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" ); assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" ); - + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" ); assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" ); assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" ); @@ -206,9 +205,8 @@ public class RepositoryPurgeConsumerTest public void testReleasedSnapshotsWereNotCleaned() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = - (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, - "repo-purge-consumer-by-retention-count" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" ); ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots. @@ -218,7 +216,8 @@ public class RepositoryPurgeConsumerTest String repoRoot = prepareTestRepos(); - repoPurgeConsumer.processFile( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); + repoPurgeConsumer.processFile( + CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); // check if the snapshot wasn't removed String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; @@ -247,9 +246,8 @@ public class RepositoryPurgeConsumerTest public void testReleasedSnapshotsWereCleaned() throws Exception { - KnownRepositoryContentConsumer repoPurgeConsumer = - (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, - "repo-purge-consumer-by-days-old" ); + KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup( + KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" ); ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); repoConfiguration.setDeleteReleasedSnapshots( true ); @@ -259,7 +257,8 @@ public class RepositoryPurgeConsumerTest String repoRoot = prepareTestRepos(); - repoPurgeConsumer.processFile( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); + repoPurgeConsumer.processFile( + CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; @@ -285,4 +284,14 @@ public class RepositoryPurgeConsumerTest "//metadata/versioning/versions/version", metadataXml ); XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); } + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + factory.setRepository( metadataRepository ); + } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java index 2f488a7c9..06ffbc8f7 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java @@ -1,7 +1,5 @@ package org.apache.maven.archiva.consumers.core.repository; -import java.util.Collections; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -11,7 +9,7 @@ import java.util.Collections; * "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 + * 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 @@ -21,24 +19,27 @@ import java.util.Collections; * under the License. */ +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; + +import java.util.Collections; +import java.util.List; + /** * Test RetentionsCountRepositoryPurgeTest - * */ public class RetentionCountRepositoryPurgeTest extends AbstractRepositoryPurgeTest { - protected void setUp() throws Exception { super.setUp(); - repoPurge = - new RetentionCountRepositoryPurge( - getRepository(), - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(), - Collections.singletonList( listener ) ); + ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + List<RepositoryListener> listeners = Collections.singletonList( listener ); + repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(), + repositorySession, listeners ); } /** @@ -50,18 +51,18 @@ public class RetentionCountRepositoryPurgeTest String repoRoot = prepareTestRepos(); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); - listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); listenerControl.replay(); - + repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); - + listenerControl.verify(); String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT"; @@ -106,18 +107,18 @@ public class RetentionCountRepositoryPurgeTest String repoRoot = prepareTestRepos(); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.codehaus.castor", "castor-anttasks", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks", "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.codehaus.castor", "castor-anttasks", + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks", "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" ); listenerControl.replay(); - + repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM ); - + listenerControl.verify(); String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT"; - + // assert if removed from repo assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" ); assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" ); @@ -154,19 +155,20 @@ public class RetentionCountRepositoryPurgeTest String repoRoot = prepareTestRepos(); // test listeners for the correct artifacts - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", - "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); - listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", - "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); listenerControl.replay(); - + repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); listenerControl.verify(); - String versionRoot = repoRoot + - "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT"; - + String versionRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT"; + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" ); assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.xml index 63f9b0d4d..4b46f0836 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.xml @@ -42,6 +42,9 @@ <role>org.apache.maven.archiva.configuration.FileTypes</role> <role-hint>retention-count</role-hint> </requirement> + <requirement> + <role>org.apache.archiva.metadata.repository.RepositorySessionFactory</role> + </requirement> </requirements> <configuration> <id>repository-purge</id> @@ -125,6 +128,9 @@ <role>org.apache.maven.archiva.configuration.FileTypes</role> <role-hint>days-old</role-hint> </requirement> + <requirement> + <role>org.apache.archiva.metadata.repository.RepositorySessionFactory</role> + </requirement> </requirements> <configuration> <id>repository-purge</id> @@ -185,5 +191,9 @@ </requirement> </requirements> </component> + <component> + <role>org.apache.archiva.metadata.repository.RepositorySessionFactory</role> + <implementation>org.apache.archiva.metadata.repository.TestRepositorySessionFactory</implementation> + </component> </components> </component-set> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index 8948f0f64..5d9af2893 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -24,8 +24,11 @@ import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepositoryException; -import org.apache.archiva.metadata.repository.MetadataResolutionException; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.RepositoryStorage; +import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException; +import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; @@ -81,9 +84,11 @@ public class ArchivaMetadataCreationConsumer private List<String> includes = new ArrayList<String>(); /** + * FIXME: can be of other types + * * @plexus.requirement */ - private MetadataRepository metadataRepository; + private RepositorySessionFactory repositorySessionFactory; /** * FIXME: this needs to be configurable based on storage type - and could also be instantiated per repo. Change to a @@ -149,31 +154,35 @@ public class ArchivaMetadataCreationConsumer project.setId( artifact.getProject() ); String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() ); - // FIXME: maybe not too efficient since it may have already been read and stored for this artifact - ProjectVersionMetadata versionMetadata = null; + + RepositorySession repositorySession = repositorySessionFactory.createSession(); try { - versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId, artifact.getNamespace(), - artifact.getProject(), projectVersion ); - } - catch ( MetadataResolutionException e ) - { - log.warn( "Error occurred resolving POM for artifact: " + path + "; message: " + e.getMessage() ); - } + MetadataRepository metadataRepository = repositorySession.getRepository(); - boolean createVersionMetadata = false; - if ( versionMetadata == null ) - { - log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" ); - versionMetadata = new ProjectVersionMetadata(); - versionMetadata.setId( projectVersion ); - versionMetadata.setIncomplete( true ); - createVersionMetadata = true; - } + boolean createVersionMetadata = false; + + // FIXME: maybe not too efficient since it may have already been read and stored for this artifact + ProjectVersionMetadata versionMetadata = null; + try + { + versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId, artifact.getNamespace(), + artifact.getProject(), projectVersion ); + } + catch ( RepositoryStorageMetadataNotFoundException e ) + { + log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" ); + + versionMetadata = new ProjectVersionMetadata(); + versionMetadata.setId( projectVersion ); + versionMetadata.setIncomplete( true ); + createVersionMetadata = true; + } + catch ( RepositoryStorageMetadataInvalidException e ) + { + log.warn( "Error occurred resolving POM for artifact: " + path + "; message: " + e.getMessage() ); + } - try - { - // FIXME: transaction // read the metadata and update it if it is newer or doesn't exist artifact.setWhenGathered( whenGathered ); metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion, @@ -184,10 +193,16 @@ public class ArchivaMetadataCreationConsumer versionMetadata ); } metadataRepository.updateProject( repoId, project ); + repositorySession.save(); } catch ( MetadataRepositoryException e ) { log.warn( "Error occurred persisting metadata for artifact: " + path + "; message: " + e.getMessage(), e ); + repositorySession.revert(); + } + finally + { + repositorySession.close(); } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java new file mode 100644 index 000000000..2082e724a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java @@ -0,0 +1,36 @@ +package org.apache.archiva.metadata.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +public class TestRepositorySessionFactory + implements RepositorySessionFactory +{ + private MetadataResolver resolver; + + public RepositorySession createSession() + { + return new RepositorySession( new TestMetadataRepository(), resolver ); + } + + public void setResolver( MetadataResolver resolver ) + { + this.resolver = resolver; + } +} diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java index fe5760870..68185312f 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java @@ -19,17 +19,6 @@ package org.apache.maven.archiva.proxy; * under the License. */ -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Locale; - import org.apache.commons.io.FileUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -48,6 +37,17 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.ArgumentsMatcher; import org.easymock.MockControl; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.Locale; + /** * AbstractProxyTestCase * @@ -88,52 +88,57 @@ public abstract class AbstractProxyTestCase protected static final String REPOPATH_LEGACY_MANAGED_TARGET = "target/test-repository/legacy-managed"; - protected static final ArgumentsMatcher customWagonGetIfNewerMatcher = new ArgumentsMatcher() { + protected static final ArgumentsMatcher customWagonGetIfNewerMatcher = new ArgumentsMatcher() + { - public boolean matches(Object[] expected, Object[] actual) { - if (expected.length < 1 || actual.length < 1) + public boolean matches( Object[] expected, Object[] actual ) + { + if ( expected.length < 1 || actual.length < 1 ) { return false; } - return MockControl.ARRAY_MATCHER.matches(ArrayUtils.remove(expected, 1), ArrayUtils.remove(actual, 1)); + return MockControl.ARRAY_MATCHER.matches( ArrayUtils.remove( expected, 1 ), ArrayUtils.remove( actual, + 1 ) ); } - public String toString(Object[] arguments) { - return ArrayUtils.toString(arguments); + public String toString( Object[] arguments ) + { + return ArrayUtils.toString( arguments ); } }; - protected static final ArgumentsMatcher customWagonGetMatcher = new ArgumentsMatcher() { + protected static final ArgumentsMatcher customWagonGetMatcher = new ArgumentsMatcher() + { - public boolean matches(Object[] expected, Object[] actual) + public boolean matches( Object[] expected, Object[] actual ) + { + if ( expected.length == 2 && actual.length == 2 ) { - if (expected.length == 2 && actual.length == 2) + if ( expected[0] == null && actual[0] == null ) { - if (expected[0] == null && actual[0] == null) - { - return true; - } - - if (expected[0] == null) - { - return actual[0] == null; - } + return true; + } - if (actual[0] == null) - { - return expected[0] == null; - } + if ( expected[0] == null ) + { + return actual[0] == null; + } - return expected[0].equals(actual[0]); + if ( actual[0] == null ) + { + return expected[0] == null; } - return false; - } - public String toString(Object[] arguments) - { - return ArrayUtils.toString(arguments); + return expected[0].equals( actual[0] ); } - }; + return false; + } + + public String toString( Object[] arguments ) + { + return ArrayUtils.toString( arguments ); + } + }; protected MockControl wagonMockControl; @@ -187,7 +192,8 @@ public abstract class AbstractProxyTestCase assertNotNull( "Actual File should not be null.", actualFile ); assertTrue( "Check actual file exists.", actualFile.exists() ); - assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), actualFile.getCanonicalPath() ); + assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), + actualFile.getCanonicalPath() ); assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), actualFile.getAbsolutePath() ); String expectedContents = FileUtils.readFileToString( sourceFile, null ); @@ -200,7 +206,7 @@ public abstract class AbstractProxyTestCase assertNull( "Found file: " + downloadedFile + "; but was expecting a failure", downloadedFile ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) protected void assertNoTempFiles( File expectedFile ) { File workingDir = expectedFile.getParentFile(); @@ -209,7 +215,7 @@ public abstract class AbstractProxyTestCase return; } - Collection<File> tmpFiles = FileUtils.listFiles( workingDir, new String[] { "tmp" }, false ); + Collection<File> tmpFiles = FileUtils.listFiles( workingDir, new String[]{"tmp"}, false ); if ( !tmpFiles.isEmpty() ) { StringBuffer emsg = new StringBuffer(); @@ -266,8 +272,8 @@ public abstract class AbstractProxyTestCase { if ( !destination.exists() && !destination.mkdirs() ) { - throw new IOException( "Could not create destination directory '" - + destination.getAbsolutePath() + "'." ); + throw new IOException( + "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } copyDirectoryStructure( file, destination ); @@ -340,8 +346,8 @@ public abstract class AbstractProxyTestCase protected void saveConnector( String sourceRepoId, String targetRepoId, boolean disabled ) { - saveConnector( sourceRepoId, targetRepoId, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, disabled ); + saveConnector( sourceRepoId, targetRepoId, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, + CachedFailuresPolicy.NO, disabled ); } protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy, String releasePolicy, @@ -352,7 +358,8 @@ public abstract class AbstractProxyTestCase } protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy, String releasePolicy, - String snapshotPolicy, String cacheFailuresPolicy, String errorPolicy, boolean disabled ) + String snapshotPolicy, String cacheFailuresPolicy, String errorPolicy, + boolean disabled ) { saveConnector( sourceRepoId, targetRepoId, checksumPolicy, releasePolicy, snapshotPolicy, cacheFailuresPolicy, errorPolicy, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT, disabled ); @@ -371,7 +378,7 @@ public abstract class AbstractProxyTestCase connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, cacheFailuresPolicy ); connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS, errorPolicy ); connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS_ON_UPDATE, errorOnUpdatePolicy ); - connectorConfig.setDisabled(disabled); + connectorConfig.setDisabled( disabled ); int count = config.getConfiguration().getProxyConnectors().size(); config.getConfiguration().addProxyConnector( connectorConfig ); @@ -385,10 +392,10 @@ public abstract class AbstractProxyTestCase config.triggerChange( prefix + ".policies.checksum", connectorConfig.getPolicy( "checksum", "" ) ); config.triggerChange( prefix + ".policies.snapshots", connectorConfig.getPolicy( "snapshots", "" ) ); config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) ); - config.triggerChange( prefix + ".policies.propagate-errors", - connectorConfig.getPolicy( "propagate-errors", "" ) ); - config.triggerChange( prefix + ".policies.propagate-errors-on-update", - connectorConfig.getPolicy( "propagate-errors-on-update", "" ) ); + config.triggerChange( prefix + ".policies.propagate-errors", connectorConfig.getPolicy( "propagate-errors", + "" ) ); + config.triggerChange( prefix + ".policies.propagate-errors-on-update", connectorConfig.getPolicy( + "propagate-errors-on-update", "" ) ); } protected void saveManagedRepositoryConfig( String id, String name, String path, String layout ) @@ -444,6 +451,7 @@ public abstract class AbstractProxyTestCase /** * {@inheritDoc} + * * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getConfigLocation() */ @Override @@ -488,19 +496,28 @@ public abstract class AbstractProxyTestCase config.getConfiguration().addManagedRepository( repoConfig ); // Setup target (proxied to) repository. - saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", new File( REPOPATH_PROXIED1 ).toURL() - .toExternalForm(), "default" ); + saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", new File( + REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository. - saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", new File( REPOPATH_PROXIED2 ).toURL() - .toExternalForm(), "default" ); + saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", new File( + REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository using legacy layout. - saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", new File( REPOPATH_PROXIED_LEGACY ) - .toURL().toExternalForm(), "legacy" ); + saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", new File( + REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" ); // Setup the proxy handler. - proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); + try + { + proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); + } + catch ( Exception e ) + { + // TODO: handle in plexus-spring instead + applicationContext.close(); + throw e; + } // Setup the wagon mock. wagonMockControl = MockControl.createNiceControl( Wagon.class ); @@ -548,8 +565,8 @@ public abstract class AbstractProxyTestCase if ( !sourceDir.exists() ) { // This is just a warning. - System.err.println( "[WARN] Skipping setup of testable managed repository, source dir does not exist: " - + sourceDir ); + System.err.println( + "[WARN] Skipping setup of testable managed repository, source dir does not exist: " + sourceDir ); } else { @@ -583,8 +600,8 @@ public abstract class AbstractProxyTestCase protected void assertNotModified( File file, long expectedModificationTime ) { - assertEquals( "File <" + file.getAbsolutePath() + "> not have been modified.", - expectedModificationTime, file.lastModified() ); + assertEquals( "File <" + file.getAbsolutePath() + "> not have been modified.", expectedModificationTime, + file.lastModified() ); } protected void assertNotExistsInManagedLegacyRepo( File file ) @@ -593,9 +610,9 @@ public abstract class AbstractProxyTestCase String managedLegacyPath = managedLegacyDir.getCanonicalPath(); String testFile = file.getCanonicalPath(); - assertTrue( "Unit Test Failure: File <" + testFile - + "> should be have been defined within the legacy managed path of <" + managedLegacyPath + ">", testFile - .startsWith( managedLegacyPath ) ); + assertTrue( "Unit Test Failure: File <" + testFile + + "> should be have been defined within the legacy managed path of <" + managedLegacyPath + ">", + testFile.startsWith( managedLegacyPath ) ); assertFalse( "File < " + testFile + "> should not exist in managed legacy repository.", file.exists() ); } @@ -606,9 +623,9 @@ public abstract class AbstractProxyTestCase String managedDefaultPath = managedDefaultDir.getCanonicalPath(); String testFile = file.getCanonicalPath(); - assertTrue( "Unit Test Failure: File <" + testFile - + "> should be have been defined within the managed default path of <" + managedDefaultPath + ">", testFile - .startsWith( managedDefaultPath ) ); + assertTrue( "Unit Test Failure: File <" + testFile + + "> should be have been defined within the managed default path of <" + managedDefaultPath + ">", + testFile.startsWith( managedDefaultPath ) ); assertFalse( "File < " + testFile + "> should not exist in managed default repository.", file.exists() ); } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java index fc377c439..39bd94a27 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java @@ -19,13 +19,6 @@ package org.apache.maven.archiva.proxy; * under the License. */ -import java.io.File; -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -46,9 +39,15 @@ import org.mortbay.jetty.Request; import org.mortbay.jetty.Server; import org.mortbay.jetty.handler.AbstractHandler; +import java.io.File; +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + /** * Integration test for connecting over a HTTP proxy. - * + * * @version $Id: ManagedDefaultTransferTest.java 677852 2008-07-18 08:16:24Z brett $ */ public class HttpProxyTransferTest @@ -75,7 +74,7 @@ public class HttpProxyTransferTest throws Exception { super.setUp(); - + // Setup source repository (using default layout) String repoPath = "target/test-repository/managed/" + getName(); @@ -96,8 +95,8 @@ public class HttpProxyTransferTest repo.setLocation( repoPath ); repo.setLayout( "default" ); - ManagedRepositoryContent repoContent = - (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); + ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, + "default" ); repoContent.setRepository( repo ); managedDefaultRepository = repoContent; @@ -113,7 +112,7 @@ public class HttpProxyTransferTest response.setStatus( HttpServletResponse.SC_OK ); response.getWriter().print( "get-default-layout-1.0.jar\n\n" ); assertNotNull( request.getHeader( "Proxy-Connection" ) ); - + ( (Request) request ).setHandled( true ); } }; @@ -130,7 +129,7 @@ public class HttpProxyTransferTest proxyConfig.setProtocol( "http" ); proxyConfig.setId( PROXY_ID ); config.getConfiguration().addNetworkProxy( proxyConfig ); - + // Setup target (proxied to) repository. RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration(); @@ -142,7 +141,16 @@ public class HttpProxyTransferTest config.getConfiguration().addRemoteRepository( repoConfig ); // Setup the proxy handler. - proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); + try + { + proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); + } + catch ( Exception e ) + { + server.stop(); + applicationContext.close(); + throw e; + } } @Override @@ -150,7 +158,7 @@ public class HttpProxyTransferTest throws Exception { super.tearDown(); - + server.stop(); } @@ -159,7 +167,7 @@ public class HttpProxyTransferTest { assertNull( System.getProperty( "http.proxyHost" ) ); assertNull( System.getProperty( "http.proxyPort" ) ); - + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; // Configure Connector (usually done within archiva.xml configuration) @@ -183,7 +191,7 @@ public class HttpProxyTransferTest String expectedContents = FileUtils.readFileToString( sourceFile, null ); String actualContents = FileUtils.readFileToString( downloadedFile, null ); assertEquals( "Check file contents.", expectedContents, actualContents ); - + assertNull( System.getProperty( "http.proxyHost" ) ); assertNull( System.getProperty( "http.proxyPort" ) ); } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml new file mode 100644 index 000000000..6a9baca85 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + <bean id="repositorySessionFactory" class="org.apache.archiva.metadata.repository.TestRepositorySessionFactory"/> +</beans>
\ No newline at end of file |