001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.launcher;
011:
012: import java.util.HashMap;
013: import java.util.HashSet;
014: import java.util.Map;
015: import java.util.Set;
016: import java.util.StringTokenizer;
017:
018: import org.eclipse.core.runtime.CoreException;
019: import org.eclipse.debug.core.ILaunchConfiguration;
020: import org.eclipse.pde.core.plugin.IPluginModelBase;
021: import org.eclipse.pde.core.plugin.ModelEntry;
022: import org.eclipse.pde.core.plugin.PluginRegistry;
023: import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
024:
025: public class BundleLauncherHelper {
026:
027: public static Map getWorkspaceBundleMap(
028: ILaunchConfiguration configuration) throws CoreException {
029: return getWorkspaceBundleMap(configuration, null);
030: }
031:
032: public static Map getWorkspaceBundleMap(
033: ILaunchConfiguration configuration, Set set)
034: throws CoreException {
035: String selected = configuration.getAttribute(
036: IPDELauncherConstants.WORKSPACE_BUNDLES, ""); //$NON-NLS-1$
037: Map map = new HashMap();
038: StringTokenizer tok = new StringTokenizer(selected, ","); //$NON-NLS-1$
039: while (tok.hasMoreTokens()) {
040: String token = tok.nextToken();
041: int index = token.indexOf('@');
042: String id = token.substring(0, index);
043: if (set != null)
044: set.add(id);
045: ModelEntry entry = PluginRegistry.findEntry(id);
046: if (entry != null) {
047: IPluginModelBase[] models = entry.getWorkspaceModels();
048: for (int i = 0; i < models.length; i++) {
049: map.put(models[i], token.substring(index + 1));
050: }
051: }
052: }
053:
054: if (configuration.getAttribute(
055: IPDELauncherConstants.AUTOMATIC_ADD, true)) {
056: Set deselectedPlugins = LaunchPluginValidator.parsePlugins(
057: configuration,
058: IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS);
059: IPluginModelBase[] models = PluginRegistry
060: .getWorkspaceModels();
061: for (int i = 0; i < models.length; i++) {
062: String id = models[i].getPluginBase().getId();
063: if (id == null)
064: continue;
065: if (!deselectedPlugins.contains(id)) {
066: if (set != null)
067: set.add(id);
068: if (!map.containsKey(models[i])) {
069: map.put(models[i], "default:default"); //$NON-NLS-1$
070: }
071: }
072: }
073: }
074: return map;
075: }
076:
077: public static IPluginModelBase[] getWorkspaceBundles(
078: ILaunchConfiguration configuration) throws CoreException {
079: Map map = getWorkspaceBundleMap(configuration);
080: return (IPluginModelBase[]) map.keySet().toArray(
081: new IPluginModelBase[map.size()]);
082: }
083:
084: public static Map getTargetBundleMap(
085: ILaunchConfiguration configuration) throws CoreException {
086: return getTargetBundleMap(configuration, new HashSet());
087: }
088:
089: public static Map getTargetBundleMap(
090: ILaunchConfiguration configuration, Set set)
091: throws CoreException {
092: String selected = configuration.getAttribute(
093: IPDELauncherConstants.TARGET_BUNDLES, ""); //$NON-NLS-1$
094: Map map = new HashMap();
095: StringTokenizer tok = new StringTokenizer(selected, ","); //$NON-NLS-1$
096: while (tok.hasMoreTokens()) {
097: String token = tok.nextToken();
098: int index = token.indexOf('@');
099: String id = token.substring(0, index);
100: if (set.contains(id))
101: continue;
102: ModelEntry entry = PluginRegistry.findEntry(id);
103: if (entry != null) {
104: IPluginModelBase[] models = entry.getExternalModels();
105: for (int i = 0; i < models.length; i++) {
106: map.put(models[i], token.substring(index + 1));
107: }
108: }
109: }
110: return map;
111: }
112:
113: public static IPluginModelBase[] getTargetBundles(
114: ILaunchConfiguration configuration) throws CoreException {
115: Map map = getTargetBundleMap(configuration);
116: return (IPluginModelBase[]) map.keySet().toArray(
117: new IPluginModelBase[map.size()]);
118: }
119:
120: public static Map getMergedMap(ILaunchConfiguration configuration)
121: throws CoreException {
122: Set set = new HashSet();
123: Map map = getWorkspaceBundleMap(configuration, set);
124: map.putAll(getTargetBundleMap(configuration, set));
125: return map;
126: }
127:
128: public static IPluginModelBase[] getMergedBundles(
129: ILaunchConfiguration configuration) throws CoreException {
130: Map map = getMergedMap(configuration);
131: return (IPluginModelBase[]) map.keySet().toArray(
132: new IPluginModelBase[map.size()]);
133: }
134:
135: }
|