geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r424854 - in /geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm: ./ src/main/java/org/apache/geronimo/repository/jdbm/ src/test/java/org/apache/geronimo/repository/jdbm/
Date Sun, 23 Jul 2006 23:23:14 GMT
Author: jdillon
Date: Sun Jul 23 16:23:13 2006
New Revision: 424854

URL: http://svn.apache.org/viewvc?rev=424854&view=rev
Log:
Clean before tests as an itty bitty hack to make sure repeatable builds
Added life-cycle to close the db on stop
Optimize query w/artifact a bit more

Modified:
    geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/pom.xml
    geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/ArtifactDatabase.java
    geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/JdbmRepository.java
    geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/RepositoryCopier.java
    geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/test/java/org/apache/geronimo/repository/jdbm/JdbmRepositoryTest.java

Modified: geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/pom.xml?rev=424854&r1=424853&r2=424854&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/pom.xml
(original)
+++ geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/pom.xml
Sun Jul 23 16:23:13 2006
@@ -45,6 +45,22 @@
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-clean-plugin</artifactId>
+                <!--
+                Nuke everything first.. else copy tests will barf
+                -->
+                <executions>
+                    <execution>
+                        <phase>validate</phase>
+                        <goals>
+                            <goal>clean</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <!--
                 Copy the m1 and m2 repos for testing w/o the .svn dirs

Modified: geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/ArtifactDatabase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/ArtifactDatabase.java?rev=424854&r1=424853&r2=424854&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/ArtifactDatabase.java
(original)
+++ geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/ArtifactDatabase.java
Sun Jul 23 16:23:13 2006
@@ -91,22 +91,28 @@
         recman.close();
     }
 
-    public boolean contains(final Artifact artifact) throws IOException {
+    public Object keyForArtifact(final Artifact artifact) {
         assert artifact != null;
         assert artifact.isResolved();
 
-        String key = artifact.toString();
+        // For now just use...
+        return artifact.toString();
+    }
+
+    public boolean contains(final Artifact artifact) throws IOException {
+        Object key = keyForArtifact(artifact);
         Object obj = artifacts.find(key);
 
         return obj != null;
     }
 
     public void insert(final Artifact artifact) throws IOException {
-        assert artifact != null;
-        assert artifact.isResolved();
-
-        String key = artifact.toString();
+        Object key = keyForArtifact(artifact);
         artifacts.insert(key, artifact, false); // do not replace
+
+        //
+        // TODO: Add indexes for artifacts's details for faster query
+        //
     }
 
     public TupleBrowser browse() throws IOException {

Modified: geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/JdbmRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/JdbmRepository.java?rev=424854&r1=424853&r2=424854&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/JdbmRepository.java
(original)
+++ geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/JdbmRepository.java
Sun Jul 23 16:23:13 2006
@@ -26,10 +26,12 @@
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
 
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.WritableListableRepository;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
+import org.apache.geronimo.kernel.repository.Version;
 
 import org.apache.geronimo.system.repository.AbstractRepository;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
@@ -43,7 +45,7 @@
  */
 public class JdbmRepository
     extends AbstractRepository
-    implements WritableListableRepository
+    implements WritableListableRepository, GBeanLifecycle
 {
     private ArtifactDatabase db;
 
@@ -75,9 +77,46 @@
     }
 
     //
-    // TODO: Add GBean lifecycle hooks
+    // GBean
     //
 
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(JdbmRepository.class, "Repository");
+
+        builder.addAttribute("root", URI.class, true);
+        builder.addReference("ServerInfo", ServerInfo.class, "GBean");
+        builder.addInterface(JdbmRepository.class);
+        builder.setConstructor(new String[]{ "root", "ServerInfo" });
+
+        GBEAN_INFO = builder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+
+    //
+    // GBeanLifecycle
+    //
+
+    public void doStart() throws Exception {
+        //
+        // ???
+        //
+    }
+
+    public void doStop() throws Exception {
+        db.close();
+    }
+
+    public void doFail() {
+        //
+        // ???
+        //
+    }
+
     //
     // Repository
     //
@@ -150,14 +189,38 @@
 
         SortedSet artifacts = new TreeSet();
 
+        //
+        // TODO: Query by index... can probably make this more efficent.
+        //
+
         try {
             TupleBrowser browser = db.browse();
             Tuple tuple = new Tuple();
 
             while (browser.getNext(tuple)) {
-                //
-                // TODO: ...
-                //
+                Artifact artifact = (Artifact)tuple.getValue();
+
+                String groupId = query.getGroupId();
+                if (groupId != null && !artifact.getGroupId().equals(groupId)) {
+                    continue;
+                }
+
+                String artifactId = query.getArtifactId();
+                if (artifactId != null && !artifact.getArtifactId().equals(artifactId))
{
+                    continue;
+                }
+
+                Version version = query.getVersion();
+                if (version != null && !artifact.getVersion().equals(version)) {
+                    continue;
+                }
+
+                String type = query.getType();
+                if (type != null && !artifact.getType().equals(type)) {
+                    continue;
+                }
+
+                artifacts.add(artifact);
             }
         }
         catch (IOException e) {
@@ -183,26 +246,5 @@
         }
 
         return artifacts;
-    }
-
-    //
-    // GBean
-    //
-
-    public static final GBeanInfo GBEAN_INFO;
-
-    static {
-        GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(JdbmRepository.class, "Repository");
-
-        builder.addAttribute("root", URI.class, true);
-        builder.addReference("ServerInfo", ServerInfo.class, "GBean");
-        builder.addInterface(JdbmRepository.class);
-        builder.setConstructor(new String[]{ "root", "ServerInfo" });
-
-        GBEAN_INFO = builder.getBeanInfo();
-    }
-
-    public static GBeanInfo getGBeanInfo() {
-        return GBEAN_INFO;
     }
 }

Modified: geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/RepositoryCopier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/RepositoryCopier.java?rev=424854&r1=424853&r2=424854&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/RepositoryCopier.java
(original)
+++ geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/main/java/org/apache/geronimo/repository/jdbm/RepositoryCopier.java
Sun Jul 23 16:23:13 2006
@@ -29,6 +29,10 @@
 import java.io.File;
 import java.io.IOException;
 
+//
+// TODO: Move to tools module
+//
+
 /**
  * Utility to copy one listable repository to another writable repository.
  *
@@ -56,7 +60,7 @@
 
     public void copy(final FileWriteMonitor monitor) throws IOException {
         assert monitor != null;
-        
+
         log.debug("Copying artifacts from " + source + " to " + target);
 
         Set artifacts = source.list();

Modified: geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/test/java/org/apache/geronimo/repository/jdbm/JdbmRepositoryTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/test/java/org/apache/geronimo/repository/jdbm/JdbmRepositoryTest.java?rev=424854&r1=424853&r2=424854&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/test/java/org/apache/geronimo/repository/jdbm/JdbmRepositoryTest.java
(original)
+++ geronimo/sandbox/svkmerge/geronimo-repository/geronimo-repository-providers/geronimo-repository-jdbm/src/test/java/org/apache/geronimo/repository/jdbm/JdbmRepositoryTest.java
Sun Jul 23 16:23:13 2006
@@ -17,11 +17,14 @@
 package org.apache.geronimo.repository.jdbm;
 
 import java.io.File;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
 import org.apache.geronimo.repository.jdbm.JdbmRepository;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Version;
+import org.apache.geronimo.system.repository.Maven1Repository;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -36,16 +39,16 @@
 {
     private static final Log log = LogFactory.getLog(JdbmRepositoryTest.class);
     
-    private File basedir = new File(new File(System.getProperty("basedir")), "target");
+    private File basedir = new File(System.getProperty("basedir"));
 
     public void testInitializeEmpty() throws Exception {
-        File root = new File(basedir, "repo1");
+        File root = new File(basedir, "target/repo1");
         root.mkdirs();
         JdbmRepository repo = new JdbmRepository(root);
     }
     
     public void testNotSuchRoot() throws Exception {
-        File root = new File(basedir, "repo-never-exists");
+        File root = new File(basedir, "target/repo-never-exists");
         try {
             JdbmRepository repo = new JdbmRepository(root);
             fail("Initialized with missing directory");
@@ -56,7 +59,7 @@
     }
 
     public void testGetLocation() throws Exception {
-        File root = new File(basedir, "repo1");
+        File root = new File(basedir, "target/repo1");
         root.mkdirs();
         JdbmRepository repo = new JdbmRepository(root);
 
@@ -65,5 +68,23 @@
 
         assertEquals("artifact-1.0.jar", file.getName());
         assertEquals("1954591822", file.getParentFile().getName()); // 1954591822 is the
expected g+a+v hash
+    }
+
+    public void testQueryByType() throws Exception {
+        File dir;
+
+        dir = new File(basedir, "target/m1");
+        Maven1Repository source = new Maven1Repository(dir);
+
+        dir = new File(basedir, "target/jdbm1");
+        dir.mkdirs();
+        JdbmRepository target = new JdbmRepository(dir);
+
+        RepositoryCopier.copy(source, target);
+
+        Artifact query = new Artifact(null, "test", (Version)null, "properties"); // must
have the artifactId
+        Set artifacts = target.list(query);
+
+        assertEquals(3, artifacts.size());
     }
 }



Mime
View raw message