From cb8e218968e666c9597967dafd0b6f560902b7ed Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 27 Feb 2007 01:47:08 +0000 Subject: [PATCH] Using updated plexus-cache for runtime creation of Cache. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@512105 13f79535-47bb-0310-9956-ffa450edef68 --- archiva-repository-layer/pom.xml | 16 +++--- .../layer/CachedRepositoryQueryLayer.java | 28 ++++++---- .../layer/DefaultRepositoryQueryLayer.java | 3 +- .../layer/CachedRepositoryQueryLayerTest.java | 5 +- .../layer/CachedRepositoryQueryLayerTest.xml | 52 ------------------- 5 files changed, 32 insertions(+), 72 deletions(-) delete mode 100644 archiva-repository-layer/src/test/resources/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.xml diff --git a/archiva-repository-layer/pom.xml b/archiva-repository-layer/pom.xml index fa9a51ab8..254c684ca 100644 --- a/archiva-repository-layer/pom.xml +++ b/archiva-repository-layer/pom.xml @@ -34,10 +34,17 @@ org.apache.maven.archiva archiva-common + + org.codehaus.plexus.cache + plexus-cache-api + 1.0-alpha-2-SNAPSHOT + compile + org.codehaus.plexus.cache plexus-cache-ehcache - 1.0-alpha-1 + 1.0-alpha-2-SNAPSHOT + compile org.apache.maven @@ -51,13 +58,6 @@ org.apache.maven maven-repository-metadata - - - org.codehaus.plexus.cache - plexus-cache-hashmap - 1.0-alpha-1 - test - diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java index 65f03c6a6..2f7f35fe9 100644 --- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java +++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java @@ -22,6 +22,9 @@ package org.apache.maven.archiva.layer; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.codehaus.plexus.cache.Cache; +import org.codehaus.plexus.cache.CacheException; +import org.codehaus.plexus.cache.CacheHints; +import org.codehaus.plexus.cache.factory.CacheFactory; import java.util.List; @@ -29,24 +32,31 @@ import java.util.List; * CachedRepositoryQueryLayer - simple wrapper around another non-cached Repository Query Layer. * * @version $Id$ - * @plexus.component role="org.apache.maven.archiva.layer.RepositoryQueryLayer" role-hint="cached" */ public class CachedRepositoryQueryLayer implements RepositoryQueryLayer { - /** - * @plexus.requirement role-hint="repository-query" - */ private Cache cache; - /** - * @plexus.requirement - */ private RepositoryQueryLayer layer; - - public CachedRepositoryQueryLayer() + + public CachedRepositoryQueryLayer( RepositoryQueryLayer layer ) + throws RepositoryQueryLayerException { + this.layer = layer; + String repoId = layer.getRepository().getId(); + CacheHints hints = new CacheHints(); + hints.setName( repoId ); + hints.setOverflowToDisk( false ); + try + { + this.cache = CacheFactory.getInstance().getCache( repoId, hints ); + } + catch ( CacheException e ) + { + throw new RepositoryQueryLayerException( "Unable to initialize cache: " + e.getMessage(), e ); + } } public boolean containsArtifact( Artifact artifact ) diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java index b46cb2263..d664dad1b 100644 --- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java +++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java @@ -36,12 +36,13 @@ import java.util.List; * DefaultRepositoryQueryLayer * * @version $Id$ + * @plexus.component role="org.apache.maven.archiva.layer.RepositoryQueryLayer" role-hint="default" */ public class DefaultRepositoryQueryLayer implements RepositoryQueryLayer { protected ArtifactRepository repository; - + public DefaultRepositoryQueryLayer( ArtifactRepository repository ) { this.repository = repository; diff --git a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java index f7da091cc..1451e380c 100644 --- a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java +++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java @@ -19,7 +19,6 @@ package org.apache.maven.archiva.layer; * under the License. */ - /** * CachedRepositoryQueryLayerTest * @@ -34,7 +33,9 @@ public class CachedRepositoryQueryLayerTest { super.setUp(); - queryLayer = (RepositoryQueryLayer) lookup( RepositoryQueryLayer.ROLE, "test-cached" ); + RepositoryQueryLayer defaultLayer = new DefaultRepositoryQueryLayer( repository ); + + queryLayer = new CachedRepositoryQueryLayer( defaultLayer ); } public void testUseFileCache() diff --git a/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.xml b/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.xml deleted file mode 100644 index 8ff658ab7..000000000 --- a/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - org.apache.maven.archiva.layer.RepositoryQueryLayer - test-cached - org.apache.maven.archiva.layer.CachedRepositoryQueryLayer - CachedRepositoryQueryLayer - simple wrapper around another non-cached Repository Query Layer. - - - org.codehaus.plexus.cache.Cache - test-repository-query - cache - - - org.apache.maven.archiva.layer.RepositoryQueryLayer - layer - - - - - - org.codehaus.plexus.cache.Cache - test-repository-query - org.codehaus.plexus.cache.hashmap.HashMapCache - - 1.0 - 0 - - - - \ No newline at end of file -- 2.39.5