You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2011/08/12 10:03:41 UTC

svn commit: r1156995 - in /karaf/sandbox/jbonofre/cave/trunk/server: backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/ backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/ command/src/main/java/org/apache/karaf/...

Author: jbonofre
Date: Fri Aug 12 08:03:40 2011
New Revision: 1156995

URL: http://svn.apache.org/viewvc?rev=1156995&view=rev
Log:
Fix the register feature.
Add destory repository.

Added:
    karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/DestroyRepositoryCommand.java
      - copied, changed from r1156806, karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java
Modified:
    karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java
    karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java
    karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java
    karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryServiceImpl.java
    karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/CreateRepositoryCommand.java
    karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java
    karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/resources/OSGI-INF/blueprint/cave-server-commands.xml

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java Fri Aug 12 08:03:40 2011
@@ -72,18 +72,18 @@ public interface CaveRepository {
     void scan() throws Exception;
 
     /**
-     * Register the repository into the OBR, giving all repository artifacts visible
-     * for the OBR client.
+     * Return the repository URL of the OBR repository.xml.
      *
-     * @throws Exception in case of register failure.
+     * @return the URL of the OBR repository.xml.
+     * @throws Exception in case of failure to get repository.xml URL.
      */
-    void register() throws Exception;
+    URL getRepositoryXml() throws Exception;
 
     /**
-     * Destroy this repository, removing the contents of the repository and OBR metadata.
+     * Cleanup the repository storage.
      *
-     * @throws Exception in case of destroy failure.
+     * @throws Exception in case of cleanup failure.
      */
-    void destroy() throws Exception;
+    void cleanup() throws Exception;
 
 }

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java Fri Aug 12 08:03:40 2011
@@ -43,6 +43,22 @@ public interface CaveRepositoryService {
     CaveRepository createRepository(String name, String location, boolean scan) throws Exception;
 
     /**
+     * Destroy an existing Karaf Cave repository.
+     *
+     * @param name the name of Karaf Cave repository to destroy.
+     * @throws Exception in case of destroy failure.
+     */
+    void destroy(String name) throws Exception;
+
+    /**
+     * Register a Karaf Cave repository into the OBR.
+     *
+     * @param name the name of the Karaf Cave repository.
+     * @throws Exception in case of registration failure.
+     */
+    void register(String name) throws Exception;
+
+    /**
      * Get the list of all Karaf Cave repositories.
      *
      * @return the Karaf Cave repositories.

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java Fri Aug 12 08:03:40 2011
@@ -38,7 +38,6 @@ public class CaveRepositoryImpl implemen
     private File location;
 
     private RepositoryImpl obrRepository;
-    private RepositoryAdmin repositoryAdmin;
 
     public CaveRepositoryImpl(String name, File location, boolean scan) throws Exception {
         this.name = name;
@@ -84,21 +83,13 @@ public class CaveRepositoryImpl implemen
         this.location = location;
     }
 
-    public RepositoryAdmin getRepositoryAdmin() {
-        return this.repositoryAdmin;
-    }
-
-    public void setRepositoryAdmin(RepositoryAdmin repositoryAdmin) {
-        this.repositoryAdmin = repositoryAdmin;
-    }
-
     /**
      * Generate the repository.xml with the artifact at the given URL.
      *
      * @throws Exception in case of repository.xml update failure.
      */
     private void generateRepositoryXml() throws Exception {
-        File repositoryXml = new File(location, "repository.xml");
+        File repositoryXml = this.getRepositoryXmlFile();
         OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(repositoryXml));
         new DataModelHelperImpl().writeRepository(obrRepository, writer);
         writer.flush();
@@ -186,25 +177,32 @@ public class CaveRepositoryImpl implemen
     }
 
     /**
-     * Register the repository (repository.xml) into the OBR (using the OBR RepositoryAdmin service).
+     * Get the File object of the OBR repository.xml file.
      *
-     * @throws Exception in case of register failure.
+     * @return the File corresponding to the OBR repository.xml.
+     * @throws Exception
      */
-    public void register() throws Exception {
-        File repositoryXml = new File(location, "repository.xml");
-        if (repositoryXml != null && repositoryXml.exists()) {
-            repositoryAdmin.addRepository(repositoryXml.toURI().toURL());
-        } else {
-            throw new IllegalStateException("OBR repository.xml not found");
-        }
+    private File getRepositoryXmlFile() throws Exception {
+        return new File(location, "repository.xml");
+    }
+
+    /**
+     * Return the OBR repository.xml corresponding to this Karaf Cave repository.
+     *
+     * @return the URL of the OBR repository.xml.
+     * @throws Exception in case of lookup failure.
+     */
+    public URL getRepositoryXml() throws Exception {
+        File repositoryXml = this.getRepositoryXmlFile();
+        return repositoryXml.toURI().toURL();
     }
 
     /**
-     * Destroy this repository by deleting the storage folder.
+     * Delete the repository storage folder.
      *
      * @throws Exception in case of destroy failure.
      */
-    public void destroy() throws Exception {
+    public void cleanup() throws Exception {
         location.delete();
     }
 

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryServiceImpl.java?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryServiceImpl.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryServiceImpl.java Fri Aug 12 08:03:40 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.karaf.cave.server.backend.impl;
 
+import com.sun.org.apache.bcel.internal.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.apache.karaf.cave.server.backend.api.CaveRepository;
 import org.apache.karaf.cave.server.backend.api.CaveRepositoryService;
 
@@ -29,6 +31,7 @@ import java.util.Map;
 public class CaveRepositoryServiceImpl implements CaveRepositoryService {
 
     private File storageLocation;
+    private RepositoryAdmin repositoryAdmin;
 
     private Map<String, CaveRepository> repositories = new HashMap<String, CaveRepository>();
 
@@ -40,11 +43,36 @@ public class CaveRepositoryServiceImpl i
         this.storageLocation = storageLocation;
     }
 
+    public RepositoryAdmin getRepositoryAdmin() {
+        return this.repositoryAdmin;
+    }
+
+    public void setRepositoryAdmin(RepositoryAdmin repositoryAdmin) {
+        this.repositoryAdmin = repositoryAdmin;
+    }
+
+    /**
+     * Create a new Karaf Cave repository.
+     *
+     * @param name the name of the repository
+     * @param scan if true, the repository is scanned at creation time.
+     * @return  the Karaf Cave repository.
+     * @throws Exception in case of creation failure.
+     */
     public synchronized CaveRepository createRepository(String name, boolean scan) throws Exception {
         File location = new File(storageLocation, name);
         return this.createRepository(name, location.getAbsolutePath(), scan);
     }
 
+    /**
+     * Create a new Karaf Cave repository.
+     *
+     * @param name the name of the repository.
+     * @param location the storage location of the repository.
+     * @param scan if true, the repostory is scanned at creation time.
+     * @return the Karaf Cave repository.
+     * @throws Exception in case of creation failure.
+     */
     public synchronized CaveRepository createRepository(String name, String location, boolean scan) throws Exception {
         if (repositories.get(name) != null) {
             throw new IllegalArgumentException("Cave repository " + name + " already exists.");
@@ -54,10 +82,46 @@ public class CaveRepositoryServiceImpl i
         return repository;
     }
 
+    /**
+     * Destroy a Karaf Cave repository.
+     *
+     * @param name the name of Karaf Cave repository to destroy.
+     * @throws Exception in case of destroy failure.
+     */
+    public synchronized void destroy(String name) throws Exception {
+        CaveRepository repository = this.getRepository(name);
+        if (repository != null) {
+            repository.cleanup();
+            repositories.remove(name);
+        }
+    }
+
+    /**
+     * Register a Karaf Cave repository in the OBR service.
+     *
+     * @param name the name of the Karaf Cave repository.
+     * @throws Exception in case of registration failure.
+     */
+    public synchronized void register(String name) throws Exception {
+        CaveRepository caveRepository = this.getRepository(name);
+        repositoryAdmin.addRepository(caveRepository.getRepositoryXml());
+    }
+
+    /**
+     * Get the list of all Karaf Cave repositories.
+     *
+     * @return the list of all Karaf Cave repositories.
+     */
     public synchronized CaveRepository[] getRepositories() {
         return repositories.values().toArray(new CaveRepository[0]);
     }
 
+    /**
+     * Get the Karaf Cave repository identified by name.
+     *
+     * @param name the name of the Karaf Cave repository to look for.
+     * @return the corresponding Karaf Cave repository.
+     */
     public synchronized CaveRepository getRepository(String name) {
         return repositories.get(name);
     }

Modified: karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/CreateRepositoryCommand.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/CreateRepositoryCommand.java?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/CreateRepositoryCommand.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/CreateRepositoryCommand.java Fri Aug 12 08:03:40 2011
@@ -50,7 +50,7 @@ public class CreateRepositoryCommand ext
             caveRepository.scan();
         }
         if (register) {
-            caveRepository.register();
+            getCaveRepositoryService().register(name);
         }
         return null;
     }

Copied: karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/DestroyRepositoryCommand.java (from r1156806, karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java)
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/DestroyRepositoryCommand.java?p2=karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/DestroyRepositoryCommand.java&p1=karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java&r1=1156806&r2=1156995&rev=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/DestroyRepositoryCommand.java Fri Aug 12 08:03:40 2011
@@ -17,21 +17,17 @@
 package org.apache.karaf.cave.server.command;
 
 import org.apache.felix.gogo.commands.Argument;
-import org.apache.felix.gogo.commands.Command;
-import org.apache.karaf.cave.server.backend.api.CaveRepository;
 
 /**
- * Command to register a Karaf Cave repository into the Karaf OBR.
+ * Destroy a Karaf Cave repository (including content).
  */
-@Command(scope = "cave", name = "register-repository", description = "Register a Karaf Cave repository in the Karaf OBR")
-public class RegisterRepositoryCommand extends CaveRepositoryCommandSupport {
+public class DestroyRepositoryCommand extends CaveRepositoryCommandSupport {
 
-    @Argument(index = 0, name = "name", description = "Name of Karaf Cave repository to register", required = true, multiValued = false)
+    @Argument(index = 0, name = "name", description = "The Karaf Cave repository name", required = true, multiValued = false)
     String name = null;
 
     protected Object doExecute() throws Exception {
-        CaveRepository caveRepository = getExistingRepository(name);
-        caveRepository.register();
+        getCaveRepositoryService().destroy(name);
         return null;
     }
 

Modified: karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/java/org/apache/karaf/cave/server/command/RegisterRepositoryCommand.java Fri Aug 12 08:03:40 2011
@@ -30,8 +30,7 @@ public class RegisterRepositoryCommand e
     String name = null;
 
     protected Object doExecute() throws Exception {
-        CaveRepository caveRepository = getExistingRepository(name);
-        caveRepository.register();
+        getCaveRepositoryService().register(name);
         return null;
     }
 

Modified: karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/resources/OSGI-INF/blueprint/cave-server-commands.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/resources/OSGI-INF/blueprint/cave-server-commands.xml?rev=1156995&r1=1156994&r2=1156995&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/resources/OSGI-INF/blueprint/cave-server-commands.xml (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/command/src/main/resources/OSGI-INF/blueprint/cave-server-commands.xml Fri Aug 12 08:03:40 2011
@@ -32,6 +32,15 @@
                 <property name="caveRepositoryService" ref="caveRepositoryService"/>
             </action>
         </command>
+        <command name="cave/destroy-repository">
+            <action class="org.apache.karaf.cave.server.command.DestroyRepositoryCommand">
+                <property name="caveRepositoryService" ref="caveRepositoryService"/>
+            </action>
+            <completers>
+                <ref component-id="repositoryCompleter"/>
+                <null/>
+            </completers>
+        </command>
         <command name="cave/scan-repository">
             <action class="org.apache.karaf.cave.server.command.ScanRepositoryCommand">
                 <property name="caveRepositoryService" ref="caveRepositoryService"/>