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
.RepositoryException
;
9 import javax
.jcr
.Session
;
11 import org
.apache
.commons
.io
.IOUtils
;
12 import org
.apache
.commons
.logging
.Log
;
13 import org
.apache
.commons
.logging
.LogFactory
;
14 import org
.argeo
.jcr
.JcrUtils
;
15 import org
.argeo
.slc
.DefaultNameVersion
;
16 import org
.argeo
.slc
.SlcException
;
17 import org
.argeo
.slc
.repo
.OsgiFactory
;
18 import org
.argeo
.slc
.repo
.RepoUtils
;
19 import org
.sonatype
.aether
.artifact
.Artifact
;
20 import org
.sonatype
.aether
.util
.artifact
.DefaultArtifact
;
21 import org
.sonatype
.aether
.util
.artifact
.SubArtifact
;
24 * BND wrapper based on a Maven artifact available from one of the configured
27 public class MavenWrapper
extends BndWrapper
implements Runnable
{
28 private final static Log log
= LogFactory
.getLog(MavenWrapper
.class);
30 private String sourceCoords
;
32 private OsgiFactory osgiFactory
;
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;
50 ByteArrayOutputStream out
;
52 distSession
= osgiFactory
.openDistSession();
53 javaSession
= osgiFactory
.openJavaSession();
56 origArtifact
= osgiFactory
.getMaven(distSession
, sourceCoords
);
57 } catch (Exception e1
) {
58 origArtifact
= osgiFactory
.getMaven(distSession
, sourceCoords
59 + ":" + getVersion());
62 in
= origArtifact
.getNode(Node
.JCR_CONTENT
)
63 .getProperty(Property
.JCR_DATA
).getBinary().getStream();
64 out
= new ByteArrayOutputStream();
66 Node newJarNode
= RepoUtils
67 .copyBytesAsArtifact(javaSession
.getRootNode(),
68 getArtifact(), out
.toByteArray());
69 osgiFactory
.indexNode(newJarNode
);
70 newJarNode
.getSession().save();
72 if (log
.isDebugEnabled())
73 log
.debug("Wrapped Maven " + sourceCoords
+ " to "
74 + newJarNode
.getPath());
77 Artifact sourcesArtifact
= new SubArtifact(new DefaultArtifact(
78 sourceCoords
), "sources", null);
79 Node sourcesArtifactNode
;
82 sourcesArtifactNode
= osgiFactory
.getMaven(distSession
,
83 sourcesArtifact
.toString());
84 } catch (SlcException e
) {
85 // no sources available
89 IOUtils
.closeQuietly(in
);
90 in
= sourcesArtifactNode
.getNode(Node
.JCR_CONTENT
)
91 .getProperty(Property
.JCR_DATA
).getBinary().getStream();
92 byte[] pdeSource
= RepoUtils
.packageAsPdeSource(in
,
93 new DefaultNameVersion(getName(), getVersion()));
94 Node pdeSourceNode
= RepoUtils
.copyBytesAsArtifact(javaSession
95 .getRootNode(), new DefaultArtifact(getCategory(),
96 getName() + ".source", "jar", getVersion()), pdeSource
);
97 osgiFactory
.indexNode(pdeSourceNode
);
98 pdeSourceNode
.getSession().save();
100 if (log
.isDebugEnabled())
101 log
.debug("Wrapped Maven " + sourcesArtifact
102 + " to PDE sources " + pdeSourceNode
.getPath());
103 } catch (RepositoryException e
) {
104 throw new SlcException("Cannot wrap Maven " + sourceCoords
, e
);
106 JcrUtils
.logoutQuietly(distSession
);
107 JcrUtils
.logoutQuietly(javaSession
);
111 public void setSourceCoords(String sourceCoords
) {
112 this.sourceCoords
= sourceCoords
;
115 public void setOsgiFactory(OsgiFactory osgiFactory
) {
116 this.osgiFactory
= osgiFactory
;