*/
public interface ArchivaConfiguration
{
- String ROLE = ArchivaConfiguration.class.getName();
-
/**
* Get the configuration.
*
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
+import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
*/
public class ArtifactMissingChecksumsConsumer
extends AbstractMonitoredConsumer
- implements KnownRepositoryContentConsumer, RegistryListener, Initializable
+ implements KnownRepositoryContentConsumer, RegistryListener
{
private String id;
this.description = description;
this.configuration = configuration;
this.filetypes = filetypes;
+
+ configuration.addChangeListener( this );
+
+ initIncludes();
}
public String getId()
}
public void initialize()
- throws InitializationException
{
configuration.addChangeListener( this );
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
* AutoRemoveConsumer
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
* role-hint="auto-remove"
* instantiation-strategy="per-lookup"
*/
+@Service("knownRepositoryContentConsumer#auto-remove")
+@Scope("prototype")
public class AutoRemoveConsumer
extends AbstractMonitoredConsumer
- implements KnownRepositoryContentConsumer, RegistryListener, Initializable
+ implements KnownRepositoryContentConsumer, RegistryListener
{
/**
- * @plexus.configuration default-value="auto-remove"
+ * plexus.configuration default-value="auto-remove"
*/
- private String id;
+ private String id = "auto-remove";
/**
- * @plexus.configuration default-value="Automatically Remove File from Filesystem."
+ * plexus.configuration default-value="Automatically Remove File from Filesystem."
*/
- private String description;
+ private String description = "Automatically Remove File from Filesystem.";
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private ArchivaConfiguration configuration;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private FileTypes filetypes;
private File repositoryDir;
includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
}
+ @PostConstruct
public void initialize()
- throws InitializationException
- {
+ {
configuration.addChangeListener( this );
initIncludes();
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
* AutoRenameConsumer
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
* role-hint="auto-rename"
* instantiation-strategy="per-lookup"
*/
+@Service("knownRepositoryContentConsumer#auto-rename")
+@Scope("prototype")
public class AutoRenameConsumer
extends AbstractMonitoredConsumer
implements KnownRepositoryContentConsumer
{
/**
- * @plexus.configuration default-value="auto-rename"
+ * plexus.configuration default-value="auto-rename"
*/
- private String id;
+ private String id = "auto-rename";
/**
- * @plexus.configuration default-value="Automatically rename common artifact mistakes."
+ * plexus.configuration default-value="Automatically rename common artifact mistakes."
*/
- private String description;
+ private String description = "Automatically rename common artifact mistakes.";
private static final String RENAME_FAILURE = "rename_failure";
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.archiva.repository.metadata.MetadataTools;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
/**
* MetadataUpdaterConsumer will create and update the metadata present within the repository.
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
* role-hint="metadata-updater"
* instantiation-strategy="per-lookup"
*/
+@Service("knownRepositoryContentConsumer#metadata-updater")
+@Scope("prototype")
public class MetadataUpdaterConsumer
extends AbstractMonitoredConsumer
- implements KnownRepositoryContentConsumer, RegistryListener, Initializable
+ implements KnownRepositoryContentConsumer, RegistryListener
{
private Logger log = LoggerFactory.getLogger( MetadataUpdaterConsumer.class );
/**
- * @plexus.configuration default-value="metadata-updater"
+ * plexus.configuration default-value="metadata-updater"
*/
- private String id;
+ private String id = "metadata-updater";
/**
- * @plexus.configuration default-value="Update / Create maven-metadata.xml files"
+ * plexus.configuration default-value="Update / Create maven-metadata.xml files"
*/
- private String description;
+ private String description = "Update / Create maven-metadata.xml files";
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private RepositoryContentFactory repositoryFactory;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private MetadataTools metadataTools;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private ArchivaConfiguration configuration;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private FileTypes filetypes;
private static final String TYPE_METADATA_BAD_INTERNAL_REF = "metadata-bad-internal-ref";
includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
}
+ @PostConstruct
public void initialize()
- throws InitializationException
{
configuration.addChangeListener( this );
* under the License.
*/
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.codehaus.plexus.digest.ChecksumFile;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
* ValidateChecksumConsumer - validate the provided checksum against the file it represents.
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
- * role-hint="validate-checksum"
- * instantiation-strategy="per-lookup"
+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
+ * role-hint="validate-checksum"
+ * instantiation-strategy="per-lookup"
*/
+@Service( "knownRepositoryContentConsumer#validate-checksum" )
+@Scope( "prototype" )
public class ValidateChecksumConsumer
extends AbstractMonitoredConsumer
- implements KnownRepositoryContentConsumer, Initializable
+ implements KnownRepositoryContentConsumer
{
private static final String NOT_VALID_CHECKSUM = "checksum-not-valid";
private static final String CHECKSUM_IO_ERROR = "checksum-io-error";
/**
- * @plexus.configuration default-value="validate-checksums"
+ * plexus.configuration default-value="validate-checksums"
*/
- private String id;
+ private String id = "validate-checksums";
/**
- * @plexus.configuration default-value="Validate checksums against file."
+ * plexus.configuration default-value="Validate checksums against file."
*/
- private String description;
+ private String description = "Validate checksums against file.";
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private ChecksumFile checksum;
/**
- * @plexus.requirement role="org.codehaus.plexus.digest.Digester"
+ * plexus.requirement role="org.codehaus.plexus.digest.Digester"
*/
private List<Digester> digesterList;
+ @Inject
+ private PlexusSisuBridge plexusSisuBridge;
+
private File repositoryDir;
private List<String> includes = new ArrayList<String>();
processFile( path );
}
+ @PostConstruct
public void initialize()
- throws InitializationException
+ throws PlexusSisuBridgeException
{
+ digesterList = plexusSisuBridge.lookupList( Digester.class );
for ( Iterator<Digester> itDigesters = digesterList.iterator(); itDigesters.hasNext(); )
{
Digester digester = itDigesters.next();
*
* @param path path to the scanned artifact
*/
- public void process( String path )
+ void process( String path )
throws RepositoryPurgeException;
}
import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
import org.apache.maven.archiva.repository.metadata.MetadataTools;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
/**
* 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"
+ * <p/>
+ * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
* role-hint="repository-purge"
* instantiation-strategy="per-lookup"
*/
+@Service( "knownRepositoryContentConsumer#repository-purge" )
+@Scope( "prototype" )
public class RepositoryPurgeConsumer
extends AbstractMonitoredConsumer
- implements KnownRepositoryContentConsumer, RegistryListener, Initializable
+ implements KnownRepositoryContentConsumer, RegistryListener
{
/**
- * @plexus.configuration default-value="repository-purge"
+ * plexus.configuration default-value="repository-purge"
*/
- private String id;
+ private String id = "repository-purge";
/**
- * @plexus.configuration default-value="Purge repository of old snapshots"
+ * plexus.configuration default-value="Purge repository of old snapshots"
*/
- private String description;
+ private String description = "Purge repository of old snapshots";
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private ArchivaConfiguration configuration;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
- private RepositoryContentFactory repositoryFactory;
+ @Inject
+ private RepositoryContentFactory repositoryContentFactory;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private MetadataTools metadataTools;
/**
- * @plexus.requirement
+ * plexus.requirement
*/
+ @Inject
private FileTypes filetypes;
private List<String> includes = new ArrayList<String>();
private boolean deleteReleasedSnapshots;
+ @Inject
+ private ApplicationContext applicationContext;
+
/**
- * @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
+ * plexus.requirement
*/
+ @Inject
private RepositorySessionFactory repositorySessionFactory;
private RepositorySession repositorySession;
ManagedRepositoryContent repositoryContent;
try
{
- repositoryContent = repositoryFactory.getManagedRepositoryContent( repository.getId() );
+ repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId() );
}
catch ( RepositoryNotFoundException e )
{
}
else
{
- repoPurge = new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(),
- repositorySession, listeners );
+ repoPurge =
+ new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), repositorySession,
+ listeners );
}
cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, configuration,
- repositoryFactory, repositorySession, listeners );
+ repositoryContentFactory, repositorySession, listeners );
deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots();
}
includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
}
+ @PostConstruct
public void initialize()
- throws InitializationException
{
+ this.listeners =
+ new ArrayList<RepositoryListener>( applicationContext.getBeansOfType( RepositoryListener.class ).values() );
configuration.addChangeListener( this );
initIncludes();
// we need to check all files for deletion, especially if not modified
return true;
}
+
+ public ArchivaConfiguration getConfiguration()
+ {
+ return configuration;
+ }
+
+ public void setConfiguration( ArchivaConfiguration configuration )
+ {
+ this.configuration = configuration;
+ }
+
+ public RepositoryContentFactory getRepositoryContentFactory()
+ {
+ return repositoryContentFactory;
+ }
+
+ public void setRepositoryContentFactory( RepositoryContentFactory repositoryContentFactory )
+ {
+ this.repositoryContentFactory = repositoryContentFactory;
+ }
+
+ public MetadataTools getMetadataTools()
+ {
+ return metadataTools;
+ }
+
+ public void setMetadataTools( MetadataTools metadataTools )
+ {
+ this.metadataTools = metadataTools;
+ }
+
+ public FileTypes getFiletypes()
+ {
+ return filetypes;
+ }
+
+ public void setFiletypes( FileTypes filetypes )
+ {
+ this.filetypes = filetypes;
+ }
+
+ public RepositoryPurge getRepoPurge()
+ {
+ return repoPurge;
+ }
+
+ public void setRepoPurge( RepositoryPurge repoPurge )
+ {
+ this.repoPurge = repoPurge;
+ }
+
+ public RepositoryPurge getCleanUp()
+ {
+ return cleanUp;
+ }
+
+ public void setCleanUp( RepositoryPurge cleanUp )
+ {
+ this.cleanUp = cleanUp;
+ }
+
+ public boolean isDeleteReleasedSnapshots()
+ {
+ return deleteReleasedSnapshots;
+ }
+
+ public void setDeleteReleasedSnapshots( boolean deleteReleasedSnapshots )
+ {
+ this.deleteReleasedSnapshots = deleteReleasedSnapshots;
+ }
+
+ public RepositorySessionFactory getRepositorySessionFactory()
+ {
+ return repositorySessionFactory;
+ }
+
+ public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
+ {
+ this.repositorySessionFactory = repositorySessionFactory;
+ }
+
+ public RepositorySession getRepositorySession()
+ {
+ return repositorySession;
+ }
+
+ public void setRepositorySession( RepositorySession repositorySession )
+ {
+ this.repositorySession = repositorySession;
+ }
}
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.maven.archiva.consumers.core"/>
+
<bean id="artifactMissingChecksumsConsumer" class="org.apache.maven.archiva.consumers.core.ArtifactMissingChecksumsConsumer" scope="prototype">
<constructor-arg>
<value>create-missing-checksums</value>
<ref bean="fileTypes"/>
</constructor-arg>
</bean>
+ <alias name="artifactMissingChecksumsConsumer" alias="knownRepositoryContentConsumer#artifact-missing-checksums-consumer"/>
</beans>
\ No newline at end of file
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.
- */
+import org.springframework.stereotype.Service;
+/*
+* 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.
+*/
+@Service("repositorySessionFactory#test")
public class TestRepositorySessionFactory
implements RepositorySessionFactory
{
* under the License.
*/
-import java.io.File;
-
+import junit.framework.TestCase;
import org.apache.maven.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.FileType;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import java.io.File;
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
public abstract class AbstractArtifactConsumerTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
private File repoLocation;
protected KnownRepositoryContentConsumer consumer;
- protected void setUp()
+ @Inject
+ protected ApplicationContext applicationContext;
+
+ @Inject
+ ArchivaConfiguration archivaConfiguration;
+
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
- ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
FileType fileType =
(FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
fileType.addPattern( "**/*.xml" );
- repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
+ repoLocation = new File( "target/test-" + getName() + "/test-repo" );
}
+ @Test
public void testConsumption()
{
File localFile =
assertFalse( predicate.evaluate( consumer ) );
}
+ @Test
public void testConsumptionOfOtherMetadata()
{
File localFile =
import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.junit.Before;
+import org.junit.Test;
import java.io.File;
import java.util.Calendar;
{
private ManagedRepositoryConfiguration repoConfig;
- @Override
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception
{
- super.setUp();
+ //super.setUp();
repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId( "test-repo" );
repoConfig.setName( "Test Repository" );
repoConfig.setLayout( "default" );
- repoConfig.setLocation( new File( getBasedir(), "target/test-classes/test-repo/" ).getPath() );
+ repoConfig.setLocation( new File( "target/test-classes/test-repo/" ).getPath() );
- consumer = (ArtifactMissingChecksumsConsumer) lookup( "artifactMissingChecksumsConsumer" );
+ consumer = applicationContext.getBean( "knownRepositoryContentConsumer#artifact-missing-checksums-consumer",
+ KnownRepositoryContentConsumer.class );
}
+ @Test
public void testNoExistingChecksums()
throws Exception
{
assertTrue( md5File.exists() );
}
+ @Test
public void testExistingIncorrectChecksums()
throws Exception
{
- File newLocation = getTestFile( "target/test-repo" );
+ File newLocation = new File( "target/test-repo" );
FileUtils.deleteDirectory( newLocation );
FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation );
repoConfig.setLocation( newLocation.getAbsolutePath() );
*/
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.junit.Before;
public class MetadataUpdateConsumerTest
extends AbstractArtifactConsumerTest
{
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception
{
- super.setUp();
-
- consumer = (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class.getName(),
- "metadata-updater" );
+ consumer = applicationContext.getBean( "knownRepositoryContentConsumer#metadata-updater",
+ KnownRepositoryContentConsumer.class );
}
}
\ No newline at end of file
* under the License.
*/
+import junit.framework.TestCase;
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.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
-
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
/**
*/
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public abstract class AbstractRepositoryPurgeTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
public static final String TEST_REPO_ID = "test-repo";
protected MetadataRepository metadataRepository;
- @Override
- protected void setUp()
+ @Inject
+ protected ApplicationContext applicationContext;
+
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
when( repositorySession.getRepository() ).thenReturn( metadataRepository );
}
- @Override
- protected void tearDown()
+ @After
+ public void tearDown()
throws Exception
{
super.tearDown();
config.setId( repoId );
config.setName( repoName );
config.setDaysOlder( TEST_DAYS_OLDER );
- config.setLocation( getTestFile( "target/test-" + getName() + "/" + repoId ).getAbsolutePath() );
+ config.setLocation( new File( "target/test-" + getName() + "/" + repoId ).getAbsolutePath() );
config.setReleases( true );
config.setSnapshots( true );
config.setDeleteReleasedSnapshots( true );
{
if ( repo == null )
{
- repo = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
+ repo = applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class );
repo.setRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) );
}
protected File getTestRepoRoot()
{
- return getTestFile( "target/test-" + getName() + "/" + TEST_REPO_ID );
+ return new File( "target/test-" + getName() + "/" + TEST_REPO_ID );
}
protected String prepareTestRepos()
{
File testDir = getTestRepoRoot();
FileUtils.deleteDirectory( testDir );
- FileUtils.copyDirectory( getTestFile( "target/test-classes/" + TEST_REPO_ID ), testDir );
+ FileUtils.copyDirectory( new File( "target/test-classes/" + TEST_REPO_ID ), testDir );
- File releasesTestDir = getTestFile( "target/test-" + getName() + "/" + RELEASES_TEST_REPO_ID );
+ File releasesTestDir = new File( "target/test-" + getName() + "/" + RELEASES_TEST_REPO_ID );
FileUtils.deleteDirectory( releasesTestDir );
- FileUtils.copyDirectory( getTestFile( "target/test-classes/" + RELEASES_TEST_REPO_ID ), releasesTestDir );
+ FileUtils.copyDirectory( new File( "target/test-classes/" + RELEASES_TEST_REPO_ID ), releasesTestDir );
return testDir.getAbsolutePath();
}
+
+ @Override
+ public String getName()
+ {
+ return StringUtils.substringAfterLast( getClass().getName(), "." );
+ }
}
import org.apache.maven.archiva.repository.metadata.MetadataTools;
import org.custommonkey.xmlunit.XMLAssert;
import org.easymock.MockControl;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import javax.inject.Inject;
import java.io.File;
import java.util.Collections;
import java.util.List;
/**
*/
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml",
+ "classpath:/spring-context-cleanup-released-snapshots.xml" } )
public class CleanupReleasedSnapshotsRepositoryPurgeTest
extends AbstractRepositoryPurgeTest
{
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()
+ @Inject
+ MetadataTools metadataTools;
+
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
- MetadataTools metadataTools = (MetadataTools) lookup( MetadataTools.class );
- RepositoryContentFactory factory = (RepositoryContentFactory) lookup( RepositoryContentFactory.class,
- "cleanup-released-snapshots" );
+ RepositoryContentFactory factory =
+ applicationContext.getBean( "repositoryContentFactory#cleanup-released-snapshots", RepositoryContentFactory.class );
- archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
- "cleanup-released-snapshots" );
+ archivaConfiguration =
+ applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class );
listenerControl = MockControl.createControl( RepositoryListener.class );
listener = (RepositoryListener) listenerControl.getMock();
List<RepositoryListener> listeners = Collections.singletonList( listener );
- repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, archivaConfiguration,
- factory, repositorySession, listeners );
+ repoPurge =
+ new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, archivaConfiguration, factory,
+ repositorySession, listeners );
}
+ @Test
public void testReleasedSnapshotsExistsInSameRepo()
throws Exception
{
XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
}
+ @Test
public void testNonArtifactFile()
throws Exception
{
assertTrue( file.exists() );
}
+ @Test
public void testReleasedSnapshotsExistsInDifferentRepo()
throws Exception
{
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 =
+ new File( "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/released-artifact-in-diff-repo-1.0.pom.sha1" );
}
+ @Test
public void testHigherSnapshotExistsInSameRepo()
throws Exception
{
String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
- String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" +
- "<version>2.0.4-SNAPSHOT</version></versions></expected>";
+ String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>"
+ + "<version>2.0.4-SNAPSHOT</version></versions></expected>";
XMLAssert.assertXpathEvaluatesTo( "2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml );
XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
import org.apache.archiva.repository.events.RepositoryListener;
import org.apache.commons.lang.time.DateUtils;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.junit.After;
+import org.junit.Test;
import java.io.File;
import java.text.SimpleDateFormat;
}
}
+ @Test
public void testByLastModified()
throws Exception
{
assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
}
+ @Test
public void testOrderOfDeletion()
throws Exception
{
assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );
}
+ @Test
public void testMetadataDrivenSnapshots()
throws Exception
{
}
}
- protected void tearDown()
+ @After
+ public void tearDown()
throws Exception
{
super.tearDown();
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate;
import org.custommonkey.xmlunit.XMLAssert;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
import java.io.File;
/**
*/
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } )
public class RepositoryPurgeConsumerTest
extends AbstractRepositoryPurgeTest
{
+ @Test
public void testConsumption()
throws Exception
{
assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
}
+ @Test
public void testConsumptionOfOtherMetadata()
throws Exception
{
private void assertNotConsumed( String path )
throws Exception
{
- ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+ ArchivaConfiguration archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
+
FileType fileType =
(FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
fileType.addPattern( "**/*.xml" );
// trigger reload
- FileTypes fileTypes = (FileTypes) lookup( FileTypes.class );
+ FileTypes fileTypes = applicationContext.getBean( FileTypes.class );
fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null );
- KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup(
- KnownRepositoryContentConsumer.class, "repository-purge" );
+ KnownRepositoryContentConsumer repoPurgeConsumer =
+ applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge",
+ KnownRepositoryContentConsumer.class );
- File repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
+ File repoLocation = new File( "target/test-" + getName() + "/test-repo" );
File localFile = new File( repoLocation, path );
}
}
+ @Test
public void testConsumerByRetentionCount()
throws Exception
{
- KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup(
- KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" );
+ KnownRepositoryContentConsumer repoPurgeConsumer =
+ applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
+ KnownRepositoryContentConsumer.class );
ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute.
private void addRepoToConfiguration( String configHint, ManagedRepositoryConfiguration repoConfiguration )
throws Exception
{
- ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
- configHint );
+ ArchivaConfiguration archivaConfiguration =
+ applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
Configuration configuration = archivaConfiguration.getConfiguration();
configuration.removeManagedRepository( configuration.findManagedRepositoryById( repoConfiguration.getId() ) );
configuration.addManagedRepository( repoConfiguration );
}
+ @Test
public void testConsumerByDaysOld()
throws Exception
{
- KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup(
- KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" );
+ KnownRepositoryContentConsumer repoPurgeConsumer =
+ applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
+ KnownRepositoryContentConsumer.class );
ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
repoConfiguration.setDaysOlder( TEST_DAYS_OLDER );
*
* @throws Exception
*/
+ @Test
public void testReleasedSnapshotsWereNotCleaned()
throws Exception
{
- KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup(
- KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-retention-count" );
+ KnownRepositoryContentConsumer repoPurgeConsumer =
+ applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
+ KnownRepositoryContentConsumer.class );
ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots.
XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
}
+ @Test
public void testReleasedSnapshotsWereCleaned()
throws Exception
{
- KnownRepositoryContentConsumer repoPurgeConsumer = (KnownRepositoryContentConsumer) lookup(
- KnownRepositoryContentConsumer.class, "repo-purge-consumer-by-days-old" );
+ KnownRepositoryContentConsumer repoPurgeConsumer =
+ applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
+ KnownRepositoryContentConsumer.class );
ManagedRepositoryConfiguration repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
repoConfiguration.setDeleteReleasedSnapshots( true );
XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
}
- @Override
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
- TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
+ TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class );
factory.setRepository( metadataRepository );
}
}
import org.apache.archiva.repository.events.RepositoryListener;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.junit.Before;
+import org.junit.Test;
import java.util.Collections;
import java.util.List;
public class RetentionCountRepositoryPurgeTest
extends AbstractRepositoryPurgeTest
{
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception
{
super.setUp();
/**
* Test if the artifact to be processed was a jar.
*/
+ @Test
public void testIfAJarWasFound()
throws Exception
{
/**
* Test if the artifact to be processed is a pom
*/
+ @Test
public void testIfAPomWasFound()
throws Exception
{
assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
}
+ @Test
public void testOrderOfDeletion()
throws Exception
{
<requirement>
<role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
<role-hint>mocked</role-hint>
- <field-name>repositoryFactory</field-name>
+ <field-name>repositoryContentFactory</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.repository.metadata.MetadataTools</role>
</requirement>
<requirement>
<role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
- <field-name>repositoryFactory</field-name>
+ <field-name>repositoryContentFactory</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.repository.content.RepositoryRequest</role>
</requirement>
<requirement>
<role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
- <field-name>repositoryFactory</field-name>
+ <field-name>repositoryContentFactory</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.repository.content.RepositoryRequest</role>