]> source.dussan.org Git - archiva.git/commitdiff
Using updated plexus-cache for runtime creation of Cache.
authorJoakim Erdfelt <joakime@apache.org>
Tue, 27 Feb 2007 01:47:08 +0000 (01:47 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Tue, 27 Feb 2007 01:47:08 +0000 (01:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@512105 13f79535-47bb-0310-9956-ffa450edef68

archiva-repository-layer/pom.xml
archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java
archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java
archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java
archiva-repository-layer/src/test/resources/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.xml [deleted file]

index fa9a51ab86d71d42f5fa84055f47a879ea8d0e73..254c684caf9b8e8bda3354e6fb61853140f9a14d 100644 (file)
       <groupId>org.apache.maven.archiva</groupId>
       <artifactId>archiva-common</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus.cache</groupId>
+      <artifactId>plexus-cache-api</artifactId>
+      <version>1.0-alpha-2-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus.cache</groupId>
       <artifactId>plexus-cache-ehcache</artifactId>
-      <version>1.0-alpha-1</version>
+      <version>1.0-alpha-2-SNAPSHOT</version>
+      <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-repository-metadata</artifactId>
     </dependency>
-    <!-- TEST DEPS -->
-    <dependency>
-      <groupId>org.codehaus.plexus.cache</groupId>
-      <artifactId>plexus-cache-hashmap</artifactId>
-      <version>1.0-alpha-1</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
   <build>
     <plugins>
index 65f03c6a6122ea9f538b7518752a5be423e3cb5f..2f7f35fe9d1a9e3c61377fb313c03aeaf0e0b547 100644 (file)
@@ -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 )
index b46cb2263a28826eaeb0fbee03665e40b6f7f0c7..d664dad1b9d58597234b52302f7f56dbae936d52 100644 (file)
@@ -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;
index f7da091cc64c67e4676cc502515c40241318d061..1451e380c9fb9436ea9e25c24bc6d15fb0f97aae 100644 (file)
@@ -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 (file)
index 8ff658a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" ?>
-
-<!--
-  ~ 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.
-  -->
-
-<component-set>
-  <components>
-    <component>
-      <role>org.apache.maven.archiva.layer.RepositoryQueryLayer</role>
-      <role-hint>test-cached</role-hint>
-      <implementation>org.apache.maven.archiva.layer.CachedRepositoryQueryLayer</implementation>
-      <description>CachedRepositoryQueryLayer - simple wrapper around another non-cached Repository Query Layer.</description>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.cache.Cache</role>
-          <role-hint>test-repository-query</role-hint>
-          <field-name>cache</field-name>
-        </requirement>
-        <requirement>
-          <role>org.apache.maven.archiva.layer.RepositoryQueryLayer</role>
-          <field-name>layer</field-name>
-        </requirement>
-      </requirements>
-    </component>
-  
-    <component>
-      <role>org.codehaus.plexus.cache.Cache</role>
-      <role-hint>test-repository-query</role-hint>
-      <implementation>org.codehaus.plexus.cache.hashmap.HashMapCache</implementation>
-      <configuration>
-        <cache-hit-ratio>1.0</cache-hit-ratio>
-        <cache-max-size>0</cache-max-size>
-      </configuration>
-    </component>
-  </components>
-</component-set>
\ No newline at end of file