KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > BundleLauncherHelper


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.launcher;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17 import java.util.StringTokenizer JavaDoc;
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 JavaDoc getWorkspaceBundleMap(ILaunchConfiguration configuration) throws CoreException {
29         return getWorkspaceBundleMap(configuration, null);
30     }
31     
32     public static Map JavaDoc getWorkspaceBundleMap(ILaunchConfiguration configuration, Set JavaDoc set) throws CoreException {
33         String JavaDoc selected = configuration.getAttribute(IPDELauncherConstants.WORKSPACE_BUNDLES, ""); //$NON-NLS-1$
34
Map JavaDoc map = new HashMap JavaDoc();
35         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(selected, ","); //$NON-NLS-1$
36
while (tok.hasMoreTokens()) {
37             String JavaDoc token = tok.nextToken();
38             int index = token.indexOf('@');
39             String JavaDoc 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 JavaDoc deselectedPlugins = LaunchPluginValidator.parsePlugins(configuration, IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS);
53             IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
54             for (int i = 0; i < models.length; i++) {
55                 String JavaDoc 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"); //$NON-NLS-1$
62
}
63             }
64         }
65         return map;
66     }
67     
68     public static IPluginModelBase[] getWorkspaceBundles(ILaunchConfiguration configuration) throws CoreException {
69         Map JavaDoc map = getWorkspaceBundleMap(configuration);
70         return (IPluginModelBase[])map.keySet().toArray(new IPluginModelBase[map.size()]);
71     }
72     
73     public static Map JavaDoc getTargetBundleMap(ILaunchConfiguration configuration) throws CoreException {
74         return getTargetBundleMap(configuration, new HashSet JavaDoc());
75     }
76     
77     public static Map JavaDoc getTargetBundleMap(ILaunchConfiguration configuration, Set JavaDoc set) throws CoreException {
78         String JavaDoc selected = configuration.getAttribute(IPDELauncherConstants.TARGET_BUNDLES, ""); //$NON-NLS-1$
79
Map JavaDoc map = new HashMap JavaDoc();
80         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(selected, ","); //$NON-NLS-1$
81
while (tok.hasMoreTokens()) {
82             String JavaDoc token = tok.nextToken();
83             int index = token.indexOf('@');
84             String JavaDoc 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 JavaDoc map = getTargetBundleMap(configuration);
100         return (IPluginModelBase[])map.keySet().toArray(new IPluginModelBase[map.size()]);
101     }
102
103     public static Map JavaDoc getMergedMap(ILaunchConfiguration configuration) throws CoreException {
104         Set JavaDoc set = new HashSet JavaDoc();
105         Map JavaDoc 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 JavaDoc map = getMergedMap(configuration);
112         return (IPluginModelBase[])map.keySet().toArray(new IPluginModelBase[map.size()]);
113     }
114
115 }
116
Popular Tags