You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/07/07 10:59:34 UTC

svn commit: r674421 - in /servicemix/smx4/kernel/trunk/filemonitor/src: main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java test/java/org/apache/servicemix/kernel/filemonitor/FileMonitorTest.java

Author: gnodet
Date: Mon Jul  7 01:59:33 2008
New Revision: 674421

URL: http://svn.apache.org/viewvc?rev=674421&view=rev
Log:
SMX4KNL-58: Hot-deploy capability of FileMonitor does not update bundles properly on Windows

Added:
    servicemix/smx4/kernel/trunk/filemonitor/src/test/java/org/apache/servicemix/kernel/filemonitor/FileMonitorTest.java
Modified:
    servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java

Modified: servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java?rev=674421&r1=674420&r2=674421&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java (original)
+++ servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java Mon Jul  7 01:59:33 2008
@@ -392,13 +392,27 @@
         for (int i = 0; i < bundles.length; i++) {
             Bundle bundle = bundles[i];
             String location = bundle.getLocation();
-            if (location.endsWith(absoluteFilePath)) {
+            if (filePathsMatch(absoluteFilePath, location)) {
                 return bundle;
             }
         }
         return null;
     }
 
+    protected static boolean filePathsMatch(String p1, String p2) {
+        p1 = normalizeFilePath(p1);
+        p2 = normalizeFilePath(p2);
+        return (p1 != null && p1.equalsIgnoreCase(p2));
+    }
+
+    protected static String normalizeFilePath( String path ) {
+        if (path != null) {
+            path = path.replaceFirst("file:/*", "");
+            path = path.replaceAll("[\\\\/]+", "/");
+        }
+        return path;
+    }
+
     protected void updateConfiguration(File file) throws IOException, InvalidSyntaxException {
         ConfigurationAdmin configurationAdmin = activator.getConfigurationAdmin();
         if (configurationAdmin == null) {

Added: servicemix/smx4/kernel/trunk/filemonitor/src/test/java/org/apache/servicemix/kernel/filemonitor/FileMonitorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/filemonitor/src/test/java/org/apache/servicemix/kernel/filemonitor/FileMonitorTest.java?rev=674421&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/filemonitor/src/test/java/org/apache/servicemix/kernel/filemonitor/FileMonitorTest.java (added)
+++ servicemix/smx4/kernel/trunk/filemonitor/src/test/java/org/apache/servicemix/kernel/filemonitor/FileMonitorTest.java Mon Jul  7 01:59:33 2008
@@ -0,0 +1,99 @@
+/**
+ *
+ * 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.servicemix.kernel.filemonitor;
+
+import junit.framework.TestCase;
+
+/**
+ * FileMonitor Tester.
+ *
+ * @author <Authors name>
+ * @version 1.0
+ * @since <pre>07/02/2008</pre>
+ */
+public class FileMonitorTest extends TestCase {
+
+    public FileMonitorTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testFilePathsMatch() throws Exception {
+        assertTrue(FileMonitor.filePathsMatch(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt"));
+
+        assertTrue(FileMonitor.filePathsMatch(
+                "C:\\Apps\\apache-servicemix-kernel-1.0.0-rc1\\src\\README.txt",
+                "C:\\Apps\\apache-servicemix-kernel-1.0.0-rc1\\src\\README.txt"));
+
+        assertTrue(FileMonitor.filePathsMatch(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                "C:\\Apps\\apache-servicemix-kernel-1.0.0-rc1\\src\\README.txt"));
+
+        assertTrue(FileMonitor.filePathsMatch(
+                "file:/C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                "C:\\Apps\\apache-servicemix-kernel-1.0.0-rc1\\src\\README.txt"));
+
+        assertTrue(FileMonitor.filePathsMatch(
+                "file://C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                "C:\\Apps\\apache-servicemix-kernel-1.0.0-rc1\\src\\README.txt"));
+    }
+
+    public void testNormalizeFilePath() throws Exception {
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("C:/Apps//apache-servicemix-kernel-1.0.0-rc1////src/////README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("C:\\Apps\\apache-servicemix-kernel-1.0.0-rc1\\src\\README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("C:\\\\Apps\\\\apache-servicemix-kernel-1.0.0-rc1\\\\src\\\\README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("C:\\Apps\\//apache-servicemix-kernel-1.0.0-rc1\\/\\src///\\\\README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("file:C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("file:/C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt"));
+
+        assertEquals(
+                "C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt",
+                FileMonitor.normalizeFilePath("file://C:/Apps/apache-servicemix-kernel-1.0.0-rc1/src/README.txt"));
+    }
+
+}