felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1700124 - in /felix/trunk/gogo/command: ./ src/main/java/org/apache/felix/gogo/command/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/felix/ src/test/java/org/apache/felix/gogo/ src/test/jav...
Date Sun, 30 Aug 2015 15:02:05 GMT
Author: djencks
Date: Sun Aug 30 15:02:05 2015
New Revision: 1700124

URL: http://svn.apache.org/r1700124
Log:
FELIX-5009: allow relative pathnames for gogo install and update.
Thanks to Benson Margulies
This closes #34

Added:
    felix/trunk/gogo/command/src/test/
    felix/trunk/gogo/command/src/test/java/
    felix/trunk/gogo/command/src/test/java/org/
    felix/trunk/gogo/command/src/test/java/org/apache/
    felix/trunk/gogo/command/src/test/java/org/apache/felix/
    felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/
    felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/
    felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java   (with
props)
Modified:
    felix/trunk/gogo/command/pom.xml
    felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
    felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Files.java
    felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java

Modified: felix/trunk/gogo/command/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/pom.xml?rev=1700124&r1=1700123&r2=1700124&view=diff
==============================================================================
--- felix/trunk/gogo/command/pom.xml (original)
+++ felix/trunk/gogo/command/pom.xml Sun Aug 30 15:02:05 2015
@@ -56,6 +56,12 @@
       <artifactId>org.apache.felix.bundlerepository</artifactId>
       <version>1.6.0</version>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>1.10.19</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java?rev=1700124&r1=1700123&r2=1700124&view=diff
==============================================================================
--- felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java (original)
+++ felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java Sun Aug
30 15:02:05 2015
@@ -423,13 +423,14 @@ public class Basic
     }
 
     @Descriptor("install bundle using URLs")
-    public void install(@Descriptor("target URLs") String[] urls)
+    public void install(@Descriptor("command session")CommandSession session,
+                        @Descriptor("target URLs") String[] urls) throws IOException
     {
         StringBuffer sb = new StringBuffer();
 
         for (String url : urls)
         {
-            String location = url.trim();
+            String location = Util.resolveUri(session, url.trim());
             Bundle bundle = null;
             try
             {
@@ -876,11 +877,13 @@ public class Basic
     }
 
     @Descriptor("update bundle from URL")
-    public void update(@Descriptor("target bundle") Bundle bundle,
-        @Descriptor("URL from where to retrieve bundle") String location)
-    {
+    public void update(
+            @Descriptor("command session") CommandSession session,
+            @Descriptor("target bundle") Bundle bundle,
+        @Descriptor("URL from where to retrieve bundle") String location) throws IOException
{
         if (location != null)
         {
+            location = Util.resolveUri(session, location.trim());
             try
             {
                 // Get the bundle.

Modified: felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Files.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Files.java?rev=1700124&r1=1700123&r2=1700124&view=diff
==============================================================================
--- felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Files.java (original)
+++ felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Files.java Sun Aug
30 15:02:05 2015
@@ -27,11 +27,10 @@ import java.util.List;
 import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.command.Descriptor;
 import org.osgi.framework.BundleContext;
+import static org.apache.felix.gogo.command.Util.CWD;
 
 public class Files
 {
-    private static final String CWD = "_cwd";
-
     private final BundleContext m_bc;
 
     public Files(BundleContext bc)

Modified: felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java?rev=1700124&r1=1700123&r2=1700124&view=diff
==============================================================================
--- felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java (original)
+++ felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java Sun Aug
30 15:02:05 2015
@@ -26,12 +26,15 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
+
+import org.apache.felix.service.command.CommandSession;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -39,6 +42,10 @@ import org.osgi.framework.ServiceReferen
 
 public class Util
 {
+
+
+    static final String CWD = "_cwd";
+
     public static String getBundleName(Bundle bundle)
     {
         if (bundle != null)
@@ -490,4 +497,29 @@ loop:   for (int i = 0; i < len; i++)
 
         return result;
     }
-}
\ No newline at end of file
+
+    /**
+     * Intepret a string as a URI relative to the current working directory.
+     * @param session the session (where the CWD is stored)
+     * @param relativeUri the input URI
+     * @return the resulting URI as a string
+     * @throws IOException
+     */
+    public static String resolveUri(CommandSession session, String relativeUri) throws IOException
+    {
+        File cwd = (File) session.get(CWD);
+        if (cwd == null)
+        {
+            cwd = new File("").getCanonicalFile();
+            session.put(CWD, cwd);
+        }
+        if ((relativeUri == null) || (relativeUri.length() == 0))
+        {
+            return relativeUri;
+        }
+
+        URI curUri = cwd.toURI();
+        URI newUri = curUri.resolve(relativeUri);
+        return newUri.toString();
+    }
+}

Added: felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java?rev=1700124&view=auto
==============================================================================
--- felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java (added)
+++ felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java Sun
Aug 30 15:02:05 2015
@@ -0,0 +1,49 @@
+/*
+ * 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.gogo.command;
+
+import org.apache.felix.service.command.CommandSession;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ *
+ */
+public class UtilTest {
+
+    @Test
+    public void relativeUri() throws Exception {
+        CommandSession session = mock(CommandSession.class);
+        when(session.get(Util.CWD)).thenReturn(null); // start with no CWD
+        String u = Util.resolveUri(session, "three");
+        assertEquals(new File(new File("").getAbsoluteFile(), "three").toURI().toString(),
u);
+
+        when(session.get(Util.CWD)).thenReturn(new File(".").getCanonicalFile());
+        u = Util.resolveUri(session, "file:/a/b/c");
+        assertEquals("file:/a/b/c", u);
+        u = Util.resolveUri(session, "three");
+        assertEquals(new File("./three").getCanonicalFile().toURI().toString(), u);
+    }
+}

Propchange: felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/gogo/command/src/test/java/org/apache/felix/gogo/command/UtilTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message