+ throw new SlcException("Cannot synchronize distribution", e);
+ }
+ }
+
+ /** Try to add PDE sources */
+ private void addPdeSource(Session session, Artifact artifact,
+ File artifactFile, Set<Artifact> artifactsWithoutSources) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ File origSourceFile = null;
+ Artifact origSourceArtifact = new DefaultArtifact(
+ artifact.getGroupId(), artifact.getArtifactId(), "sources",
+ artifact.getExtension(), artifact.getVersion());
+ Artifact targetSourceArtifact = new DefaultArtifact(
+ artifact.getGroupId(),
+ artifact.getArtifactId() + ".source",
+ artifact.getExtension(), artifact.getVersion());
+ try {
+ origSourceFile = aetherTemplate
+ .getResolvedFile(origSourceArtifact);
+ } catch (Exception e) {
+ // also try artifact following the conventions
+ origSourceArtifact = targetSourceArtifact;
+ origSourceFile = aetherTemplate
+ .getResolvedFile(origSourceArtifact);
+ }
+
+ String sourceParentPath = MavenConventionsUtils.artifactParentPath(
+ artifactBasePath, targetSourceArtifact);
+ Node sourceParentNode = JcrUtils.mkdirs(session, sourceParentPath,
+ NodeType.NT_FOLDER);
+ NameVersion bundleNameVersion = RepoUtils
+ .readNameVersion(artifactFile);
+ RepoUtils.packagesAsPdeSource(origSourceFile, bundleNameVersion,
+ out);
+ String targetSourceFileName = MavenConventionsUtils
+ .artifactFileName(targetSourceArtifact);
+ JcrUtils.copyBytesAsFile(sourceParentNode, targetSourceFileName,
+ out.toByteArray());
+ } catch (Exception e) {
+ log.error("Cannot add PDE source for " + artifact + ": " + e);
+ artifactsWithoutSources.add(artifact);
+ } finally {
+ IOUtils.closeQuietly(out);