ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1496386 - in /ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli: Main.java command/AbstractCommand.java command/DeployResources.java deployment/ContinuousDeployer.java deployment/DeployerUtil.java
Date Tue, 25 Jun 2013 09:03:37 GMT
Author: bramk
Date: Tue Jun 25 09:03:37 2013
New Revision: 1496386

URL: http://svn.apache.org/r1496386
Log:
[sandbox] Added deploy commands and support for non-bundles

Added:
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/DeployResources.java
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/command/AbstractCommand.java
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/ContinuousDeployer.java
    ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/DeployerUtil.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=1496386&r1=1496385&r2=1496386&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 Tue Jun 25 09:03:37
2013
@@ -40,6 +40,7 @@ import org.apache.ace.cli.command.Create
 import org.apache.ace.cli.command.CreateTarget;
 import org.apache.ace.cli.command.DeleteArtifacts;
 import org.apache.ace.cli.command.DeleteResources;
+import org.apache.ace.cli.command.DeployResources;
 import org.apache.ace.cli.command.ListArtifacts;
 import org.apache.ace.cli.command.ListDistributions;
 import org.apache.ace.cli.command.ListFeatures;
@@ -78,6 +79,7 @@ public class Main {
         COMMANDS.add(new ListFeatures());
         COMMANDS.add(new ListDistributions());
         COMMANDS.add(new ListTargets());
+        COMMANDS.add(new DeployResources());
     }
 
     public static void main(String[] args) throws Exception {
@@ -210,7 +212,7 @@ public class Main {
 
     private static Map<String, FixedIndexedRepo> loadRepositories(Properties properties,
File workdir) throws InstantiationException, IllegalAccessException, ClassNotFoundException
{
         Map<String, FixedIndexedRepo> repositories = new HashMap<String, FixedIndexedRepo>();
-        for (String repositoryName : new String[] { "source", "target" }) {
+        for (String repositoryName : new String[] { "source", "target", "release" }) {
 
             Map<String, String> repositoryProps = new HashMap<String, String>();
             for (Entry<Object, Object> entry : properties.entrySet()) {
@@ -220,7 +222,14 @@ public class Main {
                     repositoryProps.put(key.replaceFirst(repositoryName + ".", ""), value);
                 }
             }
+            
             String repoClass = repositoryProps.get("class");
+            if(repoClass == null){
+                System.out.println("No definition found for repository: " + repositoryName);
+                continue;
+            } else {
+                System.out.println("Initializing repository: " + repositoryName);       
        
+            }
             FixedIndexedRepo repository = (FixedIndexedRepo) Main.class.getClassLoader().loadClass(repoClass).newInstance();
             repository.setProperties(repositoryProps);
 

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=1496386&r1=1496385&r2=1496386&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
Tue Jun 25 09:03:37 2013
@@ -76,6 +76,10 @@ public abstract class AbstractCommand {
         return m_repositories.get("target");
     }
 
+    protected FixedIndexedRepo getReleaseRepository() {
+        return m_repositories.get("release");
+    }
+
     protected List<Resource> findResources(Repository repository, String bsn, String
version, String type) {
         Requirement requirement = new CapReqBuilder("osgi.identity")
             .addDirective("filter", String.format("(&(osgi.identity=%s)(version=%s)(type=*))",
bsn, version, type))

Added: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/DeployResources.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/DeployResources.java?rev=1496386&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/DeployResources.java
(added)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/command/DeployResources.java
Tue Jun 25 09:03:37 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.util.List;
+
+import org.apache.ace.cli.deployment.ContinuousDeployer;
+import org.osgi.resource.Resource;
+
+import aQute.bnd.deployer.repository.FixedIndexedRepo;
+
+/**
+ * Command that copies resources from the source repository to the target repository.
+ * 
+ */
+public class DeployResources extends AbstractCommand {
+
+    @Override
+    public String getName() {
+        return "deploy-resources";
+    }
+
+    @Override
+    public String getDescription() {
+        return "copy resource from source repository using cd heuristics";
+    }
+
+    @Override
+    public void doCommand(String command) throws Exception {
+
+        FixedIndexedRepo releaseRepo = getReleaseRepository();
+        FixedIndexedRepo sourceRepo = getSourceRepository();
+        FixedIndexedRepo targetRepo = getTargetRepository();
+        if (!targetRepo.canWrite()) {
+            throw new IllegalArgumentException("The target repository is not writable");
+        }
+
+        ContinuousDeployer cd = new ContinuousDeployer(targetRepo, sourceRepo, releaseRepo);
+
+        try {
+            List<Resource> deployed = cd.deployResources();
+            printVerbose("Deployed " + deployed.size() + " artifacts");
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+}

Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/ContinuousDeployer.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/ContinuousDeployer.java?rev=1496386&r1=1496385&r2=1496386&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/ContinuousDeployer.java
(original)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/ContinuousDeployer.java
Tue Jun 25 09:03:37 2013
@@ -2,11 +2,14 @@ package org.apache.ace.cli.deployment;
 
 import static org.apache.ace.cli.deployment.DeployerUtil.copyResources;
 import static org.apache.ace.cli.deployment.DeployerUtil.findResources;
+import static org.apache.ace.cli.deployment.DeployerUtil.getFileName;
 import static org.apache.ace.cli.deployment.DeployerUtil.getIdentity;
 import static org.apache.ace.cli.deployment.DeployerUtil.getIdentityVersionRequirement;
-import static org.apache.ace.cli.deployment.DeployerUtil.getJarWithNewVersion;
+import static org.apache.ace.cli.deployment.DeployerUtil.getBundleWithNewVersion;
+import static org.apache.ace.cli.deployment.DeployerUtil.getMimetype;
 import static org.apache.ace.cli.deployment.DeployerUtil.getNextSnapshotVersion;
 import static org.apache.ace.cli.deployment.DeployerUtil.getString;
+import static org.apache.ace.cli.deployment.DeployerUtil.getType;
 import static org.apache.ace.cli.deployment.DeployerUtil.getVersion;
 import static org.apache.ace.cli.deployment.DeployerUtil.isSameBaseVersion;
 import static org.apache.ace.cli.deployment.DeployerUtil.isSnapshotVersion;
@@ -17,6 +20,7 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.List;
 
+import org.apache.ace.cli.repository.AceObrRepository;
 import org.osgi.framework.Version;
 import org.osgi.resource.Resource;
 
@@ -81,11 +85,11 @@ public class ContinuousDeployer {
         List<Resource> deployedResources = findResources(m_deploymentRepo, getIdentity(resource),
getVersion(resource).toString());
         boolean isDeployed = deployedResources.size() > 0;
         if (!isDeployed) {
-            System.out.println("Uploading release:  " + getString(resource));
+            System.out.println("Uploading released resource:  " + getString(resource));
             copyResources(m_releaseRepo, m_deploymentRepo, getIdentityVersionRequirement(resource));
         }
         else {
-            System.out.println("Ignoring release:  " + getString(resource));
+            System.out.println("Released resource allready deployed:  " + getString(resource));
         }
     }
 
@@ -103,7 +107,7 @@ public class ContinuousDeployer {
         Version releasedBaseVersion = getReleasedBaseVersion(resource);
         Resource snapshotResource = getHighestSnapshotResource(resource, releasedBaseVersion);
         if (snapshotResource == null) {
-            System.out.println("Uploading initial snapshot:  " + getNextSnapshotVersion(releasedBaseVersion));
+            System.out.println("Uploading initial snapshot:  " + getString(resource) + "
-> " + getNextSnapshotVersion(releasedBaseVersion));
             deploySnapshotResource(resource, getNextSnapshotVersion(releasedBaseVersion));
         }
         else {
@@ -111,10 +115,10 @@ public class ContinuousDeployer {
 
             File developmentResource = m_developmentRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
             File deployedResource = m_deploymentRepo.get(getIdentity(snapshotResource), getVersion(snapshotResource).toString(),
Strategy.EXACT, null);
-            File comparableDeployedResource = getJarWithNewVersion(deployedResource, getVersion(resource).toString());
+            File comparableDeployedResource = getBundleWithNewVersion(deployedResource, getVersion(resource).toString());
 
             if (jarsDiffer(comparableDeployedResource, developmentResource)) {
-                System.out.println("Uploading new snapshot:  " + getNextSnapshotVersion(getVersion(snapshotResource)));
+                System.out.println("Uploading new snapshot:  " + getString(resource) + "
-> " + getNextSnapshotVersion(getVersion(snapshotResource)));
                 deploySnapshotResource(resource, getNextSnapshotVersion(getVersion(snapshotResource)));
             }
             else {
@@ -126,11 +130,22 @@ public class ContinuousDeployer {
     private void deploySnapshotResource(Resource resource, Version snapshotVersion) throws
Exception {
 
         File file = m_developmentRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
-        File snapshotVersionedJar = getJarWithNewVersion(file, snapshotVersion.toString());
+        if (getType(resource).equals("osgi.bundle")) {
+            file = getBundleWithNewVersion(file, snapshotVersion.toString());
+        }
+
         InputStream input = null;
         try {
-            input = new FileInputStream(snapshotVersionedJar);
-            m_deploymentRepo.put(input, null);
+            input = new FileInputStream(file);
+            if (m_deploymentRepo instanceof AceObrRepository) {
+                // ACE OBR can handle non-bundle resources if we pass a correct filename
+                AceObrRepository aceToRepo = (AceObrRepository) m_deploymentRepo;
+                aceToRepo.upload(input, getFileName(resource, snapshotVersion), getMimetype(resource));
+            }
+            else {
+                m_deploymentRepo.put(input, null);
+            }
+
         }
         finally {
             if (input != null)

Modified: ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/DeployerUtil.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/DeployerUtil.java?rev=1496386&r1=1496385&r2=1496386&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/DeployerUtil.java
(original)
+++ ace/sandbox/bramk/org.apache.ace.cli/src/org/apache/ace/cli/deployment/DeployerUtil.java
Tue Jun 25 09:03:37 2013
@@ -21,6 +21,7 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
+import org.apache.ace.cli.repository.AceObrRepository;
 import org.osgi.framework.Version;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
@@ -44,6 +45,32 @@ public final class DeployerUtil {
     private static final Pattern QUALIFIER_PATTERN = Pattern.compile(QUALIFIER_PREFIX + "([\\d]{3})$|(.*)(_"
+ QUALIFIER_PREFIX + "([\\d]{3})?$)");
 
     /**
+     * Construct a Resource filename with a specified version in the form that ACE OBR understands.
+     * 
+     * @param resource
+     *            The resource
+     * @param version
+     *            The version
+     * @return The name
+     */
+    public static String getFileName(Resource resource, Version version) {
+        String location = getUrl(resource);
+        String extension = location.substring(location.lastIndexOf(".") + 1);
+        return getIdentity(resource) + "-" + version + "." + extension;
+    }
+
+    /**
+     * Construct a Resource filename in the form that ACE OBR understands.
+     * 
+     * @param resource
+     *            The resource
+     * @return The name
+     */
+    public static String getFileName(Resource resource) {
+        return getFileName(resource, getVersion(resource));
+    }
+
+    /**
      * Given ad version, creates the 'next' snapshot version. If the version has no snapshot
qualifier a new one will be
      * added. If it does, it will be incremented.
      * 
@@ -105,7 +132,7 @@ public final class DeployerUtil {
     }
 
     /**
-     * Clones a jar file while replacing the Bundle-Version in the manifest with the specified
value.
+     * Clones a bundle file while replacing the Bundle-Version in the manifest with the specified
value.
      * 
      * @param sourceJar
      *            The existing jar
@@ -115,7 +142,7 @@ public final class DeployerUtil {
      * @throws IOException
      *             On failure
      */
-    public static File getJarWithNewVersion(File sourceJar, String version) throws IOException
{
+    public static File getBundleWithNewVersion(File sourceJar, String version) throws IOException
{
 
         File targetFile = File.createTempFile("bundle", ".jar");
         byte[] buf = new byte[1024];
@@ -128,7 +155,8 @@ public final class DeployerUtil {
             out.putNextEntry(new ZipEntry(name));
 
             if (name.equals("META-INF/MANIFEST.MF")) {
-                ByteBuffer bb = ByteBuffer.allocate(10 * 1024);
+                // FIXME quick abort
+                ByteBuffer bb = ByteBuffer.allocate(100 * 1024);
                 int len;
                 while ((len = zin.read(buf)) > 0) {
                     bb.put(buf, 0, len);
@@ -196,10 +224,18 @@ public final class DeployerUtil {
         List<Resource> resources = findResources(fromRepo, requirement);
         for (Resource resource : resources) {
             File file = fromRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
+
             InputStream input = null;
             try {
                 input = new FileInputStream(file);
-                toRepo.put(input, null);
+                if (toRepo instanceof AceObrRepository) {
+                    // ACE OBR can handle non bundle resource if we pass a filename
+                    AceObrRepository aceToRepo = (AceObrRepository) toRepo;
+                    aceToRepo.upload(input, getFileName(resource), getMimetype(resource));
+                }
+                else {
+                    toRepo.put(input, null);
+                }
             }
             finally {
                 if (input != null)



Mime
View raw message