+
+ // sources
+ Artifact origSourceArtifact = new DefaultArtifact(
+ origArtifact.getGroupId(), origArtifact.getArtifactId()
+ + ".source", "jar", origArtifact.getVersion());
+ String origSourcePath = MavenConventionsUtils.artifactPath(
+ artifactBasePath, origSourceArtifact);
+ if (origSession.itemExists(origSourcePath)) {
+ Node origSourceJarNode = origSession.getNode(origSourcePath);
+
+ Artifact targetSourceArtifact = new DefaultArtifact(targetGroupId,
+ targetArtifactId + ".source", "jar",
+ origArtifact.getVersion());
+ String targetSourceParentPath = MavenConventionsUtils
+ .artifactParentPath(artifactBasePath, targetSourceArtifact);
+ String targetSourceFileName = MavenConventionsUtils
+ .artifactFileName(targetSourceArtifact);
+ String targetSourceJarPath = targetSourceParentPath + '/'
+ + targetSourceFileName;
+
+ Node targetSourceParentNode = JcrUtils.mkfolders(targetSession,
+ targetSourceParentPath);
+ targetSession.save();
+
+ if (!targetSymbolicName.equals(origSymbolicName)) {
+ Binary origBinary = origSourceJarNode.getNode(Node.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary();
+ NameVersion targetNameVersion = RepoUtils
+ .readNameVersion(targetManifest);
+ byte[] targetJarBytes = RepoUtils.packageAsPdeSource(
+ origBinary.getStream(), targetNameVersion);
+ JcrUtils.copyBytesAsFile(targetSourceParentNode,
+ targetSourceFileName, targetJarBytes);
+ JcrUtils.closeQuietly(origBinary);
+ } else {// just copy
+ targetSession.getWorkspace().copy(sourceWorkspace,
+ origSourceJarNode.getPath(), targetSourceJarPath);
+ }
+ targetSession.save();
+
+ // reindex
+ Node targetSourceJarNode = targetSession
+ .getNode(targetSourceJarPath);
+ artifactIndexer.index(targetSourceJarNode);
+ jarFileIndexer.index(targetSourceJarNode);
+
+ targetSession.save();
+ }