ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1493063 - in /ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli: command/AbstractCommand.java command/CopyDirectory.java command/CopyResources.java repository/AceObrRepository.java
Date Fri, 14 Jun 2013 13:36:39 GMT
Author: bramk
Date: Fri Jun 14 13:36:39 2013
New Revision: 1493063

URL: http://svn.apache.org/r1493063
Log:
[sandbox] Added filename on ACE OBR uploads to support arbitrary type


Modified:
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/AbstractCommand.java
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyResources.java
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/repository/AceObrRepository.java

Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/AbstractCommand.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/AbstractCommand.java?rev=1493063&r1=1493062&r2=1493063&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/AbstractCommand.java
(original)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/AbstractCommand.java
Fri Jun 14 13:36:39 2013
@@ -98,25 +98,41 @@ public abstract class AbstractCommand {
     }
 
     protected String getIdentity(Resource resource) {
-        return (String) resource.getCapabilities("osgi.identity").get(0).getAttributes().get("osgi.identity");
+        Map<String, Object> attrs = getNamespaceAttributes(resource, "osgi.identity");
+        if (attrs == null)
+            return null;
+        return (String) attrs.get("osgi.identity");
 
     }
 
     protected String getVersion(Resource resource) {
-        return ((Version) resource.getCapabilities("osgi.identity").get(0).getAttributes().get("version")).toString();
-
+        Map<String, Object> attrs = getNamespaceAttributes(resource, "osgi.identity");
+        if (attrs == null)
+            return null;
+        Version version = (Version) attrs.get("version");
+        return version == null ? null : version.toString();
     }
 
     protected String getType(Resource resource) {
-        return (String) resource.getCapabilities("osgi.identity").get(0).getAttributes().get("type");
+        Map<String, Object> attrs = getNamespaceAttributes(resource, "osgi.identity");
+        if (attrs == null)
+            return null;
+        return (String) attrs.get("type");
     }
 
     protected String getUrl(Resource resource) {
-        return ((URI) resource.getCapabilities("osgi.content").get(0).getAttributes().get("url")).toString();
+        Map<String, Object> attrs = getNamespaceAttributes(resource, "osgi.content");
+        if (attrs == null)
+            return null;
+        URI url = (URI) attrs.get("url");
+        return url == null ? null : url.toString();
     }
 
     protected String getMimetype(Resource resource) {
-        return (String) resource.getCapabilities("osgi.content").get(0).getAttributes().get("mime");
+        Map<String, Object> attrs = getNamespaceAttributes(resource, "osgi.content");
+        if (attrs == null)
+            return null;
+        return (String) attrs.get("mime");
     }
 
     protected String toString(Resource resource) {
@@ -154,7 +170,7 @@ public abstract class AbstractCommand {
         CapReqBuilder builder = new CapReqBuilder(getFilterNamespace());
         String filter = getFilter();
         if (filter != null) {
-            builder.addDirective("filter", getFilter());
+            builder.addDirective("filter", filter);
         }
         return builder.buildSyntheticRequirement();
     }
@@ -165,4 +181,14 @@ public abstract class AbstractCommand {
             .buildSyntheticRequirement();
         return requirement;
     }
+
+    private Map<String, Object> getNamespaceAttributes(Resource resource, String namespace)
{
+        List<Capability> caps = resource.getCapabilities(namespace);
+        if (caps.isEmpty())
+            return null;
+        Map<String, Object> attrs = caps.get(0).getAttributes();
+        if (attrs == null)
+            return null;
+        return attrs;
+    }
 }

Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java?rev=1493063&r1=1493062&r2=1493063&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java
(original)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java
Fri Jun 14 13:36:39 2013
@@ -91,15 +91,10 @@ public class CopyDirectory extends Abstr
                     dirs.push(file);
                     continue;
                 }
-
-                // We need a mimetype or Jetty will throw a 500 Form too large
-                String mimeType = "application/jar";
-                if (file.getName().endsWith(".xml")) {
-                    mimeType = "text/xml";
-                }
+                
                 InputStream input = new FileInputStream(file);
                 try {
-                    URI uri = aceRepo.upload(input, file.getName(), mimeType);
+                    URI uri = aceRepo.upload(input, file.getName(), null);
                     System.out.println("Copied " + file.getAbsolutePath() + " => " + uri.toString());
                     copyCount++;
                 }

Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyResources.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyResources.java?rev=1493063&r1=1493062&r2=1493063&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyResources.java
(original)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyResources.java
Fri Jun 14 13:36:39 2013
@@ -18,11 +18,12 @@
  */
 package org.apache.ace.cli.command;
 
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.net.URI;
 import java.util.List;
 
+import org.apache.ace.cli.repository.AceObrRepository;
 import org.osgi.resource.Requirement;
 import org.osgi.resource.Resource;
 
@@ -62,7 +63,7 @@ public class CopyResources extends Abstr
 
         int copyCount = 0;
         int skipCount = 0;
-        printVerbose("Copying from source to target with directove " + getFilterNamespace()
+ ":" + getFilter());
+        printVerbose("Copying " + sourceResources.size() + " resources. Directive: " + getFilterNamespace()
+ ":" + getFilter());
         for (Resource sourceResource : sourceResources) {
 
             Requirement targetRequirement = getIdentityRequirement(getIdentity(sourceResource),
getVersion(sourceResource));
@@ -74,19 +75,39 @@ public class CopyResources extends Abstr
             }
             else {
 
-                ResourceHandle handle = sourceRepo.getHandle(getIdentity(sourceResource),
getVersion(sourceResource), Strategy.EXACT, null);
-                File file = handle.request();
-                InputStream input = new FileInputStream(file);
+                ResourceHandle handle = null;
+                InputStream input = null;
                 try {
-                    PutResult result = targetRepo.put(input, new PutOptions());
-                    System.out.println("Copied " + toString(sourceResource) + " => " +
result.artifact.toString());
+                    handle = sourceRepo.getHandle(getIdentity(sourceResource), getVersion(sourceResource),
Strategy.EXACT, null);
+                    input = new FileInputStream(handle.request());
+
+                    // AceObrRepository can accept other types then bundle, but in those
cases
+                    // needs a filename as meta-data.
+                    if (targetRepo instanceof AceObrRepository) {
+                        String fileName = getUrl(sourceResource);
+                        if (fileName.lastIndexOf("/") > 0) {
+                            fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
+                        }
+                        AceObrRepository aceTargetRepo = (AceObrRepository) targetRepo;
+                        URI location = aceTargetRepo.upload(input, fileName, getMimetype(sourceResource));
+                        System.out.println("Copied " + toString(sourceResource) + " =>
" + location.toString());
+
+                    }
+                    else {
+                        PutResult result = targetRepo.put(input, new PutOptions());
+                        System.out.println("Copied " + toString(sourceResource) + " =>
" + result.artifact.toString());
+                    }
                     copyCount++;
                 }
+                catch (Exception e) {
+                    e.printStackTrace();
+                    throw e;
+                }
                 finally {
                     input.close();
                 }
             }
         }
-        printVerbose("Copied " + copyCount + " resources (skipped " + skipCount + "existing)");
+        printVerbose("Copied " + copyCount + " resources (skipped " + skipCount + " existing)");
     }
 }

Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/repository/AceObrRepository.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/repository/AceObrRepository.java?rev=1493063&r1=1493062&r2=1493063&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/repository/AceObrRepository.java
(original)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/repository/AceObrRepository.java
Fri Jun 14 13:36:39 2013
@@ -96,6 +96,10 @@ public class AceObrRepository extends Fi
             if (mimetype != null) {
                 connection.setRequestProperty("Content-Type", mimetype);
             }
+            else {
+                // We need a mimetype or Jetty will throw a 500 Form too large
+                connection.setRequestProperty("Content-Type", "application/octet-stream");
+            }
 
             if (connection instanceof HttpURLConnection) {
                 ((HttpURLConnection) connection).setChunkedStreamingMode(8192);



Mime
View raw message