1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.util.HashMap ; 14 import java.util.HashSet ; 15 import java.util.Map ; 16 import java.util.Set ; 17 import java.util.StringTokenizer ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.core.ILaunchConfiguration; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.core.plugin.ModelEntry; 23 import org.eclipse.pde.core.plugin.PluginRegistry; 24 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 25 26 public class BundleLauncherHelper { 27 28 public static Map getWorkspaceBundleMap(ILaunchConfiguration configuration) throws CoreException { 29 return getWorkspaceBundleMap(configuration, null); 30 } 31 32 public static Map getWorkspaceBundleMap(ILaunchConfiguration configuration, Set set) throws CoreException { 33 String selected = configuration.getAttribute(IPDELauncherConstants.WORKSPACE_BUNDLES, ""); Map map = new HashMap (); 35 StringTokenizer tok = new StringTokenizer (selected, ","); while (tok.hasMoreTokens()) { 37 String token = tok.nextToken(); 38 int index = token.indexOf('@'); 39 String id = token.substring(0, index); 40 if (set != null) 41 set.add(id); 42 ModelEntry entry = PluginRegistry.findEntry(id); 43 if (entry != null) { 44 IPluginModelBase[] models = entry.getWorkspaceModels(); 45 for (int i = 0; i < models.length; i++) { 46 map.put(models[i], token.substring(index + 1)); 47 } 48 } 49 } 50 51 if (configuration.getAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true)) { 52 Set deselectedPlugins = LaunchPluginValidator.parsePlugins(configuration, IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS); 53 IPluginModelBase[] models = PluginRegistry.getWorkspaceModels(); 54 for (int i = 0; i < models.length; i++) { 55 String id = models[i].getPluginBase().getId(); 56 if (id == null) 57 continue; 58 if (set != null) 59 set.add(id); 60 if (!map.containsKey(models[i]) && !deselectedPlugins.contains(id)) { 61 map.put(models[i], "default:default"); } 63 } 64 } 65 return map; 66 } 67 68 public static IPluginModelBase[] getWorkspaceBundles(ILaunchConfiguration configuration) throws CoreException { 69 Map map = getWorkspaceBundleMap(configuration); 70 return (IPluginModelBase[])map.keySet().toArray(new IPluginModelBase[map.size()]); 71 } 72 73 public static Map getTargetBundleMap(ILaunchConfiguration configuration) throws CoreException { 74 return getTargetBundleMap(configuration, new HashSet ()); 75 } 76 77 public static Map getTargetBundleMap(ILaunchConfiguration configuration, Set set) throws CoreException { 78 String selected = configuration.getAttribute(IPDELauncherConstants.TARGET_BUNDLES, ""); Map map = new HashMap (); 80 StringTokenizer tok = new StringTokenizer (selected, ","); while (tok.hasMoreTokens()) { 82 String token = tok.nextToken(); 83 int index = token.indexOf('@'); 84 String id = token.substring(0, index); 85 if (set.contains(id)) 86 continue; 87 ModelEntry entry = PluginRegistry.findEntry(id); 88 if (entry != null) { 89 IPluginModelBase[] models = entry.getExternalModels(); 90 for (int i = 0; i < models.length; i++) { 91 map.put(models[i], token.substring(index + 1)); 92 } 93 } 94 } 95 return map; 96 } 97 98 public static IPluginModelBase[] getTargetBundles(ILaunchConfiguration configuration) throws CoreException { 99 Map map = getTargetBundleMap(configuration); 100 return (IPluginModelBase[])map.keySet().toArray(new IPluginModelBase[map.size()]); 101 } 102 103 public static Map getMergedMap(ILaunchConfiguration configuration) throws CoreException { 104 Set set = new HashSet (); 105 Map map = getWorkspaceBundleMap(configuration, set); 106 map.putAll(getTargetBundleMap(configuration, set)); 107 return map; 108 } 109 110 public static IPluginModelBase[] getMergedBundles(ILaunchConfiguration configuration) throws CoreException { 111 Map map = getMergedMap(configuration); 112 return (IPluginModelBase[])map.keySet().toArray(new IPluginModelBase[map.size()]); 113 } 114 115 } 116 | Popular Tags |