ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1505703 - in /ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo: misc/MiscCommands.java repo/ContinuousDeployer.java repo/RepositoryUtil.java
Date Mon, 22 Jul 2013 14:55:57 GMT
Author: bramk
Date: Mon Jul 22 14:55:57 2013
New Revision: 1505703

URL: http://svn.apache.org/r1505703
Log:
ACE-366 Return actual copied resources

Modified:
    ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java
    ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/ContinuousDeployer.java
    ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepositoryUtil.java

Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java?rev=1505703&r1=1505702&r2=1505703&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java Mon Jul 22
14:55:57 2013
@@ -28,10 +28,20 @@ import org.osgi.framework.BundleExceptio
 public class MiscCommands {
 
     public final static String SCOPE = "misc";
-    public final static String[] FUNCTIONS = new String[] { "shutdown" };
+    public final static String[] FUNCTIONS = new String[] { "shutdown", "sleep" };
 
     private volatile BundleContext m_context;
 
+    @Descriptor("let the thread sleep")
+    public void sleep(long delay) {
+        try {
+            Thread.sleep(delay);
+        }
+        catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
     @Descriptor("schedules a framework shutdown")
     public void shutdown(long delay) {
         Timer timer = new Timer();

Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/ContinuousDeployer.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/ContinuousDeployer.java?rev=1505703&r1=1505702&r2=1505703&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/ContinuousDeployer.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/ContinuousDeployer.java Mon
Jul 22 14:55:57 2013
@@ -19,6 +19,7 @@ import static org.apache.ace.gogo.repo.R
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.osgi.framework.Version;
@@ -46,30 +47,29 @@ public class ContinuousDeployer {
      * @throws Exception
      */
     public List<Resource> deployResources() throws Exception {
-        List<Resource> resources = findResources(m_developmentRepo, "*", "*");
-        for (Resource resource : resources) {
-            // FIXME this is the source resource
-            deployResource(resource);
+        List<Resource> developmentResources = findResources(m_developmentRepo, "*",
"*");
+        List<Resource> deployedResources = new ArrayList<Resource>();
+        for (Resource developmentResource : developmentResources) {
+            deployedResources.add(deployResource(developmentResource));
         }
-        return resources;
+        return deployedResources;
     }
 
     /**
      * Deploys a resource to the deployment repository.
      * 
-     * @param resource
+     * @param developmentResource
      *            The resource
      * @throws Exception
      *             On failure
      */
-    private void deployResource(Resource resource) throws Exception {
-        List<Resource> releaseResources = findResources(m_releaseRepo, getIdentity(resource),
getVersion(resource).toString());
-        boolean isReleased = releaseResources.size() > 0;
-        if (isReleased) {
-            deployReleasedResource(resource);
+    private Resource deployResource(Resource developmentResource) throws Exception {
+        List<Resource> releaseResources = findResources(m_releaseRepo, getIdentityVersionRequirement(developmentResource));
+        if (releaseResources.size() > 0) {
+            return deployReleasedResource(releaseResources.get(0));
         }
         else {
-            deploySnapshotResource(resource);
+            return deploySnapshotResource(developmentResource);
         }
     }
 
@@ -77,20 +77,24 @@ public class ContinuousDeployer {
      * Deploys a released resource from the release repository to the deployment repository
if it has not been deployed
      * yet.
      * 
-     * @param resource
-     *            The resource
+     * @param releasedResource
+     *            The released resource
+     * @return The deployed resource
      * @throws Exception
-     *             On failure
      */
-    private void deployReleasedResource(Resource resource) throws Exception {
-        List<Resource> deployedResources = findResources(m_deploymentRepo, getIdentity(resource),
getVersion(resource).toString());
-        boolean isDeployed = deployedResources.size() > 0;
-        if (!isDeployed) {
-            System.out.println("Uploading released resource:  " + getString(resource));
-            copyResources(m_releaseRepo, m_deploymentRepo, getIdentityVersionRequirement(resource));
+    private Resource deployReleasedResource(Resource releasedResource) throws Exception {
+        List<Resource> deployedResources = findResources(m_deploymentRepo, getIdentityVersionRequirement(releasedResource));
+        if (deployedResources.size() == 0) {
+            System.out.println("Uploading released resource:  " + getString(releasedResource));
+            List<Resource> copied = copyResources(m_releaseRepo, m_deploymentRepo,
getIdentityVersionRequirement(releasedResource));
+            if (copied.size() != 1) {
+                throw new IllegalStateException("Exepected 1 result ofter copy");
+            }
+            return copied.get(0);
         }
         else {
-            System.out.println("Released resource allready deployed:  " + getString(resource));
+            System.out.println("Released resource allready deployed:  " + getString(releasedResource));
+            return deployedResources.get(0);
         }
     }
 
@@ -98,58 +102,61 @@ public class ContinuousDeployer {
      * Deploys a snapshot resource to the deployment repository if it differs from the highest
existing snapshot
      * resource of the same base version in the deployment repository.
      * 
-     * @param resource
-     *            The resource
+     * @param developmentResource
+     *            The development resource
+     * @return The deployed resource
      * @throws Exception
-     *             On failure
      */
-    private void deploySnapshotResource(Resource resource) throws Exception {
+    private Resource deploySnapshotResource(Resource developmentResource) throws Exception
{
+
+        Version releasedBaseVersion = getReleasedBaseVersion(developmentResource);
+        Resource snapshotResource = getHighestSnapshotResource(developmentResource, releasedBaseVersion);
 
-        Version releasedBaseVersion = getReleasedBaseVersion(resource);
-        Resource snapshotResource = getHighestSnapshotResource(resource, releasedBaseVersion);
         if (snapshotResource == null) {
-            System.out.println("Uploading initial snapshot:  " + getString(resource) + "
-> " + getNextSnapshotVersion(releasedBaseVersion));
-            deploySnapshotResource(resource, getNextSnapshotVersion(releasedBaseVersion));
+            System.out.println("Uploading initial snapshot:  " + getString(developmentResource)
+ " -> " + getNextSnapshotVersion(releasedBaseVersion));
+            return deploySnapshotResource(developmentResource, getNextSnapshotVersion(releasedBaseVersion));
         }
-        else {
-            System.out.println("Found existing snapshot:  " + getString(snapshotResource));
 
+        System.out.println("Found existing snapshot:  " + getString(snapshotResource));
+        if (getIdentity(developmentResource).equals("com.google.guava")) {
             // FIXME workaround for BND#374
-            if (getIdentity(resource).equals("com.google.guava")) {
-                System.out.println("Skipping snapshot diff on Google Guava to work around
https://github.com/bndtools/bnd/issues/374");
-                return;
-            }
-
-            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);
+            System.out.println("Skipping snapshot diff on Google Guava to work around https://github.com/bndtools/bnd/issues/374");
+            return snapshotResource;
+        }
 
-            boolean snapshotModified = false;
+        File developmentFile = m_developmentRepo.get(getIdentity(developmentResource), getVersion(developmentResource).toString(),
Strategy.EXACT, null);
+        File deployedFile = m_deploymentRepo.get(getIdentity(snapshotResource), getVersion(snapshotResource).toString(),
Strategy.EXACT, null);
 
-            if (getType(resource).equals("osgi.bundle")) {
+        boolean snapshotModified = false;
+        if (getType(developmentResource).equals("osgi.bundle")) {
 
-                // Get a copy of the dep resource with the same version as the dev resource
so we can diff diff.
-                File comparableDeployedResource = getBundleWithNewVersion(deployedResource,
getVersion(resource).toString());
+            // Get a copy of the dep resource with the same version as the dev resource so
we can diff diff.
+            File comparableDeployedResource = getBundleWithNewVersion(deployedFile, getVersion(developmentResource).toString());
 
-                // This may seem strange but the value in the dev resource manifest may be
"0" which will not match
-                // "0.0.0" during diff.
-                File comparableDevelopmentResource = getBundleWithNewVersion(developmentResource,
getVersion(resource).toString());
-                snapshotModified = jarsDiffer(comparableDeployedResource, comparableDevelopmentResource);
-            }
-            else {
-                snapshotModified = filesDiffer(developmentResource, deployedResource);
-            }
+            // This may seem strange but the value in the dev resource manifest may be "0"
which will not match
+            // "0.0.0" during diff.
+            File comparableDevelopmentResource = getBundleWithNewVersion(developmentFile,
getVersion(developmentResource).toString());
+            snapshotModified = jarsDiffer(comparableDeployedResource, comparableDevelopmentResource);
+        }
+        else {
+            snapshotModified = filesDiffer(developmentFile, deployedFile);
+        }
 
-            if (snapshotModified) {
-                System.out.println("Uploading new snapshot:  " + getString(resource) + "
-> " + getNextSnapshotVersion(getVersion(snapshotResource)));
-                deploySnapshotResource(resource, getNextSnapshotVersion(getVersion(snapshotResource)));
-            }
-            else {
-                System.out.println("Ignoring new snapshot:  " + getString(resource));
+        if (snapshotModified) {
+            System.out.println("Uploading new snapshot:  " + getString(developmentResource)
+ " -> " + getNextSnapshotVersion(getVersion(snapshotResource)));
+            return deploySnapshotResource(developmentResource, getNextSnapshotVersion(getVersion(snapshotResource)));
+        }
+        else {
+            System.out.println("Ignoring new snapshot:  " + getString(developmentResource));
+            List<Resource> resultResources = findResources(m_deploymentRepo, getIdentityVersionRequirement(snapshotResource));
+            if (resultResources == null || resultResources.size() == 0) {
+                throw new IllegalStateException("Can not find target resource after put:
" + developmentResource);
             }
+            return resultResources.get(0);
         }
     }
 
-    private void deploySnapshotResource(Resource resource, Version snapshotVersion) throws
Exception {
+    private Resource deploySnapshotResource(Resource resource, Version snapshotVersion) throws
Exception {
 
         File file = m_developmentRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
         if (getType(resource).equals("osgi.bundle")) {
@@ -167,6 +174,13 @@ public class ContinuousDeployer {
             else {
                 m_deploymentRepo.put(input, null);
             }
+            m_deploymentRepo.reset();
+
+            List<Resource> resultResources = findResources(m_deploymentRepo, getIdentity(resource),
snapshotVersion.toString());
+            if (resultResources == null || resultResources.size() == 0) {
+                throw new IllegalStateException("Can not find target resource after put:
" + resource);
+            }
+            return resultResources.get(0);
 
         }
         finally {

Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepositoryUtil.java?rev=1505703&r1=1505702&r2=1505703&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepositoryUtil.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepositoryUtil.java Mon Jul
22 14:55:57 2013
@@ -185,57 +185,66 @@ public class RepositoryUtil {
         return requirement;
     }
 
-    public static List<Resource> copyResources(AbstractIndexedRepo fromRepo, AbstractIndexedRepo
toRepo, String bsn) throws Exception {
-        return copyResources(fromRepo, toRepo, bsn, "*");
+    public static List<Resource> copyResources(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, String bsn) throws Exception {
+        return copyResources(sourceRepo, targetRepo, bsn, "*");
     }
 
-    public static List<Resource> copyResources(AbstractIndexedRepo fromRepo, AbstractIndexedRepo
toRepo, String bsn, String version) throws Exception {
-        return copyResources(fromRepo, toRepo, bsn, version, "*");
+    public static List<Resource> copyResources(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, String bsn, String version) throws Exception {
+        return copyResources(sourceRepo, targetRepo, bsn, version, "*");
     }
 
-    public static List<Resource> copyResources(AbstractIndexedRepo fromRepo, AbstractIndexedRepo
toRepo, String bsn, String version, String type) throws Exception {
+    public static List<Resource> copyResources(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, String bsn, String version, String type) throws Exception {
         Requirement requirement = new CapReqBuilder("osgi.identity")
             .addDirective("filter", String.format("(&(osgi.identity=%s)(version=%s)(type=%s))",
bsn, version, type))
             .buildSyntheticRequirement();
-        return copyResources(fromRepo, toRepo, requirement);
+        return copyResources(sourceRepo, targetRepo, requirement);
     }
 
-    public static List<Resource> copyResources(AbstractIndexedRepo fromRepo, AbstractIndexedRepo
toRepo, Requirement requirement) throws Exception {
-        List<Resource> resources = findResources(fromRepo, requirement);
-        for (Resource resource : resources) {
-            File file = fromRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
+    public static List<Resource> copyResources(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, Requirement requirement) throws Exception {
+
+        List<Resource> sourceResources = findResources(sourceRepo, requirement);
+        List<Resource> targetResources = new ArrayList<Resource>();
 
+        for (Resource resource : sourceResources) {
+            File file = sourceRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
             InputStream input = null;
             try {
                 input = new FileInputStream(file);
-                if (toRepo instanceof AceObrRepository) {
+                if (targetRepo instanceof AceObrRepository) {
                     // ACE OBR can handle non bundle resource if we pass a filename
-                    AceObrRepository aceToRepo = (AceObrRepository) toRepo;
+                    AceObrRepository aceToRepo = (AceObrRepository) targetRepo;
                     aceToRepo.upload(input, getFileName(resource), getMimetype(resource));
                 }
                 else {
-                    toRepo.put(input, null);
+                    targetRepo.put(input, null);
                 }
+                targetRepo.reset();
+
+                List<Resource> copied = findResources(targetRepo, getIdentityVersionRequirement(resource));
+                if (copied.size() != 1) {
+                    throw new IllegalStateException("expected one match");
+                }
+                targetResources.addAll(copied);
             }
             finally {
                 if (input != null)
                     input.close();
             }
         }
-        return resources;
+        return targetResources;
     }
 
-    public static void uploadResource(AbstractIndexedRepo toRepo, URL location, String filename)
throws Exception {
+    public static void uploadResource(AbstractIndexedRepo targetRepo, URL location, String
filename) throws Exception {
         InputStream input = null;
         try {
             input = location.openStream();
-            if (toRepo instanceof AceObrRepository) {
+            if (targetRepo instanceof AceObrRepository) {
                 // ACE OBR can handle non bundle resource if we pass a filename
-                AceObrRepository aceToRepo = (AceObrRepository) toRepo;
+                AceObrRepository aceToRepo = (AceObrRepository) targetRepo;
                 aceToRepo.upload(input, filename, null);
             }
             else {
-                toRepo.put(input, null);
+                targetRepo.put(input, null);
             }
         }
         finally {
@@ -244,33 +253,33 @@ public class RepositoryUtil {
         }
     }
 
-    public static List<Resource> copyResources(AbstractIndexedRepo fromRepo, AbstractIndexedRepo
toRepo, List<Resource> resources) throws Exception {
+    public static List<Resource> copyResources(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, List<Resource> resources) throws Exception {
         List<Resource> targetResources = new LinkedList<Resource>();
         for (Resource resource : resources) {
-            Resource targetResource = copyResource(fromRepo, toRepo, resource);
+            Resource targetResource = copyResource(sourceRepo, targetRepo, resource);
             targetResources.add(targetResource);
         }
         return targetResources;
     }
 
-    public static Resource copyResource(AbstractIndexedRepo fromRepo, AbstractIndexedRepo
toRepo, Resource resource) throws Exception {
+    public static Resource copyResource(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, Resource resource) throws Exception {
 
-        File file = fromRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
+        File file = sourceRepo.get(getIdentity(resource), getVersion(resource).toString(),
Strategy.EXACT, null);
         InputStream input = null;
         try {
             input = new FileInputStream(file);
-            if (toRepo instanceof AceObrRepository) {
+            if (targetRepo instanceof AceObrRepository) {
                 // ACE OBR can handle non bundle resource if we pass a filename
-                AceObrRepository aceToRepo = (AceObrRepository) toRepo;
+                AceObrRepository aceToRepo = (AceObrRepository) targetRepo;
                 aceToRepo.upload(input, getFileName(resource), getMimetype(resource));
             }
             else {
-                toRepo.put(input, null);
+                targetRepo.put(input, null);
             }
 
-            List<Resource> resultResources = findResources(toRepo, getIdentity(resource),
getVersion(resource).toString());
+            List<Resource> resultResources = findResources(targetRepo, getIdentity(resource),
getVersion(resource).toString());
             if (resultResources == null || resultResources.size() == 0) {
-                throw new IllegalStateException("Can not find target resource after put:
" + resource);
+                throw new IllegalStateException("Unable to locate target resource after copy:
" + resource);
             }
             return resultResources.get(0);
         }
@@ -355,7 +364,19 @@ public class RepositoryUtil {
         Map<String, Object> attrs = getNamespaceAttributes(resource, "osgi.content");
         if (attrs == null)
             return null;
-        return (String) attrs.get("mime");
+
+        String mime = (String) attrs.get("mime");
+        if (mime == null) {
+            // FIXME this is a work around for OBR not supporting mimetype
+            String url = getUrl(resource);
+            if (url.endsWith(".jar")) {
+                mime = "application/vnd.osgi.bundle";
+            }
+            else if (url.endsWith(".xml")) {
+                mime = "application/xml:osgi-autoconf";
+            }
+        }
+        return mime;
     }
 
     public static String getSHA(Resource resource) {



Mime
View raw message