Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 123596 Details for
Bug 256910
target platform: the next wave
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
creates initial targets
more-target-work.patch (text/plain), 102.89 KB, created by
Darin Wright
on 2009-01-23 16:42:01 EST
(
hide
)
Description:
creates initial targets
Filename:
MIME Type:
Creator:
Darin Wright
Created:
2009-01-23 16:42:01 EST
Size:
102.89 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.core >Index: src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java,v >retrieving revision 1.4 >diff -u -r1.4 ITargetPlatformService.java >--- src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java 19 Jan 2009 17:54:59 -0000 1.4 >+++ src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java 23 Jan 2009 21:40:56 -0000 >@@ -1,136 +1,147 @@ >-/******************************************************************************* >- * Copyright (c) 2008, 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.pde.internal.core.target.provisional; >- >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IProgressMonitor; >- >-/** >- * A service to manage target platform definitions available to the workspace. >- * >- * @since 3.5 >- */ >-public interface ITargetPlatformService { >- >- /** >- * Returns handles to all target definitions known in the workspace. >- * >- * @return handles to all target definitions known in the workspace >- */ >- public ITargetHandle[] getTargets(IProgressMonitor monitor); >- >- /** >- * Returns a handle to a target definition backed by the underlying file. >- * The target definition may or may not exist. If the file does not exist >- * then this is a new target definition which becomes one of the known >- * workspace target definitions when it is saved. >- * >- * @param file target definition file that may or may not exist >- * @return target handle >- */ >- public ITargetHandle getTarget(IFile file); >- >- /** >- * Returns a new target definition to be stored with local metadata. The target >- * becomes one of the known workspace target definitions when it is saved. >- * >- * @return new empty target definition >- */ >- public ITargetDefinition newTarget(); >- >- /** >- * Persists the given target definition. The target becomes one of known >- * workspace target definitions when it is saved. >- * <p> >- * The target is persisted in a location determined by its handle. A handle >- * may refer to an {@link IFile} or a workspace metadata location. Any existing >- * target definition at the same location is overwritten. >- * </p> >- * @param definition definition to persist >- * @throws CoreException if unable to persist the definition >- */ >- public void saveTargetDefinition(ITargetDefinition definition) throws CoreException; >- >- /** >- * Deletes the target definition associated with the given handle. >- * >- * @param handle target handle >- * @throws CoreException if the associated target does not exist or deletion fails >- */ >- public void deleteTarget(ITargetHandle handle) throws CoreException; >- >- /** >- * Creates and returns a target handle from the given memento. The memento must >- * have been generated from {@link ITargetHandle#getMemento()}. >- * >- * @param memento a target handle memento >- * @return target handle >- * @throws CoreException if the target handle format is invalid >- */ >- public ITargetHandle getTarget(String memento) throws CoreException; >- >- /** >- * Creates and returns a bundle container that contains all bundles in the >- * specified directory which may contain string substitution variables. >- * >- * @param path absolute path in the local file system, may contain string variables >- * @return bundle container >- */ >- public IBundleContainer newDirectoryContainer(String path); >- >- /** >- * Creates and returns a bundle container that contains all bundles installed in >- * a profile at the specified location with the specified configuration area. If >- * a configuration area is not specified the default location is used. The specified >- * home location and configuration location may contain string substitution variables. >- * >- * @param home absolute path in the local file system to the root of an installed profile >- * which may contain string substitution variables >- * @param configurationLocation absolute path in the local file system to the >- * configuration area for the specified installation which may contain string substitution >- * variables or <code>null</code> to use the default location >- * @return bundle container >- */ >- public IBundleContainer newProfileContainer(String home, String configurationLocation); >- >- /** >- * Creates and returns a bundle container that contains all bundles referenced by >- * the feature at the specified location. The location is the directory that defines >- * the feature. >- * >- * @param home installation location containing a features directory which may contain >- * string substitution variables >- * @param featureId feature symbolic name >- * @param version feature version identifier or <code>null</code> to use most recent available >- * @return bundle container >- */ >- public IBundleContainer newFeatureContainer(String home, String featureId, String version); >- >- /** >- * Returns a handle to the target definition that corresponds to the active target platform >- * or <code>null</code> if none. >- * >- * @return handle to workspace target platform or <code>null</code> if none >- * @exception CoreException if an error occurs generating the handle >- */ >- public ITargetHandle getWorkspaceTargetHandle() throws CoreException; >- >- /** >- * Copies all attributes from one target definition to another. >- * >- * @param from attributes are copied from this definition >- * @param to attributes are copied to this definition >- * @throws CoreException in copy fails >- */ >- public void copyTargetDefinition(ITargetDefinition from, ITargetDefinition to) throws CoreException; >- >-} >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.core.target.provisional; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+ >+/** >+ * A service to manage target platform definitions available to the workspace. >+ * >+ * @since 3.5 >+ */ >+public interface ITargetPlatformService { >+ >+ /** >+ * Returns handles to all target definitions known in the workspace. >+ * >+ * @return handles to all target definitions known in the workspace >+ */ >+ public ITargetHandle[] getTargets(IProgressMonitor monitor); >+ >+ /** >+ * Returns a handle to a target definition backed by the underlying file. >+ * The target definition may or may not exist. If the file does not exist >+ * then this is a new target definition which becomes one of the known >+ * workspace target definitions when it is saved. >+ * >+ * @param file target definition file that may or may not exist >+ * @return target handle >+ */ >+ public ITargetHandle getTarget(IFile file); >+ >+ /** >+ * Returns a new target definition to be stored with local metadata. The target >+ * becomes one of the known workspace target definitions when it is saved. >+ * >+ * @return new empty target definition >+ */ >+ public ITargetDefinition newTarget(); >+ >+ /** >+ * Persists the given target definition. The target becomes one of known >+ * workspace target definitions when it is saved. >+ * <p> >+ * The target is persisted in a location determined by its handle. A handle >+ * may refer to an {@link IFile} or a workspace metadata location. Any existing >+ * target definition at the same location is overwritten. >+ * </p> >+ * @param definition definition to persist >+ * @throws CoreException if unable to persist the definition >+ */ >+ public void saveTargetDefinition(ITargetDefinition definition) throws CoreException; >+ >+ /** >+ * Deletes the target definition associated with the given handle. >+ * >+ * @param handle target handle >+ * @throws CoreException if the associated target does not exist or deletion fails >+ */ >+ public void deleteTarget(ITargetHandle handle) throws CoreException; >+ >+ /** >+ * Creates and returns a target handle from the given memento. The memento must >+ * have been generated from {@link ITargetHandle#getMemento()}. >+ * >+ * @param memento a target handle memento >+ * @return target handle >+ * @throws CoreException if the target handle format is invalid >+ */ >+ public ITargetHandle getTarget(String memento) throws CoreException; >+ >+ /** >+ * Creates and returns a bundle container that contains all bundles in the >+ * specified directory which may contain string substitution variables. >+ * >+ * @param path absolute path in the local file system, may contain string variables >+ * @return bundle container >+ */ >+ public IBundleContainer newDirectoryContainer(String path); >+ >+ /** >+ * Creates and returns a bundle container that contains all bundles installed in >+ * a profile at the specified location with the specified configuration area. If >+ * a configuration area is not specified the default location is used. The specified >+ * home location and configuration location may contain string substitution variables. >+ * >+ * @param home absolute path in the local file system to the root of an installed profile >+ * which may contain string substitution variables >+ * @param configurationLocation absolute path in the local file system to the >+ * configuration area for the specified installation which may contain string substitution >+ * variables or <code>null</code> to use the default location >+ * @return bundle container >+ */ >+ public IBundleContainer newProfileContainer(String home, String configurationLocation); >+ >+ /** >+ * Creates and returns a bundle container that contains all bundles referenced by >+ * the feature at the specified location. The location is the directory that defines >+ * the feature. >+ * >+ * @param home installation location containing a features directory which may contain >+ * string substitution variables >+ * @param featureId feature symbolic name >+ * @param version feature version identifier or <code>null</code> to use most recent available >+ * @return bundle container >+ */ >+ public IBundleContainer newFeatureContainer(String home, String featureId, String version); >+ >+ /** >+ * Returns a handle to the target definition that corresponds to the active target platform >+ * or <code>null</code> if none. >+ * >+ * @return handle to workspace target platform or <code>null</code> if none >+ * @exception CoreException if an error occurs generating the handle >+ */ >+ public ITargetHandle getWorkspaceTargetHandle() throws CoreException; >+ >+ /** >+ * Copies all attributes from one target definition to another. >+ * >+ * @param from attributes are copied from this definition >+ * @param to attributes are copied to this definition >+ * @throws CoreException in copy fails >+ */ >+ public void copyTargetDefinition(ITargetDefinition from, ITargetDefinition to) throws CoreException; >+ >+ /** >+ * Sets the content of the given target definition based on the target file supplied >+ * by an <code>org.eclipse.pde.core.targets</code> extension with the specified identifier. >+ * >+ * @param definition target definition to load >+ * @param targetExtensionId identifier of a targets extension >+ * @throws CoreException if the extension is not found or an error occurs reading the target >+ * file or loading the target definition >+ */ >+ public void loadTargetDefinition(ITargetDefinition definition, String targetExtensionId) throws CoreException; >+ >+} >Index: src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java,v >retrieving revision 1.5 >diff -u -r1.5 LoadTargetDefinitionJob.java >--- src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java 21 Jan 2009 20:40:14 -0000 1.5 >+++ src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java 23 Jan 2009 21:40:56 -0000 >@@ -1,327 +1,379 @@ >-/******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.pde.internal.core.target.provisional; >- >-import java.io.File; >-import java.net.MalformedURLException; >-import java.net.URL; >-import java.util.*; >-import org.eclipse.core.resources.WorkspaceJob; >-import org.eclipse.core.runtime.*; >-import org.eclipse.core.runtime.jobs.Job; >-import org.eclipse.core.variables.IStringVariableManager; >-import org.eclipse.core.variables.VariablesPlugin; >-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >-import org.eclipse.jdt.launching.IVMInstall; >-import org.eclipse.jdt.launching.JavaRuntime; >-import org.eclipse.pde.core.plugin.IPluginModelBase; >-import org.eclipse.pde.core.plugin.TargetPlatform; >-import org.eclipse.pde.internal.core.*; >-import org.eclipse.pde.internal.core.target.impl.*; >- >-/** >- * Sets the current target platform based on a target definition. >- * >- * @since 3.5 >- */ >-public class LoadTargetDefinitionJob extends WorkspaceJob { >- >- /** >- * Target definition being loaded >- */ >- private ITargetDefinition fTarget; >- >- /** >- * Whether a target definition was specified >- */ >- private boolean fNone = false; >- >- /** >- * Constructs a new operation to load the specified target definition >- * as the current target platform. When <code>null</code> is specified >- * the target platform is empty and all other settings are default. >- * >- * @param target target definition or <code>null</code> if none >- */ >- public LoadTargetDefinitionJob(ITargetDefinition target) { >- super(Messages.LoadTargetDefinitionJob_0); >- fTarget = target; >- if (target == null) { >- fNone = true; >- ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); >- fTarget = service.newTarget(); >- } >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor) >- */ >- public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { >- try { >- Preferences preferences = PDECore.getDefault().getPluginPreferences(); >- monitor.beginTask(Messages.LoadTargetOperation_mainTaskName, 100); >- loadEnvironment(preferences, new SubProgressMonitor(monitor, 5)); >- loadArgs(preferences, new SubProgressMonitor(monitor, 5)); >- loadJRE(preferences, new SubProgressMonitor(monitor, 15)); >- loadImplicitPlugins(preferences, new SubProgressMonitor(monitor, 15)); >- loadPlugins(preferences, new SubProgressMonitor(monitor, 60)); >- loadAdditionalPreferences(preferences); >- PDECore.getDefault().savePluginPreferences(); >- } finally { >- monitor.done(); >- } >- return Status.OK_STATUS; >- } >- >- /** >- * Configures program and VM argument preferences based on the target >- * definition. >- * >- * @param pref preference store >- * @param monitor progress monitor >- */ >- private void loadArgs(Preferences pref, IProgressMonitor monitor) { >- monitor.beginTask(Messages.LoadTargetOperation_argsTaskName, 2); >- String args = fTarget.getProgramArguments(); >- pref.setValue(ICoreConstants.PROGRAM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$ >- monitor.worked(1); >- args = fTarget.getVMArguments(); >- pref.setValue(ICoreConstants.VM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$ >- monitor.done(); >- } >- >- /** >- * Configures the environment preferences from the target definition. >- * >- * @param pref preference store >- * @param monitor progress monitor >- */ >- private void loadEnvironment(Preferences pref, IProgressMonitor monitor) { >- monitor.beginTask(Messages.LoadTargetOperation_envTaskName, 1); >- setEnvironmentPref(pref, ICoreConstants.ARCH, fTarget.getArch()); >- setEnvironmentPref(pref, ICoreConstants.NL, fTarget.getNL()); >- setEnvironmentPref(pref, ICoreConstants.OS, fTarget.getOS()); >- setEnvironmentPref(pref, ICoreConstants.WS, fTarget.getWS()); >- monitor.done(); >- } >- >- /** >- * Sets the given preference to default when <code>null</code> or the >- * specified value. >- * >- * @param pref preference store >- * @param key preference key >- * @param value preference value or <code>null</code> >- */ >- private void setEnvironmentPref(Preferences pref, String key, String value) { >- if (value == null) { >- pref.setToDefault(key); >- } else { >- pref.setValue(key, value); >- } >- } >- >- /** >- * Sets the workspace default JRE based on the target's JRE container. >- * >- * @param pref >- * @param monitor >- */ >- private void loadJRE(Preferences pref, IProgressMonitor monitor) { >- IPath container = fTarget.getJREContainer(); >- monitor.beginTask(Messages.LoadTargetOperation_jreTaskName, 1); >- if (container != null) { >- IVMInstall jre = JavaRuntime.getVMInstall(container); >- if (jre != null) { >- IVMInstall def = JavaRuntime.getDefaultVMInstall(); >- if (!jre.equals(def)) { >- try { >- JavaRuntime.setDefaultVMInstall(jre, null); >- } catch (CoreException e) { >- } >- } >- } >- } >- monitor.done(); >- } >- >- /** >- * Sets implicit dependencies, if any >- * >- * @param pref preference store >- * @param monitor progress monitor >- */ >- private void loadImplicitPlugins(Preferences pref, IProgressMonitor monitor) { >- BundleInfo[] infos = fTarget.getImplicitDependencies(); >- if (infos != null) { >- monitor.beginTask(Messages.LoadTargetOperation_implicitPluginsTaskName, infos.length + 1); >- StringBuffer buffer = new StringBuffer(); >- for (int i = 0; i < infos.length; i++) { >- buffer.append(infos[i].getSymbolicName()).append(','); >- monitor.worked(1); >- } >- if (infos.length > 0) >- buffer.setLength(buffer.length() - 1); >- pref.setValue(ICoreConstants.IMPLICIT_DEPENDENCIES, buffer.toString()); >- } >- monitor.done(); >- } >- >- /** >- * Resolves the bundles in the target platform and sets them in the corresponding >- * CHECKED_PLUGINS preference. Sets home and addition location preferences as well. >- * >- * @param pref >- * @param monitor >- * @throws CoreException >- */ >- private void loadPlugins(Preferences pref, IProgressMonitor monitor) throws CoreException { >- monitor.beginTask(Messages.LoadTargetOperation_loadPluginsTaskName, 100); >- String currentPath = pref.getString(ICoreConstants.PLATFORM_PATH); >- IBundleContainer[] containers = fTarget.getBundleContainers(); >- // the first container is assumed to be the primary/home location >- String path = null; >- if (containers != null && containers.length > 0) { >- path = ((AbstractBundleContainer) containers[0]).getLocation(true); >- } >- if (path == null) { >- path = TargetPlatform.getDefaultLocation(); >- } else { >- try { >- IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); >- path = manager.performStringSubstitution(path); >- } catch (CoreException e) { >- return; >- } >- } >- monitor.worked(10); >- List additional = getAdditionalLocs(); >- handleReload(path, additional, pref, new SubProgressMonitor(monitor, 85)); >- >- // update preferences (Note: some preferences updated in handleReload()) >- pref.setValue(ICoreConstants.PLATFORM_PATH, path); >- String mode = new Path(path).equals(new Path(TargetPlatform.getDefaultLocation())) ? ICoreConstants.VALUE_USE_THIS : ICoreConstants.VALUE_USE_OTHER; >- pref.setValue(ICoreConstants.TARGET_MODE, mode); >- >- ListIterator li = additional.listIterator(); >- StringBuffer buffer = new StringBuffer(); >- while (li.hasNext()) >- buffer.append(li.next()).append(","); //$NON-NLS-1$ >- if (buffer.length() > 0) >- buffer.setLength(buffer.length() - 1); >- pref.setValue(ICoreConstants.ADDITIONAL_LOCATIONS, buffer.toString()); >- >- String newValue = currentPath; >- for (int i = 0; i < 4; i++) { >- String value = pref.getString(ICoreConstants.SAVED_PLATFORM + i); >- pref.setValue(ICoreConstants.SAVED_PLATFORM + i, newValue); >- if (!value.equals(currentPath)) >- newValue = value; >- else >- break; >- } >- monitor.done(); >- } >- >- /** >- * Sets the TARGET_PROFILE preference which stores the ID of the target profile used >- * (if based on an target extension) or the workspace location of the file that >- * was used. For now we just clear it. >- * <p> >- * Sets the WORKSPACE_TARGET_HANDLE. >- * </p> >- * @param pref >- */ >- private void loadAdditionalPreferences(Preferences pref) throws CoreException { >- pref.setValue(ICoreConstants.TARGET_PROFILE, ""); //$NON-NLS-1$ >- String memento = fTarget.getHandle().getMemento(); >- if (fNone) { >- memento = ""; //$NON-NLS-1$ >- } >- pref.setValue(ICoreConstants.WORKSPACE_TARGET_HANDLE, memento); >- IBundleContainer[] containers = fTarget.getBundleContainers(); >- boolean profile = false; >- if (containers.length > 0) { >- profile = containers[0] instanceof ProfileBundleContainer; >- } >- pref.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, profile); >- } >- >- /** >- * Returns a list of additional locations of bundles. >- * >- * @return additional bundle locations >- */ >- private List getAdditionalLocs() throws CoreException { >- ArrayList additional = new ArrayList(); >- // secondary containers are considered additional >- IBundleContainer[] containers = fTarget.getBundleContainers(); >- if (containers != null && containers.length > 1) { >- for (int i = 1; i < containers.length; i++) { >- additional.add(((AbstractBundleContainer) containers[i]).getLocation(true)); >- } >- } >- return additional; >- } >- >- private void handleReload(String targetLocation, List additionalLocations, Preferences pref, IProgressMonitor monitor) throws CoreException { >- monitor.beginTask(Messages.LoadTargetOperation_reloadTaskName, 85); >- >- List infos = new ArrayList(); >- BundleInfo[] code = fTarget.resolveBundles(null); >- for (int i = 0; i < code.length; i++) { >- infos.add(code[i]); >- } >- // to be consistent with previous implementation, add source bundles >- BundleInfo[] sourceBundles = fTarget.resolveSourceBundles(null); >- for (int i = 0; i < sourceBundles.length; i++) { >- infos.add(sourceBundles[i]); >- } >- BundleInfo[] bundles = (BundleInfo[]) infos.toArray(new BundleInfo[infos.size()]); >- // generate URLs and save CHECKED_PLUGINS >- StringBuffer checked = new StringBuffer(); >- >- URL[] paths = new URL[bundles.length]; >- for (int i = 0; i < paths.length; i++) { >- try { >- paths[i] = new File(bundles[i].getLocation()).toURL(); >- if (i > 0) { >- checked.append(" "); //$NON-NLS-1$ >- } >- checked.append(bundles[i].getSymbolicName()); >- } catch (MalformedURLException e) { >- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.LoadTargetDefinitionJob_1, e)); >- } >- } >- >- PDEState state = new PDEState(paths, true, new SubProgressMonitor(monitor, 45)); >- IPluginModelBase[] models = state.getTargetModels(); >- for (int i = 0; i < models.length; i++) { >- models[i].setEnabled(true); >- } >- // save CHECKED_PLUGINS >- if (paths.length == 0) { >- pref.setValue(ICoreConstants.CHECKED_PLUGINS, ICoreConstants.VALUE_SAVED_NONE); >- } else { >- pref.setValue(ICoreConstants.CHECKED_PLUGINS, checked.toString()); >- } >- >- Job job = new TargetPlatformResetJob(state); >- job.schedule(); >- try { >- job.join(); >- } catch (InterruptedException e) { >- // TODO Auto-generated catch block >- } >- monitor.done(); >- } >- >-} >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.core.target.provisional; >+ >+import java.io.File; >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.util.*; >+import org.eclipse.core.resources.WorkspaceJob; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.core.variables.IStringVariableManager; >+import org.eclipse.core.variables.VariablesPlugin; >+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >+import org.eclipse.jdt.launching.IVMInstall; >+import org.eclipse.jdt.launching.JavaRuntime; >+import org.eclipse.pde.core.plugin.IPluginModelBase; >+import org.eclipse.pde.core.plugin.TargetPlatform; >+import org.eclipse.pde.internal.core.*; >+import org.eclipse.pde.internal.core.target.impl.*; >+ >+/** >+ * Sets the current target platform based on a target definition. >+ * >+ * @since 3.5 >+ */ >+public class LoadTargetDefinitionJob extends WorkspaceJob { >+ >+ /** >+ * Target definition being loaded >+ */ >+ private ITargetDefinition fTarget; >+ >+ /** >+ * Whether a target definition was specified >+ */ >+ private boolean fNone = false; >+ >+ /** >+ * Constructs a new operation to load the specified target definition >+ * as the current target platform. When <code>null</code> is specified >+ * the target platform is empty and all other settings are default. >+ * >+ * @param target target definition or <code>null</code> if none >+ */ >+ public LoadTargetDefinitionJob(ITargetDefinition target) { >+ super(Messages.LoadTargetDefinitionJob_0); >+ fTarget = target; >+ if (target == null) { >+ fNone = true; >+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); >+ fTarget = service.newTarget(); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { >+ try { >+ Preferences preferences = PDECore.getDefault().getPluginPreferences(); >+ monitor.beginTask(Messages.LoadTargetOperation_mainTaskName, 100); >+ loadEnvironment(preferences, new SubProgressMonitor(monitor, 5)); >+ loadArgs(preferences, new SubProgressMonitor(monitor, 5)); >+ loadJRE(preferences, new SubProgressMonitor(monitor, 15)); >+ loadImplicitPlugins(preferences, new SubProgressMonitor(monitor, 15)); >+ loadPlugins(preferences, new SubProgressMonitor(monitor, 60)); >+ loadAdditionalPreferences(preferences); >+ PDECore.getDefault().savePluginPreferences(); >+ } finally { >+ monitor.done(); >+ } >+ return Status.OK_STATUS; >+ } >+ >+ /** >+ * Configures program and VM argument preferences based on the target >+ * definition. >+ * >+ * @param pref preference store >+ * @param monitor progress monitor >+ */ >+ private void loadArgs(Preferences pref, IProgressMonitor monitor) { >+ monitor.beginTask(Messages.LoadTargetOperation_argsTaskName, 2); >+ String args = fTarget.getProgramArguments(); >+ pref.setValue(ICoreConstants.PROGRAM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$ >+ monitor.worked(1); >+ args = fTarget.getVMArguments(); >+ pref.setValue(ICoreConstants.VM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$ >+ monitor.done(); >+ } >+ >+ /** >+ * Configures the environment preferences from the target definition. >+ * >+ * @param pref preference store >+ * @param monitor progress monitor >+ */ >+ private void loadEnvironment(Preferences pref, IProgressMonitor monitor) { >+ monitor.beginTask(Messages.LoadTargetOperation_envTaskName, 1); >+ setEnvironmentPref(pref, ICoreConstants.ARCH, fTarget.getArch()); >+ setEnvironmentPref(pref, ICoreConstants.NL, fTarget.getNL()); >+ setEnvironmentPref(pref, ICoreConstants.OS, fTarget.getOS()); >+ setEnvironmentPref(pref, ICoreConstants.WS, fTarget.getWS()); >+ monitor.done(); >+ } >+ >+ /** >+ * Sets the given preference to default when <code>null</code> or the >+ * specified value. >+ * >+ * @param pref preference store >+ * @param key preference key >+ * @param value preference value or <code>null</code> >+ */ >+ private void setEnvironmentPref(Preferences pref, String key, String value) { >+ if (value == null) { >+ pref.setToDefault(key); >+ } else { >+ pref.setValue(key, value); >+ } >+ } >+ >+ /** >+ * Sets the workspace default JRE based on the target's JRE container. >+ * >+ * @param pref >+ * @param monitor >+ */ >+ private void loadJRE(Preferences pref, IProgressMonitor monitor) { >+ IPath container = fTarget.getJREContainer(); >+ monitor.beginTask(Messages.LoadTargetOperation_jreTaskName, 1); >+ if (container != null) { >+ IVMInstall jre = JavaRuntime.getVMInstall(container); >+ if (jre != null) { >+ IVMInstall def = JavaRuntime.getDefaultVMInstall(); >+ if (!jre.equals(def)) { >+ try { >+ JavaRuntime.setDefaultVMInstall(jre, null); >+ } catch (CoreException e) { >+ } >+ } >+ } >+ } >+ monitor.done(); >+ } >+ >+ /** >+ * Sets implicit dependencies, if any >+ * >+ * @param pref preference store >+ * @param monitor progress monitor >+ */ >+ private void loadImplicitPlugins(Preferences pref, IProgressMonitor monitor) { >+ BundleInfo[] infos = fTarget.getImplicitDependencies(); >+ if (infos != null) { >+ monitor.beginTask(Messages.LoadTargetOperation_implicitPluginsTaskName, infos.length + 1); >+ StringBuffer buffer = new StringBuffer(); >+ for (int i = 0; i < infos.length; i++) { >+ buffer.append(infos[i].getSymbolicName()).append(','); >+ monitor.worked(1); >+ } >+ if (infos.length > 0) >+ buffer.setLength(buffer.length() - 1); >+ pref.setValue(ICoreConstants.IMPLICIT_DEPENDENCIES, buffer.toString()); >+ } >+ monitor.done(); >+ } >+ >+ /** >+ * Resolves the bundles in the target platform and sets them in the corresponding >+ * CHECKED_PLUGINS preference. Sets home and addition location preferences as well. >+ * >+ * @param pref >+ * @param monitor >+ * @throws CoreException >+ */ >+ private void loadPlugins(Preferences pref, IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask(Messages.LoadTargetOperation_loadPluginsTaskName, 100); >+ String currentPath = pref.getString(ICoreConstants.PLATFORM_PATH); >+ IBundleContainer[] containers = fTarget.getBundleContainers(); >+ // the first container is assumed to be the primary/home location >+ String path = null; >+ if (containers != null && containers.length > 0) { >+ path = ((AbstractBundleContainer) containers[0]).getLocation(true); >+ } >+ if (path == null) { >+ path = TargetPlatform.getDefaultLocation(); >+ } else { >+ try { >+ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); >+ path = manager.performStringSubstitution(path); >+ } catch (CoreException e) { >+ return; >+ } >+ } >+ monitor.worked(10); >+ List additional = getAdditionalLocs(); >+ handleReload(path, additional, pref, new SubProgressMonitor(monitor, 85)); >+ >+ // update preferences (Note: some preferences updated in handleReload()) >+ pref.setValue(ICoreConstants.PLATFORM_PATH, path); >+ String mode = new Path(path).equals(new Path(TargetPlatform.getDefaultLocation())) ? ICoreConstants.VALUE_USE_THIS : ICoreConstants.VALUE_USE_OTHER; >+ pref.setValue(ICoreConstants.TARGET_MODE, mode); >+ >+ ListIterator li = additional.listIterator(); >+ StringBuffer buffer = new StringBuffer(); >+ while (li.hasNext()) >+ buffer.append(li.next()).append(","); //$NON-NLS-1$ >+ if (buffer.length() > 0) >+ buffer.setLength(buffer.length() - 1); >+ pref.setValue(ICoreConstants.ADDITIONAL_LOCATIONS, buffer.toString()); >+ >+ String newValue = currentPath; >+ for (int i = 0; i < 4; i++) { >+ String value = pref.getString(ICoreConstants.SAVED_PLATFORM + i); >+ pref.setValue(ICoreConstants.SAVED_PLATFORM + i, newValue); >+ if (!value.equals(currentPath)) >+ newValue = value; >+ else >+ break; >+ } >+ monitor.done(); >+ } >+ >+ /** >+ * Sets the TARGET_PROFILE preference which stores the ID of the target profile used >+ * (if based on an target extension) or the workspace location of the file that >+ * was used. For now we just clear it. >+ * <p> >+ * Sets the WORKSPACE_TARGET_HANDLE. >+ * </p> >+ * @param pref >+ */ >+ private void loadAdditionalPreferences(Preferences pref) throws CoreException { >+ pref.setValue(ICoreConstants.TARGET_PROFILE, ""); //$NON-NLS-1$ >+ String memento = fTarget.getHandle().getMemento(); >+ if (fNone) { >+ memento = ""; //$NON-NLS-1$ >+ } >+ pref.setValue(ICoreConstants.WORKSPACE_TARGET_HANDLE, memento); >+ IBundleContainer[] containers = fTarget.getBundleContainers(); >+ boolean profile = false; >+ if (containers != null && containers.length > 0) { >+ profile = containers[0] instanceof ProfileBundleContainer; >+ } >+ pref.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, profile); >+ } >+ >+ /** >+ * Returns a list of additional locations of bundles. >+ * >+ * @return additional bundle locations >+ */ >+ private List getAdditionalLocs() throws CoreException { >+ ArrayList additional = new ArrayList(); >+ // secondary containers are considered additional >+ IBundleContainer[] containers = fTarget.getBundleContainers(); >+ if (containers != null && containers.length > 1) { >+ for (int i = 1; i < containers.length; i++) { >+ additional.add(((AbstractBundleContainer) containers[i]).getLocation(true)); >+ } >+ } >+ return additional; >+ } >+ >+ private void handleReload(String targetLocation, List additionalLocations, Preferences pref, IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask(Messages.LoadTargetOperation_reloadTaskName, 85); >+ >+ Set included = new HashSet(); >+ List infos = new ArrayList(); >+ BundleInfo[] code = fTarget.resolveBundles(null); >+ for (int i = 0; i < code.length; i++) { >+ infos.add(code[i]); >+ included.add(code[i]); >+ } >+ // to be consistent with previous implementation, add source bundles >+ BundleInfo[] sourceBundles = fTarget.resolveSourceBundles(null); >+ for (int i = 0; i < sourceBundles.length; i++) { >+ infos.add(sourceBundles[i]); >+ included.add(sourceBundles[i]); >+ } >+ >+ // Compute missing bundles >+ List missing = new ArrayList(); >+ IBundleContainer[] containers = fTarget.getBundleContainers(); >+ if (containers != null) { >+ for (int i = 0; i < containers.length; i++) { >+ IBundleContainer container = containers[i]; >+ BundleInfo[] restrictions = container.getRestrictions(); >+ if (restrictions != null) { >+ try { >+ container.setRestrictions(null); >+ BundleInfo[] all = container.resolveBundles(null); >+ for (int j = 0; j < all.length; j++) { >+ BundleInfo bi = all[j]; >+ if (!included.contains(bi)) { >+ missing.add(bi); >+ } >+ } >+ all = container.resolveSourceBundles(null); >+ for (int j = 0; j < all.length; j++) { >+ BundleInfo bi = all[j]; >+ if (!included.contains(bi)) { >+ missing.add(bi); >+ } >+ } >+ } finally { >+ container.setRestrictions(restrictions); >+ } >+ } >+ } >+ } >+ >+ List paths = new ArrayList(infos.size() + missing.size()); >+ Iterator iterator = infos.iterator(); >+ while (iterator.hasNext()) { >+ BundleInfo info = (BundleInfo) iterator.next(); >+ try { >+ paths.add(new File(info.getLocation()).toURL()); >+ } catch (MalformedURLException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.LoadTargetDefinitionJob_1, e)); >+ } >+ } >+ >+ // generate URLs and save CHECKED_PLUGINS (which are missing), and add to master list of paths >+ StringBuffer checked = new StringBuffer(); >+ int i = 0; >+ iterator = missing.iterator(); >+ Set missingIds = new HashSet(missing.size()); >+ while (iterator.hasNext()) { >+ BundleInfo bi = (BundleInfo) iterator.next(); >+ missingIds.add(bi.getSymbolicName()); >+ try { >+ paths.add(new File(bi.getLocation()).toURL()); >+ } catch (MalformedURLException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.LoadTargetDefinitionJob_1, e)); >+ } >+ if (i > 0) { >+ checked.append(" "); //$NON-NLS-1$ >+ } >+ checked.append(bi.getSymbolicName()); >+ i++; >+ } >+ >+ URL[] urls = (URL[]) paths.toArray(new URL[paths.size()]); >+ PDEState state = new PDEState(urls, true, new SubProgressMonitor(monitor, 45)); >+ IPluginModelBase[] models = state.getTargetModels(); >+ for (i = 0; i < models.length; i++) { >+ models[i].setEnabled(!missingIds.contains(models[i].getPluginBase().getId())); >+ } >+ // save CHECKED_PLUGINS >+ if (urls.length == 0) { >+ pref.setValue(ICoreConstants.CHECKED_PLUGINS, ICoreConstants.VALUE_SAVED_NONE); >+ } else if (missing.size() == 0) { >+ pref.setValue(ICoreConstants.CHECKED_PLUGINS, ICoreConstants.VALUE_SAVED_ALL); >+ } else { >+ pref.setValue(ICoreConstants.CHECKED_PLUGINS, checked.toString()); >+ } >+ >+ Job job = new TargetPlatformResetJob(state); >+ job.schedule(); >+ try { >+ job.join(); >+ } catch (InterruptedException e) { >+ // TODO Auto-generated catch block >+ } >+ monitor.done(); >+ } >+ >+} >Index: src/org/eclipse/pde/internal/core/PluginModelManager.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java,v >retrieving revision 1.123 >diff -u -r1.123 PluginModelManager.java >--- src/org/eclipse/pde/internal/core/PluginModelManager.java 13 Oct 2008 19:21:11 -0000 1.123 >+++ src/org/eclipse/pde/internal/core/PluginModelManager.java 23 Jan 2009 21:40:56 -0000 >@@ -14,14 +14,15 @@ > import java.util.*; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.*; > import org.eclipse.jdt.core.*; > import org.eclipse.osgi.service.resolver.*; > import org.eclipse.pde.core.*; > import org.eclipse.pde.core.build.IBuild; > import org.eclipse.pde.core.build.IBuildEntry; > import org.eclipse.pde.core.plugin.*; >+import org.eclipse.pde.internal.core.target.impl.*; >+import org.eclipse.pde.internal.core.target.provisional.*; > > public class PluginModelManager implements IModelProviderListener { > >@@ -420,6 +421,64 @@ > } > > fEntries = entries; >+ >+ // Create default target platform definition if required >+ initDefaultTargetPlatformDefinition(); >+ } >+ >+ /** >+ * Creates initial target platform definition in local metadata if not already created. >+ */ >+ private synchronized void initDefaultTargetPlatformDefinition() { >+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); >+ if (service != null) { >+ String memento = PDECore.getDefault().getPluginPreferences().getString(ICoreConstants.WORKSPACE_TARGET_HANDLE); >+ if (memento.equals("")) { //$NON-NLS-1$ >+ // no workspace target handle set, check for local targets >+ ITargetHandle[] targets = service.getTargets(null); >+ boolean local = false; >+ for (int i = 0; i < targets.length; i++) { >+ if (targets[i] instanceof LocalTargetHandle) { >+ local = true; >+ break; >+ } >+ } >+ if (!local) { >+ // no local targets, no workspace preference > create default target platform >+ ITargetDefinition def = null; >+ TargetPlatformService ts = (TargetPlatformService) service; >+ ITargetDefinition host = ts.newDefaultTargetDefinition(); >+ try { >+ service.saveTargetDefinition(host); >+ } catch (CoreException e) { >+ PDECore.log(e); >+ } >+ // create target platform from current workspace settings >+ TargetDefinition curr = (TargetDefinition) ts.newTarget(); >+ try { >+ ts.loadTargetDefinitionFromPreferences(curr); >+ if (curr.isContentEqual(host)) { >+ // current settings are the same as the default target platform >+ def = host; >+ } else { >+ // current settings are different than default >+ service.saveTargetDefinition(curr); >+ def = curr; >+ } >+ } catch (CoreException e) { >+ PDECore.log(e); >+ } >+ if (def != null) { >+ Preferences preferences = PDECore.getDefault().getPluginPreferences(); >+ try { >+ preferences.setValue(ICoreConstants.WORKSPACE_TARGET_HANDLE, def.getHandle().getMemento()); >+ } catch (CoreException e) { >+ PDECore.log(e); >+ } >+ } >+ } >+ } >+ } > } > > /** >Index: src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java,v >retrieving revision 1.7 >diff -u -r1.7 AbstractBundleContainer.java >--- src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java 23 Jan 2009 16:04:27 -0000 1.7 >+++ src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java 23 Jan 2009 21:40:56 -0000 >@@ -1,207 +1,208 @@ >-/******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.pde.internal.core.target.impl; >- >-import java.util.*; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.variables.IStringVariableManager; >-import org.eclipse.core.variables.VariablesPlugin; >-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >-import org.eclipse.pde.internal.core.target.provisional.IBundleContainer; >- >-/** >- * Common function for bundle containers. >- * >- * @since 3.5 >- */ >-public abstract class AbstractBundleContainer implements IBundleContainer { >- >- /** >- * Bundle restrictions (subset) this container is restricted to or <code>null</code> if >- * no restrictions. >- */ >- private BundleInfo[] fRestrictions; >- >- /** >- * Resolves any string substitution variables in the given text returning >- * the result. >- * >- * @param text text to resolve >- * @return result of the resolution >- * @throws CoreException if unable to resolve >- */ >- protected String resolveVariables(String text) throws CoreException { >- IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); >- return manager.performStringSubstitution(text); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor) >- */ >- public final BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException { >- BundleInfo[] all = resolveAllBundles(monitor); >- return getMatchingBundles(all, getRestrictions()); >- } >- >- /** >- * Resolves all executable bundles in this container regardless of any bundle restrictions. >- * <p> >- * Subclasses must implement this method. >- * </p> >- * @param monitor progress monitor >- * @return all executable bundles in this container regardless of any bundle restrictions >- * @throws CoreException if an error occurs >- */ >- protected abstract BundleInfo[] resolveAllBundles(IProgressMonitor monitor) throws CoreException; >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor) >- */ >- public final BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException { >- BundleInfo[] all = resolveAllSourceBundles(monitor); >- return getMatchingBundles(all, getRestrictions()); >- } >- >- /** >- * Resolves all source bundles in this container regardless of any bundle restrictions. >- * <p> >- * Subclasses must implement this method. >- * </p> >- * @param monitor progress monitor >- * @return all source bundles in this container regardless of any bundle restrictions >- * @throws CoreException if an error occurs >- */ >- protected abstract BundleInfo[] resolveAllSourceBundles(IProgressMonitor monitor) throws CoreException; >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getRestrictions() >- */ >- public BundleInfo[] getRestrictions() { >- return fRestrictions; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#setRestrictions(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo[]) >- */ >- public void setRestrictions(BundleInfo[] bundles) { >- fRestrictions = bundles; >- } >- >- /** >- * Returns bundles from the specified collection that match the symbolic names >- * and/or version in the specified criteria. When no version is specified >- * the newest version (if any) is selected. >- * >- * @param collection bundles to resolve against match criteria >- * @param criteria bundles to select or <code>null</code> if no restrictions >- * @return bundles that match this container's restrictions >- */ >- static BundleInfo[] getMatchingBundles(BundleInfo[] collection, BundleInfo[] criteria) { >- if (criteria == null) { >- return collection; >- } >- // map bundles names to available versions >- Map bundleMap = new HashMap(collection.length); >- for (int i = 0; i < collection.length; i++) { >- BundleInfo info = collection[i]; >- List list = (List) bundleMap.get(info.getSymbolicName()); >- if (list == null) { >- list = new ArrayList(3); >- bundleMap.put(info.getSymbolicName(), list); >- } >- list.add(info); >- } >- List subset = new ArrayList(criteria.length); >- for (int i = 0; i < criteria.length; i++) { >- BundleInfo info = criteria[i]; >- List list = (List) bundleMap.get(info.getSymbolicName()); >- if (list != null) { >- String version = info.getVersion(); >- if (version == null) { >- // select newest >- if (list.size() > 1) { >- // sort the list >- Collections.sort(list, new Comparator() { >- public int compare(Object o1, Object o2) { >- return ((BundleInfo) o1).getVersion().compareTo(((BundleInfo) o2).getVersion()); >- } >- }); >- } >- // select the last one >- subset.add(list.get(list.size() - 1)); >- } else { >- Iterator iterator = list.iterator(); >- boolean found = false; >- while (iterator.hasNext() && !found) { >- BundleInfo bundle = (BundleInfo) iterator.next(); >- if (bundle.getVersion().equals(version)) { >- subset.add(bundle); >- found = true; >- } >- } >- if (!found) { >- // TODO: report not found? exception? >- } >- } >- } else { >- // TODO: report not found? exception? >- } >- } >- return (BundleInfo[]) subset.toArray(new BundleInfo[subset.size()]); >- } >- >- /** >- * Returns a string that identifies the type of bundle container. This type is persisted to xml >- * so that the correct bundle container is created when deserializing the xml. This type is also >- * used to alter how the containers are presented to the user in the UI. >- * >- * @return string identifier for the type of bundle container. >- */ >- public abstract String getType(); >- >- /** >- * Returns a path in the local file system to the root of the bundle container. >- * <p> >- * TODO: Ideally we won't need this method. Currently the PDE target platform preferences are >- * based on a home location and additional locations, so we need the information. >- * </p> >- * @param resolve whether to resolve variables in the path >- * @return home location >- * @exception CoreException if unable to resolve the location >- */ >- public abstract String getLocation(boolean resolve) throws CoreException; >- >- /** >- * Returns whether restrictions are equivalent. Subclasses should override for other data. >- * >- * @param container bundle container >- * @return whether content is equivalent >- */ >- public boolean isContentEqual(AbstractBundleContainer container) { >- if (fRestrictions == null) { >- return container.fRestrictions == null; >- } >- if (container.fRestrictions == null) { >- return false; >- } >- if (fRestrictions.length == container.fRestrictions.length) { >- for (int i = 0; i < fRestrictions.length; i++) { >- if (!fRestrictions[i].equals(container.fRestrictions[i])) { >- return false; >- } >- } >- return true; >- } >- return false; >- } >- >-} >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.core.target.impl; >+ >+import java.util.*; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.variables.IStringVariableManager; >+import org.eclipse.core.variables.VariablesPlugin; >+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >+import org.eclipse.pde.internal.core.target.provisional.IBundleContainer; >+ >+/** >+ * Common function for bundle containers. >+ * >+ * @since 3.5 >+ */ >+public abstract class AbstractBundleContainer implements IBundleContainer { >+ >+ /** >+ * Bundle restrictions (subset) this container is restricted to or <code>null</code> if >+ * no restrictions. >+ */ >+ private BundleInfo[] fRestrictions; >+ >+ /** >+ * Resolves any string substitution variables in the given text returning >+ * the result. >+ * >+ * @param text text to resolve >+ * @return result of the resolution >+ * @throws CoreException if unable to resolve >+ */ >+ protected String resolveVariables(String text) throws CoreException { >+ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); >+ return manager.performStringSubstitution(text); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public final BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException { >+ BundleInfo[] all = resolveAllBundles(monitor); >+ return getMatchingBundles(all, getRestrictions()); >+ } >+ >+ /** >+ * Resolves all executable bundles in this container regardless of any bundle restrictions. >+ * <p> >+ * Subclasses must implement this method. >+ * </p> >+ * @param monitor progress monitor >+ * @return all executable bundles in this container regardless of any bundle restrictions >+ * @throws CoreException if an error occurs >+ */ >+ protected abstract BundleInfo[] resolveAllBundles(IProgressMonitor monitor) throws CoreException; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public final BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException { >+ BundleInfo[] all = resolveAllSourceBundles(monitor); >+ // for now, don't restrict source bundles >+ return all; >+ } >+ >+ /** >+ * Resolves all source bundles in this container regardless of any bundle restrictions. >+ * <p> >+ * Subclasses must implement this method. >+ * </p> >+ * @param monitor progress monitor >+ * @return all source bundles in this container regardless of any bundle restrictions >+ * @throws CoreException if an error occurs >+ */ >+ protected abstract BundleInfo[] resolveAllSourceBundles(IProgressMonitor monitor) throws CoreException; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getRestrictions() >+ */ >+ public BundleInfo[] getRestrictions() { >+ return fRestrictions; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#setRestrictions(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo[]) >+ */ >+ public void setRestrictions(BundleInfo[] bundles) { >+ fRestrictions = bundles; >+ } >+ >+ /** >+ * Returns bundles from the specified collection that match the symbolic names >+ * and/or version in the specified criteria. When no version is specified >+ * the newest version (if any) is selected. >+ * >+ * @param collection bundles to resolve against match criteria >+ * @param criteria bundles to select or <code>null</code> if no restrictions >+ * @return bundles that match this container's restrictions >+ */ >+ static BundleInfo[] getMatchingBundles(BundleInfo[] collection, BundleInfo[] criteria) { >+ if (criteria == null) { >+ return collection; >+ } >+ // map bundles names to available versions >+ Map bundleMap = new HashMap(collection.length); >+ for (int i = 0; i < collection.length; i++) { >+ BundleInfo info = collection[i]; >+ List list = (List) bundleMap.get(info.getSymbolicName()); >+ if (list == null) { >+ list = new ArrayList(3); >+ bundleMap.put(info.getSymbolicName(), list); >+ } >+ list.add(info); >+ } >+ List subset = new ArrayList(criteria.length); >+ for (int i = 0; i < criteria.length; i++) { >+ BundleInfo info = criteria[i]; >+ List list = (List) bundleMap.get(info.getSymbolicName()); >+ if (list != null) { >+ String version = info.getVersion(); >+ if (version == null) { >+ // select newest >+ if (list.size() > 1) { >+ // sort the list >+ Collections.sort(list, new Comparator() { >+ public int compare(Object o1, Object o2) { >+ return ((BundleInfo) o1).getVersion().compareTo(((BundleInfo) o2).getVersion()); >+ } >+ }); >+ } >+ // select the last one >+ subset.add(list.get(list.size() - 1)); >+ } else { >+ Iterator iterator = list.iterator(); >+ boolean found = false; >+ while (iterator.hasNext() && !found) { >+ BundleInfo bundle = (BundleInfo) iterator.next(); >+ if (bundle.getVersion().equals(version)) { >+ subset.add(bundle); >+ found = true; >+ } >+ } >+ if (!found) { >+ // TODO: report not found? exception? >+ } >+ } >+ } else { >+ // TODO: report not found? exception? >+ } >+ } >+ return (BundleInfo[]) subset.toArray(new BundleInfo[subset.size()]); >+ } >+ >+ /** >+ * Returns a string that identifies the type of bundle container. This type is persisted to xml >+ * so that the correct bundle container is created when deserializing the xml. This type is also >+ * used to alter how the containers are presented to the user in the UI. >+ * >+ * @return string identifier for the type of bundle container. >+ */ >+ public abstract String getType(); >+ >+ /** >+ * Returns a path in the local file system to the root of the bundle container. >+ * <p> >+ * TODO: Ideally we won't need this method. Currently the PDE target platform preferences are >+ * based on a home location and additional locations, so we need the information. >+ * </p> >+ * @param resolve whether to resolve variables in the path >+ * @return home location >+ * @exception CoreException if unable to resolve the location >+ */ >+ public abstract String getLocation(boolean resolve) throws CoreException; >+ >+ /** >+ * Returns whether restrictions are equivalent. Subclasses should override for other data. >+ * >+ * @param container bundle container >+ * @return whether content is equivalent >+ */ >+ public boolean isContentEqual(AbstractBundleContainer container) { >+ if (fRestrictions == null) { >+ return container.fRestrictions == null; >+ } >+ if (container.fRestrictions == null) { >+ return false; >+ } >+ if (fRestrictions.length == container.fRestrictions.length) { >+ for (int i = 0; i < fRestrictions.length; i++) { >+ if (!fRestrictions[i].equals(container.fRestrictions[i])) { >+ return false; >+ } >+ } >+ return true; >+ } >+ return false; >+ } >+ >+} >Index: src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java,v >retrieving revision 1.5 >diff -u -r1.5 TargetPlatformService.java >--- src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java 19 Jan 2009 17:54:59 -0000 1.5 >+++ src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java 23 Jan 2009 21:40:56 -0000 >@@ -1,219 +1,440 @@ >-/******************************************************************************* >- * Copyright (c) 2008, 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.pde.internal.core.target.impl; >- >-import java.io.*; >-import java.net.URI; >-import java.net.URISyntaxException; >-import java.util.*; >-import org.eclipse.core.resources.*; >-import org.eclipse.core.runtime.*; >-import org.eclipse.pde.internal.core.ICoreConstants; >-import org.eclipse.pde.internal.core.PDECore; >-import org.eclipse.pde.internal.core.target.provisional.*; >- >-/** >- * Target platform service implementation. >- * >- * @since 3.5 >- */ >-public class TargetPlatformService implements ITargetPlatformService { >- >- /** >- * Service instance >- */ >- private static ITargetPlatformService fgDefault; >- >- /** >- * Collects target files in the workspace >- */ >- class ResourceProxyVisitor implements IResourceProxyVisitor { >- >- private List fList; >- >- protected ResourceProxyVisitor(List list) { >- fList = list; >- } >- >- /** >- * @see org.eclipse.core.resources.IResourceProxyVisitor#visit(org.eclipse.core.resources.IResourceProxy) >- */ >- public boolean visit(IResourceProxy proxy) { >- if (proxy.getType() == IResource.FILE) { >- if (ICoreConstants.TARGET_FILE_EXTENSION.equalsIgnoreCase(new Path(proxy.getName()).getFileExtension())) { >- fList.add(proxy.requestResource()); >- } >- return false; >- } >- return true; >- } >- } >- >- private TargetPlatformService() { >- } >- >- public synchronized static ITargetPlatformService getDefault() { >- if (fgDefault == null) { >- fgDefault = new TargetPlatformService(); >- } >- return fgDefault; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#deleteTarget(org.eclipse.pde.internal.core.target.provisional.ITargetHandle) >- */ >- public void deleteTarget(ITargetHandle handle) throws CoreException { >- ((AbstractTargetHandle) handle).delete(); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(org.eclipse.core.resources.IFile) >- */ >- public ITargetHandle getTarget(IFile file) { >- return new WorkspaceFileTargetHandle(file); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(java.lang.String) >- */ >- public ITargetHandle getTarget(String memento) throws CoreException { >- try { >- URI uri = new URI(memento); >- String scheme = uri.getScheme(); >- if (WorkspaceFileTargetHandle.SCHEME.equals(scheme)) { >- return WorkspaceFileTargetHandle.restoreHandle(uri); >- } else if (LocalTargetHandle.SCHEME.equals(scheme)) { >- return LocalTargetHandle.restoreHandle(uri); >- } >- } catch (URISyntaxException e) { >- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_0, e)); >- } >- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_1, null)); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTargets(org.eclipse.core.runtime.IProgressMonitor) >- */ >- public ITargetHandle[] getTargets(IProgressMonitor monitor) { >- List local = findLocalTargetDefinitions(); >- List ws = findWorkspaceTargetDefinitions(); >- local.addAll(ws); >- return (ITargetHandle[]) local.toArray(new ITargetHandle[local.size()]); >- } >- >- /** >- * Finds and returns all local target definition handles >- * >- * @return all local target definition handles >- */ >- private List findLocalTargetDefinitions() { >- IPath containerPath = LocalTargetHandle.LOCAL_TARGET_CONTAINER_PATH; >- List handles = new ArrayList(10); >- final File directory = containerPath.toFile(); >- if (directory.isDirectory()) { >- FilenameFilter filter = new FilenameFilter() { >- public boolean accept(File dir, String name) { >- return dir.equals(directory) && name.endsWith(ICoreConstants.TARGET_FILE_EXTENSION); >- } >- }; >- File[] files = directory.listFiles(filter); >- for (int i = 0; i < files.length; i++) { >- try { >- handles.add(LocalTargetHandle.restoreHandle(files[i].toURI())); >- } catch (CoreException e) { >- PDECore.log(e); >- } >- } >- } >- return handles; >- } >- >- /** >- * Finds and returns all target definition handles defined by workspace files >- * >- * @return all target definition handles in the workspace >- */ >- private List findWorkspaceTargetDefinitions() { >- List files = new ArrayList(10); >- ResourceProxyVisitor visitor = new ResourceProxyVisitor(files); >- try { >- ResourcesPlugin.getWorkspace().getRoot().accept(visitor, IResource.NONE); >- } catch (CoreException e) { >- PDECore.log(e); >- return new ArrayList(0); >- } >- Iterator iter = files.iterator(); >- List handles = new ArrayList(files.size()); >- while (iter.hasNext()) { >- IFile file = (IFile) iter.next(); >- handles.add(new WorkspaceFileTargetHandle(file)); >- } >- return handles; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newDirectoryContainer(java.lang.String) >- */ >- public IBundleContainer newDirectoryContainer(String path) { >- return new DirectoryBundleContainer(path); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String, java.lang.String) >- */ >- public IBundleContainer newProfileContainer(String home, String configurationLocation) { >- return new ProfileBundleContainer(home, configurationLocation); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newTarget() >- */ >- public ITargetDefinition newTarget() { >- return new TargetDefinition(new LocalTargetHandle()); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#saveTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition) >- */ >- public void saveTargetDefinition(ITargetDefinition definition) throws CoreException { >- ((AbstractTargetHandle) definition.getHandle()).save(definition); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newFeatureContainer(java.lang.String, java.lang.String, java.lang.String) >- */ >- public IBundleContainer newFeatureContainer(String home, String id, String version) { >- return new FeatureBundleContainer(home, id, version); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getWorkspaceTargetDefinition() >- */ >- public ITargetHandle getWorkspaceTargetHandle() throws CoreException { >- Preferences preferences = PDECore.getDefault().getPluginPreferences(); >- String memento = preferences.getString(ICoreConstants.WORKSPACE_TARGET_HANDLE); >- if (memento != null && memento.length() != 0) { >- return getTarget(memento); >- } >- return null; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#copyTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition, org.eclipse.pde.internal.core.target.provisional.ITargetDefinition) >- */ >- public void copyTargetDefinition(ITargetDefinition from, ITargetDefinition to) throws CoreException { >- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); >- ((TargetDefinition) from).write(outputStream); >- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); >- ((TargetDefinition) to).setContents(inputStream); >- } >- >-} >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.core.target.impl; >+ >+import java.io.*; >+import java.net.*; >+import java.util.*; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >+import org.eclipse.osgi.service.datalocation.Location; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.pde.core.plugin.IPluginModelBase; >+import org.eclipse.pde.core.plugin.PluginRegistry; >+import org.eclipse.pde.internal.core.*; >+import org.eclipse.pde.internal.core.target.provisional.*; >+ >+/** >+ * Target platform service implementation. >+ * >+ * @since 3.5 >+ */ >+public class TargetPlatformService implements ITargetPlatformService { >+ >+ /** >+ * Service instance >+ */ >+ private static ITargetPlatformService fgDefault; >+ >+ /** >+ * Collects target files in the workspace >+ */ >+ class ResourceProxyVisitor implements IResourceProxyVisitor { >+ >+ private List fList; >+ >+ protected ResourceProxyVisitor(List list) { >+ fList = list; >+ } >+ >+ /** >+ * @see org.eclipse.core.resources.IResourceProxyVisitor#visit(org.eclipse.core.resources.IResourceProxy) >+ */ >+ public boolean visit(IResourceProxy proxy) { >+ if (proxy.getType() == IResource.FILE) { >+ if (ICoreConstants.TARGET_FILE_EXTENSION.equalsIgnoreCase(new Path(proxy.getName()).getFileExtension())) { >+ fList.add(proxy.requestResource()); >+ } >+ return false; >+ } >+ return true; >+ } >+ } >+ >+ private TargetPlatformService() { >+ } >+ >+ public synchronized static ITargetPlatformService getDefault() { >+ if (fgDefault == null) { >+ fgDefault = new TargetPlatformService(); >+ } >+ return fgDefault; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#deleteTarget(org.eclipse.pde.internal.core.target.provisional.ITargetHandle) >+ */ >+ public void deleteTarget(ITargetHandle handle) throws CoreException { >+ ((AbstractTargetHandle) handle).delete(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(org.eclipse.core.resources.IFile) >+ */ >+ public ITargetHandle getTarget(IFile file) { >+ return new WorkspaceFileTargetHandle(file); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(java.lang.String) >+ */ >+ public ITargetHandle getTarget(String memento) throws CoreException { >+ try { >+ URI uri = new URI(memento); >+ String scheme = uri.getScheme(); >+ if (WorkspaceFileTargetHandle.SCHEME.equals(scheme)) { >+ return WorkspaceFileTargetHandle.restoreHandle(uri); >+ } else if (LocalTargetHandle.SCHEME.equals(scheme)) { >+ return LocalTargetHandle.restoreHandle(uri); >+ } >+ } catch (URISyntaxException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_0, e)); >+ } >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_1, null)); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTargets(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public ITargetHandle[] getTargets(IProgressMonitor monitor) { >+ List local = findLocalTargetDefinitions(); >+ List ws = findWorkspaceTargetDefinitions(); >+ local.addAll(ws); >+ return (ITargetHandle[]) local.toArray(new ITargetHandle[local.size()]); >+ } >+ >+ /** >+ * Finds and returns all local target definition handles >+ * >+ * @return all local target definition handles >+ */ >+ private List findLocalTargetDefinitions() { >+ IPath containerPath = LocalTargetHandle.LOCAL_TARGET_CONTAINER_PATH; >+ List handles = new ArrayList(10); >+ final File directory = containerPath.toFile(); >+ if (directory.isDirectory()) { >+ FilenameFilter filter = new FilenameFilter() { >+ public boolean accept(File dir, String name) { >+ return dir.equals(directory) && name.endsWith(ICoreConstants.TARGET_FILE_EXTENSION); >+ } >+ }; >+ File[] files = directory.listFiles(filter); >+ for (int i = 0; i < files.length; i++) { >+ try { >+ handles.add(LocalTargetHandle.restoreHandle(files[i].toURI())); >+ } catch (CoreException e) { >+ PDECore.log(e); >+ } >+ } >+ } >+ return handles; >+ } >+ >+ /** >+ * Finds and returns all target definition handles defined by workspace files >+ * >+ * @return all target definition handles in the workspace >+ */ >+ private List findWorkspaceTargetDefinitions() { >+ List files = new ArrayList(10); >+ ResourceProxyVisitor visitor = new ResourceProxyVisitor(files); >+ try { >+ ResourcesPlugin.getWorkspace().getRoot().accept(visitor, IResource.NONE); >+ } catch (CoreException e) { >+ PDECore.log(e); >+ return new ArrayList(0); >+ } >+ Iterator iter = files.iterator(); >+ List handles = new ArrayList(files.size()); >+ while (iter.hasNext()) { >+ IFile file = (IFile) iter.next(); >+ handles.add(new WorkspaceFileTargetHandle(file)); >+ } >+ return handles; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newDirectoryContainer(java.lang.String) >+ */ >+ public IBundleContainer newDirectoryContainer(String path) { >+ return new DirectoryBundleContainer(path); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String, java.lang.String) >+ */ >+ public IBundleContainer newProfileContainer(String home, String configurationLocation) { >+ return new ProfileBundleContainer(home, configurationLocation); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newTarget() >+ */ >+ public ITargetDefinition newTarget() { >+ return new TargetDefinition(new LocalTargetHandle()); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#saveTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition) >+ */ >+ public void saveTargetDefinition(ITargetDefinition definition) throws CoreException { >+ ((AbstractTargetHandle) definition.getHandle()).save(definition); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newFeatureContainer(java.lang.String, java.lang.String, java.lang.String) >+ */ >+ public IBundleContainer newFeatureContainer(String home, String id, String version) { >+ return new FeatureBundleContainer(home, id, version); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getWorkspaceTargetDefinition() >+ */ >+ public ITargetHandle getWorkspaceTargetHandle() throws CoreException { >+ Preferences preferences = PDECore.getDefault().getPluginPreferences(); >+ String memento = preferences.getString(ICoreConstants.WORKSPACE_TARGET_HANDLE); >+ if (memento != null && memento.length() != 0) { >+ return getTarget(memento); >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#copyTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition, org.eclipse.pde.internal.core.target.provisional.ITargetDefinition) >+ */ >+ public void copyTargetDefinition(ITargetDefinition from, ITargetDefinition to) throws CoreException { >+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); >+ ((TargetDefinition) from).write(outputStream); >+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); >+ ((TargetDefinition) to).setContents(inputStream); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#loadTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition, java.lang.String) >+ */ >+ public void loadTargetDefinition(ITargetDefinition definition, String targetExtensionId) throws CoreException { >+ IConfigurationElement elem = PDECore.getDefault().getTargetProfileManager().getTarget(targetExtensionId); >+ if (elem == null) { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind("Target extension does not exist: {0}", targetExtensionId))); >+ } >+ String path = elem.getAttribute("definition"); //$NON-NLS-1$ >+ String symbolicName = elem.getDeclaringExtension().getNamespaceIdentifier(); >+ URL url = TargetDefinitionManager.getResourceURL(symbolicName, path); >+ if (url != null) { >+ try { >+ ((TargetDefinition) definition).setContents(new BufferedInputStream(url.openStream())); >+ } catch (IOException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind("Error reading target extension file: {0}", path), e)); >+ } >+ } else { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind("Target extension file does not exist: {0}", path))); >+ } >+ } >+ >+ /** >+ * This is a utility method to initialize a target definition based on current workspace >+ * preference settings (target platform settings). It is not part of the service API since >+ * the preference settings should eventually be removed. >+ * >+ * @param definition target definition >+ * @throws CoreException >+ */ >+ public void loadTargetDefinitionFromPreferences(ITargetDefinition target) throws CoreException { >+ Preferences preferences = PDECore.getDefault().getPluginPreferences(); >+ initializeArgumentsInfo(preferences, target); >+ initializeEnvironmentInfo(preferences, target); >+ initializeImplicitInfo(preferences, target); >+ initializeLocationInfo(preferences, target); >+ initializeAdditionalLocsInfo(preferences, target); >+ initializeJREInfo(target); >+ initializePluginContent(preferences, target); >+ } >+ >+ /** >+ * Returns the given string or <code>null</code> if the empty string. >+ * >+ * @param value >+ * @return value or <code>null</code> >+ */ >+ private String getValueOrNull(String value) { >+ if (value == null) { >+ return null; >+ } >+ if (value.length() == 0) { >+ return null; >+ } >+ return value; >+ } >+ >+ private void initializeArgumentsInfo(Preferences preferences, ITargetDefinition target) { >+ target.setProgramArguments(getValueOrNull(preferences.getString(ICoreConstants.PROGRAM_ARGS))); >+ target.setVMArguments(getValueOrNull(preferences.getString(ICoreConstants.VM_ARGS))); >+ } >+ >+ private void initializeEnvironmentInfo(Preferences preferences, ITargetDefinition target) { >+ target.setOS(getValueOrNull(preferences.getString(ICoreConstants.OS))); >+ target.setWS(getValueOrNull(preferences.getString(ICoreConstants.WS))); >+ target.setNL(getValueOrNull(preferences.getString(ICoreConstants.NL))); >+ target.setArch(getValueOrNull(preferences.getString(ICoreConstants.ARCH))); >+ } >+ >+ private void initializeImplicitInfo(Preferences preferences, ITargetDefinition target) { >+ String value = preferences.getString(ICoreConstants.IMPLICIT_DEPENDENCIES); >+ if (value.length() > 0) { >+ StringTokenizer tokenizer = new StringTokenizer(value, ","); //$NON-NLS-1$ >+ BundleInfo[] plugins = new BundleInfo[tokenizer.countTokens()]; >+ int i = 0; >+ while (tokenizer.hasMoreTokens()) { >+ String id = tokenizer.nextToken(); >+ plugins[i++] = new BundleInfo(id, null, null, BundleInfo.NO_LEVEL, false); >+ } >+ target.setImplicitDependencies(plugins); >+ } >+ } >+ >+ private void initializeLocationInfo(Preferences preferences, ITargetDefinition target) { >+ boolean useThis = preferences.getString(ICoreConstants.TARGET_MODE).equals(ICoreConstants.VALUE_USE_THIS); >+ boolean profile = preferences.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION); >+ String home = null; >+ // Target weaving >+ Location configArea = Platform.getConfigurationLocation(); >+ String configLocation = null; >+ if (configArea != null) { >+ configLocation = configArea.getURL().getFile(); >+ } >+ if (configLocation != null) { >+ Location location = Platform.getInstallLocation(); >+ if (location != null) { >+ URL url = location.getURL(); >+ if (url != null) { >+ IPath installPath = new Path(url.getFile()); >+ IPath configPath = new Path(configLocation); >+ if (installPath.isPrefixOf(configPath)) { >+ // if it is the default configuration area, do not specify explicitly >+ configPath = configPath.removeFirstSegments(installPath.segmentCount()); >+ configPath = configPath.setDevice(null); >+ if (configPath.segmentCount() == 1 && configPath.lastSegment().equals("configuration")) { //$NON-NLS-1$ >+ configLocation = null; >+ } >+ } >+ } >+ } >+ } >+ if (useThis) { >+ home = "${eclipse_home}"; //$NON-NLS-1$ >+ } else { >+ home = preferences.getString(ICoreConstants.PLATFORM_PATH); >+ } >+ IBundleContainer primary = null; >+ if (profile) { >+ primary = newProfileContainer(home, configLocation); >+ } else { >+ primary = newDirectoryContainer(home); >+ } >+ try { >+ String location = ((AbstractBundleContainer) primary).getLocation(true); >+ target.setName(location); >+ } catch (CoreException e) { >+ target.setName("Restored Target Platform"); >+ } >+ target.setBundleContainers(new IBundleContainer[] {primary}); >+ } >+ >+ private void initializeAdditionalLocsInfo(Preferences preferences, ITargetDefinition target) { >+ String additional = preferences.getString(ICoreConstants.ADDITIONAL_LOCATIONS); >+ StringTokenizer tokenizer = new StringTokenizer(additional, ","); //$NON-NLS-1$ >+ int size = tokenizer.countTokens(); >+ if (size > 0) { >+ IBundleContainer[] locations = new IBundleContainer[size + 1]; >+ locations[0] = target.getBundleContainers()[0]; >+ int i = 1; >+ while (tokenizer.hasMoreTokens()) { >+ locations[i++] = newDirectoryContainer(tokenizer.nextToken().trim()); >+ } >+ target.setBundleContainers(locations); >+ } >+ } >+ >+ private void initializeJREInfo(ITargetDefinition target) { >+ target.setJREContainer(null); >+ } >+ >+ private void initializePluginContent(Preferences preferences, ITargetDefinition target) { >+ String value = preferences.getString(ICoreConstants.CHECKED_PLUGINS); >+ IBundleContainer primary = target.getBundleContainers()[0]; >+ if (value.length() == 0 || value.equals(ICoreConstants.VALUE_SAVED_NONE)) { >+ // no bundles >+ target.setBundleContainers(null); >+ return; >+ } >+ if (!value.equals(ICoreConstants.VALUE_SAVED_ALL)) { >+ // restrictions on container >+ IPluginModelBase[] models = PluginRegistry.getExternalModels(); >+ ArrayList list = new ArrayList(models.length); >+ for (int i = 0; i < models.length; i++) { >+ if (models[i].isEnabled()) { >+ String id = models[i].getPluginBase().getId(); >+ if (id != null) { >+ list.add(new BundleInfo(id, null, null, BundleInfo.NO_LEVEL, false)); >+ } >+ } >+ } >+ if (list.size() > 0) { >+ primary.setRestrictions((BundleInfo[]) list.toArray(new BundleInfo[list.size()])); >+ } >+ } >+ >+ } >+ >+ /** >+ * Creates a target definition with default settings - i.e. the running host. >+ * Uses an explicit configuration area if not equal to the default location. >+ * >+ * @return target definition >+ */ >+ public ITargetDefinition newDefaultTargetDefinition() { >+ ITargetDefinition target = newTarget(); >+ Location configArea = Platform.getConfigurationLocation(); >+ String configLocation = null; >+ if (configArea != null) { >+ configLocation = configArea.getURL().getFile(); >+ } >+ if (configLocation != null) { >+ Location location = Platform.getInstallLocation(); >+ if (location != null) { >+ URL url = location.getURL(); >+ if (url != null) { >+ IPath installPath = new Path(url.getFile()); >+ IPath configPath = new Path(configLocation); >+ if (installPath.isPrefixOf(configPath)) { >+ // if it is the default configuration area, do not specify explicitly >+ configPath = configPath.removeFirstSegments(installPath.segmentCount()); >+ configPath = configPath.setDevice(null); >+ if (configPath.segmentCount() == 1 && configPath.lastSegment().equals("configuration")) { //$NON-NLS-1$ >+ configLocation = null; >+ } >+ } >+ } >+ } >+ } >+ IBundleContainer container = newProfileContainer("${eclipse_home}", configLocation); //$NON-NLS-1$ >+ target.setBundleContainers(new IBundleContainer[] {container}); >+ try { >+ String location = ((AbstractBundleContainer) container).getLocation(true); >+ target.setName(NLS.bind("Running Platform ({0})", location)); >+ } catch (CoreException e) { >+ target.setName("Running Platform (Default)"); >+ } >+ return target; >+ } >+} >#P org.eclipse.pde.ui >Index: src/org/eclipse/pde/internal/ui/wizards/target/TargetCreationPage.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/target/TargetCreationPage.java,v >retrieving revision 1.1 >diff -u -r1.1 TargetCreationPage.java >--- src/org/eclipse/pde/internal/ui/wizards/target/TargetCreationPage.java 23 Jan 2009 20:30:20 -0000 1.1 >+++ src/org/eclipse/pde/internal/ui/wizards/target/TargetCreationPage.java 23 Jan 2009 21:40:57 -0000 >@@ -1,252 +1,249 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.pde.internal.ui.wizards.target; >- >-import org.eclipse.pde.internal.ui.PDEUIMessages; >- >-import java.io.*; >-import java.net.URL; >-import javax.xml.parsers.ParserConfigurationException; >-import org.eclipse.core.runtime.*; >-import org.eclipse.jface.dialogs.Dialog; >-import org.eclipse.jface.wizard.IWizardPage; >-import org.eclipse.jface.wizard.WizardSelectionPage; >-import org.eclipse.pde.internal.core.PDECore; >-import org.eclipse.pde.internal.core.TargetDefinitionManager; >-import org.eclipse.pde.internal.core.itarget.ITargetModel; >-import org.eclipse.pde.internal.core.target.TargetModel; >-import org.eclipse.pde.internal.core.target.impl.TargetDefinitionPersistenceHelper; >-import org.eclipse.pde.internal.core.target.provisional.*; >-import org.eclipse.pde.internal.ui.*; >-import org.eclipse.pde.internal.ui.editor.target.OpenTargetProfileAction; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.widgets.*; >-import org.xml.sax.SAXException; >- >-/** >- * First wizard page used to create a target definition. Defines the location where >- * the definition will be created and how to seed the definition. >- */ >-public class TargetCreationPage extends WizardSelectionPage { >- >- protected static final int USE_EMPTY = 0; >- protected static final int USE_DEFAULT = 1; >- protected static final int USE_CURRENT_TP = 2; >- protected static final int USE_EXISTING_TARGET = 3; >- >- private Button fEmptyButton; >- private Button fDefaultButton; >- private Button fCurrentTPButton; >- private Button fExistingTargetButton; >- private Combo fTargets; >- private String[] fTargetIds; >- private Button fPreviewButton; >- >- public TargetCreationPage(String pageName) { >- super(pageName); >- setTitle(PDEUIMessages.TargetProfileWizardPage_title); >- setDescription(PDEUIMessages.TargetProfileWizardPage_description); >- } >- >- /** >- * Returns the target service or <code>null</code> if none. >- * >- * @return target service or <code>null</code> >- */ >- protected ITargetPlatformService getTargetService() { >- return (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) >- */ >- public void createControl(Composite parent) { >- Composite comp = SWTFactory.createComposite(parent, 3, 1, GridData.FILL_BOTH); >- SWTFactory.createLabel(comp, PDEUIMessages.TargetCreationPage_0, 3); >- >- fEmptyButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_1, 3); >- fDefaultButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_2, 3); >- fCurrentTPButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_3, 3); >- fExistingTargetButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_4, 1); >- fExistingTargetButton.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- boolean enabled = fExistingTargetButton.getSelection(); >- fTargets.setEnabled(enabled); >- fPreviewButton.setEnabled(enabled); >- } >- }); >- >- fEmptyButton.setSelection(true); >- >- fTargets = SWTFactory.createCombo(comp, SWT.SINGLE | SWT.READ_ONLY, 1, null); >- fTargets.setEnabled(false); >- initializeTargetCombo(); >- >- fPreviewButton = SWTFactory.createPushButton(comp, PDEUIMessages.TargetCreationPage_5, null); >- fPreviewButton.setEnabled(false); >- fPreviewButton.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- InputStream stream = null; >- try { >- URL url = getExternalTargetURL(); >- if (url != null) >- stream = new BufferedInputStream(url.openStream()); >- if (stream != null) { >- ITargetModel model = new TargetModel(); >- model.load(stream, false); >- new OpenTargetProfileAction(getShell(), model, fTargets.getText()).run(); >- } >- } catch (IOException e1) { >- } catch (CoreException e2) { >- } finally { >- try { >- if (stream != null) >- stream.close(); >- } catch (IOException e3) { >- } >- } >- } >- }); >- >- Dialog.applyDialogFont(comp); >- setSelectedNode(new EditTargetNode()); >- setControl(comp); >- setPageComplete(true); >- } >- >- private URL getExternalTargetURL() { >- TargetDefinitionManager manager = PDECore.getDefault().getTargetProfileManager(); >- IConfigurationElement elem = manager.getTarget(fTargetIds[fTargets.getSelectionIndex()]); >- if (elem != null) { >- String path = elem.getAttribute("definition"); //$NON-NLS-1$ >- String symbolicName = elem.getDeclaringExtension().getNamespaceIdentifier(); >- return TargetDefinitionManager.getResourceURL(symbolicName, path); >- } >- return null; >- } >- >- protected void initializeTargetCombo() { >- IConfigurationElement[] elements = PDECore.getDefault().getTargetProfileManager().getSortedTargets(); >- fTargetIds = new String[elements.length]; >- for (int i = 0; i < elements.length; i++) { >- String name = elements[i].getAttribute("name"); //$NON-NLS-1$ >- if (fTargets.indexOf(name) == -1) >- fTargets.add(name); >- fTargetIds[i] = elements[i].getAttribute("id"); //$NON-NLS-1$ >- } >- if (elements.length > 0) >- fTargets.select(0); >- } >- >- protected int getInitializationOption() { >- if (fEmptyButton.getSelection()) >- return USE_EMPTY; >- if (fDefaultButton.getSelection()) >- return USE_DEFAULT; >- else if (fCurrentTPButton.getSelection()) >- return USE_CURRENT_TP; >- return USE_EXISTING_TARGET; >- } >- >- protected String getTargetId() { >- return fTargetIds[fTargets.getSelectionIndex()]; >- } >- >- private ITargetDefinition createTarget() { >- ITargetPlatformService service = getTargetService(); >- if (service != null) { >- ITargetDefinition definition = service.newTarget(); >- switch (getInitializationOption()) { >- case USE_EMPTY : >- definition.setName(PDEUIMessages.TargetCreationPage_6); >- break; >- case USE_DEFAULT : >- populateBasicTarget(definition); >- break; >- case USE_CURRENT_TP : >- populateFromCurrentTargetPlatform(definition); >- break; >- case USE_EXISTING_TARGET : >- try { >- populateFromTemplate(definition, getTargetId()); >- } catch (CoreException e) { >- setErrorMessage(e.getMessage()); >- return null; >- } >- break; >- } >- return definition; >- } >- return null; >- } >- >- /** >- * Applies basic target settings to the given target definition. >- * >- * @param definition >- */ >- private void populateBasicTarget(ITargetDefinition definition) { >- ITargetPlatformService service = getTargetService(); >- if (service != null) { >- definition.setName(PDEUIMessages.TargetCreationPage_7); >- definition.setBundleContainers(new IBundleContainer[] {service.newProfileContainer("${eclipse_home}", null)}); //$NON-NLS-1$ >- } >- } >- >- /** >- * Populates the given definition from current target platform settings. >- * >- * @param definition >- */ >- private void populateFromCurrentTargetPlatform(ITargetDefinition definition) { >- // TODO: >- } >- >- /** >- * Populates the given definition from the specified target template. >- * >- * @param definition >- * @param id target extension identifier >- * @exception CoreException if unable to complete >- */ >- private void populateFromTemplate(ITargetDefinition definition, String id) throws CoreException { >- IConfigurationElement elem = PDECore.getDefault().getTargetProfileManager().getTarget(id); >- String path = elem.getAttribute("definition"); //$NON-NLS-1$ >- String symbolicName = elem.getDeclaringExtension().getNamespaceIdentifier(); >- URL url = TargetDefinitionManager.getResourceURL(symbolicName, path); >- if (url != null) { >- try { >- TargetDefinitionPersistenceHelper.initFromXML(definition, new BufferedInputStream(url.openStream())); >- } catch (IOException e) { >- throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), PDEUIMessages.TargetCreationPage_8, e)); >- } catch (ParserConfigurationException e) { >- throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), PDEUIMessages.TargetCreationPage_8, e)); >- } catch (SAXException e) { >- throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), PDEUIMessages.TargetCreationPage_8, e)); >- } >- } >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.wizard.WizardSelectionPage#getNextPage() >- */ >- public IWizardPage getNextPage() { >- ITargetDefinition target = createTarget(); >- if (target != null) { >- ((EditTargetNode) getSelectedNode()).setTargetDefinition(target); >- return super.getNextPage(); >- } >- return null; >- } >-} >+/******************************************************************************* >+ * Copyright (c) 2005, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ui.wizards.target; >+ >+import java.io.*; >+import java.net.URL; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.jface.wizard.WizardSelectionPage; >+import org.eclipse.pde.internal.core.PDECore; >+import org.eclipse.pde.internal.core.TargetDefinitionManager; >+import org.eclipse.pde.internal.core.itarget.ITargetModel; >+import org.eclipse.pde.internal.core.target.TargetModel; >+import org.eclipse.pde.internal.core.target.impl.TargetPlatformService; >+import org.eclipse.pde.internal.core.target.provisional.*; >+import org.eclipse.pde.internal.ui.PDEUIMessages; >+import org.eclipse.pde.internal.ui.SWTFactory; >+import org.eclipse.pde.internal.ui.editor.target.OpenTargetProfileAction; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.*; >+ >+/** >+ * First wizard page used to create a target definition. Defines the location where >+ * the definition will be created and how to seed the definition. >+ */ >+public class TargetCreationPage extends WizardSelectionPage { >+ >+ protected static final int USE_EMPTY = 0; >+ protected static final int USE_DEFAULT = 1; >+ protected static final int USE_CURRENT_TP = 2; >+ protected static final int USE_EXISTING_TARGET = 3; >+ >+ private Button fEmptyButton; >+ private Button fDefaultButton; >+ private Button fCurrentTPButton; >+ private Button fExistingTargetButton; >+ private Combo fTargets; >+ private String[] fTargetIds; >+ private Button fPreviewButton; >+ >+ public TargetCreationPage(String pageName) { >+ super(pageName); >+ setTitle(PDEUIMessages.TargetProfileWizardPage_title); >+ setDescription(PDEUIMessages.TargetProfileWizardPage_description); >+ } >+ >+ /** >+ * Returns the target service or <code>null</code> if none. >+ * >+ * @return target service or <code>null</code> >+ */ >+ protected ITargetPlatformService getTargetService() { >+ return (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) >+ */ >+ public void createControl(Composite parent) { >+ Composite comp = SWTFactory.createComposite(parent, 3, 1, GridData.FILL_BOTH); >+ SWTFactory.createLabel(comp, PDEUIMessages.TargetCreationPage_0, 3); >+ >+ fEmptyButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_1, 3); >+ fDefaultButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_2, 3); >+ fCurrentTPButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_3, 3); >+ fExistingTargetButton = SWTFactory.createRadioButton(comp, PDEUIMessages.TargetCreationPage_4, 1); >+ fExistingTargetButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ boolean enabled = fExistingTargetButton.getSelection(); >+ fTargets.setEnabled(enabled); >+ fPreviewButton.setEnabled(enabled); >+ } >+ }); >+ >+ fEmptyButton.setSelection(true); >+ >+ fTargets = SWTFactory.createCombo(comp, SWT.SINGLE | SWT.READ_ONLY, 1, null); >+ fTargets.setEnabled(false); >+ initializeTargetCombo(); >+ >+ fPreviewButton = SWTFactory.createPushButton(comp, PDEUIMessages.TargetCreationPage_5, null); >+ fPreviewButton.setEnabled(false); >+ fPreviewButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ InputStream stream = null; >+ try { >+ URL url = getExternalTargetURL(); >+ if (url != null) >+ stream = new BufferedInputStream(url.openStream()); >+ if (stream != null) { >+ ITargetModel model = new TargetModel(); >+ model.load(stream, false); >+ new OpenTargetProfileAction(getShell(), model, fTargets.getText()).run(); >+ } >+ } catch (IOException e1) { >+ } catch (CoreException e2) { >+ } finally { >+ try { >+ if (stream != null) >+ stream.close(); >+ } catch (IOException e3) { >+ } >+ } >+ } >+ }); >+ >+ Dialog.applyDialogFont(comp); >+ setSelectedNode(new EditTargetNode()); >+ setControl(comp); >+ setPageComplete(true); >+ } >+ >+ private URL getExternalTargetURL() { >+ TargetDefinitionManager manager = PDECore.getDefault().getTargetProfileManager(); >+ IConfigurationElement elem = manager.getTarget(fTargetIds[fTargets.getSelectionIndex()]); >+ if (elem != null) { >+ String path = elem.getAttribute("definition"); //$NON-NLS-1$ >+ String symbolicName = elem.getDeclaringExtension().getNamespaceIdentifier(); >+ return TargetDefinitionManager.getResourceURL(symbolicName, path); >+ } >+ return null; >+ } >+ >+ protected void initializeTargetCombo() { >+ IConfigurationElement[] elements = PDECore.getDefault().getTargetProfileManager().getSortedTargets(); >+ fTargetIds = new String[elements.length]; >+ for (int i = 0; i < elements.length; i++) { >+ String name = elements[i].getAttribute("name"); //$NON-NLS-1$ >+ if (fTargets.indexOf(name) == -1) >+ fTargets.add(name); >+ fTargetIds[i] = elements[i].getAttribute("id"); //$NON-NLS-1$ >+ } >+ if (elements.length > 0) >+ fTargets.select(0); >+ } >+ >+ protected int getInitializationOption() { >+ if (fEmptyButton.getSelection()) >+ return USE_EMPTY; >+ if (fDefaultButton.getSelection()) >+ return USE_DEFAULT; >+ else if (fCurrentTPButton.getSelection()) >+ return USE_CURRENT_TP; >+ return USE_EXISTING_TARGET; >+ } >+ >+ protected String getTargetId() { >+ return fTargetIds[fTargets.getSelectionIndex()]; >+ } >+ >+ private ITargetDefinition createTarget() { >+ ITargetPlatformService service = getTargetService(); >+ if (service != null) { >+ ITargetDefinition definition = service.newTarget(); >+ switch (getInitializationOption()) { >+ case USE_EMPTY : >+ definition.setName(PDEUIMessages.TargetCreationPage_6); >+ break; >+ case USE_DEFAULT : >+ populateBasicTarget(definition); >+ break; >+ case USE_CURRENT_TP : >+ try { >+ populateFromCurrentTargetPlatform(definition); >+ } catch (CoreException e) { >+ setErrorMessage(e.getMessage()); >+ return null; >+ } >+ break; >+ case USE_EXISTING_TARGET : >+ try { >+ populateFromTemplate(definition, getTargetId()); >+ } catch (CoreException e) { >+ setErrorMessage(e.getMessage()); >+ return null; >+ } >+ break; >+ } >+ return definition; >+ } >+ return null; >+ } >+ >+ /** >+ * Applies basic target settings to the given target definition. >+ * >+ * @param definition >+ */ >+ private void populateBasicTarget(ITargetDefinition definition) { >+ ITargetPlatformService service = getTargetService(); >+ if (service != null) { >+ definition.setName(PDEUIMessages.TargetCreationPage_7); >+ definition.setBundleContainers(new IBundleContainer[] {service.newProfileContainer("${eclipse_home}", null)}); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * Populates the given definition from current target platform settings. >+ * >+ * @param definition >+ * @throws CoreException >+ */ >+ private void populateFromCurrentTargetPlatform(ITargetDefinition definition) throws CoreException { >+ ITargetPlatformService service = getTargetService(); >+ if (service instanceof TargetPlatformService) { >+ TargetPlatformService ts = (TargetPlatformService) service; >+ ts.loadTargetDefinitionFromPreferences(definition); >+ } >+ } >+ >+ /** >+ * Populates the given definition from the specified target template. >+ * >+ * @param definition >+ * @param id target extension identifier >+ * @exception CoreException if unable to complete >+ */ >+ private void populateFromTemplate(ITargetDefinition definition, String id) throws CoreException { >+ ITargetPlatformService service = getTargetService(); >+ if (service != null) { >+ service.loadTargetDefinition(definition, id); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.wizard.WizardSelectionPage#getNextPage() >+ */ >+ public IWizardPage getNextPage() { >+ ITargetDefinition target = createTarget(); >+ if (target != null) { >+ ((EditTargetNode) getSelectedNode()).setTargetDefinition(target); >+ return super.getNextPage(); >+ } >+ return null; >+ } >+} >Index: src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java,v >retrieving revision 1.86 >diff -u -r1.86 TargetPlatformPreferencePage.java >--- src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java 22 May 2008 19:18:04 -0000 1.86 >+++ src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java 23 Jan 2009 21:40:57 -0000 >@@ -565,6 +565,8 @@ > fArgumentsTab.performOk(); > fImplicitDependenciesTab.performOk(); > saveTarget(); >+ // the old page has been use - wipe out current target setting for new pref page >+ fPreferences.setValue(ICoreConstants.WORKSPACE_TARGET_HANDLE, ""); //$NON-NLS-1$ > return super.performOk(); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 256910
:
119021
|
119023
|
119050
|
119547
|
120975
|
120980
|
121558
|
121570
|
122001
|
122175
|
122423
|
122424
|
122437
|
122498
|
122768
|
122847
|
122848
|
122849
|
122885
|
122887
|
123013
|
123025
|
123285
|
123446
| 123596 |
123639
|
123770
|
123771