Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 210529 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-2 / +2 lines)
Lines 80-86 Link Here
80
 org.eclipse.search;bundle-version="[3.1.0,4.0.0)",
80
 org.eclipse.search;bundle-version="[3.1.0,4.0.0)",
81
 org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
81
 org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
82
 org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
82
 org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
83
 org.eclipse.update.core;bundle-version="[3.1.0,4.0.0)",
84
 org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)",
83
 org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)",
85
 org.eclipse.ant.ui;bundle-version="[3.1.0,4.0.0)",
84
 org.eclipse.ant.ui;bundle-version="[3.1.0,4.0.0)",
86
 org.eclipse.jdt.junit;bundle-version="[3.2.0,4.0.0)",
85
 org.eclipse.jdt.junit;bundle-version="[3.2.0,4.0.0)",
Lines 107-113 Link Here
107
 org.eclipse.equinox.frameworkadmin;bundle-version="[2.0.0,3.0.0)",
106
 org.eclipse.equinox.frameworkadmin;bundle-version="[2.0.0,3.0.0)",
108
 org.eclipse.equinox.frameworkadmin.equinox;bundle-version="[1.0.100,2.0.0)",
107
 org.eclipse.equinox.frameworkadmin.equinox;bundle-version="[1.0.100,2.0.0)",
109
 org.eclipse.pde.launching;bundle-version="[3.6.0,4.0.0)";visibility:=reexport,
108
 org.eclipse.pde.launching;bundle-version="[3.6.0,4.0.0)";visibility:=reexport,
110
 org.eclipse.ui.console;bundle-version="[3.5.0,4.0.0)"
109
 org.eclipse.ui.console;bundle-version="[3.5.0,4.0.0)",
110
 org.eclipse.equinox.simpleconfigurator;bundle-version="1.0.200"
111
Eclipse-LazyStart: true
111
Eclipse-LazyStart: true
112
Import-Package: com.ibm.icu.text,
112
Import-Package: com.ibm.icu.text,
113
 org.eclipse.jdt.debug.core
113
 org.eclipse.jdt.debug.core
(-)src/org/eclipse/pde/internal/ui/PDEPlugin.java (+1 lines)
Lines 188-193 Link Here
188
			LogFilesManager.removeLogFileProvider(fLogFileProvider);
188
			LogFilesManager.removeLogFileProvider(fLogFileProvider);
189
			fLogFileProvider = null;
189
			fLogFileProvider = null;
190
		}
190
		}
191
		Utilities.shutdown();
191
		super.stop(context);
192
		super.stop(context);
192
	}
193
	}
193
194
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (-2 / +3 lines)
Lines 1441-1446 Link Here
1441
	public static String SearchAction_Declaration;
1441
	public static String SearchAction_Declaration;
1442
	public static String ShowDescriptionAction_label;
1442
	public static String ShowDescriptionAction_label;
1443
	public static String ShowDescriptionAction_title;
1443
	public static String ShowDescriptionAction_title;
1444
	public static String ShowSampleAction_installing;
1445
	public static String ShowSampleAction_title;
1446
	public static String ShowSampleAction_msgDesc;
1444
	public static String ShowSampleAction_msgTitle;
1447
	public static String ShowSampleAction_msgTitle;
1445
	public static String DependencyExtent_singular;
1448
	public static String DependencyExtent_singular;
1446
	public static String DependencyExtent_plural;
1449
	public static String DependencyExtent_plural;
Lines 1763-1770 Link Here
1763
	public static String ReviewPage_desc;
1766
	public static String ReviewPage_desc;
1764
	public static String ReviewPage_descContent;
1767
	public static String ReviewPage_descContent;
1765
	public static String ReviewPage_content;
1768
	public static String ReviewPage_content;
1766
	public static String ShowSampleAction_title;
1767
	public static String ShowSampleAction_msgDesc;
1768
	public static String SelfHostingPropertyPage_label;
1769
	public static String SelfHostingPropertyPage_label;
1769
	public static String SelfHostingPropertyPage_viewerLabel;
1770
	public static String SelfHostingPropertyPage_viewerLabel;
1770
	public static String RuntimePage_tabName;
1771
	public static String RuntimePage_tabName;
(-)src/org/eclipse/pde/internal/ui/Utilities.java (+111 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2000, 2010 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui;
12
13
import java.io.*;
14
import java.util.Date;
15
import org.eclipse.core.runtime.Platform;
16
17
/**
18
 * This class is a collection of utility functions for creating and using temporary working directories. 
19
 */
20
public class Utilities {
21
22
	private static long tmpseed = (new Date()).getTime();
23
	private static String dirRoot = null;
24
25
	/**
26
	 * Returns a new working directory (in temporary space). Ensures
27
	 * the directory exists. Any directory levels that had to be created
28
	 * are marked for deletion on exit.
29
	 * 
30
	 * @return working directory
31
	 * @exception IOException
32
	 * @since 2.0
33
	 */
34
	public static synchronized File createWorkingDirectory() throws IOException {
35
36
		if (dirRoot == null) {
37
			dirRoot = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
38
			// in Linux, returns '/tmp', we must add '/'
39
			if (!dirRoot.endsWith(File.separator))
40
				dirRoot += File.separator;
41
42
			// on Unix/Linux, the temp dir is shared by many users, so we need to ensure 
43
			// that the top working directory is different for each user
44
			if (!Platform.getOS().equals("win32")) { //$NON-NLS-1$
45
				String home = System.getProperty("user.home"); //$NON-NLS-1$
46
				home = Integer.toString(home.hashCode());
47
				dirRoot += home + File.separator;
48
			}
49
			dirRoot += "eclipse" + File.separator + ".update" + File.separator + Long.toString(tmpseed) + File.separator; //$NON-NLS-1$ //$NON-NLS-2$
50
		}
51
52
		String tmpName = dirRoot + Long.toString(++tmpseed) + File.separator;
53
54
		File tmpDir = new File(tmpName);
55
		verifyPath(tmpDir, false);
56
		if (!tmpDir.exists())
57
			throw new FileNotFoundException(tmpName);
58
		return tmpDir;
59
	}
60
61
	/**
62
	 * Perform shutdown processing for temporary file handling.
63
	 * This method is called when platform is shutting down.
64
	 * It is not intended to be called at any other time under
65
	 * normal circumstances. A side-effect of calling this method
66
	 * is that the contents of the temporary directory managed 
67
	 * by this class are deleted. 
68
	 * 
69
	 * @since 2.0
70
	 */
71
	public static void shutdown() {
72
		if (dirRoot == null)
73
			return;
74
		File temp = new File(dirRoot); // temp directory root for this run
75
		cleanupTemp(temp);
76
		temp.delete();
77
	}
78
79
	private static void cleanupTemp(File root) {
80
		File[] files = root.listFiles();
81
		for (int i = 0; files != null && i < files.length; i++) {
82
			if (files[i].isDirectory())
83
				cleanupTemp(files[i]);
84
			files[i].delete();
85
		}
86
	}
87
88
	private static void verifyPath(File path, boolean isFile) {
89
		// if we are expecting a file back off 1 path element
90
		if (isFile) {
91
			if (path.getAbsolutePath().endsWith(File.separator)) {
92
				// make sure this is a file
93
				path = path.getParentFile();
94
				isFile = false;
95
			}
96
		}
97
98
		// already exists ... just return
99
		if (path.exists())
100
			return;
101
102
		// does not exist ... ensure parent exists
103
		File parent = path.getParentFile();
104
		verifyPath(parent, false);
105
106
		// ensure directories are made. Mark files or directories for deletion
107
		if (!isFile)
108
			path.mkdir();
109
		path.deleteOnExit();
110
	}
111
}
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (-1 / +2 lines)
Lines 1235-1241 Link Here
1235
SearchAction_Declaration = Find Declaratio&n
1235
SearchAction_Declaration = Find Declaratio&n
1236
ShowDescriptionAction_label = Sho&w Description
1236
ShowDescriptionAction_label = Sho&w Description
1237
ShowDescriptionAction_title=Extension Point Description
1237
ShowDescriptionAction_title=Extension Point Description
1238
ShowSampleAction_msgTitle=Samples
1239
DefinitionPage_0=Definition
1238
DefinitionPage_0=Definition
1240
DefinitionPage_1=Target Definition
1239
DefinitionPage_1=Target Definition
1241
DependencyExtent_singular = dependency
1240
DependencyExtent_singular = dependency
Lines 1720-1725 Link Here
1720
<p>If the selection is correct, press <b>Finish</b> to create the sample.</p>
1719
<p>If the selection is correct, press <b>Finish</b> to create the sample.</p>
1721
ShowSampleAction_title=Eclipse Samples
1720
ShowSampleAction_title=Eclipse Samples
1722
ShowSampleAction_msgDesc=The samples are currently not installed. Do you want to download samples from Eclipse.org?
1721
ShowSampleAction_msgDesc=The samples are currently not installed. Do you want to download samples from Eclipse.org?
1722
ShowSampleAction_installing=Installing sample plug-ins
1723
ShowSampleAction_msgTitle=Samples
1723
SelfHostingPropertyPage_label=By default, all output folders are put on the plug-in's classpath when running a runtime Eclipse application.
1724
SelfHostingPropertyPage_label=By default, all output folders are put on the plug-in's classpath when running a runtime Eclipse application.
1724
SecondaryBundlesSection_title=Automated Management of Dependencies
1725
SecondaryBundlesSection_title=Automated Management of Dependencies
1725
SelfHostingPropertyPage_viewerLabel=Deselect the folders to be excluded:
1726
SelfHostingPropertyPage_viewerLabel=Deselect the folders to be excluded:
(-)src/org/eclipse/pde/internal/ui/search/ShowDescriptionAction.java (-1 lines)
Lines 32-38 Link Here
32
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.browser.IWebBrowser;
33
import org.eclipse.ui.browser.IWebBrowser;
34
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
34
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
35
import org.eclipse.update.core.Utilities;
36
35
37
public class ShowDescriptionAction extends Action {
36
public class ShowDescriptionAction extends Action {
38
	private String fPointID;
37
	private String fPointID;
(-)src_samples/org/eclipse/pde/internal/ui/samples/ShowSampleAction.java (-27 / +110 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2000, 2008 IBM Corporation and others.
2
 *  Copyright (c) 2000, 2010 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 10-35 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.samples;
11
package org.eclipse.pde.internal.ui.samples;
12
12
13
import java.io.IOException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.net.URI;
16
import java.net.URISyntaxException;
17
import java.util.Collection;
14
import java.util.Properties;
18
import java.util.Properties;
15
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
20
import org.eclipse.equinox.internal.provisional.configurator.Configurator;
21
import org.eclipse.equinox.p2.core.IProvisioningAgent;
22
import org.eclipse.equinox.p2.core.ProvisionException;
23
import org.eclipse.equinox.p2.engine.IProfile;
24
import org.eclipse.equinox.p2.engine.IProfileRegistry;
25
import org.eclipse.equinox.p2.operations.InstallOperation;
26
import org.eclipse.equinox.p2.operations.ProvisioningJob;
27
import org.eclipse.equinox.p2.query.IQuery;
28
import org.eclipse.equinox.p2.query.QueryUtil;
29
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
30
import org.eclipse.equinox.p2.ui.ProvisioningUI;
16
import org.eclipse.jface.action.Action;
31
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.dialogs.MessageDialog;
32
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.operation.IRunnableWithProgress;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
19
import org.eclipse.jface.window.Window;
34
import org.eclipse.jface.window.Window;
20
import org.eclipse.jface.wizard.WizardDialog;
35
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.pde.internal.core.util.VersionUtil;
36
import org.eclipse.pde.internal.ui.*;
22
import org.eclipse.pde.internal.ui.PDEPlugin;
23
import org.eclipse.pde.internal.ui.PDEUIMessages;
24
import org.eclipse.swt.widgets.Shell;
37
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.ui.PlatformUI;
38
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.WorkbenchException;
39
import org.eclipse.ui.WorkbenchException;
27
import org.eclipse.ui.intro.IIntroSite;
40
import org.eclipse.ui.intro.IIntroSite;
28
import org.eclipse.ui.intro.config.*;
41
import org.eclipse.ui.intro.config.*;
29
import org.eclipse.update.configurator.ConfiguratorUtils;
42
import org.osgi.framework.BundleContext;
30
import org.eclipse.update.configurator.IPlatformConfiguration;
43
import org.osgi.framework.ServiceReference;
31
import org.eclipse.update.standalone.InstallCommand;
32
import org.osgi.framework.Version;
33
44
34
public class ShowSampleAction extends Action implements IIntroAction {
45
public class ShowSampleAction extends Action implements IIntroAction {
35
	private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$
46
	private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$
Lines 37-46 Link Here
37
	private static final String UPDATE_SITE = "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/pde-ui-home/samples/"; //$NON-NLS-1$
48
	private static final String UPDATE_SITE = "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/pde-ui-home/samples/"; //$NON-NLS-1$
38
	private String sampleId;
49
	private String sampleId;
39
50
51
	private ProvisioningUI provUI;
52
40
	/**
53
	/**
41
	 *  
54
	 *  
42
	 */
55
	 */
43
	public ShowSampleAction() {
56
	public ShowSampleAction() {
57
		provUI = ProvisioningUI.getDefaultUI();
44
	}
58
	}
45
59
46
	public void run(IIntroSite site, Properties params) {
60
	public void run(IIntroSite site, Properties params) {
Lines 109-116 Link Here
109
	private void enableActivities(IConfigurationElement sample) {
123
	private void enableActivities(IConfigurationElement sample) {
110
	}
124
	}
111
125
126
	/**
127
	 * Ensure the sample feature is present. If not present, attempt to install it.
128
	 * 
129
	 * @return <code>true</code> if the sample features are present, and
130
	 * <code>false</code> otherwise.
131
	 */
112
	private boolean ensureSampleFeaturePresent() {
132
	private boolean ensureSampleFeaturePresent() {
113
		if (checkFeature())
133
		IProfile profile = getProfile();
134
		if (profile == null)
135
			return false;
136
		if (checkFeature(profile))
114
			return true;
137
			return true;
115
		// the feature is not present - ask to download
138
		// the feature is not present - ask to download
116
		if (MessageDialog.openQuestion(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.ShowSampleAction_msgTitle, PDEUIMessages.ShowSampleAction_msgDesc)) {
139
		if (MessageDialog.openQuestion(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.ShowSampleAction_msgTitle, PDEUIMessages.ShowSampleAction_msgDesc)) {
Lines 119-147 Link Here
119
		return false;
142
		return false;
120
	}
143
	}
121
144
122
	private boolean checkFeature() {
145
	private boolean checkFeature(IProfile profile) {
123
		IPlatformConfiguration config = ConfiguratorUtils.getCurrentPlatformConfiguration();
146
		return !profile.query(getSampleFeatureQuery(), null).isEmpty();
124
		IPlatformConfiguration.IFeatureEntry[] features = config.getConfiguredFeatureEntries();
147
	}
125
		Version sampleVersion = new Version(SAMPLE_FEATURE_VERSION);
148
126
		for (int i = 0; i < features.length; i++) {
149
	/**
127
			String id = features[i].getFeatureIdentifier();
150
	 * Returns <code>true</code> if the sample feature is already installed, or if
128
			if (SAMPLE_FEATURE_ID.equals(id)) {
151
	 * it won't be possible to install the feature (required services are missing). Returns
129
				String version = features[i].getFeatureVersion();
152
	 * <code>false</code> if the features are missing and should be installed.
130
				Version fversion = Version.parseVersion(version);
153
	 */
131
				if (VersionUtil.isCompatibleWith(fversion, sampleVersion))
154
	private IProfile getProfile() {
132
					return true;
155
		IProvisioningAgent agent = provUI.getSession().getProvisioningAgent();
133
			}
156
		if (agent == null)
134
		}
157
			return null;
135
		return false;
158
		IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
159
		if (registry == null)
160
			return null;
161
		return registry.getProfile(provUI.getProfileId());
162
	}
163
164
	IQuery getSampleFeatureQuery() {
165
		return QueryUtil.createIUQuery(SAMPLE_FEATURE_ID, org.eclipse.equinox.p2.metadata.Version.parseVersion(SAMPLE_FEATURE_VERSION));
136
	}
166
	}
137
167
168
	/**
169
	 * Download the sample feature, returning <code>true</code> if the feature
170
	 * was installed successfully, and <code>false</code> otherwise.
171
	 */
138
	private boolean downloadFeature() {
172
	private boolean downloadFeature() {
139
		IRunnableWithProgress op = new IRunnableWithProgress() {
173
		IRunnableWithProgress op = new IRunnableWithProgress() {
140
			public void run(IProgressMonitor monitor) throws InvocationTargetException {
174
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
141
				try {
175
				try {
142
					InstallCommand command = new InstallCommand(SAMPLE_FEATURE_ID, SAMPLE_FEATURE_VERSION, UPDATE_SITE, null, "false"); //$NON-NLS-1$
176
					SubMonitor sub = SubMonitor.convert(monitor, PDEUIMessages.ShowSampleAction_installing, 100);
143
					command.run(monitor);
177
					InstallOperation operation = createInstallOperation(sub.newChild(10));
144
					command.applyChangesNow();
178
					operation.resolveModal(sub.newChild(20));
179
					IStatus status = operation.getResolutionResult();
180
					if (status.getSeverity() == IStatus.CANCEL) {
181
						throw new InterruptedException();
182
					} else if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) {
183
						throw new CoreException(status);
184
					}
185
					ProvisioningJob job = operation.getProvisioningJob(null);
186
					status = job.runModal(sub.newChild(70));
187
					if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) {
188
						throw new CoreException(status);
189
					}
190
					applyConfiguration();
145
				} catch (Exception e) {
191
				} catch (Exception e) {
146
					throw new InvocationTargetException(e);
192
					throw new InvocationTargetException(e);
147
				}
193
				}
Lines 157-160 Link Here
157
		}
203
		}
158
		return true;
204
		return true;
159
	}
205
	}
206
207
	/**
208
	 * Returns a Collection<IInstallableUnit> of the installable units that contain the samples
209
	 * to be installed.
210
	 */
211
	protected Collection findSampleIUs(URI location, SubMonitor monitor) throws ProvisionException {
212
		IMetadataRepository repository = provUI.loadMetadataRepository(location, false, monitor.newChild(5));
213
		return repository.query(getSampleFeatureQuery(), monitor.newChild(5)).toUnmodifiableSet();
214
	}
215
216
	/**
217
	 * Creates the operation that will install the sample features in the running platform.
218
	 */
219
	InstallOperation createInstallOperation(SubMonitor monitor) throws URISyntaxException, ProvisionException {
220
		URI repositoryLocation = new URI(UPDATE_SITE);
221
		Collection sampleIUs = findSampleIUs(repositoryLocation, monitor);
222
		URI[] repos = new URI[] {repositoryLocation};
223
		InstallOperation operation = provUI.getInstallOperation(sampleIUs, repos);
224
		return operation;
225
	}
226
227
	/**
228
	 * Apply the profile changes to the currently running configuration.
229
	 */
230
	void applyConfiguration() throws CoreException {
231
		BundleContext context = PDEPlugin.getDefault().getBundle().getBundleContext();
232
		ServiceReference reference = context.getServiceReference(Configurator.class.getName());
233
		Configurator configurator = (Configurator) context.getService(reference);
234
		try {
235
			configurator.applyConfiguration();
236
		} catch (IOException e) {
237
			throw new CoreException(new Status(IStatus.ERROR, IPDEUIConstants.PLUGIN_ID, "Unexpected failure applying configuration", e)); //$NON-NLS-1$
238
		} finally {
239
			context.ungetService(reference);
240
		}
241
	}
242
160
}
243
}

Return to bug 210529