+ log.trace("MANIFEST of " + origSymbolicName + " was not modified");
+ }
+
+ // target coordinates
+ final String targetGroupId;
+ if (origArtifact.getGroupId().startsWith("org.eclipse"))
+ targetGroupId = "org.argeo.tp.eclipse";
+ else
+ targetGroupId = "org.argeo.tp";
+
+ String targetArtifactId = targetSymbolicName.split(";")[0];
+ Artifact targetArtifact = new DefaultArtifact(targetGroupId,
+ targetArtifactId, "jar", origArtifact.getVersion());
+ String targetParentPath = MavenConventionsUtils.artifactParentPath(
+ artifactBasePath, targetArtifact);
+ String targetFileName = MavenConventionsUtils
+ .artifactFileName(targetArtifact);
+ String targetJarPath = targetParentPath + '/' + targetFileName;
+
+ // copy
+ Node targetParentNode = JcrUtils.mkfolders(targetSession,
+ targetParentPath);
+ targetSession.save();
+ if (manifestModified) {
+ Binary origBinary = origJarNode.getNode(Node.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary();
+ byte[] targetJarBytes = RepoUtils.modifyManifest(
+ origBinary.getStream(), targetManifest);
+ JcrUtils.copyBytesAsFile(targetParentNode, targetFileName,
+ targetJarBytes);
+ JcrUtils.closeQuietly(origBinary);
+ } else {// just copy
+ targetSession.getWorkspace().copy(sourceWorkspace,
+ origJarNode.getPath(), targetJarPath);
+ }
+ targetSession.save();
+
+ // reindex
+ Node targetJarNode = targetSession.getNode(targetJarPath);
+ artifactIndexer.index(targetJarNode);
+ jarFileIndexer.index(targetJarNode);
+
+ targetSession.save();
+
+ // 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();