* under the License.
*/
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.FileTypes;
* ArtifactMissingChecksumsConsumer - Create missing checksums for the artifact.
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
- * role-hint="create-missing-checksums"
- * instantiation-strategy="per-lookup"
*/
public class ArtifactMissingChecksumsConsumer
extends AbstractMonitoredConsumer
implements KnownRepositoryContentConsumer, RegistryListener, Initializable
{
- /**
- * @plexus.configuration default-value="create-missing-checksums"
- */
private String id;
- /**
- * @plexus.configuration default-value="Create Missing Checksums (.sha1 & .md5)"
- */
private String description;
- /**
- * @plexus.requirement
- */
private ArchivaConfiguration configuration;
- /**
- * @plexus.requirement
- */
private FileTypes filetypes;
- /**
- * @plexus.requirement role-hint="sha1"
- */
private Digester digestSha1;
- /**
- * @plexus.requirement role-hint="md5";
- */
private Digester digestMd5;
- /**
- * @plexus.requirement
- */
private ChecksumFile checksum;
private static final String TYPE_CHECKSUM_NOT_FILE = "checksum-bad-not-file";
private List<String> includes = new ArrayList<String>();
+ public ArtifactMissingChecksumsConsumer(String id,
+ String description,
+ ArchivaConfiguration configuration,
+ FileTypes filetypes,
+ Digester digestSha1,
+ Digester digestMd5,
+ ChecksumFile checksum) {
+ this.id = id;
+ this.description = description;
+ this.configuration = configuration;
+ this.filetypes = filetypes;
+ this.digestSha1 = digestSha1;
+ this.digestMd5 = digestMd5;
+ this.checksum = checksum;
+ }
+
public String getId()
{
return this.id;
import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
/**
* RepositoryContentConsumerUtil
*
* @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers"
*/
-public class RepositoryContentConsumers
+public class RepositoryContentConsumers implements ApplicationContextAware
{
- private Logger log = LoggerFactory.getLogger( RepositoryContentConsumers.class );
+ private ApplicationContext applicationContext;
- /**
- * @plexus.requirement
- */
private ArchivaConfiguration archivaConfiguration;
- /**
- * @plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
- */
- private List<KnownRepositoryContentConsumer> availableKnownConsumers;
-
- /**
- * @plexus.requirement role="org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer"
- */
- private List<InvalidRepositoryContentConsumer> availableInvalidConsumers;
-
private List<KnownRepositoryContentConsumer> selectedKnownConsumers;
private List<InvalidRepositoryContentConsumer> selectedInvalidConsumers;
-
+
+ public RepositoryContentConsumers(ArchivaConfiguration archivaConfiguration)
+ {
+ this.archivaConfiguration = archivaConfiguration;
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException
+ {
+ this.applicationContext = applicationContext;
+ }
+
/**
* <p>
* Get the list of Ids associated with those {@link KnownRepositoryContentConsumer} that have
List<String> knownSelected = getSelectedKnownConsumerIds();
- for ( KnownRepositoryContentConsumer consumer : availableKnownConsumers )
+ for ( KnownRepositoryContentConsumer consumer : getAvailableKnownConsumers() )
{
if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() )
{
List<String> invalidSelected = getSelectedInvalidConsumerIds();
- for ( InvalidRepositoryContentConsumer consumer : availableInvalidConsumers )
+ for ( InvalidRepositoryContentConsumer consumer : getAvailableInvalidConsumers() )
{
if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() )
{
*/
public List<KnownRepositoryContentConsumer> getAvailableKnownConsumers()
{
- return availableKnownConsumers;
+ return new ArrayList(applicationContext.getBeansOfType(KnownRepositoryContentConsumer.class).values());
}
/**
*/
public List<InvalidRepositoryContentConsumer> getAvailableInvalidConsumers()
{
- return availableInvalidConsumers;
- }
-
- /**
- * Set the list of {@link KnownRepositoryContentConsumer} objects that are
- * available.
- *
- * NOTE: This is an override for the base functionality as a component, this
- * is used by archiva-cli and the unit testing framework.
- *
- * @return the list of available {@link KnownRepositoryContentConsumer}.
- */
- public void setAvailableKnownConsumers( List<KnownRepositoryContentConsumer> availableKnownConsumers )
- {
- this.availableKnownConsumers = availableKnownConsumers;
- }
-
- /**
- * Set the list of {@link InvalidRepositoryContentConsumer} objects that are
- * available.
- *
- * NOTE: This is an override for the base functionality as a component, this
- * is used by archiva-cli and the unit testing framework.
- *
- * @return the list of available {@link InvalidRepositoryContentConsumer}.
- */
- public void setAvailableInvalidConsumers( List<InvalidRepositoryContentConsumer> availableInvalidConsumers )
- {
- this.availableInvalidConsumers = availableInvalidConsumers;
+ return new ArrayList(applicationContext.getBeansOfType(InvalidRepositoryContentConsumer.class).values());
}
/**
* under the License.
*/
+import java.io.IOException;
+import java.util.Locale;
import org.apache.commons.lang.SystemUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.MessageSourceResolvable;
+import org.springframework.context.NoSuchMessageException;
+import org.springframework.core.io.Resource;
/**
* RepositoryContentConsumersTest
private RepositoryContentConsumers lookupRepositoryConsumers()
throws Exception
{
- RepositoryContentConsumers consumerUtilStub = (RepositoryContentConsumers) lookup( RepositoryContentConsumers.class
- .getName(), "test" );
- ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+ ArchivaConfiguration configuration = (ArchivaConfiguration)lookup(ArchivaConfiguration.class);
+
+ RepositoryContentConsumers consumerUtilStub = new RepositoryContentConsumersStub(configuration);
+
RepositoryContentConsumers consumerUtil = (RepositoryContentConsumers) lookup( RepositoryContentConsumers.class
.getName() );
-
- consumerUtilStub.setAvailableKnownConsumers( consumerUtil.getAvailableKnownConsumers() );
- consumerUtilStub.setAvailableInvalidConsumers( consumerUtil.getAvailableInvalidConsumers() );
+ ApplicationContext context = new MockApplicationContext(consumerUtil.getAvailableKnownConsumers(), consumerUtil.getAvailableInvalidConsumers());
+
+ consumerUtilStub.setApplicationContext(context);
consumerUtilStub.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers() );
consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers() );
- consumerUtilStub.setArchivaConfiguration( archivaConfiguration );
+ consumerUtilStub.setArchivaConfiguration( configuration );
assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtilStub );
KnownRepositoryContentConsumer unselectedKnownConsumer =
(KnownRepositoryContentConsumer) MockControl.createNiceControl(
KnownRepositoryContentConsumer.class ).getMock();
- consumers.setAvailableKnownConsumers( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ) );
+
+ consumers.setApplicationContext(new MockApplicationContext(Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null));
+
consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) );
MockControl invalidControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
InvalidRepositoryContentConsumer unselectedInvalidConsumer =
(InvalidRepositoryContentConsumer) MockControl.createControl(
InvalidRepositoryContentConsumer.class ).getMock();
- consumers.setAvailableInvalidConsumers( Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) );
+
+ consumers.setApplicationContext( new MockApplicationContext(null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer )));
+
consumers.setSelectedInvalidConsumers( Collections.singletonList( selectedInvalidConsumer ) );
ManagedRepositoryConfiguration repo = createRepository( "id", "name", getTestFile( "target/test-repo" ) );
Date startTime = new Date( System.currentTimeMillis() );
startTime.setTime( 12345678 );
-
+
selectedKnownConsumer.beginScan( repo, startTime );
selectedKnownConsumer.getExcludes();
knownControl.setReturnValue( Collections.EMPTY_LIST );
selectedInvalidConsumer.beginScan( repo, startTime );
// invalidConsumer.completeScan();
invalidControl.replay();
-
+
consumers.executeConsumers( repo, testFile );
knownControl.verify();
}
return path;
}
+
+ private static Map convertToMap(List objects)
+ {
+ HashMap map = new HashMap();
+ for (Object o : objects)
+ {
+ map.put(o, o);
+ }
+ return map;
+ }
+
+ public class MockApplicationContext implements ApplicationContext
+ {
+ private List<KnownRepositoryContentConsumer> knownRepositoryContentConsumer;
+
+ private List<InvalidRepositoryContentConsumer> invalidRepositoryContentConsumers;
+
+ public MockApplicationContext(List<KnownRepositoryContentConsumer> knownRepositoryContentConsumer, List<InvalidRepositoryContentConsumer> invalidRepositoryContentConsumers)
+ {
+ this.knownRepositoryContentConsumer = knownRepositoryContentConsumer;
+ this.invalidRepositoryContentConsumers = invalidRepositoryContentConsumers;
+ }
+
+ public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getDisplayName() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getId() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public ApplicationContext getParent() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public long getStartupDate() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean containsBeanDefinition(String beanName) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public int getBeanDefinitionCount() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getBeanDefinitionNames() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getBeanNamesForType(Class type) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Map getBeansOfType(Class type) throws BeansException {
+ if (type == KnownRepositoryContentConsumer.class)
+ {
+ return convertToMap(knownRepositoryContentConsumer);
+ }
+ if (type == InvalidRepositoryContentConsumer.class)
+ {
+ return convertToMap(invalidRepositoryContentConsumers);
+ }
+ throw new UnsupportedOperationException("Should not have been called");
+ }
+
+ public Map getBeansOfType(Class type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean containsBean(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getAliases(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getBean(String name) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getBean(String name, Class requiredType) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getBean(String name, Object[] args) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Class getType(String name) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isPrototype(String name) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean containsLocalBean(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public BeanFactory getParentBeanFactory() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void publishEvent(ApplicationEvent event) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Resource[] getResources(String locationPattern) throws IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public ClassLoader getClassLoader() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Resource getResource(String location) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
}