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 1708D10687 for ; Thu, 13 Jun 2013 09:16:02 +0000 (UTC) Received: (qmail 54165 invoked by uid 500); 13 Jun 2013 09:16:02 -0000 Delivered-To: apmail-ace-commits-archive@ace.apache.org Received: (qmail 54144 invoked by uid 500); 13 Jun 2013 09:16:00 -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 54128 invoked by uid 99); 13 Jun 2013 09:15:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2013 09:15:57 +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; Thu, 13 Jun 2013 09:15:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 39D9F2388A64; Thu, 13 Jun 2013 09:15:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1492589 - in /ace/sandbox/bramk/org.apache.ace.cli: .settings/org.eclipse.jdt.core.prefs src/org/apache/ace/cli/Main.java src/org/apache/ace/cli/command/CopyDirectory.java src/org/apache/ace/cli/repository/AceObrRepository.java Date: Thu, 13 Jun 2013 09:15:33 -0000 To: commits@ace.apache.org From: bramk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130613091533.39D9F2388A64@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bramk Date: Thu Jun 13 09:15:32 2013 New Revision: 1492589 URL: http://svn.apache.org/r1492589 Log: [sandbox] Added initial copy directory command Added: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java Removed: ace/sandbox/bramk/org.apache.ace.cli/.settings/org.eclipse.jdt.core.prefs Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/Main.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/Main.java URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/Main.java?rev=1492589&r1=1492588&r2=1492589&view=diff ============================================================================== --- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/Main.java (original) +++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/Main.java Thu Jun 13 09:15:32 2013 @@ -31,6 +31,7 @@ import java.util.Map.Entry; import java.util.Properties; import org.apache.ace.cli.command.AbstractCommand; +import org.apache.ace.cli.command.CopyDirectory; import org.apache.ace.cli.command.CopyResources; import org.apache.ace.cli.command.CreateArtifacts; import org.apache.ace.cli.command.CreateDistribution; @@ -61,6 +62,7 @@ public class Main { private final static List COMMANDS = new ArrayList(); static { + COMMANDS.add(new CopyDirectory()); COMMANDS.add(new ListResources()); COMMANDS.add(new DeleteResources()); COMMANDS.add(new CopyResources()); @@ -123,6 +125,9 @@ public class Main { if (commandLine.hasOption("f")) { configuration.put("filter", commandLine.getOptionValue("f")); } + if (commandLine.hasOption("d")) { + configuration.put("directory", commandLine.getOptionValue("d")); + } if (commandLine.hasOption("assign-name")) { configuration.put("assign-name", commandLine.getOptionValue("assign-name")); @@ -159,6 +164,7 @@ public class Main { options.addOption("h", "help", false, "print this message"); options.addOption("f", "filter", true, "<[:]>, default namespace is osgi.identity"); options.addOption("r", "repository", true, ", default is target"); + options.addOption("d", "directory", true, "source directory for copy-directory"); options.addOption(OptionBuilder .withLongOpt("assign-name").hasArg() Added: 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=1492589&view=auto ============================================================================== --- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java (added) +++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/CopyDirectory.java Thu Jun 13 09:15:32 2013 @@ -0,0 +1,117 @@ +/* + * 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.ace.cli.command; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URI; +import java.util.Stack; + +import org.apache.ace.cli.repository.AceObrRepository; + +import aQute.bnd.deployer.repository.FixedIndexedRepo; + +/** + * Command that recursively copies resources from a local directory to a target ACE repository. + * + * + * Notes: + *
    + *
  1. Standard BND repository put is bypassed because ACE OBR needs filename for non-bundles
  2. + *
  3. This just tries an upload per file that may fail due to the fact a resource already exists.
  4. + *
  5. Locally we do not have a Repository so can not check for existence or location
  6. + *
  7. ACE OBR does not return location upon conflict so we can not delete it based on this
  8. + *
  9. Because locally we do not have a Repository we can not check for existence in the target repository.
  10. + *
+ * + * FIXME We should generate a local repository index first in order to be able to address the notes. + * + */ +public class CopyDirectory extends AbstractCommand { + + @Override + public String getName() { + return "copy-directory"; + } + + @Override + public String getDescription() { + return "copy directory recursively to the target repository (no filter support)"; + } + + @Override + public void doCommand(String command) throws Exception { + + FixedIndexedRepo targetRepo = getTargetRepository(); + if (!targetRepo.canWrite()) { + throw new IllegalArgumentException("The target repository is not writable"); + } + if (!(targetRepo instanceof AceObrRepository)) { + throw new IllegalArgumentException("The target repository is not an ACE OBR"); + } + String dirName = getConfiguration().get("directory"); + if (dirName == null) { + throw new IllegalArgumentException("Copying a directory requires valid -d"); + } + File dirFile = new File(dirName); + if (!dirFile.exists() || !dirFile.isDirectory()) { + throw new IllegalArgumentException("Copying a directory requires valid -d"); + } + + AceObrRepository aceRepo = (AceObrRepository) targetRepo; + + int copyCount = 0; + int skipCount = 0; + printVerbose("Recursively copying directory to target from " + getFilterNamespace() + ":" + getFilter()); + + Stack dirs = new Stack(); + dirs.push(dirFile); + while (!dirs.isEmpty()) { + File dir = dirs.pop(); + File[] files = dir.listFiles(); + for (File file : files) { + if (file.isDirectory()) { + 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); + System.out.println("Copied " + file.getAbsolutePath() + " => " + uri.toString()); + copyCount++; + } + catch (Exception e) { + System.out.println("Failed to upload " + file.getAbsolutePath()); + e.printStackTrace(); + } + finally { + input.close(); + } + } + } + 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=1492589&r1=1492588&r2=1492589&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 Thu Jun 13 09:15:32 2013 @@ -71,19 +71,23 @@ public class AceObrRepository extends Fi throw new IllegalArgumentException("No stream and/or options specified"); PutResult result = new PutResult(); - result.artifact = upload(m_endpoint, stream, "", options.type); + result.artifact = upload(stream, "", options.type); reset(); return result; } - private URI upload(URL aceOBR, InputStream stream, String filename, String mimetype) throws Exception { + public URL getEndpoint() { + return m_endpoint; + } + + public URI upload(InputStream stream, String filename, String mimetype) throws Exception { OutputStream output = null; String location = null; try { - URL url = new URL(aceOBR.toExternalForm() + "?filename=" + filename); + URL url = new URL(m_endpoint, "?filename=" + filename); URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); @@ -104,7 +108,7 @@ public class AceObrRepository extends Fi output.write(buffer, 0, count); size += count; if (m_verbose) - System.err.println("Uploaded bytes... " + size); + System.out.println("Uploaded bytes... " + size); } output.close();