diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-05-17 22:16:57 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-05-17 22:16:57 +0000 |
commit | 2ae3268ff900a8b649f8cc46fe6a23302978cacc (patch) | |
tree | ad7d7051e9a736eb61d95636eb88feeb7594295e /archiva-database | |
parent | 45ab16622e24b784e597d77cdff9cd99bec575f9 (diff) | |
download | archiva-2ae3268ff900a8b649f8cc46fe6a23302978cacc.tar.gz archiva-2ae3268ff900a8b649f8cc46fe6a23302978cacc.zip |
[MRM-346]: Show Artifact results in error 500.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@539145 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database')
14 files changed, 810 insertions, 145 deletions
diff --git a/archiva-database/pom.xml b/archiva-database/pom.xml index e53bfdcf8..94811fd12 100755 --- a/archiva-database/pom.xml +++ b/archiva-database/pom.xml @@ -99,6 +99,11 @@ </dependency> <!-- TEST DEPS --> <dependency> + <groupId>org.codehaus.plexus.registry</groupId> + <artifactId>plexus-registry-commons</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>test</scope> diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java index 5434e78d9..7ce38abf7 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java @@ -25,6 +25,8 @@ import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.constraints.UniqueArtifactIdConstraint; import org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; +import org.apache.maven.archiva.database.updater.DatabaseUpdater; +import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -37,7 +39,6 @@ import java.util.List; * @version $Id$ * * @plexus.component role="org.apache.maven.archiva.database.browsing.RepositoryBrowsing" - * role-hint="default" */ public class DefaultRepositoryBrowsing extends AbstractLogEnabled @@ -48,6 +49,11 @@ public class DefaultRepositoryBrowsing */ private ArchivaDAO dao; + /** + * @plexus.requirement role-hint="jdo" + */ + private DatabaseUpdater dbUpdater; + public BrowsingResults getRoot() { List groups = dao.query( new UniqueGroupIdConstraint() ); @@ -89,10 +95,51 @@ public class DefaultRepositoryBrowsing public ArchivaProjectModel selectVersion( String groupId, String artifactId, String version ) throws ObjectNotFoundException, ArchivaDatabaseException { - ArchivaProjectModel model = dao.getProjectModelDAO().getProjectModel( groupId, artifactId, version ); - - // TODO: if the model isn't found. load it from disk, insert into DB, and then return it. - - return model; + ArchivaArtifact pomArtifact = null; + + try + { + pomArtifact = dao.getArtifactDAO().getArtifact( groupId, artifactId, version, null, "pom" ); + + if ( pomArtifact == null ) + { + throw new ObjectNotFoundException( "Unable to find artifact [" + groupId + ":" + artifactId + ":" + + version + "]" ); + } + } + catch ( ObjectNotFoundException e ) + { + throw e; + } + + ArchivaProjectModel model; + + if ( pomArtifact.getModel().isProcessed() ) + { + // It's been processed. return it. + model = dao.getProjectModelDAO().getProjectModel( groupId, artifactId, version ); + return model; + } + + // Process it. + dbUpdater.updateUnprocessed( pomArtifact ); + + // Find it. + try + { + model = dao.getProjectModelDAO().getProjectModel( groupId, artifactId, version ); + + if ( model == null ) + { + throw new ObjectNotFoundException( "Unable to find project model for [" + groupId + ":" + artifactId + ":" + + version + "]" ); + } + + return model; + } + catch ( ObjectNotFoundException e ) + { + throw e; + } } } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java index 69172a33a..330b78247 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java @@ -19,26 +19,21 @@ package org.apache.maven.archiva.database.updater; * under the License. */ -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.IteratorUtils; +import org.apache.commons.collections.Predicate; +import org.apache.commons.collections.functors.NotPredicate; import org.apache.maven.archiva.consumers.ArchivaArtifactConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.constraints.ArtifactsProcessedConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; +import org.apache.maven.archiva.model.functors.UnprocessedArtifactPredicate; import org.codehaus.plexus.logging.AbstractLogEnabled; -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 java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; -import java.util.Map; /** * JdoDatabaseUpdater @@ -51,7 +46,7 @@ import java.util.Map; */ public class JdoDatabaseUpdater extends AbstractLogEnabled - implements DatabaseUpdater, RegistryListener, Initializable + implements DatabaseUpdater { /** * @plexus.requirement role-hint="jdo" @@ -61,28 +56,9 @@ public class JdoDatabaseUpdater /** * @plexus.requirement */ - private ArchivaConfiguration configuration; + private DatabaseConsumers dbConsumers; - /** - * The collection of available consumers. - * @plexus.requirement role="org.apache.maven.archiva.consumers.ArchivaArtifactConsumer" - */ - private Map availableConsumers; - - /** - * The list of active consumers for unprocessed content. - */ - private List activeUnprocessedConsumers = new ArrayList(); - - /** - * The list of active consumers for processed content. - */ - private List activeProcessedConsumers = new ArrayList(); - - /** - * The list of registry (configuration) property names that will trigger a refresh of the activeConsumers list. - */ - private List propertyNameTriggers = new ArrayList(); + private ProcessArchivaArtifactClosure processArtifactClosure = new ProcessArchivaArtifactClosure(); public void update() throws ArchivaDatabaseException @@ -96,56 +72,52 @@ public class JdoDatabaseUpdater { List unprocessedArtifacts = dao.getArtifactDAO().queryArtifacts( new ArtifactsProcessedConstraint( false ) ); - beginConsumerLifecycle( this.activeUnprocessedConsumers ); + beginConsumerLifecycle( dbConsumers.getSelectedUnprocessedConsumers() ); try { // Process each consumer. - Iterator it = unprocessedArtifacts.iterator(); + Predicate predicate = UnprocessedArtifactPredicate.getInstance(); + + Iterator it = IteratorUtils.filteredIterator( unprocessedArtifacts.iterator(), predicate ); while ( it.hasNext() ) { ArchivaArtifact artifact = (ArchivaArtifact) it.next(); - - if ( !artifact.getModel().isProcessed() ) - { - updateUnprocessed( artifact ); - } + updateUnprocessed( artifact ); } } finally { - consumerConsumerLifecycle( this.activeUnprocessedConsumers ); + endConsumerLifecycle( dbConsumers.getSelectedUnprocessedConsumers() ); } - } + } public void updateAllProcessed() throws ArchivaDatabaseException { List processedArtifacts = dao.getArtifactDAO().queryArtifacts( new ArtifactsProcessedConstraint( true ) ); - beginConsumerLifecycle( this.activeProcessedConsumers ); + beginConsumerLifecycle( dbConsumers.getSelectedCleanupConsumers() ); try { // Process each consumer. - Iterator it = processedArtifacts.iterator(); + Predicate predicate = NotPredicate.getInstance( UnprocessedArtifactPredicate.getInstance() ); + + Iterator it = IteratorUtils.filteredIterator( processedArtifacts.iterator(), predicate ); while ( it.hasNext() ) { ArchivaArtifact artifact = (ArchivaArtifact) it.next(); - - if ( !artifact.getModel().isProcessed() ) - { - updateProcessed( artifact ); - } + updateProcessed( artifact ); } } finally { - consumerConsumerLifecycle( this.activeProcessedConsumers ); + endConsumerLifecycle( dbConsumers.getSelectedCleanupConsumers() ); } } - private void consumerConsumerLifecycle( List consumers ) + private void endConsumerLifecycle( List consumers ) { Iterator it = consumers.iterator(); while ( it.hasNext() ) @@ -168,19 +140,16 @@ public class JdoDatabaseUpdater public void updateUnprocessed( ArchivaArtifact artifact ) throws ArchivaDatabaseException { - Iterator it = this.activeUnprocessedConsumers.iterator(); - while ( it.hasNext() ) + List consumers = dbConsumers.getSelectedUnprocessedConsumers(); + + if ( CollectionUtils.isEmpty( consumers ) ) { - ArchivaArtifactConsumer consumer = (ArchivaArtifactConsumer) it.next(); - try - { - consumer.processArchivaArtifact( artifact ); - } - catch ( ConsumerException e ) - { - getLogger().warn( "Unable to consume (unprocessed) artifact: " + artifact ); - } + getLogger().warn( "There are no selected consumers for unprocessed artifacts." ); + return; } + + this.processArtifactClosure.setArtifact( artifact ); + CollectionUtils.forAllDo( consumers, this.processArtifactClosure ); artifact.getModel().setWhenProcessed( new Date() ); dao.getArtifactDAO().saveArtifact( artifact ); @@ -189,86 +158,15 @@ public class JdoDatabaseUpdater public void updateProcessed( ArchivaArtifact artifact ) throws ArchivaDatabaseException { - Iterator it = this.activeProcessedConsumers.iterator(); - while ( it.hasNext() ) - { - ArchivaArtifactConsumer consumer = (ArchivaArtifactConsumer) it.next(); - try - { - consumer.processArchivaArtifact( artifact ); - } - catch ( ConsumerException e ) - { - getLogger().warn( "Unable to consume (processed) artifact: " + artifact ); - } - } - } - - private void updateActiveConsumers() - { - this.activeUnprocessedConsumers.clear(); - this.activeProcessedConsumers.clear(); + List consumers = dbConsumers.getSelectedCleanupConsumers(); - DatabaseScanningConfiguration dbScanning = configuration.getConfiguration().getDatabaseScanning(); - if ( dbScanning == null ) + if ( CollectionUtils.isEmpty( consumers ) ) { - getLogger().error( "No Database Consumers found!" ); + getLogger().warn( "There are no selected consumers for artifact cleanup." ); return; } - - this.activeUnprocessedConsumers.addAll( getActiveConsumerList( dbScanning.getUnprocessedConsumers() ) ); - this.activeProcessedConsumers.addAll( getActiveConsumerList( dbScanning.getCleanupConsumers() ) ); - } - - private List getActiveConsumerList( List potentialConsumerList ) - { - if ( ( potentialConsumerList == null ) || ( potentialConsumerList.isEmpty() ) ) - { - return Collections.EMPTY_LIST; - } - - List ret = new ArrayList(); - - Iterator it = potentialConsumerList.iterator(); - while ( it.hasNext() ) - { - String consumerName = (String) it.next(); - if ( !availableConsumers.containsKey( consumerName ) ) - { - getLogger().warn( "Requested Consumer [" + consumerName + "] does not exist. Disabling." ); - continue; - } - - ret.add( consumerName ); - } - - return ret; - } - - public void initialize() - throws InitializationException - { - propertyNameTriggers = new ArrayList(); - propertyNameTriggers.add( "databaseScanning" ); - propertyNameTriggers.add( "unprocessedConsumers" ); - propertyNameTriggers.add( "unprocessedConsumer" ); - propertyNameTriggers.add( "processedConsumers" ); - propertyNameTriggers.add( "processedConsumer" ); - - configuration.addChangeListener( this ); - updateActiveConsumers(); - } - - public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - if ( propertyNameTriggers.contains( propertyName ) ) - { - updateActiveConsumers(); - } - } - - public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - /* nothing to do here */ + + this.processArtifactClosure.setArtifact( artifact ); + CollectionUtils.forAllDo( consumers, this.processArtifactClosure ); } } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/ProcessArchivaArtifactClosure.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/ProcessArchivaArtifactClosure.java new file mode 100644 index 000000000..f3334e256 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/ProcessArchivaArtifactClosure.java @@ -0,0 +1,73 @@ +package org.apache.maven.archiva.database.updater; + +/* + * 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.apache.commons.collections.Closure; +import org.apache.maven.archiva.consumers.ArchivaArtifactConsumer; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.model.ArchivaArtifact; +import org.codehaus.plexus.logging.AbstractLogEnabled; + +/** + * ProcessArchivaArtifactClosure + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="org.apache.commons.collections.Closure" + * role-hint="process-artifact" + * instantiation-strategy="per-lookup" + */ +class ProcessArchivaArtifactClosure + extends AbstractLogEnabled + implements Closure +{ + private ArchivaArtifact artifact; + + public void execute( Object input ) + { + if ( input instanceof ArchivaArtifactConsumer ) + { + ArchivaArtifactConsumer consumer = (ArchivaArtifactConsumer) input; + + try + { + consumer.processArchivaArtifact( artifact ); + } + catch ( ConsumerException e ) + { + getLogger().warn( + "Unable to process artifact [" + artifact + "] with consumer [" + consumer.getId() + + "]" ); + } + } + + } + + public ArchivaArtifact getArtifact() + { + return artifact; + } + + public void setArtifact( ArchivaArtifact artifact ) + { + this.artifact = artifact; + } +}
\ No newline at end of file diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java index 4deedfc9e..935ff5a0c 100644 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java @@ -19,6 +19,10 @@ package org.apache.maven.archiva.database; * under the License. */ +import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer; +import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer; +import org.apache.maven.archiva.database.updater.TestDatabaseCleanupConsumer; +import org.apache.maven.archiva.database.updater.TestDatabaseUnprocessedConsumer; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory; import org.codehaus.plexus.jdo.JdoFactory; @@ -127,6 +131,25 @@ public class AbstractArchivaDatabaseTestCase this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" ); } + protected TestDatabaseCleanupConsumer lookupTestCleanupConsumer() + throws Exception + { + TestDatabaseCleanupConsumer consumer = (TestDatabaseCleanupConsumer) lookup( DatabaseCleanupConsumer.class, + "test-db-cleanup" ); + assertNotNull( "Test Database Cleanup Consumer should not be null.", consumer ); + return consumer; + } + + protected TestDatabaseUnprocessedConsumer lookupTestUnprocessedConsumer() + throws Exception + { + TestDatabaseUnprocessedConsumer consumer = (TestDatabaseUnprocessedConsumer) lookup( + DatabaseUnprocessedArtifactConsumer.class, + "test-db-unprocessed" ); + assertNotNull( "Test Database Unprocessed Consumer should not be null.", consumer ); + return consumer; + } + protected Date toDate( String txt ) throws Exception { diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java index 11d62cd48..a885908db 100644 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java @@ -94,7 +94,7 @@ public class RepositoryBrowsingTest public RepositoryBrowsing lookupBrowser() throws Exception { - RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class.getName(), "default" ); + RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class.getName() ); assertNotNull( "RepositoryBrowsing should not be null.", browser ); return browser; } diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.java new file mode 100644 index 000000000..040065c35 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.java @@ -0,0 +1,84 @@ +package org.apache.maven.archiva.database.updater; + +/* + * 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.apache.commons.collections.CollectionUtils; +import org.codehaus.plexus.PlexusTestCase; + +import java.util.List; + +/** + * DatabaseConsumersTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class DatabaseConsumersTest + extends PlexusTestCase +{ + private DatabaseConsumers lookupDbConsumers() + throws Exception + { + DatabaseConsumers dbconsumers = (DatabaseConsumers) lookup( DatabaseConsumers.class ); + assertNotNull( "DatabaseConsumers should not be null.", dbconsumers ); + return dbconsumers; + } + + public void testGetAvailableCleanupConsumers() + throws Exception + { + DatabaseConsumers dbconsumers = lookupDbConsumers(); + List available = dbconsumers.getAvailableCleanupConsumers(); + assertNotNull( "Available Cleanup Consumers should never be null.", available ); + + assertTrue( "Available Cleanup Consumers should have entries.", CollectionUtils.isNotEmpty( available ) ); + } + + public void testGetAvailableUnprocessedConsumers() + throws Exception + { + DatabaseConsumers dbconsumers = lookupDbConsumers(); + List available = dbconsumers.getAvailableUnprocessedConsumers(); + assertNotNull( "Available Unprocessed Consumers should never be null.", available ); + + assertTrue( "Available Unprocessed Consumers should have entries.", CollectionUtils.isNotEmpty( available ) ); + } + + public void testGetSelectedCleanupConsumers() + throws Exception + { + DatabaseConsumers dbconsumers = lookupDbConsumers(); + List available = dbconsumers.getSelectedCleanupConsumers(); + assertNotNull( "Selected Cleanup Consumers should never be null.", available ); + + assertTrue( "Selected Cleanup Consumers should have entries.", CollectionUtils.isNotEmpty( available ) ); + } + + public void testGetSelectedUnprocessedConsumers() + throws Exception + { + DatabaseConsumers dbconsumers = lookupDbConsumers(); + List available = dbconsumers.getSelectedUnprocessedConsumers(); + assertNotNull( "Selected Unprocessed Consumers should never be null.", available ); + + assertTrue( "Selected Unprocessed Consumers should have entries.", CollectionUtils.isNotEmpty( available ) ); + } + +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.java new file mode 100644 index 000000000..d19f8b227 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.java @@ -0,0 +1,103 @@ +package org.apache.maven.archiva.database.updater; + +/* + * 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.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; +import org.apache.maven.archiva.database.ArtifactDAO; +import org.apache.maven.archiva.model.ArchivaArtifact; + +import java.util.Date; + +/** + * DatabaseUpdaterTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class DatabaseUpdaterTest + extends AbstractArchivaDatabaseTestCase +{ + private DatabaseUpdater dbupdater; + + public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String whenProcessed ) + throws Exception + { + ArchivaArtifact artifact = dao.getArtifactDAO().createArtifact( groupId, artifactId, version, "", "jar" ); + assertNotNull( "Artifact should not be null.", artifact ); + Date dateWhenProcessed = null; + + if ( whenProcessed != null ) + { + dateWhenProcessed = toDate( whenProcessed ); + } + + artifact.getModel().setWhenProcessed( dateWhenProcessed ); + + // Satisfy table / column requirements. + artifact.getModel().setLastModified( new Date() ); + + return artifact; + } + + protected void setUp() + throws Exception + { + super.setUp(); + + ArtifactDAO adao = dao.getArtifactDAO(); + assertNotNull( "Artifact DAO should not be null.", adao ); + + adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-common", "1.0-SNAPSHOT", null ) ); + adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-utils", "1.0-SNAPSHOT", null ) ); + adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-old", "0.1", "2004/02/15 9:01:00" ) ); + adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-database", "1.0-SNAPSHOT", null ) ); + + dbupdater = (DatabaseUpdater) lookup( DatabaseUpdater.class, "jdo" ); + assertNotNull( "DatabaseUpdater should not be null.", dbupdater ); + } + + public void testUpdateUnprocessed() + throws Exception + { + String groupId = "org.apache.maven.archiva"; + String artifactId = "archiva-utils"; + String version = "1.0-SNAPSHOT"; + String classifier = ""; + String type = "jar"; + + TestDatabaseUnprocessedConsumer consumer = lookupTestUnprocessedConsumer(); + consumer.resetCount(); + + // Check the state of the artifact in the DB. + ArchivaArtifact savedArtifact = dao.getArtifactDAO().getArtifact( groupId, artifactId, version, classifier, + type ); + assertFalse( "Artifact should not be considered processed (yet).", savedArtifact.getModel().isProcessed() ); + + // Update the artifact + dbupdater.updateUnprocessed( savedArtifact ); + + // Check the update. + ArchivaArtifact processed = dao.getArtifactDAO().getArtifact( groupId, artifactId, version, classifier, type ); + assertTrue( "Artifact should be flagged as processed.", processed.getModel().isProcessed() ); + + // Did the unprocessed consumer do it's thing? + assertEquals( "Processed Count.", 1, consumer.getCountProcessed() ); + } +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java new file mode 100644 index 000000000..ba885936e --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java @@ -0,0 +1,100 @@ +package org.apache.maven.archiva.database.updater; + +/* + * 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.apache.maven.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer; +import org.apache.maven.archiva.model.ArchivaArtifact; + +import java.util.List; + +/** + * TestDatabaseCleanupConsumer + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class TestDatabaseCleanupConsumer + extends AbstractMonitoredConsumer + implements DatabaseCleanupConsumer +{ + private int countBegin = 0; + private int countComplete = 0; + private int countProcessed = 0; + + public void resetCount() + { + countBegin = 0; + countProcessed = 0; + countComplete = 0; + } + + public void beginScan() + { + countBegin++; + } + + public void completeScan() + { + countComplete++; + } + + public List getIncludedTypes() + { + return null; + } + + public void processArchivaArtifact( ArchivaArtifact artifact ) + throws ConsumerException + { + countProcessed++; + } + + public String getDescription() + { + return "Test Consumer for Database Unprocessed"; + } + + public String getId() + { + return "test-db-unprocessed"; + } + + public boolean isPermanent() + { + return false; + } + + public int getCountBegin() + { + return countBegin; + } + + public int getCountComplete() + { + return countComplete; + } + + public int getCountProcessed() + { + return countProcessed; + } +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseUnprocessedConsumer.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseUnprocessedConsumer.java new file mode 100644 index 000000000..d71894ba0 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseUnprocessedConsumer.java @@ -0,0 +1,107 @@ +package org.apache.maven.archiva.database.updater; + +/* + * 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.apache.maven.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer; +import org.apache.maven.archiva.model.ArchivaArtifact; + +import java.util.ArrayList; +import java.util.List; + +/** + * TestDatabaseUnprocessedConsumer + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class TestDatabaseUnprocessedConsumer + extends AbstractMonitoredConsumer + implements DatabaseUnprocessedArtifactConsumer +{ + private int countBegin = 0; + + private int countComplete = 0; + + private int countProcessed = 0; + + public void resetCount() + { + countBegin = 0; + countProcessed = 0; + countComplete = 0; + } + + public void beginScan() + { + countBegin++; + } + + public void completeScan() + { + countComplete++; + } + + public List getIncludedTypes() + { + List types = new ArrayList(); + types.add( "pom" ); + types.add( "jar" ); + return types; + } + + public void processArchivaArtifact( ArchivaArtifact artifact ) + throws ConsumerException + { + getLogger().info( "Processing Artifact: " + artifact ); + countProcessed++; + } + + public String getDescription() + { + return "Test Consumer for Database Unprocessed"; + } + + public String getId() + { + return "test-db-unprocessed"; + } + + public boolean isPermanent() + { + return false; + } + + public int getCountBegin() + { + return countBegin; + } + + public int getCountComplete() + { + return countComplete; + } + + public int getCountProcessed() + { + return countProcessed; + } +} diff --git a/archiva-database/src/test/resources/META-INF/plexus/components.xml b/archiva-database/src/test/resources/META-INF/plexus/components.xml index cd924e95c..c7d80f05e 100644 --- a/archiva-database/src/test/resources/META-INF/plexus/components.xml +++ b/archiva-database/src/test/resources/META-INF/plexus/components.xml @@ -14,6 +14,18 @@ </otherProperties> </configuration> </component> + + <component> + <role>org.apache.maven.archiva.consumers.DatabaseCleanupConsumer</role> + <role-hint>test-db-cleanup</role-hint> + <implementation>org.apache.maven.archiva.database.updater.TestDatabaseCleanupConsumer</implementation> + </component> + + <component> + <role>org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer</role> + <role-hint>test-db-unprocessed</role-hint> + <implementation>org.apache.maven.archiva.database.updater.TestDatabaseUnprocessedConsumer</implementation> + </component> <component> <role>org.codehaus.plexus.logging.LoggerManager</role> diff --git a/archiva-database/src/test/resources/archiva-test.xml b/archiva-database/src/test/resources/archiva-test.xml new file mode 100644 index 000000000..66021220b --- /dev/null +++ b/archiva-database/src/test/resources/archiva-test.xml @@ -0,0 +1,155 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ 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. + --> + +<configuration> + <repositories> + <repository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <url>file://${appserver.home}/repositories/internal</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>true</indexed> + <refreshCronExpression>0 0 * * ?</refreshCronExpression> + </repository> + <repository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <url>file://${appserver.home}/repositories/internal</url> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <indexed>true</indexed> + <refreshCronExpression>0 0,30 * * ?</refreshCronExpression> + </repository> + <repository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>false</indexed> + </repository> + <repository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>https://maven2-repository.dev.java.net/nonav/repository</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>false</indexed> + </repository> + </repositories> + + <proxyConnectors /> + + <networkProxies /> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>test-db-unprocessed</unprocessedConsumer> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>test-db-cleanup</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + +</configuration> diff --git a/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml new file mode 100644 index 000000000..07ff811a5 --- /dev/null +++ b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" ?> + +<component-set> + <components> + <component> + <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> + <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> + <requirements> + <requirement> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>configured</role-hint> + </requirement> + </requirements> + </component> + <component> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>configured</role-hint> + <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> + <configuration> + <properties> + <system/> + <xml fileName="${basedir}/src/test/resources/archiva-test.xml" + config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> + </properties> + </configuration> + </component> + </components> +</component-set> + diff --git a/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml new file mode 100644 index 000000000..07ff811a5 --- /dev/null +++ b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" ?> + +<component-set> + <components> + <component> + <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> + <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> + <requirements> + <requirement> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>configured</role-hint> + </requirement> + </requirements> + </component> + <component> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>configured</role-hint> + <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> + <configuration> + <properties> + <system/> + <xml fileName="${basedir}/src/test/resources/archiva-test.xml" + config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> + </properties> + </configuration> + </component> + </components> +</component-set> + |