1 package org
.argeo
.slc
.repo
.osgi
;
3 import java
.io
.ByteArrayInputStream
;
5 import java
.util
.ArrayList
;
7 import java
.util
.jar
.JarInputStream
;
8 import java
.util
.jar
.Manifest
;
9 import java
.util
.zip
.ZipEntry
;
10 import java
.util
.zip
.ZipInputStream
;
12 import javax
.jcr
.Node
;
13 import javax
.jcr
.Repository
;
14 import javax
.jcr
.Session
;
16 import org
.apache
.commons
.io
.IOUtils
;
17 import org
.argeo
.api
.cms
.CmsLog
;
18 import org
.argeo
.jcr
.JcrUtils
;
19 import org
.argeo
.slc
.NameVersion
;
20 import org
.argeo
.slc
.SlcException
;
21 import org
.argeo
.slc
.repo
.ArtifactIndexer
;
22 import org
.argeo
.slc
.repo
.JarFileIndexer
;
23 import org
.argeo
.slc
.repo
.RepoUtils
;
24 import org
.eclipse
.aether
.artifact
.Artifact
;
25 import org
.eclipse
.aether
.artifact
.DefaultArtifact
;
28 * Import all bundles in a zip file (typically an Eclipse distribution) into the
31 * @deprecated Use {@link ArchiveWrapper} instead.
34 public class ImportBundlesZip
implements Runnable
{
35 private final static CmsLog log
= CmsLog
.getLog(ImportBundlesZip
.class);
36 private Repository repository
;
37 private String workspace
;
38 private String groupId
;
39 private String artifactBasePath
= "/";
41 private ArtifactIndexer artifactIndexer
= new ArtifactIndexer();
42 private JarFileIndexer jarFileIndexer
= new JarFileIndexer();
44 private String zipFile
;
46 private List
<String
> excludedBundles
= new ArrayList
<String
>();
49 ZipInputStream zipIn
= null;
50 JarInputStream jarIn
= null;
51 Session session
= null;
53 URL url
= new URL(zipFile
);
54 session
= repository
.login(workspace
);
57 // String groupPath = MavenConventionsUtils.groupPath(
58 // artifactBasePath, groupId);
59 // if (session.itemExists(groupPath)) {
60 // session.getNode(groupPath).remove();
62 // if (log.isDebugEnabled())
63 // log.debug("Cleared " + groupPath);
66 zipIn
= new ZipInputStream(url
.openStream());
67 ZipEntry zipEntry
= null;
68 entries
: while ((zipEntry
= zipIn
.getNextEntry()) != null) {
69 String entryName
= zipEntry
.getName();
70 if (!entryName
.endsWith(".jar") || entryName
.contains("feature"))
71 continue entries
;// skip
72 byte[] jarBytes
= IOUtils
.toByteArray(zipIn
);
74 jarIn
= new JarInputStream(new ByteArrayInputStream(jarBytes
));
75 Manifest manifest
= jarIn
.getManifest();
76 IOUtils
.closeQuietly(jarIn
);
77 if (manifest
== null) {
78 log
.warn(entryName
+ " has no MANIFEST");
83 nv
= RepoUtils
.readNameVersion(manifest
);
84 } catch (Exception e
) {
85 log
.warn("Cannot read name version from " + entryName
, e
);
89 String bundleName
= RepoUtils
.extractBundleNameFromSourceName(nv
.getName());
90 // skip excluded bundles and their sources
91 if (excludedBundles
.contains(bundleName
))
93 // for(String excludedBundle:excludedBundles){
94 // if(bundleName.contains(excludedBundle))
98 Artifact artifact
= new DefaultArtifact(groupId
, nv
.getName(), "jar", nv
.getVersion());
99 Node artifactNode
= RepoUtils
.copyBytesAsArtifact(session
.getNode(artifactBasePath
), artifact
,
101 jarBytes
= null;// superstition, in order to free memory
104 artifactIndexer
.index(artifactNode
);
105 jarFileIndexer
.index(artifactNode
);
107 if (log
.isDebugEnabled())
108 log
.debug("Imported " + entryName
+ " to " + artifactNode
);
110 } catch (Exception e
) {
111 throw new SlcException("Cannot import zip " + zipFile
+ " to " + workspace
, e
);
113 IOUtils
.closeQuietly(zipIn
);
114 IOUtils
.closeQuietly(jarIn
);
115 JcrUtils
.logoutQuietly(session
);
120 public void setRepository(Repository repository
) {
121 this.repository
= repository
;
124 public void setWorkspace(String workspace
) {
125 this.workspace
= workspace
;
128 public void setGroupId(String groupId
) {
129 this.groupId
= groupId
;
132 public void setArtifactBasePath(String artifactBasePath
) {
133 this.artifactBasePath
= artifactBasePath
;
136 public void setZipFile(String zipFile
) {
137 this.zipFile
= zipFile
;
140 public void setExcludedBundles(List
<String
> excludedBundles
) {
141 this.excludedBundles
= excludedBundles
;