]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/Migration_01_03.java
Change workspace names
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / maven / Migration_01_03.java
index 9e37f7592516e5de8b0aa099f7c57050516615b1..25ebdab71919484ee85b2ad5b39bcc7fe1377e83 100644 (file)
@@ -1,8 +1,10 @@
 package org.argeo.slc.repo.maven;
 
 import java.io.IOException;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.jar.Attributes.Name;
 import java.util.jar.Manifest;
 
@@ -31,6 +33,7 @@ import org.argeo.slc.jcr.SlcTypes;
 import org.argeo.slc.repo.ArtifactIndexer;
 import org.argeo.slc.repo.JarFileIndexer;
 import org.argeo.slc.repo.RepoUtils;
+import org.argeo.slc.repo.osgi.OsgiProfile;
 import org.osgi.framework.Constants;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
@@ -52,10 +55,14 @@ public class Migration_01_03 implements Runnable, SlcNames {
        private String sourceWorkspace;
        private String targetWorkspace;
 
+       private List<String> excludedBundles = new ArrayList<String>();
+       private Map<String, String> symbolicNamesMapping = new HashMap<String, String>();
+
        private Session origSession;
        private Session targetSession;
 
-       private List<String> systemPackages;
+       private List<String> systemPackages = OsgiProfile.PROFILE_JAVA_SE_1_6
+                       .getSystemPackages();
 
        private String artifactBasePath = "/";
 
@@ -69,8 +76,8 @@ public class Migration_01_03 implements Runnable, SlcNames {
                                targetWorkspace);
 
                // works only in OSGi!!
-               systemPackages = Arrays.asList(System.getProperty(
-                               "org.osgi.framework.system.packages").split(","));
+               // systemPackages = Arrays.asList(System.getProperty(
+               // "org.osgi.framework.system.packages").split(","));
        }
 
        public void destroy() {
@@ -81,19 +88,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();
@@ -113,6 +122,24 @@ public class Migration_01_03 implements Runnable, SlcNames {
        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))
@@ -133,35 +160,56 @@ 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 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);
                        }
                }
 
@@ -183,7 +231,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
@@ -191,8 +239,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)
@@ -217,8 +266,16 @@ public class Migration_01_03 implements Runnable, SlcNames {
 
                // target coordinates
                final String targetGroupId;
-               if (origArtifact.getGroupId().startsWith("org.eclipse"))
-                       targetGroupId = "org.argeo.tp.eclipse";
+               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";
 
@@ -340,4 +397,13 @@ public class Migration_01_03 implements Runnable, SlcNames {
        public void setTargetWorkspace(String targetWorkspace) {
                this.targetWorkspace = targetWorkspace;
        }
+
+       public void setExcludedBundles(List<String> excludedBundles) {
+               this.excludedBundles = excludedBundles;
+       }
+
+       public void setSymbolicNamesMapping(Map<String, String> symbolicNamesMapping) {
+               this.symbolicNamesMapping = symbolicNamesMapping;
+       }
+
 }