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;
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;
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,
return loadUrlToPath(url, distSession, distPath);
} catch (FileNotFoundException e) {
if (log.isDebugEnabled())
- log.debug("Cannot download" + url
+ log.debug("Cannot download " + url
+ ", trying another mirror");
}
}
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);
throw e;
} catch (IOException e) {
throw new SlcException("Cannot load " + url + " to " + path, e);
+ } finally {
+ IOUtils.closeQuietly(in);
}
}
this.mirrors = mirrors;
}
+ public void setMavenRepositories(List<String> mavenRepositories) {
+ this.mavenRepositories = mavenRepositories;
+ }
+
+ public void setMavenProxyBase(String mavenProxyBase) {
+ this.mavenProxyBase = mavenProxyBase;
+ }
+
}