]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/OsgiFactoryImpl.java
Deal with already existing MANIFEST
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / osgi / OsgiFactoryImpl.java
index e6b8b323e624f1e8dcfd3e9223f0c1211dd52da8..bd4f4311ce94595120145ce67dfafb8ed58d1984 100644 (file)
@@ -1,10 +1,12 @@
 package org.argeo.slc.repo.osgi;
 
+import java.io.BufferedInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -15,6 +17,7 @@ import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.jcr.JcrUtils;
@@ -58,6 +61,8 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames {
                Session javaSession = null;
                Session distSession = null;
                try {
+                       // TODO rather user a JavaRepoManager that will also implicitely
+                       // manage the indexing of newly created nodes.
                        javaSession = JcrUtils.loginOrCreateWorkspace(javaRepository,
                                        workspace);
                        distSession = JcrUtils.loginOrCreateWorkspace(distRepository,
@@ -169,7 +174,7 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames {
                                return loadUrlToPath(url, distSession, distPath);
                        } catch (FileNotFoundException e) {
                                if (log.isDebugEnabled())
-                                       log.debug("Cannot download" + url
+                                       log.debug("Cannot download " + url
                                                        + ", trying another mirror");
                        }
                }
@@ -184,11 +189,17 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames {
                        log.debug("Downloading " + url + "...");
 
                InputStream in = null;
+               URLConnection conn = null;
                Node folderNode = JcrUtils.mkfolders(distSession,
                                JcrUtils.parentPath(path));
                try {
                        URL u = new URL(url);
-                       in = u.openStream();
+                       conn = u.openConnection();
+                       conn.connect();
+                       in = new BufferedInputStream(conn.getInputStream());
+                       // byte[] arr = IOUtils.toByteArray(in);
+                       // Node fileNode = JcrUtils.copyBytesAsFile(folderNode,
+                       // JcrUtils.nodeNameFromPath(path), arr);
                        Node fileNode = JcrUtils.copyStreamAsFile(folderNode,
                                        JcrUtils.nodeNameFromPath(path), in);
                        fileNode.addMixin(SlcTypes.SLC_KNOWN_ORIGIN);
@@ -202,6 +213,8 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames {
                        throw e;
                } catch (IOException e) {
                        throw new SlcException("Cannot load " + url + " to " + path, e);
+               } finally {
+                       IOUtils.closeQuietly(in);
                }
 
        }
@@ -226,4 +239,12 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames {
                this.mirrors = mirrors;
        }
 
+       public void setMavenRepositories(List<String> mavenRepositories) {
+               this.mavenRepositories = mavenRepositories;
+       }
+
+       public void setMavenProxyBase(String mavenProxyBase) {
+               this.mavenProxyBase = mavenProxyBase;
+       }
+
 }