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 2012/06/13 11:47:30 UTC

svn commit: r1349711 - in /karaf/trunk: deployer/kar/src/main/java/org/apache/karaf/deployer/kar/ kar/command/src/main/java/org/apache/karaf/kar/command/ kar/core/src/main/java/org/apache/karaf/kar/internal/

Author: jbonofre
Date: Wed Jun 13 09:47:30 2012
New Revision: 1349711

URL: http://svn.apache.org/viewvc?rev=1349711&view=rev
Log:
[KARAF-1392] Uninstall a kar now remove the features, bundles, repositories

Modified:
    karaf/trunk/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java
    karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/UninstallKarCommand.java
    karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java

Modified: karaf/trunk/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java
URL: http://svn.apache.org/viewvc/karaf/trunk/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java?rev=1349711&r1=1349710&r2=1349711&view=diff
==============================================================================
--- karaf/trunk/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java (original)
+++ karaf/trunk/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/KarArtifactInstaller.java Wed Jun 13 09:47:30 2012
@@ -51,14 +51,12 @@ public class KarArtifactInstaller implem
 
     public void uninstall(File file) throws Exception {
         LOGGER.info("Uninstalling KAR {}", file.getName());
-        karService.uninstall(file.getName());
-        LOGGER.warn("KAR {} has been removed; however, its feature URLs have not been deregistered, " +
-                "and its bundles are still available in the system repository.", file.getName());
+        karService.uninstall(file.getName(), true);
 	}
 
 	public void update(File file) throws Exception {
         LOGGER.warn("Karaf archive {}' has been updated; redeploying.", file);
-        karService.uninstall(file.getName());
+        karService.uninstall(file.getName(), true);
         karService.install(file.toURI());
 	}
 

Modified: karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/UninstallKarCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/UninstallKarCommand.java?rev=1349711&r1=1349710&r2=1349711&view=diff
==============================================================================
--- karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/UninstallKarCommand.java (original)
+++ karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/UninstallKarCommand.java Wed Jun 13 09:47:30 2012
@@ -26,7 +26,7 @@ public class UninstallKarCommand extends
     @Argument(index = 0, name = "name", description = "The name of the KAR file to uninstall.", required = true, multiValued = false)
     private String name;
 
-    @Option(name = "-c", aliases = { "--clean" }, description = "Cleanup the system repository from the KAR content", required = false, multiValued = false)
+    @Option(name = "-c", aliases = { "--clean" }, description = "Uninstall features and cleanup the system repository from the KAR content", required = false, multiValued = false)
     private boolean clean = false;
     
     public Object doExecute() throws Exception {

Modified: karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java?rev=1349711&r1=1349710&r2=1349711&view=diff
==============================================================================
--- karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java (original)
+++ karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java Wed Jun 13 09:47:30 2012
@@ -120,11 +120,11 @@ public class KarServiceImpl implements K
         
         zipFile.close();
     }
-    
+
     public void uninstall(String karName) throws Exception {
         uninstall(karName, false);
     }
-    
+
     public void uninstall(String karName, boolean clean) throws Exception {
         File karStorage = new File(storage);
         File karFile = new File(karStorage, karName);
@@ -132,29 +132,43 @@ public class KarServiceImpl implements K
         if (!karFile.exists()) {
             throw new IllegalArgumentException("The KAR " + karName + " is not installed");
         }
-        
+
         if (clean) {
             LOGGER.debug("Looking for KAR entries to purge the local repository");
+            List<URI> featuresRepositories = new ArrayList<URI>();
             ZipFile zipFile = new ZipFile(karFile);
             Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile.entries();
             while (entries.hasMoreElements()) {
                 ZipEntry entry = entries.nextElement();
                 String repoEntryName = getRepoEntryName(entry);
                 if (repoEntryName != null) {
-                    File toDelete = new File(base + File.separator + repoEntryName);
-                    if (toDelete.exists()) {
-                        toDelete.delete();
+                    File toDelete = new File(localRepo + File.separator + repoEntryName);
+                    if (isFeaturesRepository(toDelete)) {
+                        featuresRepositories.add(toDelete.toURI());
+                    } else {
+                        if (toDelete.isFile() && toDelete.exists()) {
+                            toDelete.delete();
+                        }
                     }
                 }
                 if (entry.getName().startsWith("resource")) {
                     String resourceEntryName = entry.getName().substring("resource/".length());
                     File toDelete = new File(base + File.separator + resourceEntryName);
-                    if (toDelete.exists()) {
+                    if (toDelete.isFile() && toDelete.exists()) {
                         toDelete.delete();
                     }
                 }
             }
             zipFile.close();
+
+            uninstallFeatures(featuresRepositories);
+            for (URI featuresRepository : featuresRepositories) {
+                featuresService.removeRepository(featuresRepository);
+                File toDelete = new File(featuresRepository);
+                if (toDelete.exists() && toDelete.isFile()) {
+                    toDelete.delete();
+                }
+            }
         }
         
         karFile.delete();
@@ -342,6 +356,31 @@ public class KarServiceImpl implements K
         }
     }
 
+    /**
+     * Uninstall all features contained in the list of features XML.
+     *
+     * @param featuresRepositories the list of features XML.
+     */
+    private void uninstallFeatures(List<URI> featuresRepositories) {
+        for (Repository repository : featuresService.listRepositories()) {
+            for (URI karFeatureRepoUri : featuresRepositories) {
+                if (repository.getURI().equals(karFeatureRepoUri)) {
+                    try {
+                        for (Feature feature : repository.getFeatures()) {
+                            try {
+                                featuresService.uninstallFeature(feature.getName(), feature.getVersion());
+                            } catch (Exception e) {
+                                LOGGER.warn("Unable to uninstall Kar feature {}", feature.getName() + "/" + feature.getVersion(), e);
+                            }
+                        }
+                    } catch (Exception e) {
+                        LOGGER.warn("Can't get features for KAR {}", karFeatureRepoUri, e);
+                    }
+                }
+            }
+        }
+    }
+
     public FeaturesService getFeaturesService() {
         return featuresService;
     }