INtroduce symbolic names mapping
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 18 May 2012 12:55:20 +0000 (12:55 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 18 May 2012 12:55:20 +0000 (12:55 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5304 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/Migration_01_03.java

index bd8c78838cee3d5bdf2a1fe54b48db0eff1233ff..56ffd7f67f5dd18cbba7863a8fc0448a33da1113 100644 (file)
@@ -3,7 +3,9 @@ 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;
 
@@ -54,6 +56,7 @@ public class Migration_01_03 implements Runnable, SlcNames {
        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;
@@ -138,18 +141,23 @@ 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
@@ -161,16 +169,24 @@ public class Migration_01_03 implements Runnable, SlcNames {
                                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);
                        }
                }
 
@@ -355,4 +371,8 @@ public class Migration_01_03 implements Runnable, SlcNames {
                this.excludedBundles = excludedBundles;
        }
 
+       public void setSymbolicNamesMapping(Map<String, String> symbolicNamesMapping) {
+               this.symbolicNamesMapping = symbolicNamesMapping;
+       }
+
 }