X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FMigration_01_03.java;h=56ffd7f67f5dd18cbba7863a8fc0448a33da1113;hb=0e2862f3efc104beecea43b054e2ba00b03fd2c2;hp=b93831cc191c8bf0f071791030b84cba30e4582d;hpb=418a82cb85b477af9f2b8d850ca14c8512546643;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/Migration_01_03.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/Migration_01_03.java index b93831cc1..56ffd7f67 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/Migration_01_03.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/Migration_01_03.java @@ -1,8 +1,11 @@ package org.argeo.slc.repo.maven; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.jar.Attributes.Name; import java.util.jar.Manifest; @@ -24,6 +27,7 @@ import javax.jcr.query.qom.Selector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; +import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; @@ -51,6 +55,9 @@ public class Migration_01_03 implements Runnable, SlcNames { private String sourceWorkspace; private String targetWorkspace; + private List excludedBundles = new ArrayList(); + private Map symbolicNamesMapping = new HashMap(); + private Session origSession; private Session targetSession; @@ -80,19 +87,21 @@ public class Migration_01_03 implements Runnable, SlcNames { public void run() { try { - NodeIterator origArtifacts = listArtifactVersions(origSession); - // clear target NodeIterator nit = targetSession.getNode(artifactBasePath) .getNodes(); while (nit.hasNext()) { Node node = nit.nextNode(); if (node.isNodeType(NodeType.NT_FOLDER) - || node.isNodeType(NodeType.NT_UNSTRUCTURED)) + || node.isNodeType(NodeType.NT_UNSTRUCTURED)) { node.remove(); + node.getSession().save(); + if (log.isDebugEnabled()) + log.debug("Cleared " + node); + } } - targetSession.save(); + NodeIterator origArtifacts = listArtifactVersions(origSession); // process while (origArtifacts.hasNext()) { Node origArtifactNode = origArtifacts.nextNode(); @@ -132,35 +141,52 @@ public class Migration_01_03 implements Runnable, SlcNames { String origSymbolicName = origManifest.getMainAttributes().getValue( Constants.BUNDLE_SYMBOLICNAME); final String targetSymbolicName; - if (origSymbolicName.startsWith(SPRING_SOURCE_PREFIX) + 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); - if (log.isDebugEnabled()) - log.debug(Constants.BUNDLE_SYMBOLICNAME + " to " - + targetSymbolicName + " \t\tfrom " + origSymbolicName); + } else { + targetSymbolicName = origSymbolicName; + } + + if (!targetSymbolicName.equals(origSymbolicName)) { targetManifest.getMainAttributes().putValue( Constants.BUNDLE_SYMBOLICNAME, targetSymbolicName); manifestModified = true; - } else { - targetSymbolicName = origSymbolicName; + 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); - if (origFragmentHost.startsWith(SPRING_SOURCE_PREFIX) + String targetFragmentHost; + if (symbolicNamesMapping.containsKey(origFragmentHost)) { + targetFragmentHost = symbolicNamesMapping.get(origFragmentHost); + } else if (origFragmentHost.startsWith(SPRING_SOURCE_PREFIX) && !origFragmentHost.equals(SPRING_SOURCE_PREFIX + ".json")) { - String targetFragmentHost = origFragmentHost + targetFragmentHost = origFragmentHost .substring(SPRING_SOURCE_PREFIX.length() + 1); - if (log.isDebugEnabled()) - log.debug(Constants.FRAGMENT_HOST + " to " - + targetFragmentHost + " from " + origFragmentHost); + } 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); } } @@ -182,7 +208,7 @@ public class Migration_01_03 implements Runnable, SlcNames { if (systemPackages.contains(pkg)) { if (!(sourceVersion.trim().equals("0") || sourceVersion .trim().equals("0.0.0"))) { - targetVersion = "0"; + targetVersion = null; importPackagesModified = true; if (log.isDebugEnabled()) log.debug(origSymbolicName @@ -190,8 +216,9 @@ public class Migration_01_03 implements Runnable, SlcNames { + sourceVersion); } } - targetImportPackages.append(";version=\"") - .append(targetVersion).append("\""); + if (targetVersion != null) + targetImportPackages.append(";version=\"") + .append(targetVersion).append("\""); } if (importPackage.hasProperty(SLC_OPTIONAL)) { Boolean optional = importPackage.getProperty(SLC_OPTIONAL) @@ -254,6 +281,54 @@ public class Migration_01_03 implements Runnable, SlcNames { 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(); + } } /* @@ -291,4 +366,13 @@ public class Migration_01_03 implements Runnable, SlcNames { public void setTargetWorkspace(String targetWorkspace) { this.targetWorkspace = targetWorkspace; } + + public void setExcludedBundles(List excludedBundles) { + this.excludedBundles = excludedBundles; + } + + public void setSymbolicNamesMapping(Map symbolicNamesMapping) { + this.symbolicNamesMapping = symbolicNamesMapping; + } + }