1 package org
.argeo
.slc
.repo
.osgi
;
3 import java
.io
.ByteArrayOutputStream
;
4 import java
.io
.InputStream
;
7 import javax
.jcr
.Property
;
8 import javax
.jcr
.Session
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.jcr
.JcrUtils
;
13 import org
.argeo
.slc
.SlcException
;
14 import org
.argeo
.slc
.repo
.OsgiFactory
;
15 import org
.argeo
.slc
.repo
.RepoUtils
;
17 public class UriWrapper
extends BndWrapper
implements Runnable
{
18 private final static Log log
= LogFactory
.getLog(UriWrapper
.class);
21 private String baseUri
;
22 private String versionSeparator
= "-";
23 private String extension
= "jar";
25 private OsgiFactory osgiFactory
;
27 // private SourcesProvider sourcesProvider;
34 Session distSession
= null;
35 Session javaSession
= null;
37 ByteArrayOutputStream out
;
40 distSession
= osgiFactory
.openDistSession();
41 javaSession
= osgiFactory
.openJavaSession();
43 uri
= baseUri
+ '/' + getName() + versionSeparator
44 + getVersion() + "." + extension
;
46 Node sourceArtifact
= osgiFactory
.getDist(distSession
, uri
);
48 // TODO factorize with Maven
49 in
= sourceArtifact
.getNode(Node
.JCR_CONTENT
)
50 .getProperty(Property
.JCR_DATA
).getBinary().getStream();
51 out
= new ByteArrayOutputStream();
53 Node newJarNode
= RepoUtils
54 .copyBytesAsArtifact(javaSession
.getRootNode(),
55 getArtifact(), out
.toByteArray());
56 osgiFactory
.indexNode(newJarNode
);
57 newJarNode
.getSession().save();
58 if (log
.isDebugEnabled())
59 log
.debug("Wrapped " + uri
+ " to " + newJarNode
.getPath());
62 // if (sourcesProvider != null) {
63 // IOUtils.closeQuietly(in);
64 // in = new ByteArrayInputStream(out.toByteArray());
65 // jar = new Jar(null, in);
66 // List<String> packages = jar.getPackages();
68 // IOUtils.closeQuietly(out);
69 // out = new ByteArrayOutputStream();
71 // .writeSources(packages, new ZipOutputStream(out));
73 // IOUtils.closeQuietly(in);
74 // in = new ByteArrayInputStream(out.toByteArray());
75 // byte[] sourcesJar = RepoUtils.packageAsPdeSource(in,
76 // new DefaultNameVersion(this));
77 // Artifact sourcesArtifact = new DefaultArtifact(getArtifact()
78 // .getGroupId(), getArtifact().getArtifactId()
79 // + ".source", "jar", getArtifact().getVersion());
80 // Node sourcesJarNode = RepoUtils.copyBytesAsArtifact(
81 // javaSession.getRootNode(), sourcesArtifact, sourcesJar);
82 // sourcesJarNode.getSession().save();
84 // if (log.isDebugEnabled())
85 // log.debug("Added sources " + sourcesArtifact
86 // + " for bundle " + getArtifact());
88 } catch (Exception e
) {
89 throw new SlcException("Cannot wrap URI " + uri
, e
);
91 JcrUtils
.logoutQuietly(distSession
);
92 JcrUtils
.logoutQuietly(javaSession
);
98 public void setUri(String sourceCoords
) {
99 this.uri
= sourceCoords
;
102 public void setOsgiFactory(OsgiFactory osgiFactory
) {
103 this.osgiFactory
= osgiFactory
;
106 public void setBaseUri(String baseUri
) {
107 this.baseUri
= baseUri
;
110 public void setVersionSeparator(String versionSeparator
) {
111 this.versionSeparator
= versionSeparator
;