summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Windatt2013-07-17 17:26:53 (EDT)
committerCurtis Windatt2013-07-17 17:26:53 (EDT)
commit94121f1382c8a36d769a9ef211ed09725419df46 (patch)
treec5f4ab677e78799350f8c66594c219c728f2c4d9
parenta5288231bd5908bb02c8e9413c664b7e6e609aca (diff)
downloadeclipse.pde.ui-94121f1382c8a36d769a9ef211ed09725419df46.zip
eclipse.pde.ui-94121f1382c8a36d769a9ef211ed09725419df46.tar.gz
eclipse.pde.ui-94121f1382c8a36d769a9ef211ed09725419df46.tar.bz2
Bug 283731 - [target] Remove target state dependence on preferences
-rw-r--r--ui/org.eclipse.pde.core/META-INF/MANIFEST.MF2
-rw-r--r--ui/org.eclipse.pde.core/pom.xml2
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/ITargetPlatformService.java13
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ExternalModelManager.java11
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ICoreConstants.java13
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java234
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java19
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java22
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetMetadataCollector.java7
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java108
-rw-r--r--ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchArgumentsHelper.java12
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/MainPreferencePage.java11
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/TargetRepositorySearchHandler.java3
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationsGroup.java15
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/imagebrowser/repositories/TargetPlatformRepository.java18
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java11
16 files changed, 348 insertions, 153 deletions
diff --git a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
index a30dcdb..cee8c14 100644
--- a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %name
Bundle-SymbolicName: org.eclipse.pde.core; singleton:=true
-Bundle-Version: 3.9.100.qualifier
+Bundle-Version: 3.10.0.qualifier
Bundle-Activator: org.eclipse.pde.internal.core.PDECore
Bundle-Vendor: %provider-name
Bundle-Localization: plugin
diff --git a/ui/org.eclipse.pde.core/pom.xml b/ui/org.eclipse.pde.core/pom.xml
index 9550801..fd3a6d3 100644
--- a/ui/org.eclipse.pde.core/pom.xml
+++ b/ui/org.eclipse.pde.core/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.pde</groupId>
<artifactId>org.eclipse.pde.core</artifactId>
- <version>3.9.100-SNAPSHOT</version>
+ <version>3.10.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/ITargetPlatformService.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/ITargetPlatformService.java
index c9bd01c..f7cc010 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/ITargetPlatformService.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/ITargetPlatformService.java
@@ -183,6 +183,19 @@ public interface ITargetPlatformService {
public ITargetHandle getWorkspaceTargetHandle() throws CoreException;
/**
+ * Returns a {@link ITargetDefinition} that corresponds to the active target platform. Will
+ * create a new target definition if one does not exist. The returned target definition may
+ * have been resolved previously, but this is not guaranteed. This method replaces
+ * {@link #getWorkspaceTargetHandle()}.
+ *
+ * @return a target definition corresponding to the active target platform
+ * @throws CoreException if an error occurs loading the workspace target definition
+ *
+ * @since 3.10 Added in the Luna 4.4 release
+ */
+ public ITargetDefinition getWorkspaceTargetDefinition() throws CoreException;
+
+ /**
* Returns a status describing whether the given target definition is synchronized with
* workspace's target platform state. It is possible that bundles could have been added/removed
* from the underlying target location storage making the current target platform state out of
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ExternalModelManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ExternalModelManager.java
index 7184381..ac20b2c 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ExternalModelManager.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ExternalModelManager.java
@@ -10,10 +10,6 @@
*******************************************************************************/
package org.eclipse.pde.internal.core;
-import java.io.File;
-
-import org.eclipse.pde.core.target.NameVersionDescriptor;
-
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
@@ -25,6 +21,7 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.pde.core.plugin.IPluginLibrary;
import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.core.target.NameVersionDescriptor;
import org.eclipse.pde.internal.core.target.P2TargetUtils;
import org.eclipse.pde.internal.core.util.CoreUtility;
@@ -37,6 +34,10 @@ public class ExternalModelManager extends AbstractModelManager {
return fModels;
}
+ /**
+ * TODO Remove for bug 283731
+ * @param models
+ */
protected void initializeModels(IPluginModelBase[] models) {
fModels = models;
PDEPreferencesManager pref = PDECore.getDefault().getPreferencesManager();
@@ -82,6 +83,7 @@ public class ExternalModelManager extends AbstractModelManager {
}
/**
+ * TODO Remove for bug 283731
* Returns the URLs of all external plug-ins referenced by PDE target platform preferences.
* <p>
* Note this method is public for testing purposes only.
@@ -164,6 +166,7 @@ public class ExternalModelManager extends AbstractModelManager {
}
/**
+ * TODO Remove for bug 283731
* Appends one {@link URL} to another
*
* @param base first URL
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ICoreConstants.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ICoreConstants.java
index 0acb5f0..5b7a3f3 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ICoreConstants.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ICoreConstants.java
@@ -15,6 +15,7 @@ import java.util.Locale;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.target.ITargetPlatformService;
import org.osgi.framework.Constants;
public interface ICoreConstants {
@@ -32,6 +33,11 @@ public interface ICoreConstants {
String P_SOURCE_LOCATIONS = "source_locations"; //$NON-NLS-1$
String P_EXT_LOCATIONS = "ext_locations"; //$NON-NLS-1$
String PROGRAM_ARGS = "program_args"; //$NON-NLS-1$
+ /**
+ * Preferences key that stores a String containing additional arguments to
+ * add to the VM arguments list.
+ * @deprecated Since the 4.4 Luna release, target platform information is no longer stored in preferences. Instead use {@link ITargetPlatformService}.
+ */
String VM_ARGS = "vm_args"; //$NON-NLS-1$
String VM_LAUNCHER_INI = "vm_launcher_ini"; //$NON-NLS-1$
String IMPLICIT_DEPENDENCIES = "implicit_dependencies"; //$NON-NLS-1$
@@ -364,12 +370,15 @@ public interface ICoreConstants {
public static final String TARGET_FILE_EXTENSION = "target"; //$NON-NLS-1$
/**
- * Preference key for the active workspace target platform handle memento
+ * Preference key for the active workspace target platform handle memento. If not set,
+ * old target preferences will be used to create a default. If no external bundles are
+ * wanted, this value should be set to {@link #NO_TARGET}.
*/
public static final String WORKSPACE_TARGET_HANDLE = "workspace_target_handle"; //$NON-NLS-1$
/**
- * Explicit setting when the user chooses no target for the workspace.
+ * Explicit preference value for {@link #WORKSPACE_TARGET_HANDLE} when the user chooses no
+ * target for the workspace (no external bundles).
*/
public static final String NO_TARGET = "NO_TARGET"; //$NON-NLS-1$
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java
index fc751af..acebb51 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java
@@ -11,6 +11,9 @@
*******************************************************************************/
package org.eclipse.pde.internal.core;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.*;
import java.util.Map.Entry;
import org.eclipse.core.resources.*;
@@ -23,7 +26,7 @@ import org.eclipse.pde.core.build.IBuild;
import org.eclipse.pde.core.build.IBuildEntry;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.core.target.*;
-import org.eclipse.pde.internal.core.target.*;
+import org.eclipse.pde.internal.core.target.IUBundleContainer;
public class PluginModelManager implements IModelProviderListener {
@@ -203,7 +206,7 @@ public class PluginModelManager implements IModelProviderListener {
// Removes from the master table and the state all workspace plug-ins that have been
// removed (project closed/deleted) from the workspace.
- // Also if the taget location changes, all models from the old target are removed
+ // Also if the target location changes, all models from the old target are removed
if ((e.getEventTypes() & IModelProviderEvent.MODELS_REMOVED) != 0) {
IModel[] removed = e.getRemovedModels();
for (int i = 0; i < removed.length; i++) {
@@ -504,10 +507,72 @@ public class PluginModelManager implements IModelProviderListener {
if (fEntries != null)
return;
+ // Compare the performance by performing both the old and the new way
+
+ // TODO Cannot access init from here, which could be adding some performance hit
+// initDefaultTargetPlatformDefinition(); // Init here outside of the performance checking
+
+ // New way
long startTime = System.currentTimeMillis();
// Cannot assign to fEntries here - will create a race condition with isInitialized()
- Map<String, LocalModelEntry> entries = Collections.synchronizedMap(new TreeMap<String, LocalModelEntry>());
+ Map<String, LocalModelEntry> entries1 = Collections.synchronizedMap(new TreeMap<String, LocalModelEntry>());
+
+ // Create a state that contains all bundles from the target and workspace
+ // If a workspace bundle has the same symbolic name as a target bundle,
+ // the target counterpart is subsequently removed from the state.
+ fState = new PDEState(fWorkspaceManager.getPluginPaths(), getExternalBundles(), true, true, new NullProgressMonitor());
+
+ // initialize the enabled/disabled state of target models
+ // based on whether the bundle is checked/unchecked on the Target Platform
+ // preference page.
+ fExternalManager.initializeModels(fState.getTargetModels());
+
+ // add target models to the master table
+ boolean statechanged = addToTable(entries1, fExternalManager.getAllModels());
+
+ // a state is combined only if the workspace plug-ins have not changed
+ // since the last shutdown of the workbench
+ if (fState.isCombined()) {
+ IPluginModelBase[] models = fState.getWorkspaceModels();
+ // initialize the workspace models from the cached state
+ fWorkspaceManager.initializeModels(models);
+ // add workspace models to the master table
+ addToTable(entries1, models);
+ // resolve the state incrementally if some target models
+ // were removed
+ if (statechanged)
+ fState.resolveState(true);
+ } else {
+ // if we have no good cached state of workspace plug-ins,
+ // re-parse all/any workspace plug-ins
+ IPluginModelBase[] models = fWorkspaceManager.getPluginModels();
+
+ // add workspace plug-ins to the master table
+ addToTable(entries1, models);
+
+ // add workspace plug-ins to the state
+ // and remove their target counterparts from the state.
+ for (int i = 0; i < models.length; i++) {
+ addWorkspaceBundleToState(entries1, models[i]);
+ }
+
+ // resolve the state incrementally if any workspace plug-ins were found
+ if (models.length > 0)
+ fState.resolveState(true);
+
+ // flush the extension registry cache since workspace data (BundleDescription id's) have changed.
+ PDECore.getDefault().getExtensionsRegistry().targetReloaded();
+ }
+
+ // TODO Remove
+ long newWay = System.currentTimeMillis() - startTime;
+
+ // Old way
+ startTime = System.currentTimeMillis();
+
+ // Cannot assign to fEntries here - will create a race condition with isInitialized()
+ Map<String, LocalModelEntry> entries2 = Collections.synchronizedMap(new TreeMap<String, LocalModelEntry>());
// Create a state that contains all bundles from the target and workspace
// If a workspace bundle has the same symbolic name as a target bundle,
@@ -520,7 +585,7 @@ public class PluginModelManager implements IModelProviderListener {
fExternalManager.initializeModels(fState.getTargetModels());
// add target models to the master table
- boolean statechanged = addToTable(entries, fExternalManager.getAllModels());
+ statechanged = addToTable(entries2, fExternalManager.getAllModels());
// a state is combined only if the workspace plug-ins have not changed
// since the last shutdown of the workbench
@@ -529,7 +594,7 @@ public class PluginModelManager implements IModelProviderListener {
// initialize the workspace models from the cached state
fWorkspaceManager.initializeModels(models);
// add workspace models to the master table
- addToTable(entries, models);
+ addToTable(entries2, models);
// resolve the state incrementally if some target models
// were removed
if (statechanged)
@@ -540,12 +605,12 @@ public class PluginModelManager implements IModelProviderListener {
IPluginModelBase[] models = fWorkspaceManager.getPluginModels();
// add workspace plug-ins to the master table
- addToTable(entries, models);
+ addToTable(entries2, models);
// add workspace plug-ins to the state
// and remove their target counterparts from the state.
for (int i = 0; i < models.length; i++) {
- addWorkspaceBundleToState(entries, models[i]);
+ addWorkspaceBundleToState(entries2, models[i]);
}
// resolve the state incrementally if any workspace plug-ins were found
@@ -556,10 +621,10 @@ public class PluginModelManager implements IModelProviderListener {
PDECore.getDefault().getExtensionsRegistry().targetReloaded();
}
- fEntries = entries;
+ // fEntries = entries2;
// Create default target platform definition if required
- initDefaultTargetPlatformDefinition();
+// initDefaultTargetPlatformDefinition();
// re-load the target if the corrupt POOLED_BUNDLES preference was being used
PDEPreferencesManager pref = PDECore.getDefault().getPreferencesManager();
@@ -578,75 +643,104 @@ public class PluginModelManager implements IModelProviderListener {
}
}
- if (PDECore.DEBUG_MODEL) {
- long time = System.currentTimeMillis() - startTime;
- System.out.println("PDE plug-in model initialization complete: " + time + " ms"); //$NON-NLS-1$//$NON-NLS-2$
- }
+ // TODO Remove
+ long oldWay = System.currentTimeMillis() - startTime;
+ System.out.println("Time to complete using preferences: " + oldWay);
+ System.out.println("Time to complete using target definition file: " + newWay);
+ System.err.println("New way took " + (newWay - oldWay) + " ms longer");
+ System.err.println("Old Bundles: " + entries2.size() + " New Bundles: " + entries1.size());
+
+ fEntries = entries1;
+// if (PDECore.DEBUG_MODEL) {
+// long time = System.currentTimeMillis() - startTime;
+// System.out.println("PDE plug-in model initialization complete: " + time + " ms"); //$NON-NLS-1$//$NON-NLS-2$
+// }
}
/**
- * Sets active target definition handle if not yet set. If an existing target
- * definition corresponds to workspace target settings, it is selected as the
- * active target. If there are no targets that correspond to workspace settings
- * a new definition is created.
+ * Returns an array of URL plug-in locations for external bundles loaded from the
+ * current target platform. The URLs will not be encoded.
+ *
+ * @return array of URLs for external bundles
*/
- private synchronized void initDefaultTargetPlatformDefinition() {
- ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
- if (service != null) {
- String memento = PDECore.getDefault().getPreferencesManager().getString(ICoreConstants.WORKSPACE_TARGET_HANDLE);
- if (memento.equals("")) { //$NON-NLS-1$
- // no workspace target handle set, check if any targets are equivalent to current settings
- ITargetHandle[] targets = service.getTargets(null);
- TargetPlatformService ts = (TargetPlatformService) service;
- // create target platform from current workspace settings
- TargetDefinition curr = (TargetDefinition) ts.newTarget();
- ITargetHandle wsHandle = null;
- try {
- ts.loadTargetDefinitionFromPreferences(curr);
- for (int i = 0; i < targets.length; i++) {
- if (curr.isContentEquivalent(targets[i].getTargetDefinition())) {
- wsHandle = targets[i];
- break;
- }
- }
- if (wsHandle == null) {
- // restore settings from preferences
- ITargetDefinition def = ts.newDefaultTarget();
- String defVMargs = def.getVMArguments();
- if (curr.getVMArguments() == null) {
- // previous to 3.5, default VM arguments were null instead of matching the host's
- // so compare to null VM arguments
- def.setVMArguments(null);
- }
- if (curr.isContentEquivalent(def)) {
- // Target is equivalent to the default settings, just add it as active
- curr.setName(Messages.TargetPlatformService_7);
- curr.setVMArguments(defVMargs); // restore default VM arguments
- } else {
- // Custom target settings, add as new target platform and add default as well
- curr.setName(PDECoreMessages.PluginModelManager_0);
-
- boolean defaultExists = false;
- for (int i = 0; i < targets.length; i++) {
- if (((TargetDefinition) def).isContentEquivalent(targets[i].getTargetDefinition())) {
- defaultExists = true;
- break;
- }
- }
- if (!defaultExists) {
- ts.saveTargetDefinition(def);
- }
- }
- ts.saveTargetDefinition(curr);
- wsHandle = curr.getHandle();
+ private URL[] getExternalBundles() {
+ final ITargetDefinition target;
+ try {
+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
+ if (service == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, "Could not acquire target platform service"));
+ }
+ target = service.getWorkspaceTargetDefinition();
+ } catch (CoreException e) {
+ PDECore.log(e);
+ return new URL[0];
+ }
+
+ // Don't resolve again if we don't have to
+ if (!target.isResolved()) {
+
+ // TODO Performance hack, avoid p2 pinging remote sites or downloading at this time
+ ITargetLocation[] locations = target.getTargetLocations();
+ for (int i = 0; i < locations.length; i++) {
+ if (locations[i] instanceof IUBundleContainer) {
+ ((IUBundleContainer) locations[i]).setRemoteFetch(false);
+ }
+ }
+
+ // Resolve the target definition in a separate job to allow cancellation
+ Job job = new Job("Loading external bundles from target platform") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return target.resolve(monitor);
+ }
+ };
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException e1) {
+ }
+
+ // TODO Performance hack, avoid p2 pinging remote sites or downloading at this time
+ for (int i = 0; i < locations.length; i++) {
+ if (locations[i] instanceof IUBundleContainer) {
+ ((IUBundleContainer) locations[i]).setRemoteFetch(true);
+ }
+ }
+
+ if (job.getResult().getSeverity() == IStatus.CANCEL) {
+ // TODO Do we want to schedule a job for later to complete?
+ return new URL[0];
+ }
+ }
+
+ // Log any known issues with the target platform to warn user
+ if (target.getStatus().getSeverity() == IStatus.ERROR) {
+ PDECore.log(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, "The current target platform contains errors, open Window > Preferences > Plug-in Development > Target Platform for details.", new CoreException(target.getStatus())));
+ }
+
+ URL[] externalURLs = new URL[0];
+ TargetBundle[] bundles = target.getBundles();
+ if (bundles != null) {
+ List<URL> urls = new ArrayList<URL>(bundles.length);
+ for (int i = 0; i < bundles.length; i++) {
+ if (bundles[i].getStatus().isOK()) {
+ try {
+ File file = URIUtil.toFile(bundles[i].getBundleInfo().getLocation());
+ urls.add(file.toURL());
+ } catch (MalformedURLException e) {
+ // Ignore bad urls as they should be caught by the target resolution
}
- PDEPreferencesManager preferences = PDECore.getDefault().getPreferencesManager();
- preferences.setValue(ICoreConstants.WORKSPACE_TARGET_HANDLE, wsHandle.getMemento());
- } catch (CoreException e) {
- PDECore.log(e);
}
}
+ externalURLs = urls.toArray(new URL[urls.size()]);
}
+
+ if (PDECore.DEBUG_MODEL) {
+ System.out.println("External models loaded from target definition: " + externalURLs.length); //$NON-NLS-1$
+ }
+
+ return externalURLs;
+
}
/**
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java
index 259fe1d..3f28870 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java
@@ -115,6 +115,8 @@ public class IUBundleContainer extends AbstractBundleContainer {
*/
private ITargetDefinition fTarget;
+ private boolean fRemoteFetch = true;
+
/**
* Constructs a installable unit bundle container for the specified units.
*
@@ -179,7 +181,7 @@ public class IUBundleContainer extends AbstractBundleContainer {
*/
protected TargetFeature[] resolveFeatures(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
fTarget = definition;
- fSynchronizer.synchronize(definition, monitor);
+ fSynchronizer.synchronize(definition, monitor, fRemoteFetch);
return fFeatures;
}
@@ -246,11 +248,17 @@ public class IUBundleContainer extends AbstractBundleContainer {
*/
protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
fTarget = definition;
- fSynchronizer.synchronize(definition, monitor);
+ fSynchronizer.synchronize(definition, monitor, fRemoteFetch);
return fBundles;
}
/**
+ */
+ public void setRemoteFetch(boolean remote) {
+ fRemoteFetch = remote;
+ }
+
+ /**
* Update this container's cache of top level IUs based on the given profile.
* NOTE: this method expects the synchronizer to be synchronized and is called
* as a result of a synchronization operation.
@@ -368,11 +376,6 @@ public class IUBundleContainer extends AbstractBundleContainer {
return updated;
}
- protected void clearResolutionStatus() {
- super.clearResolutionStatus();
- fSynchronizer.markDirty();
- }
-
/**
* Collects all available installable units from the given source that represent OSGI
* bundles. A IResolvedBundle is created for each and a map containing all results
@@ -628,8 +631,6 @@ public class IUBundleContainer extends AbstractBundleContainer {
protected void associateWithTarget(ITargetDefinition target) {
super.associateWithTarget(target);
fSynchronizer = getSynchronizer(target);
- // The synchronizer is being made dirty because this IU container is being associated with it
- fSynchronizer.markDirty();
fSynchronizer.setIncludeAllRequired((fFlags & INCLUDE_REQUIRED) == INCLUDE_REQUIRED);
fSynchronizer.setIncludeAllEnvironments((fFlags & INCLUDE_ALL_ENVIRONMENTS) == INCLUDE_ALL_ENVIRONMENTS);
fSynchronizer.setIncludeSource((fFlags & INCLUDE_SOURCE) == INCLUDE_SOURCE);
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java
index da9e5d6..925597f 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java
@@ -152,11 +152,6 @@ public class P2TargetUtils {
private boolean fIncludeConfigurePhase = false;
/**
- * Whether or not this synchronizer is dirty by means other than target tweaks etc.
- */
- private boolean fDirty = false;
-
- /**
* Deletes any profiles associated with target definitions that no longer exist
* and returns a list of profile identifiers that were deleted.
*/
@@ -445,8 +440,6 @@ public class P2TargetUtils {
return false;
}
- if (fDirty)
- return false;
// check that the target and profiles are in sync. If they are then life is good.
// If they are not equal, there is still a chance that everything is ok.
String profileNumber = fProfile.getProperty(PROP_SEQUENCE_NUMBER);
@@ -674,7 +667,7 @@ public class P2TargetUtils {
P2TargetUtils synchronizer = getSynchronizer(target);
if (synchronizer == null)
return null;
- synchronizer.synchronize(target, monitor);
+ synchronizer.synchronize(target, monitor, true);
return synchronizer.getProfile().query(QueryUtil.createIUAnyQuery(), null);
}
@@ -692,7 +685,7 @@ public class P2TargetUtils {
*
* @throws CoreException if there was a problem synchronizing
*/
- public synchronized void synchronize(ITargetDefinition target, IProgressMonitor monitor) throws CoreException {
+ public synchronized void synchronize(ITargetDefinition target, IProgressMonitor monitor, boolean remoteFetch) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 100);
// Happiness if we have a profile and it checks out or if we can load one and it checks out.
@@ -722,7 +715,6 @@ public class P2TargetUtils {
// If we are updating a profile then delete the old snapshot on success.
notify(target, progress.newChild(15));
- fDirty = false;
}
private void createProfile(ITargetDefinition target) throws CoreException, ProvisionException {
@@ -1447,14 +1439,4 @@ public class P2TargetUtils {
return fProfile;
}
-// /**
-// * @return the target definition associated with this synchronizer
-// */
-// ITargetDefinition getTargetDefinition() {
-// return fTarget;
-// }
-
- void markDirty() {
- fDirty = true;
- }
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetMetadataCollector.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetMetadataCollector.java
index 97bd06c..abd6078 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetMetadataCollector.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetMetadataCollector.java
@@ -10,14 +10,13 @@
*******************************************************************************/
package org.eclipse.pde.internal.core.target;
-import org.eclipse.pde.core.target.*;
-
import java.io.File;
import java.net.URI;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.pde.core.target.*;
import org.eclipse.pde.internal.core.PDECore;
/**
@@ -47,8 +46,8 @@ public class TargetMetadataCollector {
if (service == null) {
return null;
}
- ITargetHandle handle = service.getWorkspaceTargetHandle();
- definition = handle.getTargetDefinition();
+ // Use the non-api method to get active target definition
+ definition = service.getWorkspaceTargetDefinition();
}
Set<URI> repos = new HashSet<URI>();
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java
index 6430049..20e5b8a 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java
@@ -10,11 +10,6 @@
*******************************************************************************/
package org.eclipse.pde.internal.core.target;
-import java.net.URI;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.pde.core.target.ITargetHandle;
-import org.eclipse.pde.core.target.NameVersionDescriptor;
-
import java.io.*;
import java.net.*;
import java.util.*;
@@ -47,6 +42,12 @@ public class TargetPlatformService implements ITargetPlatformService {
private static Map<URI, ExternalFileTargetHandle> fExtTargetHandles;
/**
+ * The target definition currently being used as the target platform for
+ * the workspace.
+ */
+ private ITargetDefinition fWorkspaceTarget;
+
+ /**
* Collects target files in the workspace
*/
class ResourceProxyVisitor implements IResourceProxyVisitor {
@@ -257,9 +258,12 @@ public class TargetPlatformService implements ITargetPlatformService {
}
/* (non-Javadoc)
- * @see org.eclipse.pde.core.target.ITargetPlatformService#getWorkspaceTargetDefinition()
+ * @see org.eclipse.pde.core.target.ITargetPlatformService#getWorkspaceTargetHandle()
*/
public ITargetHandle getWorkspaceTargetHandle() throws CoreException {
+
+ // TODO Go through all uses of this and update to getWorkspaceTargetDefinition
+
// If the plug-in registry has not been initialized we may not have a target set, getting the start forces the init
PluginModelManager manager = PDECore.getDefault().getModelManager();
if (!manager.isInitialized()) {
@@ -275,6 +279,98 @@ public class TargetPlatformService implements ITargetPlatformService {
}
/* (non-Javadoc)
+ * @see org.eclipse.pde.core.target.ITargetPlatformService#getWorkspaceTargetDefinition()
+ */
+ public synchronized ITargetDefinition getWorkspaceTargetDefinition() throws CoreException {
+ if (fWorkspaceTarget != null) {
+ return fWorkspaceTarget;
+ }
+
+ // If no target definition has been chosen before, try using preferences
+ initDefaultTargetPlatformDefinition();
+
+ // Load and resolve
+ String memento = PDECore.getDefault().getPreferencesManager().getString(ICoreConstants.WORKSPACE_TARGET_HANDLE);
+ ITargetDefinition target = null;
+ if (memento == null || memento.equals("") || memento.equals(ICoreConstants.NO_TARGET)) { //$NON-NLS-1$
+ if (PDECore.DEBUG_MODEL) {
+ System.out.println("No target memento, using empty target."); //$NON-NLS-1$
+ }
+ target = newTarget();
+ } else {
+ ITargetHandle handle = getTarget(memento);
+ target = handle.getTargetDefinition();
+ }
+
+ fWorkspaceTarget = target;
+ return target;
+ }
+
+ /**
+ * Sets active target definition handle if not yet set. If an existing target
+ * definition corresponds to workspace target settings, it is selected as the
+ * active target. If there are no targets that correspond to workspace settings
+ * a new definition is created.
+ */
+ private synchronized void initDefaultTargetPlatformDefinition() {
+ String memento = PDECore.getDefault().getPreferencesManager().getString(ICoreConstants.WORKSPACE_TARGET_HANDLE);
+ if (memento == null || memento.equals("")) { //$NON-NLS-1$
+ if (PDECore.DEBUG_MODEL) {
+ System.out.println("No target memento, loading target info from old preferences.");
+ }
+ // no workspace target handle set, check if any targets are equivalent to current settings
+ ITargetHandle[] targets = getTargets(null);
+ // create target platform from current workspace settings
+ TargetDefinition curr = (TargetDefinition) newTarget();
+ ITargetHandle wsHandle = null;
+ try {
+ loadTargetDefinitionFromPreferences(curr);
+ for (int i = 0; i < targets.length; i++) {
+ if (curr.isContentEquivalent(targets[i].getTargetDefinition())) {
+ wsHandle = targets[i];
+ break;
+ }
+ }
+ if (wsHandle == null) {
+ // restore settings from preferences
+ ITargetDefinition def = newDefaultTarget();
+ String defVMargs = def.getVMArguments();
+ if (curr.getVMArguments() == null) {
+ // previous to 3.5, default VM arguments were null instead of matching the host's
+ // so compare to null VM arguments
+ def.setVMArguments(null);
+ }
+ if (curr.isContentEquivalent(def)) {
+ // Target is equivalent to the default settings, just add it as active
+ curr.setName(Messages.TargetPlatformService_7);
+ curr.setVMArguments(defVMargs); // restore default VM arguments
+ } else {
+ // Custom target settings, add as new target platform and add default as well
+ curr.setName(PDECoreMessages.PluginModelManager_0);
+
+ boolean defaultExists = false;
+ for (int i = 0; i < targets.length; i++) {
+ if (((TargetDefinition) def).isContentEquivalent(targets[i].getTargetDefinition())) {
+ defaultExists = true;
+ break;
+ }
+ }
+ if (!defaultExists) {
+ saveTargetDefinition(def);
+ }
+ }
+ saveTargetDefinition(curr);
+ wsHandle = curr.getHandle();
+ }
+ PDEPreferencesManager preferences = PDECore.getDefault().getPreferencesManager();
+ preferences.setValue(ICoreConstants.WORKSPACE_TARGET_HANDLE, wsHandle.getMemento());
+ } catch (CoreException e) {
+ PDECore.log(e);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.pde.core.target.ITargetPlatformService#copyTargetDefinition(org.eclipse.pde.core.target.ITargetDefinition, org.eclipse.pde.core.target.ITargetDefinition)
*/
public void copyTargetDefinition(ITargetDefinition from, ITargetDefinition to) throws CoreException {
diff --git a/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchArgumentsHelper.java b/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchArgumentsHelper.java
index 1bf968c..c1b16ef 100644
--- a/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchArgumentsHelper.java
+++ b/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchArgumentsHelper.java
@@ -24,7 +24,6 @@ import org.eclipse.jdt.core.*;
import org.eclipse.jdt.launching.ExecutionArguments;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.pde.core.plugin.*;
-import org.eclipse.pde.core.target.ITargetHandle;
import org.eclipse.pde.core.target.ITargetPlatformService;
import org.eclipse.pde.internal.build.IPDEBuildConstants;
import org.eclipse.pde.internal.core.*;
@@ -128,14 +127,13 @@ public class LaunchArgumentsHelper {
try {
ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
if (service != null) {
- ITargetHandle target = service.getWorkspaceTargetHandle();
- if (target != null) {
- String result = target.getTargetDefinition().getVMArguments();
- result = result != null ? result : ""; //$NON-NLS-1$
- return result;
- }
+ String result = service.getWorkspaceTargetDefinition().getVMArguments();
+ result = result != null ? result : ""; //$NON-NLS-1$
+ return result;
}
} catch (CoreException e) {
+ PDECore.log(e);
+ return ""; //$NON-NLS-1$
}
// TODO: Generally, once the new preference target platform preference page is in use,
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/MainPreferencePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/MainPreferencePage.java
index 4b213b7..4a467d3 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/MainPreferencePage.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/MainPreferencePage.java
@@ -11,15 +11,14 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.preferences;
-import org.eclipse.pde.core.target.ITargetHandle;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.pde.core.target.ITargetPlatformService;
+import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PDEPreferencesManager;
-import org.eclipse.pde.internal.core.target.TargetPlatformService;
import org.eclipse.pde.internal.launching.ILaunchingPreferenceConstants;
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
import org.eclipse.pde.internal.ui.*;
@@ -222,9 +221,9 @@ public class MainPreferencePage extends PreferencePage implements IWorkbenchPref
store.setValue(IPreferenceConstants.ADD_TO_JAVA_SEARCH, synchJavaSearch);
try {
if (synchJavaSearch) {
- ITargetHandle target = TargetPlatformService.getDefault().getWorkspaceTargetHandle();
- if (target != null) {
- AddToJavaSearchJob.synchWithTarget(target.getTargetDefinition());
+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
+ if (service != null) {
+ AddToJavaSearchJob.synchWithTarget(service.getWorkspaceTargetDefinition());
}
} else {
AddToJavaSearchJob.clearAll();
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/TargetRepositorySearchHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/TargetRepositorySearchHandler.java
index f5c3fdf..26b8078 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/TargetRepositorySearchHandler.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/TargetRepositorySearchHandler.java
@@ -76,8 +76,7 @@ public class TargetRepositorySearchHandler extends AbstractHandler implements IH
*/
private static void installIntoActiveTarget(IInstallableUnit[] units, URI[] repositories) throws CoreException {
ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
- ITargetHandle currentTarget = service.getWorkspaceTargetHandle();
- ITargetDefinition definition = currentTarget.getTargetDefinition();
+ ITargetDefinition definition = service.getWorkspaceTargetDefinition();
// Force the target into slicer mode as all requirements may not be available
int flags = IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS | IUBundleContainer.INCLUDE_SOURCE;
IUBundleContainer container = (IUBundleContainer) service.newIULocation(units, repositories, flags);
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationsGroup.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationsGroup.java
index 6b6f8ed..ed19eb5 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationsGroup.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationsGroup.java
@@ -21,7 +21,9 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.pde.core.target.*;
-import org.eclipse.pde.internal.core.target.*;
+import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.target.AbstractBundleContainer;
+import org.eclipse.pde.internal.core.target.IUBundleContainer;
import org.eclipse.pde.internal.ui.SWTFactory;
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
import org.eclipse.pde.internal.ui.editor.targetdefinition.TargetEditor;
@@ -439,11 +441,14 @@ public class TargetLocationsGroup {
fTreeViewer.refresh(true);
// If the target is the current platform, run a load job for the user
try {
- ITargetHandle currentTarget = TargetPlatformService.getDefault().getWorkspaceTargetHandle();
- if (fTarget.getHandle().equals(currentTarget))
- LoadTargetDefinitionJob.load(fTarget);
+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
+ if (service != null) {
+ ITargetHandle currentTarget = service.getWorkspaceTargetHandle();
+ if (fTarget.getHandle().equals(currentTarget))
+ LoadTargetDefinitionJob.load(fTarget);
+ }
} catch (CoreException e) {
- // do nothing if we could not see the current target.
+ // do nothing if we could not set the current target.
}
updateButtons();
}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/imagebrowser/repositories/TargetPlatformRepository.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/imagebrowser/repositories/TargetPlatformRepository.java
index 1e8e9d8..f98ea7e 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/imagebrowser/repositories/TargetPlatformRepository.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/imagebrowser/repositories/TargetPlatformRepository.java
@@ -71,10 +71,7 @@ public class TargetPlatformRepository extends AbstractRepository {
if (service != null) {
ITargetDefinition fDefinition = null;
if (fUseCurrent) {
- ITargetHandle workspaceTargetHandle = service.getWorkspaceTargetHandle();
- if (workspaceTargetHandle != null) {
- fDefinition = workspaceTargetHandle.getTargetDefinition();
- }
+ fDefinition = service.getWorkspaceTargetDefinition();
} else {
fDefinition = service.newDefaultTarget();
}
@@ -111,15 +108,12 @@ public class TargetPlatformRepository extends AbstractRepository {
try {
ITargetPlatformService service = (ITargetPlatformService) PlatformUI.getWorkbench().getService(ITargetPlatformService.class);
if (service != null) {
- ITargetHandle workspaceTargetHandle = service.getWorkspaceTargetHandle();
- if (workspaceTargetHandle != null) {
- ITargetDefinition definition = workspaceTargetHandle.getTargetDefinition();
- String name = definition.getName();
- if (name.length() > 30) {
- name = name.substring(0, 30);
- }
- return NLS.bind(PDEUIMessages.TargetPlatformRepository_TargetPlatformLabel, name);
+ ITargetDefinition definition = service.getWorkspaceTargetDefinition();
+ String name = definition.getName();
+ if (name.length() > 30) {
+ name = name.substring(0, 30);
}
+ return NLS.bind(PDEUIMessages.TargetPlatformRepository_TargetPlatformLabel, name);
}
} catch (CoreException e) {
PDEPlugin.log(e);
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java
index 6d748ad..52c2f00 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java
@@ -18,8 +18,9 @@ import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.pde.core.target.ITargetDefinition;
+import org.eclipse.pde.core.target.ITargetPlatformService;
+import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.target.ExportTargetJob;
-import org.eclipse.pde.internal.core.target.TargetPlatformService;
import org.eclipse.pde.internal.ui.*;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
@@ -51,10 +52,12 @@ public class TargetDefinitionExportWizard extends Wizard implements IExportWizar
fTarget = target;
if (fTarget == null)
try {
- fTarget = TargetPlatformService.getDefault().getWorkspaceTargetHandle().getTargetDefinition();
+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
+ if (service != null) {
+ fTarget = service.getWorkspaceTargetDefinition();
+ }
} catch (CoreException e) {
- // TODO log something?
- return;
+ PDEPlugin.log(e);
}
setNeedsProgressMonitor(true);
setWindowTitle(PDEUIMessages.ExportActiveTargetDefinition);