]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArchiveSourcesProvider.java
1 package org
.argeo
.slc
.repo
.osgi
;
5 import java
.util
.TreeSet
;
6 import java
.util
.jar
.JarEntry
;
7 import java
.util
.zip
.ZipEntry
;
8 import java
.util
.zip
.ZipInputStream
;
9 import java
.util
.zip
.ZipOutputStream
;
11 import javax
.jcr
.Node
;
12 import javax
.jcr
.Property
;
13 import javax
.jcr
.Session
;
15 import org
.apache
.commons
.io
.FilenameUtils
;
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
.SlcException
;
20 import org
.argeo
.slc
.repo
.OsgiFactory
;
22 public class ArchiveSourcesProvider
implements SourcesProvider
{
23 private final static CmsLog log
= CmsLog
.getLog(ArchiveSourcesProvider
.class);
25 private OsgiFactory osgiFactory
;
27 private String base
= "";
30 public void writeSources(List
<String
> packages
, ZipOutputStream zout
) {
31 Session distSession
= null;
32 ZipInputStream zin
= null;
34 distSession
= osgiFactory
.openDistSession();
36 if (log
.isDebugEnabled())
37 log
.debug("Wrapping " + uri
);
39 Node distNode
= osgiFactory
.getDist(distSession
, uri
);
40 zin
= new ZipInputStream(
41 distNode
.getNode(Node
.JCR_CONTENT
).getProperty(Property
.JCR_DATA
).getBinary().getStream());
44 Set
<String
> directories
= new TreeSet
<String
>();
45 for (String pkg
: packages
)
46 if (!pkg
.equals("META-INF"))
47 directories
.add(base
+ pkg
.replace('.', '/') + '/');
49 ZipEntry zentry
= null;
50 entries
: while ((zentry
= zin
.getNextEntry()) != null) {
51 String name
= zentry
.getName();
52 if (!name
.startsWith(base
))
55 String dirPath
= FilenameUtils
.getPath(name
);
56 if (name
.equals(dirPath
))// directory
59 if (directories
.contains(dirPath
)) {
60 String path
= name
.substring(base
.length());
61 zout
.putNextEntry(new JarEntry(path
));
62 IOUtils
.copy(zin
, zout
);
68 } catch (Exception e
) {
69 throw new SlcException("Cannot retrieve sources from " + uri
, e
);
71 IOUtils
.closeQuietly(zin
);
72 JcrUtils
.logoutQuietly(distSession
);
77 public void setOsgiFactory(OsgiFactory osgiFactory
) {
78 this.osgiFactory
= osgiFactory
;
81 public void setUri(String uri
) {
85 public void setBase(String base
) {