diff options
author | Brett Porter <brett@apache.org> | 2008-09-14 02:10:59 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2008-09-14 02:10:59 +0000 |
commit | 442f4a8749f679fe9ec664bbfdb94fde12f0db41 (patch) | |
tree | 08edf648e9a5df8bd865ab605598db3c304140c3 /archiva-modules/archiva-database | |
parent | 1a1d1bbf8fe9f8b5e7a31a5e4bc858d087da28ca (diff) | |
download | archiva-442f4a8749f679fe9ec664bbfdb94fde12f0db41.tar.gz archiva-442f4a8749f679fe9ec664bbfdb94fde12f0db41.zip |
[MRM-948] remove direct use of database and indexer from the core consumers, trim database related dependencies
Merged from: r694625
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@695101 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-database')
3 files changed, 145 insertions, 4 deletions
diff --git a/archiva-modules/archiva-database/pom.xml b/archiva-modules/archiva-database/pom.xml index 5268b9531..fad154168 100755 --- a/archiva-modules/archiva-database/pom.xml +++ b/archiva-modules/archiva-database/pom.xml @@ -74,10 +74,6 @@ <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - </dependency> <!-- TEST DEPS --> <dependency> <groupId>org.codehaus.plexus.registry</groupId> diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDatabaseEventListener.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDatabaseEventListener.java new file mode 100644 index 000000000..fa865e3ba --- /dev/null +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDatabaseEventListener.java @@ -0,0 +1,55 @@ +package org.apache.maven.archiva.database; + +/* + * 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.model.ArchivaArtifact; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.archiva.repository.events.RepositoryListener; + +/** + * Process repository management events and respond appropriately. + * + * @plexus.component role="org.apache.maven.archiva.repository.events.RepositoryListener" role-hint="database" + */ +public class RepositoryDatabaseEventListener + implements RepositoryListener +{ + /** + * @plexus.requirement role-hint="jdo" + */ + private ArtifactDAO artifactDAO; + + public void deleteArtifact( ManagedRepositoryContent repository, ArchivaArtifact artifact ) + { + try + { + ArchivaArtifact queriedArtifact = + artifactDAO.getArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getClassifier(), artifact.getType() ); + artifactDAO.deleteArtifact( queriedArtifact ); + } + catch ( ArchivaDatabaseException e ) + { + // ignored + } + + // TODO [MRM-37]: re-run the database consumers to clean up + } +} diff --git a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/RepositoryDatabaseEventListenerTest.java b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/RepositoryDatabaseEventListenerTest.java new file mode 100644 index 000000000..7e76ee6b0 --- /dev/null +++ b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/RepositoryDatabaseEventListenerTest.java @@ -0,0 +1,90 @@ +package org.apache.maven.archiva.database; + +/* + * 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 java.util.Date; +import java.util.List; + +import org.apache.maven.archiva.model.ArchivaArtifact; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.archiva.repository.events.RepositoryListener; +import org.codehaus.plexus.spring.PlexusToSpringUtils; + +public class RepositoryDatabaseEventListenerTest + extends AbstractArchivaDatabaseTestCase +{ + private RepositoryListener listener; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + listener = (RepositoryListener) lookup( RepositoryListener.class.getName(), "database" ); + } + + public void testWiring() + { + List<RepositoryListener> listeners = + PlexusToSpringUtils.lookupList( PlexusToSpringUtils.buildSpringId( RepositoryListener.class ), + getApplicationContext() ); + + assertEquals( 1, listeners.size() ); + assertEquals( listener, listeners.get( 0 ) ); + } + + public ArchivaArtifact createArtifact( String artifactId, String version, ArtifactDAO artifactDao ) + { + ArchivaArtifact artifact = + artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version, "", "jar" ); + artifact.getModel().setLastModified( new Date() ); + artifact.getModel().setRepositoryId( "testable_repo" ); + return artifact; + } + + public void testDeleteArtifact() + throws Exception + { + ArtifactDAO artifactDao = (ArtifactDAO) lookup( ArtifactDAO.class.getName(), "jdo" ); + + // Setup artifacts in fresh DB. + ArchivaArtifact artifact = createArtifact( "test-artifact", "1.0", artifactDao ); + artifactDao.saveArtifact( artifact ); + + assertEquals( artifact, artifactDao.getArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, + "jar" ) ); + + artifact = new ArchivaArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, "jar" ); + ManagedRepositoryContent repository = + (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class.getName(), "default" ); + listener.deleteArtifact( repository, artifact ); + + try + { + artifactDao.getArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, "jar" ); + fail( "Should not find artifact" ); + } + catch ( ObjectNotFoundException e ) + { + assertTrue( true ); + } + } +} |