+ protected void processOrigArtifactVersion(Node origArtifactNode)
+ throws RepositoryException, IOException {
+ Artifact origArtifact = RepoUtils.asArtifact(origArtifactNode);
+
+ // skip eclipse artifacts
+ if ((origArtifact.getGroupId().startsWith("org.eclipse") && !(origArtifact
+ .getArtifactId().equals("org.eclipse.osgi")
+ || origArtifact.getArtifactId().equals(
+ "org.eclipse.osgi.source") || origArtifact
+ .getArtifactId().startsWith("org.eclipse.rwt.widgets.upload")))
+ || origArtifact.getArtifactId().startsWith("com.ibm.icu")) {
+ if (log.isDebugEnabled())
+ log.debug("Skip " + origArtifact);
+ return;
+ }
+
+ // skip SpringSource ActiveMQ
+ if (origArtifact.getArtifactId().startsWith(
+ "com.springsource.org.apache.activemq"))
+ return;
+
+ String origJarNodeName = MavenConventionsUtils
+ .artifactFileName(origArtifact);
+ if (!origArtifactNode.hasNode(origJarNodeName))
+ throw new SlcException("Cannot find jar node for "
+ + origArtifactNode);
+ Node origJarNode = origArtifactNode.getNode(origJarNodeName);
+
+ // read MANIFEST
+ Binary manifestBinary = origJarNode.getProperty(SLC_MANIFEST)
+ .getBinary();
+ Manifest origManifest = new Manifest(manifestBinary.getStream());
+ JcrUtils.closeQuietly(manifestBinary);
+
+ Boolean manifestModified = false;
+ Manifest targetManifest = new Manifest(origManifest);
+
+ // transform symbolic name
+ String origSymbolicName = origManifest.getMainAttributes().getValue(
+ Constants.BUNDLE_SYMBOLICNAME);
+ final String targetSymbolicName;
+ if (symbolicNamesMapping.containsKey(origSymbolicName)) {
+ targetSymbolicName = symbolicNamesMapping.get(origSymbolicName);
+ } else if (origSymbolicName.startsWith(SPRING_SOURCE_PREFIX)
+ && !origSymbolicName.equals(SPRING_SOURCE_PREFIX + ".json")) {
+ targetSymbolicName = origSymbolicName
+ .substring(SPRING_SOURCE_PREFIX.length() + 1);
+ } else {
+ targetSymbolicName = origSymbolicName;
+ }
+
+ if (!targetSymbolicName.equals(origSymbolicName)) {
+ targetManifest.getMainAttributes().putValue(
+ Constants.BUNDLE_SYMBOLICNAME, targetSymbolicName);
+ manifestModified = true;
+ if (log.isDebugEnabled())
+ log.debug(Constants.BUNDLE_SYMBOLICNAME + " to "
+ + targetSymbolicName + " \t\tfrom " + origSymbolicName);
+ }
+
+ // skip excluded bundles
+ if (excludedBundles.contains(targetSymbolicName))
+ return;
+
+ // check fragment host
+ if (origManifest.getMainAttributes().containsKey(
+ new Name(Constants.FRAGMENT_HOST))) {
+ String origFragmentHost = origManifest.getMainAttributes()
+ .getValue(Constants.FRAGMENT_HOST);
+ String targetFragmentHost;
+ if (symbolicNamesMapping.containsKey(origFragmentHost)) {
+ targetFragmentHost = symbolicNamesMapping.get(origFragmentHost);
+ } else if (origFragmentHost.startsWith(SPRING_SOURCE_PREFIX)
+ && !origFragmentHost.equals(SPRING_SOURCE_PREFIX + ".json")) {
+ targetFragmentHost = origFragmentHost
+ .substring(SPRING_SOURCE_PREFIX.length() + 1);
+ } else if (origFragmentHost
+ .equals("org.argeo.dep.jacob;bundle-version=\"[1.14.3,1.14.4)\"")) {
+ // this one for those who think I cannot be pragmatic - mbaudier
+ targetFragmentHost = "com.jacob;bundle-version=\"[1.14.3,1.14.4)\"";
+ } else {
+ targetFragmentHost = origFragmentHost;
+ }
+
+ if (!targetFragmentHost.equals(origFragmentHost)) {
+ targetManifest.getMainAttributes().putValue(
+ Constants.FRAGMENT_HOST, targetFragmentHost);
+ manifestModified = true;
+ if (log.isDebugEnabled())
+ log.debug(Constants.FRAGMENT_HOST + " to "
+ + targetFragmentHost + " from " + origFragmentHost);
+ }
+ }
+
+ // we assume there is no Require-Bundle in com.springsource.* bundles
+
+ // javax with versions
+ StringBuffer targetImportPackages = new StringBuffer("");
+ NodeIterator origImportPackages = origJarNode.getNodes(SLC_
+ + Constants.IMPORT_PACKAGE);
+ Boolean importPackagesModified = false;
+ while (origImportPackages.hasNext()) {
+ Node importPackage = origImportPackages.nextNode();
+ String pkg = importPackage.getProperty(SLC_NAME).getString();
+ targetImportPackages.append(pkg);
+ if (importPackage.hasProperty(SLC_VERSION)) {
+ String sourceVersion = importPackage.getProperty(SLC_VERSION)
+ .getString();
+ String targetVersion = sourceVersion;
+ if (systemPackages.contains(pkg)) {
+ if (!(sourceVersion.trim().equals("0") || sourceVersion
+ .trim().equals("0.0.0"))) {
+ targetVersion = null;
+ importPackagesModified = true;
+ if (log.isDebugEnabled())
+ log.debug(origSymbolicName
+ + ": Nullify version of " + pkg + " from "
+ + sourceVersion);
+ }
+ }
+ if (targetVersion != null)
+ targetImportPackages.append(";version=\"")
+ .append(targetVersion).append("\"");
+ }
+ if (importPackage.hasProperty(SLC_OPTIONAL)) {
+ Boolean optional = importPackage.getProperty(SLC_OPTIONAL)
+ .getBoolean();
+ if (optional)
+ targetImportPackages.append(";resolution:=\"optional\"");
+
+ }
+ if (origImportPackages.hasNext())
+ targetImportPackages.append(",");
+ }
+
+ if (importPackagesModified) {
+ targetManifest.getMainAttributes().putValue(
+ Constants.IMPORT_PACKAGE, targetImportPackages.toString());
+ manifestModified = true;
+ }
+
+ if (!manifestModified && log.isTraceEnabled()) {
+ log.trace("MANIFEST of " + origSymbolicName + " was not modified");
+ }
+
+ // target coordinates
+ final String targetGroupId;
+ if (origArtifact.getArtifactId().startsWith(
+ "org.eclipse.rwt.widgets.upload"))
+ targetGroupId = "org.argeo.tp.rap";
+ else if (origArtifact.getArtifactId().startsWith("org.polymap"))
+ targetGroupId = "org.argeo.tp.rap";
+ else if (origArtifact.getGroupId().startsWith("org.eclipse")
+ && !origArtifact.getArtifactId().equals("org.eclipse.osgi"))
+ throw new SlcException(origArtifact + " should have been excluded");// 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();
+ }
+ }
+
+ /*
+ * UTILITIES
+ */
+