]>
git.argeo.org Git - gpl/argeo-slc.git/blob - 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
.apache
.commons
.logging
.Log
;
18 import org
.apache
.commons
.logging
.LogFactory
;
19 import org
.argeo
.jcr
.JcrUtils
;
20 import org
.argeo
.slc
.SlcException
;
21 import org
.argeo
.slc
.repo
.OsgiFactory
;
23 public class ArchiveSourcesProvider
implements SourcesProvider
{
24 private final static Log log
= LogFactory
25 .getLog(ArchiveSourcesProvider
.class);
27 private OsgiFactory osgiFactory
;
29 private String base
= "";
32 public void writeSources(List
<String
> packages
, ZipOutputStream zout
) {
33 Session distSession
= null;
34 ZipInputStream zin
= null;
36 distSession
= osgiFactory
.openDistSession();
38 if (log
.isDebugEnabled())
39 log
.debug("Wrapping " + uri
);
41 Node distNode
= osgiFactory
.getDist(distSession
, uri
);
42 zin
= new ZipInputStream(distNode
.getNode(Node
.JCR_CONTENT
)
43 .getProperty(Property
.JCR_DATA
).getBinary().getStream());
46 Set
<String
> directories
= new TreeSet
<String
>();
47 for (String pkg
: packages
)
48 if (!pkg
.equals("META-INF"))
49 directories
.add(base
+ pkg
.replace('.', '/') + '/');
51 ZipEntry zentry
= null;
52 entries
: while ((zentry
= zin
.getNextEntry()) != null) {
53 String name
= zentry
.getName();
54 if (!name
.startsWith(base
))
57 String dirPath
= FilenameUtils
.getPath(name
);
58 if (name
.equals(dirPath
))// directory
61 if (directories
.contains(dirPath
)) {
62 String path
= name
.substring(base
.length());
63 zout
.putNextEntry(new JarEntry(path
));
64 IOUtils
.copy(zin
, zout
);
70 } catch (Exception e
) {
71 throw new SlcException("Cannot retrieve sources from " + uri
, e
);
73 IOUtils
.closeQuietly(zin
);
74 JcrUtils
.logoutQuietly(distSession
);
79 public void setOsgiFactory(OsgiFactory osgiFactory
) {
80 this.osgiFactory
= osgiFactory
;
83 public void setUri(String uri
) {
87 public void setBase(String base
) {