felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1643202 [1/2] - in /felix/trunk/deploymentadmin: deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ deploymentadmin/src/test/java/org/apache/felix/deploymenta...
Date Fri, 05 Dec 2014 09:20:42 GMT
Author: jawi
Date: Fri Dec  5 09:20:42 2014
New Revision: 1643202

URL: http://svn.apache.org/viewvc?rev=1643202&view=rev
Log:
FELIX-4491, FELIX-4718, FELIX-4719:

- (large patch due to unexpected downtime of SVN);
- added support for non-processed resources in deployment packages, which
  makes the Felix DP a little more compliant to the OSGi specification. This
  should fix FELIX-4491 (and FELIX-4516 as well?);
- reviewed and fixed the snapshot creation/restore functionality used for
  the data area of bundles that are upgraded. Both pieces of functionality
  were broken and in desparate need of fixing. Added several tests to cover
  this functionality.


Added:
    felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/
    felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java   (with props)
    felix/trunk/deploymentadmin/itest/src/test/resources/LICENSE   (with props)
    felix/trunk/deploymentadmin/itest/src/test/resources/logo.png   (with props)
Modified:
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminEventTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/InstallDeploymentPackageTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/InstallFixPackageTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/ResourceSharingTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/UninstallDeploymentPackageTest.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/util/ArtifactData.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/util/DeploymentPackageBuilder.java
    felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/util/ResourceDataBuilder.java
    felix/trunk/deploymentadmin/testbundles/bundleimpl1/pom.xml
    felix/trunk/deploymentadmin/testbundles/bundleimpl2/pom.xml

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java Fri Dec  5 09:20:42 2014
@@ -27,7 +27,7 @@ import org.osgi.service.deploymentadmin.
  */
 public class ResourceInfoImpl extends AbstractInfo {
 
-    private String m_resourceProcessor;
+    private final String m_resourceProcessor;
 
     /**
      * Create an instance of this class.
@@ -38,7 +38,21 @@ public class ResourceInfoImpl extends Ab
      */
     public ResourceInfoImpl(String path, Attributes attributes) throws DeploymentException {
         super(path, attributes);
-        m_resourceProcessor = attributes.getValue(RESOURCE_PROCESSOR);
+
+        String rp = attributes.getValue(RESOURCE_PROCESSOR);
+        if (rp != null && "".equals(rp.trim())) {
+            rp = null;
+        }
+
+        m_resourceProcessor = rp;
+    }
+
+    /**
+     * @return <code>true</code> if this resource needs to be processed by a customizer/resource processor,
+     *         <code>false</code> otherwise.
+     */
+    public boolean isProcessedResource() {
+        return m_resourceProcessor != null;
     }
 
     /**

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java Fri Dec  5 09:20:42 2014
@@ -61,18 +61,21 @@ public class DropAllResourcesCommand ext
         ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
         for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
             ResourceInfoImpl resourceInfo = orderedTargetResources[i];
+            // FELIX-4491: only resources that need to be processed should be handled...
+            if (!resourceInfo.isProcessedResource()) {
+                session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
+                continue;
+            }
 
             String rpName = resourceInfo.getResourceProcessor();
             String path = resourceInfo.getPath();
 
-            if (resourceProcessors.contains(rpName)) {
+            // Keep track of which resource processors we've seen already...
+            if (!resourceProcessors.add(rpName)) {
                 // Already seen this RP; continue on the next one...
                 continue;
             }
 
-            // Keep track of which resource processors we've seen already...
-            resourceProcessors.add(rpName);
-
             ServiceReference ref = target.getResourceProcessor(path);
             if (ref == null) {
                 log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java Fri Dec  5 09:20:42 2014
@@ -56,6 +56,12 @@ public class DropResourceCommand extends
         ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
         for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
             ResourceInfoImpl resourceInfo = orderedTargetResources[i];
+            // FELIX-4491: only resources that need to be processed should be handled...
+            if (!resourceInfo.isProcessedResource()) {
+                session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
+                continue;
+            }
+
             String path = resourceInfo.getPath();
             if (source.getResourceInfoByPath(path) == null) {
                 ServiceReference ref = target.getResourceProcessor(path);

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java Fri Dec  5 09:20:42 2014
@@ -30,6 +30,7 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.deploymentadmin.DeploymentException;
 import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
 import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
+import org.osgi.service.log.LogService;
 
 /**
  * Command that processes all the processed resources in the source deployment
@@ -49,7 +50,7 @@ public class ProcessResourceCommand exte
      * committed at a later stage in the deployment session.
      * 
      * @param commitCommand The <code>CommitCommand</code> that will commit all
-     *        resource processors used in this command.
+     *            resource processors used in this command.
      */
     public ProcessResourceCommand(CommitResourceCommand commitCommand) {
         m_commitCommand = commitCommand;
@@ -84,6 +85,11 @@ public class ProcessResourceCommand exte
                 if (resourceInfo == null) {
                     throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
                 }
+                // FELIX-4491: only resources that need to be processed should be handled...
+                if (!resourceInfo.isProcessedResource()) {
+                    session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
+                    continue;
+                }
 
                 ServiceReference ref = source.getResourceProcessor(name);
                 if (ref == null) {

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java Fri Dec  5 09:20:42 2014
@@ -81,48 +81,114 @@ public class SnapshotCommand extends Com
         }
     }
 
-    private void store(File source, File target) throws IOException {
-        ZipOutputStream output = null;
+    protected static void delete(File root, boolean deleteRoot) {
+        if (root.isDirectory()) {
+            File[] childs = root.listFiles();
+            for (int i = 0; i < childs.length; i++) {
+                delete(childs[i], true);
+            }
+        }
+        if (deleteRoot) {
+            root.delete();
+        }
+    }
+
+    protected static void restore(File archiveFile, File targetDir) throws IOException {
+        ZipInputStream input = null;
         try {
-            File[] children = source.listFiles();
-            output = new ZipOutputStream(new FileOutputStream(target));
-            for (int i = 0; i < children.length; i++) {
-                storeRecursive(source, new File(children[i].getName()), output);
+            input = new ZipInputStream(new FileInputStream(archiveFile));
+
+            ZipEntry entry;
+            while ((entry = input.getNextEntry()) != null) {
+                File targetEntry = new File(targetDir, entry.getName());
+
+                if (entry.isDirectory()) {
+                    if (!targetEntry.mkdirs()) {
+                        throw new IOException("Failed to create one or more sub-directories!");
+                    }
+                }
+                else {
+                    OutputStream output = null;
+                    try {
+                        output = new FileOutputStream(targetEntry);
+                        copy(input, output);
+                    }
+                    finally {
+                        closeSilently(output);
+                    }
+                }
+
+                input.closeEntry();
             }
         }
         finally {
+            closeSilently(input);
+        }
+    }
+
+    protected static void store(File sourceDir, File archiveFile) throws IOException {
+        ZipOutputStream output = null;
+        try {
+            output = new ZipOutputStream(new FileOutputStream(archiveFile));
+            // Traverse source directory recursively, and store all entries...
+            store(output, sourceDir, "");
+        }
+        finally {
             closeSilently(output);
         }
     }
 
-    private void storeRecursive(File current, File path, ZipOutputStream output) throws IOException {
-        output.putNextEntry(new ZipEntry(path.getPath()));
-        if (current.isDirectory()) {
-            output.closeEntry();
-            File[] childs = current.listFiles();
-            for (int i = 0; i < childs.length; i++) {
-                storeRecursive(childs[i], new File(path, childs[i].getName()), output);
+    protected static void copy(InputStream is, OutputStream os) throws IOException {
+        byte[] buffer = new byte[8192];
+        int read;
+        try {
+            while ((read = is.read(buffer)) != -1) {
+                os.write(buffer, 0, read);
             }
         }
-        else {
+        finally {
+            os.flush();
+        }
+    }
+
+    private static void store(ZipOutputStream output, File sourceDir, String entryName) throws IOException {
+        File entry = new File(sourceDir, entryName);
+
+        if (entry.isFile()) {
+            ZipEntry zipEntry = new ZipEntry(entryName);
+            zipEntry.setSize(entry.length());
+            zipEntry.setTime(entry.lastModified());
+
+            output.putNextEntry(zipEntry);
+
             InputStream input = null;
             try {
-                input = new FileInputStream(current);
-                byte[] buffer = new byte[4096];
-                for (int i = input.read(buffer); i != -1; i = input.read(buffer)) {
-                    output.write(buffer, 0, i);
-                }
-                output.closeEntry();
+                input = new FileInputStream(entry);
+                copy(input, output);
             }
             finally {
                 closeSilently(input);
+                output.closeEntry();
+            }
+        }
+        else if (entry.isDirectory()) {
+            String baseDir = "";
+            if (!"".equals(entryName)) {
+                baseDir = entryName.concat(File.separator);
+
+                output.putNextEntry(new ZipEntry(baseDir));
+                output.closeEntry();
+            }
+
+            String[] entries = entry.list();
+            for (int i = 0; i < entries.length; i++) {
+                store(output, sourceDir, baseDir.concat(entries[i]));
             }
         }
     }
 
     private static class DeleteSnapshotRunnable extends AbstractAction {
         private final DeploymentSessionImpl m_session;
-
         private final File m_snapshot;
 
         private DeleteSnapshotRunnable(DeploymentSessionImpl session, File snapshot) {
@@ -139,9 +205,7 @@ public class SnapshotCommand extends Com
 
     private static class RestoreSnapshotRunnable extends AbstractAction {
         private final DeploymentSessionImpl m_session;
-
         private final File m_snapshot;
-
         private final File m_root;
 
         private RestoreSnapshotRunnable(DeploymentSessionImpl session, File snapshot, File root) {
@@ -152,8 +216,8 @@ public class SnapshotCommand extends Com
 
         protected void doRun() throws Exception {
             try {
-                delete(m_root, false);
-                unpack(m_snapshot, m_root);
+                delete(m_root, false /* deleteRoot */);
+                restore(m_snapshot, m_root);
             }
             finally {
                 m_snapshot.delete();
@@ -163,46 +227,5 @@ public class SnapshotCommand extends Com
         protected void onFailure(Exception e) {
             m_session.getLog().log(LogService.LOG_WARNING, "Failed to restore snapshot!", e);
         }
-
-        private void delete(File root, boolean deleteRoot) {
-            if (root.isDirectory()) {
-                File[] childs = root.listFiles();
-                for (int i = 0; i < childs.length; i++) {
-                    delete(childs[i], true);
-                }
-            }
-            if (deleteRoot) {
-                root.delete();
-            }
-        }
-
-        private void unpack(File source, File target) throws IOException {
-            ZipInputStream input = null;
-            try {
-                input = new ZipInputStream(new FileInputStream(source));
-                for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
-                    if (entry.isDirectory()) {
-                        (new File(target, entry.getName())).mkdirs();
-                    }
-                    else {
-                        OutputStream output = null;
-                        try {
-                            output = new FileOutputStream(target);
-                            byte[] buffer = new byte[4096];
-                            for (int i = input.read(buffer); i > -1; i = input.read(buffer)) {
-                                output.write(buffer, 0, i);
-                            }
-                        }
-                        finally {
-                            closeSilently(output);
-                        }
-                    }
-                    input.closeEntry();
-                }
-            }
-            finally {
-                closeSilently(input);
-            }
-        }
     }
 }
\ No newline at end of file

Added: felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java?rev=1643202&view=auto
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java (added)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java Fri Dec  5 09:20:42 2014
@@ -0,0 +1,227 @@
+/*
+ * 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.
+ */
+package org.apache.felix.deploymentadmin.spi;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link SnapshotCommand}.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class SnapshotCommandTest extends TestCase {
+    private final List m_cleanup = new ArrayList();
+
+    /**
+     * Tests that an archive can be correctly restored.
+     * <p>
+     * This tests FELIX-4719.
+     * </p>
+     */
+    public void testRestoreArchiveOk() throws Exception {
+        // Set up a file-hierarchy we can archive...
+        File baseDir = createFileHierarchy();
+
+        File archiveFile = new File(baseDir, "../archive.zip");
+        m_cleanup.add(archiveFile.getCanonicalFile());
+
+        SnapshotCommand.store(baseDir, archiveFile);
+        assertTrue("Archive not created?!", archiveFile.exists());
+
+        File targetDir = createTempDir();
+        SnapshotCommand.restore(archiveFile, targetDir);
+
+        verifyDirContents(baseDir, targetDir);
+    }
+
+    /**
+     * Tests that a directory (data-area) is correctly archived, and that the contents of that archive are as expected.
+     * <p>
+     * This tests FELIX-4718.
+     * </p>
+     */
+    public void testStoreDataAreaOk() throws Exception {
+        // Set up a file-hierarchy we can archive...
+        File baseDir = createFileHierarchy();
+
+        File archiveFile = new File(baseDir, "../archive.zip");
+        m_cleanup.add(archiveFile.getCanonicalFile());
+
+        SnapshotCommand.store(baseDir, archiveFile);
+        assertTrue("Archive not created?!", archiveFile.exists());
+
+        verifyArchiveContents(archiveFile, 3 /* dirs */, 6 /* files */);
+    }
+
+    protected void tearDown() throws Exception {
+        Iterator iter = m_cleanup.iterator();
+        while (iter.hasNext()) {
+            File file = (File) iter.next();
+            if (file.isFile()) {
+                file.delete();
+            }
+            else if (file.isDirectory()) {
+                SnapshotCommand.delete(file, true /* deleteRoot */);
+            }
+            iter.remove();
+        }
+    }
+
+    private void close(Closeable resource) throws IOException {
+        if (resource != null) {
+            resource.close();
+        }
+    }
+
+    private void createFile(File file, int size) throws IOException {
+        assertTrue(file.createNewFile());
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(file);
+
+            byte[] data = new byte[size];
+            new Random().nextBytes(data);
+
+            fos.write(data);
+        }
+        finally {
+            close(fos);
+        }
+    }
+
+    /**
+     * Creates a simple file hierarchy with a couple of files and directories (6 files and 3 directories).
+     * 
+     * @return the base directory where the file hierarchy is stored, never <code>null</code>.
+     */
+    private File createFileHierarchy() throws IOException {
+        File base = createTempDir();
+
+        File dir1 = new File(base, "dir1");
+        assertTrue(dir1.mkdir());
+
+        File dir2 = new File(dir1, "dir1a");
+        assertTrue(dir2.mkdir());
+
+        File dir3 = new File(dir1, "dir1b");
+        assertTrue(dir3.mkdir());
+
+        createFile(new File(base, "file1"), 1024);
+        createFile(new File(dir1, "file2"), 2048);
+        createFile(new File(dir2, "file3"), 4096);
+        createFile(new File(base, "file4"), 8192);
+        createFile(new File(dir2, "file5"), 16384);
+        createFile(new File(dir3, "file6"), 32768);
+
+        return base;
+    }
+
+    private File createTempDir() throws IOException {
+        File dir = File.createTempFile("felix4718-", "");
+        assertTrue(dir.delete());
+        assertTrue(dir.mkdirs());
+        // For test cleanup...
+        m_cleanup.add(dir);
+        return dir;
+    }
+
+    private void verifyArchiveContents(File archive, int expectedDirCount, int expectedFileCount) throws IOException {
+        FileInputStream fis = null;
+        ZipInputStream zis = null;
+
+        try {
+            fis = new FileInputStream(archive);
+            zis = new ZipInputStream(fis);
+
+            int dirCount = 0;
+            int fileCount = 0;
+
+            ZipEntry entry;
+            while ((entry = zis.getNextEntry()) != null) {
+                if (entry.isDirectory()) {
+                    dirCount++;
+                }
+                else {
+                    fileCount++;
+                }
+                zis.closeEntry();
+            }
+
+            assertEquals("Unexpected number of files", expectedFileCount, fileCount);
+            assertEquals("Unexpected number of directories", expectedDirCount, dirCount);
+        }
+        finally {
+            close(fis);
+            close(zis);
+        }
+    }
+
+    private void verifyDirContents(File expectedBase, File actualBase) throws IOException {
+        String[] expectedFiles = expectedBase.list();
+        for (int i = 0; i < expectedFiles.length; i++) {
+            File expected = new File(expectedBase, expectedFiles[i]);
+            File actual = new File(actualBase, expectedFiles[i]);
+
+            if (expected.isDirectory()) {
+                assertTrue("Directory '" + expectedFiles[i] + "' does not exist in " + actualBase, actual.isDirectory());
+                verifyDirContents(expected, actual);
+            }
+            else if (expected.isFile()) {
+                assertTrue("File '" + expectedFiles[i] + "' does not exist in " + actualBase, actual.isFile());
+                verifyFileContents(expected, actual);
+            }
+            else {
+                fail("Unknown entity: '" + expectedFiles[i] + "'");
+            }
+        }
+    }
+
+    private void verifyFileContents(File expected, File actual) throws IOException {
+        assertEquals("File size mismatch!", expected.length(), actual.length());
+
+        FileInputStream fis1 = null;
+        FileInputStream fis2 = null;
+        try {
+            fis1 = new FileInputStream(expected);
+            fis2 = new FileInputStream(actual);
+
+            int eb;
+            while ((eb = fis1.read()) != -1) {
+                int ab = fis2.read();
+                assertEquals(eb, ab);
+            }
+        }
+        finally {
+            close(fis2);
+            close(fis1);
+        }
+    }
+}

Propchange: felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java (original)
+++ felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java Fri Dec  5 09:20:42 2014
@@ -169,7 +169,10 @@ public abstract class BaseIntegrationTes
     }
     
     protected final DeploymentPackage installDeploymentPackage(DeploymentPackageBuilder dpBuilder) throws Exception {
-        InputStream is = dpBuilder.generate();
+        return installDeploymentPackage(dpBuilder.generate());
+    }
+    
+    protected final DeploymentPackage installDeploymentPackage(InputStream is) throws Exception {
         try {
             return m_deploymentAdmin.installDeploymentPackage(is);
         } finally {
@@ -227,17 +230,24 @@ public abstract class BaseIntegrationTes
         return resource;
     }
 
-    protected URL getTestBundle(String baseName) throws MalformedURLException {
-    	return getTestBundle(baseName, "1.0.0");
+    protected Bundle getBundle(String bsn) {
+        for (Bundle b : m_context.getBundles()) {
+            if (bsn.equals(b.getSymbolicName())) {
+                return b;
+            }
+        }
+        return null;
+    }
+
+    protected URL getTestBundleURL(String baseName) throws MalformedURLException {
+    	return getTestBundleURL(baseName, "1.0.0");
     }
-    protected URL getTestBundle(String baseName, String version) throws MalformedURLException {
-    	return getTestBundle(baseName, baseName, version);
+    protected URL getTestBundleURL(String baseName, String version) throws MalformedURLException {
+    	return getTestBundleURL(baseName, baseName, version);
     }
 
-    protected URL getTestBundle(String artifactName, String baseName, String version) throws MalformedURLException {
-    	if (version == null) {
-    		version = "0.0.0";
-    	}
+    protected URL getTestBundleURL(String artifactName, String baseName, String version) throws MalformedURLException {
+        assertNotNull("Version cannot be null!", version);
         File f = new File(m_testBundleBasePath, String.format("%1$s/target/org.apache.felix.deploymentadmin.test.%2$s-%3$s.jar", artifactName, baseName, version));
         assertTrue("No such bundle: " + f, f.exists() && f.isFile());
         return f.toURI().toURL();

Modified: felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java (original)
+++ felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java Fri Dec  5 09:20:42 2014
@@ -39,6 +39,37 @@ import org.osgi.service.deploymentadmin.
 public class CustomizerTest extends BaseIntegrationTest {
 
     /**
+     * FELIX-4491 - Only resources with a resource processor defined should be processed. 
+     */
+    @Test
+    public void testInstallBundleWithNonProcessedResourcesOk() throws Exception {
+        DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
+        dpBuilder
+            .add(dpBuilder.createResource().setNeedResourceProcessor(false).setUrl(getTestResource("LICENSE")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
+            .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
+
+        DeploymentPackage dp = installDeploymentPackage(dpBuilder);
+        assertNotNull("No deployment package returned?!", dp);
+
+        assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
+
+        awaitRefreshPackagesEvent();
+
+        assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
+        
+        // Check that only the processed resources are dropped...
+        dp.uninstall();
+
+        assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
+
+        awaitRefreshPackagesEvent();
+        
+        assertBundleNotExists(getSymbolicName("bundle1"), "1.0.0");
+    }
+    
+    /**
      * Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
      */
     @Test
@@ -47,9 +78,9 @@ public class CustomizerTest extends Base
 
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -72,7 +103,7 @@ public class CustomizerTest extends Base
 
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
 
         try {
@@ -98,7 +129,7 @@ public class CustomizerTest extends Base
 
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
 
         try {
@@ -124,7 +155,7 @@ public class CustomizerTest extends Base
 
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
@@ -146,9 +177,9 @@ public class CustomizerTest extends Base
 
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         try {
             installDeploymentPackage(dpBuilder);
@@ -170,7 +201,7 @@ public class CustomizerTest extends Base
     public void testInstallResourceWithForeignCustomizerFail() throws Exception {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")));
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
 
         installDeploymentPackage(dpBuilder);
 

Modified: felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminEventTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminEventTest.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminEventTest.java (original)
+++ felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminEventTest.java Fri Dec  5 09:20:42 2014
@@ -51,8 +51,8 @@ public class DeploymentAdminEventTest ex
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         // incluse two different versions of the same bundle (with the same BSN), this is *not* allowed per the DA spec...
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi1", "bundleapi1", "1.0.0")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi2", "bundleapi2", "2.0.0")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
 
         final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
         final AtomicReference<Event> installEventRef = new AtomicReference<Event>();
@@ -114,8 +114,8 @@ public class DeploymentAdminEventTest ex
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi1", "bundleapi1", "1.0.0")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleimpl1", "bundleimpl1", "1.0.0")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
 
         final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
         final AtomicReference<Event> installEventRef = new AtomicReference<Event>();
@@ -173,8 +173,8 @@ public class DeploymentAdminEventTest ex
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi1", "bundleapi1", "1.0.0")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleimpl1", "bundleimpl1", "1.0.0")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
 
         final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
         final AtomicReference<Event> uninstallEventRef = new AtomicReference<Event>();
@@ -237,8 +237,8 @@ public class DeploymentAdminEventTest ex
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
 
         final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();

Modified: felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminTest.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminTest.java (original)
+++ felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DeploymentAdminTest.java Fri Dec  5 09:20:42 2014
@@ -38,8 +38,8 @@ import org.osgi.service.deploymentadmin.
  * Generic tests for {@link DeploymentAdmin}.
  */
 @RunWith(PaxExam.class)
-public class DeploymentAdminTest extends BaseIntegrationTest {
-
+public class DeploymentAdminTest extends BaseIntegrationTest
+{
     /**
      * Tests that we can update the configuration of {@link DeploymentAdmin} at runtime. Based on the test case for FELIX-4184, see 
      * {@link org.apache.felix.deploymentadmin.itest.InstallFixPackageTest#testInstallAndUpdateImplementationBundleWithSeparateAPIBundle_FELIX4184()}
@@ -57,21 +57,22 @@ public class DeploymentAdminTest extends
         Thread.sleep(100);
 
         // This test case will only work if stopUnaffectedBundle is set to 'false'...
-        try {
+        try
+        {
             // first, install a deployment package with implementation and api bundles in version 1.0.0
             DeploymentPackageBuilder dpBuilder = createDeploymentPackageBuilder("a", "1.0.0");
-            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleimpl1", "bundleimpl1", "1.0.0")));
-            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi1", "bundleapi1", "1.0.0")));
-    
+            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
+            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")));
+
             DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
             assertNotNull("No deployment package returned?!", dp1);
-    
+
             assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
-    
+
             // then, install a fix package with implementation and api bundles in version 2.0.0
             dpBuilder = createDeploymentPackageBuilder("a", "2.0.0").setFixPackage("[1.0.0,2.0.0]");
-            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleimpl2", "bundleimpl2", "2.0.0")));
-            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi2", "bundleapi2", "2.0.0")));
+            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl2", "bundleimpl2", "2.0.0")));
+            dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
 
             DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
             assertNotNull("No deployment package returned?!", dp2);
@@ -82,94 +83,82 @@ public class DeploymentAdminTest extends
             assertBundleExists(getSymbolicName("bundleapi"), "2.0.0");
             assertBundleNotExists(getSymbolicName("bundleimpl"), "1.0.0");
             assertBundleNotExists(getSymbolicName("bundleapi"), "1.0.0");
-        } finally {
+        }
+        finally
+        {
             config.delete();
         }
     }
 
     @Test
-    public void testBundleSymbolicNameMustMatchManifestEntry() throws Exception {
+    public void testBundleSymbolicNameMustMatchManifestEntry() throws Exception
+    {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder
-            .add(dpBuilder.createBundleResource()
-                .setUrl(getTestBundle("bundle1"))
-            )
-            .add(dpBuilder.createBundleResource()
-                .setUrl(getTestBundle("bundle2"))
-                .setFilter(new JarManifestManipulatingFilter("Bundle-SymbolicName", "foo"))
-            );
-        
-        try {
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(
+            dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setFilter(new JarManifestManipulatingFilter("Bundle-SymbolicName", "foo")));
+
+        try
+        {
             installDeploymentPackage(dpBuilder);
             fail("Succeeded into installing a bundle with a fake symbolic name?!");
         }
-        catch (DeploymentException exception) {
+        catch (DeploymentException exception)
+        {
             // Ok; expected...
             assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
         }
     }
 
     @Test
-    public void testBundleVersionMustMatchManifestEntry() throws Exception {
+    public void testBundleVersionMustMatchManifestEntry() throws Exception
+    {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder
-            .add(dpBuilder.createBundleResource()
-                .setUrl(getTestBundle("bundle1"))
-            )
-            .add(dpBuilder.createBundleResource()
-                .setUrl(getTestBundle("bundle2"))
-                .setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0"))
-            );
-        
-        try {
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(
+            dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0")));
+
+        try
+        {
             installDeploymentPackage(dpBuilder);
             fail("Succeeded into installing a bundle with a fake version?!");
         }
-        catch (DeploymentException exception) {
+        catch (DeploymentException exception)
+        {
             // Ok; expected...
             assertDeploymentException(CODE_OTHER_ERROR, exception);
         }
     }
 
     @Test
-    public void testManifestEntryMustMatchBundleSymbolicName() throws Exception {
+    public void testManifestEntryMustMatchBundleSymbolicName() throws Exception
+    {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder
-            .add(dpBuilder.createBundleResource()
-                .setUrl(getTestBundle("bundle1"))
-            )
-            .add(dpBuilder.createBundleResource()
-                .setSymbolicName("foo")
-                .setUrl(getTestBundle("bundle2"))
-            );
-        
-        try {
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setSymbolicName("foo").setUrl(getTestBundleURL("bundle2")));
+
+        try
+        {
             installDeploymentPackage(dpBuilder);
             fail("Succeeded into installing a bundle with a fake symbolic name?!");
         }
-        catch (DeploymentException exception) {
+        catch (DeploymentException exception)
+        {
             // Ok; expected...
             assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
         }
     }
 
     @Test
-    public void testManifestEntryMustMatchBundleVersion() throws Exception {
+    public void testManifestEntryMustMatchBundleVersion() throws Exception
+    {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder
-            .add(dpBuilder.createBundleResource()
-                .setUrl(getTestBundle("bundle1"))
-            )
-            .add(dpBuilder.createBundleResource()
-                .setVersion("1.1.0")
-                .setUrl(getTestBundle("bundle2"))
-            );
-        
-        try {
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle2")));
+
+        try
+        {
             installDeploymentPackage(dpBuilder);
             fail("Succeeded into installing a bundle with a fake version?!");
         }
-        catch (DeploymentException exception) {
+        catch (DeploymentException exception)
+        {
             // Ok; expected...
             assertDeploymentException(CODE_OTHER_ERROR, exception);
         }

Modified: felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/InstallDeploymentPackageTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/InstallDeploymentPackageTest.java?rev=1643202&r1=1643201&r2=1643202&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/InstallDeploymentPackageTest.java (original)
+++ felix/trunk/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/InstallDeploymentPackageTest.java Fri Dec  5 09:20:42 2014
@@ -18,7 +18,10 @@
  */
 package org.apache.felix.deploymentadmin.itest;
 
+import java.io.File;
+
 import org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder;
+import org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.PaxExam;
@@ -42,8 +45,8 @@ public class InstallDeploymentPackageTes
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         // incluse two different versions of the same bundle (with the same BSN), this is *not* allowed per the DA spec...
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi1", "bundleapi1", "1.0.0")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi2", "bundleapi2", "2.0.0")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
 
         try
         {
@@ -69,8 +72,8 @@ public class InstallDeploymentPackageTes
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         // incluse two different versions of the same bundle (with the same BSN), this is *not* allowed per the DA spec...
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleapi1", "bundleapi1", "1.0.0")).setFilename("bundles/bundleapi1.jar"))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundleimpl1", "bundleimpl1", "1.0.0")).setFilename("bundles/bundleimpl1.jar"));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")).setFilename("bundles/bundleapi1.jar"))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")).setFilename("bundles/bundleimpl1.jar"));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull(dp);
@@ -91,7 +94,7 @@ public class InstallDeploymentPackageTes
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         // missing bundle1 as dependency...
-        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")));
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
 
         DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp1);
@@ -105,8 +108,8 @@ public class InstallDeploymentPackageTes
 
         dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
 
         DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp2);
@@ -124,7 +127,7 @@ public class InstallDeploymentPackageTes
     public void testInstallBundleWithDependencyInSeparatePackageOk() throws Exception
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")));
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
 
         DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp1);
@@ -140,7 +143,7 @@ public class InstallDeploymentPackageTes
 
         dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         // as missing bundle1...
-        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")));
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
 
         DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp2);
@@ -167,8 +170,8 @@ public class InstallDeploymentPackageTes
 
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -193,8 +196,8 @@ public class InstallDeploymentPackageTes
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("fragment1")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("fragment1")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -217,7 +220,7 @@ public class InstallDeploymentPackageTes
     public void testInstallBundleWithMissingDependencyOk() throws Exception
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")));
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -240,9 +243,9 @@ public class InstallDeploymentPackageTes
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
             .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -263,7 +266,7 @@ public class InstallDeploymentPackageTes
     public void testInstallSingleValidBundleOk() throws Exception
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
-        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")));
+        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -284,8 +287,8 @@ public class InstallDeploymentPackageTes
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -309,8 +312,8 @@ public class InstallDeploymentPackageTes
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -323,8 +326,8 @@ public class InstallDeploymentPackageTes
 
         dpBuilder = dpBuilder.create("1.0.1");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
 
         dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -347,8 +350,8 @@ public class InstallDeploymentPackageTes
     {
         DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         DeploymentPackage dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -361,9 +364,9 @@ public class InstallDeploymentPackageTes
 
         dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
         dpBuilder
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")))
-            .add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle3")));
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")))
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
 
         dp = installDeploymentPackage(dpBuilder);
         assertNotNull("No deployment package returned?!", dp);
@@ -378,4 +381,207 @@ public class InstallDeploymentPackageTes
 
         assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
     }
+
+    /**
+     * Tests that we can correctly rollback the installation of a deployment package for bundles that have their data area populated. 
+     */
+    @Test
+    public void testRollbackWithPopulatedDataAreaOk() throws Exception {
+        // Install a first version, in which we're going to change the data area of a bundle...
+        DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
+        dpBuilder
+            .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
+
+        DeploymentPackage dp = installDeploymentPackage(dpBuilder);
+        assertNotNull("No deployment package returned?!", dp);
+
+        awaitRefreshPackagesEvent();
+
+        Bundle bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+
+        File dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Populate the data area...
+        assertTrue("No file created?!", new File(dataArea, "file1").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file2").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file3").createNewFile());
+
+        // This will cause the new bundle to fail in its stop method...
+        System.setProperty("rp1", "process");
+
+        // Simulate an upgrade for our bundle, which should cause its data area to be retained...
+        dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
+        dpBuilder
+        .add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle1")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
+            .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
+
+        try {
+            dp = installDeploymentPackage(dpBuilder); // should fail!
+            fail("Deployment of upgrade package should have failed?!");
+        }
+        catch (DeploymentException e) {
+            // Ok; expected...
+        }
+
+        // We should still have this bundle..
+        bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+        
+        dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Data area should be restored exactly as-is...
+        assertTrue("File not restored?!", new File(dataArea, "file1").exists());
+        assertTrue("File not restored?!", new File(dataArea, "file2").exists());
+        assertTrue("File not restored?!", new File(dataArea, "file3").exists());
+    }
+
+    /**
+     * Tests that we can correctly install a deployment package with bundles that have their data area populated. 
+     */
+    @Test
+    public void testUpgradeWithPopulatedDataAreaOk() throws Exception {
+        // Install a first version, in which we're going to change the data area of a bundle...
+        DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
+        dpBuilder
+            .add(dpBuilder.createBundleResource().setVersion("1.0.0").setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
+
+        DeploymentPackage dp = installDeploymentPackage(dpBuilder);
+        assertNotNull("No deployment package returned?!", dp);
+
+        awaitRefreshPackagesEvent();
+
+        Bundle bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+
+        File dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Populate the data area...
+        assertTrue("No file created?!", new File(dataArea, "file1").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file2").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file3").createNewFile());
+
+        dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
+        dpBuilder
+            .add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle1")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
+            .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
+
+        dp = installDeploymentPackage(dpBuilder); // should succeed!
+
+        // We should still have this bundle..
+        bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+        
+        dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Data area should be restored exactly as-is...
+        assertTrue("File not restored?!", new File(dataArea, "file1").exists());
+        assertTrue("File not restored?!", new File(dataArea, "file2").exists());
+        assertTrue("File not restored?!", new File(dataArea, "file3").exists());
+    }
+
+    /**
+     * Tests that we can correctly install a deployment package with bundles that have their data area populated. 
+     */
+    @Test
+    public void testUninstallBundleWithPopulatedDataAreaOk() throws Exception {
+        // Install a first version, in which we're going to change the data area of a bundle...
+        DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
+        dpBuilder
+            .add(dpBuilder.createBundleResource().setVersion("1.0.0").setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
+
+        DeploymentPackage dp = installDeploymentPackage(dpBuilder);
+        assertNotNull("No deployment package returned?!", dp);
+
+        awaitRefreshPackagesEvent();
+
+        Bundle bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+
+        File dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Populate the data area...
+        assertTrue("No file created?!", new File(dataArea, "file1").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file2").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file3").createNewFile());
+
+        dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
+        dpBuilder
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
+            .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
+
+        dp = installDeploymentPackage(dpBuilder); // should succeed!
+
+        // We should no longer have this bundle..
+        bundle1 = getBundle("testbundles.bundle1");
+        assertNull("Unable to get installed test bundle?!", bundle1);
+
+        // Data area should be restored exactly as-is...
+        assertFalse("Data area not purged?!", dataArea.exists());
+    }
+    /**
+     * Tests that we can correctly install a deployment package with bundles that have their data area populated. 
+     */
+    @Test
+    public void testRollbackUninstallBundleWithPopulatedDataAreaOk() throws Exception {
+        // Install a first version, in which we're going to change the data area of a bundle...
+        DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
+        dpBuilder
+            .add(dpBuilder.createBundleResource().setVersion("1.0.0").setUrl(getTestBundleURL("bundle1")))
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
+
+        DeploymentPackage dp = installDeploymentPackage(dpBuilder);
+        assertNotNull("No deployment package returned?!", dp);
+
+        awaitRefreshPackagesEvent();
+
+        Bundle bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+
+        File dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Populate the data area...
+        assertTrue("No file created?!", new File(dataArea, "file1").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file2").createNewFile());
+        assertTrue("No file created?!", new File(dataArea, "file3").createNewFile());
+
+        // This will cause the new bundle to fail in its stop method...
+        System.setProperty("rp1", "process");
+
+        dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
+        dpBuilder
+            .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
+            .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
+
+        try {
+            dp = installDeploymentPackage(dpBuilder); // should fail!
+            fail("Deployment of upgrade package should have failed?!");
+        }
+        catch (DeploymentException e) {
+            // Ok; expected...
+        }
+
+        // We should still have this bundle..
+        bundle1 = getBundle("testbundles.bundle1");
+        assertNotNull("Unable to get installed test bundle?!", bundle1);
+        
+        dataArea = bundle1.getDataFile("");
+        assertNotNull("No data area obtained for test bundle?!", dataArea);
+
+        // Data area should be restored exactly as-is...
+        assertTrue("File not restored?!", new File(dataArea, "file1").exists());
+        assertTrue("File not restored?!", new File(dataArea, "file2").exists());
+        assertTrue("File not restored?!", new File(dataArea, "file3").exists());
+    }
 }



Mime
View raw message