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
.io
.IOUtils
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.jcr
.JcrUtils
;
14 import org
.argeo
.slc
.DefaultNameVersion
;
15 import org
.argeo
.slc
.SlcException
;
16 import org
.argeo
.slc
.repo
.OsgiFactory
;
17 import org
.argeo
.slc
.repo
.RepoUtils
;
18 import org
.eclipse
.aether
.artifact
.Artifact
;
19 import org
.eclipse
.aether
.artifact
.DefaultArtifact
;
22 * BND wrapper based on a Maven artifact available from one of the configured
25 public class MavenWrapper
extends BndWrapper
implements Runnable
{
26 private final static Log log
= LogFactory
.getLog(MavenWrapper
.class);
28 private String sourceCoords
;
30 private OsgiFactory osgiFactory
;
32 private Boolean doNotModifySources
= false;
34 public MavenWrapper() {
39 public String
getVersion() {
40 String version
= super.getVersion();
43 return new DefaultArtifact(sourceCoords
).getVersion();
47 Session distSession
= null;
48 Session javaSession
= null;
49 InputStream in
= null;
50 ByteArrayOutputStream out
= null;
52 distSession
= osgiFactory
.openDistSession();
53 javaSession
= osgiFactory
.openJavaSession();
56 origArtifact
= osgiFactory
.getMaven(distSession
, sourceCoords
);
57 } catch (Exception e1
) {
58 origArtifact
= osgiFactory
.getMaven(distSession
, sourceCoords
+ ":" + getVersion());
61 in
= origArtifact
.getNode(Node
.JCR_CONTENT
).getProperty(Property
.JCR_DATA
).getBinary().getStream();
62 out
= new ByteArrayOutputStream();
64 Node newJarNode
= RepoUtils
.copyBytesAsArtifact(javaSession
.getRootNode(), getArtifact(),
66 osgiFactory
.indexNode(newJarNode
);
67 newJarNode
.getSession().save();
69 if (log
.isDebugEnabled())
70 log
.debug("Wrapped Maven " + sourceCoords
+ " to " + newJarNode
.getPath());
73 Artifact sourcesArtifact
= new SubArtifact(new DefaultArtifact(sourceCoords
), "sources", null);
74 Node sourcesArtifactNode
;
77 sourcesArtifactNode
= osgiFactory
.getMaven(distSession
, sourcesArtifact
.toString());
78 } catch (SlcException e
) {
79 // no sources available
83 IOUtils
.closeQuietly(in
);
84 in
= sourcesArtifactNode
.getNode(Node
.JCR_CONTENT
).getProperty(Property
.JCR_DATA
).getBinary().getStream();
86 if (doNotModifySources
)
87 pdeSource
= IOUtils
.toByteArray(in
);
89 pdeSource
= RepoUtils
.packageAsPdeSource(in
, new DefaultNameVersion(getName(), getVersion()));
90 Node pdeSourceNode
= RepoUtils
.copyBytesAsArtifact(javaSession
.getRootNode(),
91 new DefaultArtifact(getCategory(), getName() + ".source", "jar", getVersion()), pdeSource
);
92 osgiFactory
.indexNode(pdeSourceNode
);
93 pdeSourceNode
.getSession().save();
95 if (log
.isDebugEnabled())
96 log
.debug("Wrapped Maven " + sourcesArtifact
+ " to PDE sources " + pdeSourceNode
.getPath());
97 } catch (Exception e
) {
98 throw new SlcException("Cannot wrap Maven " + sourceCoords
, e
);
100 JcrUtils
.logoutQuietly(distSession
);
101 JcrUtils
.logoutQuietly(javaSession
);
102 IOUtils
.closeQuietly(in
);
103 IOUtils
.closeQuietly(out
);
107 public void setSourceCoords(String sourceCoords
) {
108 this.sourceCoords
= sourceCoords
;
111 public String
getSourceCoords() {
115 public void setOsgiFactory(OsgiFactory osgiFactory
) {
116 this.osgiFactory
= osgiFactory
;
119 public void setDoNotModifySources(Boolean doNotModifySources
) {
120 this.doNotModifySources
= doNotModifySources
;