ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1509243 - in /ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo: RepoCommands.java RepositoryUtil.java
Date Thu, 01 Aug 2013 14:17:30 GMT
Author: bramk
Date: Thu Aug  1 14:17:30 2013
New Revision: 1509243

URL: http://svn.apache.org/r1509243
Log:
ACE-366 Do not copy resources that exist in target repo

Modified:
    ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepoCommands.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/repo/RepoCommands.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepoCommands.java?rev=1509243&r1=1509242&r2=1509243&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepoCommands.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/repo/RepoCommands.java Thu Aug 
1 14:17:30 2013
@@ -19,9 +19,11 @@
 package org.apache.ace.gogo.repo;
 
 import static org.apache.ace.gogo.repo.RepositoryUtil.copyResources;
+import static org.apache.ace.gogo.repo.RepositoryUtil.copyResource;
 import static org.apache.ace.gogo.repo.RepositoryUtil.createRepository;
 import static org.apache.ace.gogo.repo.RepositoryUtil.deleteResource;
 import static org.apache.ace.gogo.repo.RepositoryUtil.findResources;
+import static org.apache.ace.gogo.repo.RepositoryUtil.getIdentityVersionRequirement;
 import static org.apache.ace.gogo.repo.RepositoryUtil.getRequirement;
 import static org.apache.ace.gogo.repo.RepositoryUtil.getUrl;
 import static org.apache.ace.gogo.repo.RepositoryUtil.indexDirectory;
@@ -86,7 +88,17 @@ public class RepoCommands {
 
         Requirement requirement = getRequirement(filter);
         List<Resource> resources = findResources(sourceRepo, requirement);
-        copyResources(sourceRepo, targetRepo, resources);
+
+        for (Resource resource : resources) {
+            List<Resource> existingResources = findResources(targetRepo, getIdentityVersionRequirement(resource));
+            if (existingResources.size() == 0) {
+                Resource copied = copyResource(sourceRepo, targetRepo, resource);
+                System.out.println("copied: " + copied);
+            }
+            else {
+                System.out.println("skipped: " + existingResources.get(0));
+            }
+        }
     }
 
     @Descriptor("remove resources from a repository")

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=1509243&r1=1509242&r2=1509243&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 Thu Aug
 1 14:17:30 2013
@@ -201,58 +201,14 @@ public class RepositoryUtil {
     }
 
     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 (targetRepo instanceof AceObrRepository) {
-                    // ACE OBR can handle non bundle resource if we pass a filename
-                    AceObrRepository aceToRepo = (AceObrRepository) targetRepo;
-                    aceToRepo.upload(input, getFileName(resource), getMimetype(resource));
-                }
-                else {
-                    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();
-            }
+            targetResources.add(copyResource(sourceRepo, targetRepo, resource));
         }
         return targetResources;
     }
 
-    public static void uploadResource(AbstractIndexedRepo targetRepo, URL location, String
filename) throws Exception {
-        InputStream input = null;
-        try {
-            input = location.openStream();
-            if (targetRepo instanceof AceObrRepository) {
-                // ACE OBR can handle non bundle resource if we pass a filename
-                AceObrRepository aceToRepo = (AceObrRepository) targetRepo;
-                aceToRepo.upload(input, filename, null);
-            }
-            else {
-                targetRepo.put(input, null);
-            }
-        }
-        finally {
-            if (input != null)
-                input.close();
-        }
-    }
-
     public static List<Resource> copyResources(AbstractIndexedRepo sourceRepo, AbstractIndexedRepo
targetRepo, List<Resource> resources) throws Exception {
         List<Resource> targetResources = new LinkedList<Resource>();
         for (Resource resource : resources) {
@@ -276,6 +232,7 @@ public class RepositoryUtil {
             else {
                 targetRepo.put(input, null);
             }
+            targetRepo.reset();
 
             List<Resource> resultResources = findResources(targetRepo, getIdentity(resource),
getVersion(resource).toString());
             if (resultResources == null || resultResources.size() == 0) {
@@ -289,6 +246,25 @@ public class RepositoryUtil {
         }
     }
 
+    public static void uploadResource(AbstractIndexedRepo targetRepo, URL location, String
filename) throws Exception {
+        InputStream input = null;
+        try {
+            input = location.openStream();
+            if (targetRepo instanceof AceObrRepository) {
+                // ACE OBR can handle non bundle resource if we pass a filename
+                AceObrRepository aceToRepo = (AceObrRepository) targetRepo;
+                aceToRepo.upload(input, filename, null);
+            }
+            else {
+                targetRepo.put(input, null);
+            }
+        }
+        finally {
+            if (input != null)
+                input.close();
+        }
+    }
+
     public static List<Resource> findResources(Repository repository) {
         return findResources(repository, "*");
     }



Mime
View raw message