X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2FRepoUtils.java;h=4a175ac594ce641569e269bd37c6c201d753e5a3;hb=399702cec859f48ec171c30d268c55eb632d472a;hp=fa4fa0c70cfb03a0424a0c0565c7c541c7339533;hpb=7ac8a536076af44569a23d9d67bb443cdc06018b;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java index fa4fa0c70..4a175ac59 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java @@ -32,6 +32,7 @@ import java.util.jar.JarFile; import java.util.jar.JarInputStream; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; +import java.util.zip.ZipInputStream; import javax.jcr.Credentials; import javax.jcr.GuestCredentials; @@ -199,16 +200,20 @@ public class RepoUtils implements ArgeoNames, SlcNames { jarOut = new JarOutputStream(out, manifest); JarEntry jarEntry = null; while ((jarEntry = jarIn.getNextJarEntry()) != null) { - jarOut.putNextEntry(jarEntry); - IOUtils.copy(jarIn, jarOut); - jarIn.closeEntry(); - jarOut.closeEntry(); + if (!jarEntry.getName().equals("META-INF/MANIFEST.MF")) { + JarEntry newJarEntry = new JarEntry(jarEntry.getName()); + jarOut.putNextEntry(newJarEntry); + IOUtils.copy(jarIn, jarOut); + jarIn.closeEntry(); + jarOut.closeEntry(); + } } } catch (IOException e) { throw new SlcException("Could not copy jar with MANIFEST " + manifest.getMainAttributes(), e); } finally { - IOUtils.closeQuietly(jarIn); + if (!(in instanceof ZipInputStream)) + IOUtils.closeQuietly(jarIn); IOUtils.closeQuietly(jarOut); } } @@ -311,6 +316,10 @@ public class RepoUtils implements ArgeoNames, SlcNames { .getProperty(SLC_ARTIFACT_CLASSIFIER).getString(), node.getProperty(SLC_ARTIFACT_EXTENSION).getString(), node .getProperty(SLC_ARTIFACT_VERSION).getString()); + } else if (node.isNodeType(SlcTypes.SLC_MODULE_COORDINATES)) { + return new DefaultArtifact(node.getProperty(SLC_CATEGORY) + .getString(), node.getProperty(SLC_NAME).getString(), + "jar", node.getProperty(SLC_VERSION).getString()); } else { throw new SlcException("Unsupported node type for " + node); } @@ -420,14 +429,13 @@ public class RepoUtils implements ArgeoNames, SlcNames { /** * Shortcut to retrieve a session given variable information: Handle the * case where we only have an URI of the repository, that we want to connect - * as anonymous or the case of a identified connexion to a local or remote + * as anonymous or the case of a identified connection to a local or remote * repository. * * Callers must close the session once it has been used */ - public static Session getCorrespondingSession( - RepositoryFactory repositoryFactory, Keyring keyring, - Node repoNode, String uri, String workspaceName) { + public static Session getRemoteSession(RepositoryFactory repositoryFactory, + Keyring keyring, Node repoNode, String uri, String workspaceName) { try { if (repoNode == null && uri == null) throw new SlcException( @@ -453,9 +461,38 @@ public class RepoUtils implements ArgeoNames, SlcNames { } } + /** + * Shortcut to retrieve a session on a remote Jrc Repository from + * information stored in a local argeo node or from an URI: Handle the case + * where we only have an URI of the repository, that we want to connect as + * anonymous or the case of a identified connection to a local or remote + * repository. + * + * Callers must close the session once it has been used + */ + public static Session getRemoteSession(RepositoryFactory repositoryFactory, + Keyring keyring, Repository localRepository, String repoNodePath, + String uri, String workspaceName) { + Session localSession = null; + Node repoNode = null; + try { + localSession = localRepository.login(); + if (repoNodePath != null && localSession.nodeExists(repoNodePath)) + repoNode = localSession.getNode(repoNodePath); + + return RepoUtils.getRemoteSession(repositoryFactory, keyring, + repoNode, uri, workspaceName); + } catch (RepositoryException e) { + throw new SlcException("Cannot log to workspace " + workspaceName + + " for repo defined in " + repoNodePath, e); + } finally { + JcrUtils.logoutQuietly(localSession); + } + } + /** * Write group indexes: 'binaries' lists all bundles and their versions, - * 'sources' list theire sources, and 'sdk' aggregates both. + * 'sources' list their sources, and 'sdk' aggregates both. */ public static void writeGroupIndexes(Session session, String artifactBasePath, String groupId, String version,