+ protected void packageSourcesAsPdeSource(Node sourcesNode) {
+ Binary origBinary = null;
+ Binary osgiBinary = null;
+ try {
+ Session session = sourcesNode.getSession();
+ Artifact sourcesArtifact = AetherUtils.convertPathToArtifact(
+ sourcesNode.getPath(), null);
+
+ // read name version from manifest
+ Artifact osgiArtifact = new DefaultArtifact(
+ sourcesArtifact.getGroupId(),
+ sourcesArtifact.getArtifactId(),
+ sourcesArtifact.getExtension(),
+ sourcesArtifact.getVersion());
+ String osgiPath = MavenConventionsUtils.artifactPath(
+ artifactBasePath, osgiArtifact);
+ osgiBinary = session.getNode(osgiPath).getNode(Node.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary();
+
+ NameVersion nameVersion = RepoUtils.readNameVersion(osgiBinary
+ .getStream());
+
+ // create PDe sources artifact
+ Artifact pdeSourceArtifact = new DefaultArtifact(
+ sourcesArtifact.getGroupId(),
+ sourcesArtifact.getArtifactId() + ".source",
+ sourcesArtifact.getExtension(),
+ sourcesArtifact.getVersion());
+ String targetSourceParentPath = MavenConventionsUtils
+ .artifactParentPath(artifactBasePath, pdeSourceArtifact);
+ String targetSourceFileName = MavenConventionsUtils
+ .artifactFileName(pdeSourceArtifact);
+ String targetSourceJarPath = targetSourceParentPath + '/'
+ + targetSourceFileName;
+
+ Node targetSourceParentNode = JcrUtils.mkfolders(session,
+ targetSourceParentPath);
+ origBinary = sourcesNode.getNode(Node.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary();
+ byte[] targetJarBytes = RepoUtils.packageAsPdeSource(
+ origBinary.getStream(), nameVersion);
+ JcrUtils.copyBytesAsFile(targetSourceParentNode,
+ targetSourceFileName, targetJarBytes);
+
+ // reindex
+ Node targetSourceJarNode = session.getNode(targetSourceJarPath);
+ artifactIndexer.index(targetSourceJarNode);
+ jarFileIndexer.index(targetSourceJarNode);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot add PDE sources for " + sourcesNode,
+ e);
+ } finally {
+ JcrUtils.closeQuietly(origBinary);
+ JcrUtils.closeQuietly(osgiBinary);
+ }
+
+ }
+