Return-Path: X-Original-To: apmail-ace-commits-archive@www.apache.org Delivered-To: apmail-ace-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 90BADCA40 for ; Fri, 14 Jun 2013 13:37:05 +0000 (UTC) Received: (qmail 79277 invoked by uid 500); 14 Jun 2013 13:37:05 -0000 Delivered-To: apmail-ace-commits-archive@ace.apache.org Received: (qmail 79256 invoked by uid 500); 14 Jun 2013 13:37:05 -0000 Mailing-List: contact commits-help@ace.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ace.apache.org Delivered-To: mailing list commits@ace.apache.org Received: (qmail 79241 invoked by uid 99); 14 Jun 2013 13:37:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jun 2013 13:37:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jun 2013 13:37:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0755F2388906; Fri, 14 Jun 2013 13:36:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@ace.apache.org From: bramk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130614133640.0755F2388906@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 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 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 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 getNamespaceAttributes(Resource resource, String namespace) { + List caps = resource.getCapabilities(namespace); + if (caps.isEmpty()) + return null; + Map 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);