View | Details | Raw Unified | Return to bug 250126 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/P2Utils.java (-1 / +161 lines)
Lines 17-32 Link Here
17
import java.net.URL;
17
import java.net.URL;
18
import java.util.*;
18
import java.util.*;
19
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
20
import org.eclipse.equinox.internal.p2.engine.*;
20
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
21
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
22
import org.eclipse.equinox.internal.provisional.p2.director.PlannerHelper;
23
import org.eclipse.equinox.internal.provisional.p2.engine.*;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.*;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription;
21
import org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
27
import org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
28
import org.eclipse.osgi.service.resolver.*;
22
import org.eclipse.pde.core.plugin.IPluginBase;
29
import org.eclipse.pde.core.plugin.IPluginBase;
23
import org.eclipse.pde.core.plugin.IPluginModelBase;
30
import org.eclipse.pde.core.plugin.IPluginModelBase;
24
import org.eclipse.pde.internal.build.BundleHelper;
31
import org.eclipse.pde.internal.build.BundleHelper;
25
import org.eclipse.pde.internal.build.IPDEBuildConstants;
32
import org.eclipse.pde.internal.build.IPDEBuildConstants;
26
import org.eclipse.pde.internal.core.plugin.PluginBase;
33
import org.eclipse.pde.internal.core.plugin.PluginBase;
34
import org.osgi.framework.Constants;
27
35
28
/**
36
/**
29
 * Utilities to read and write bundle and source information files.
37
 * Utilities to read and write p2 files
30
 * 
38
 * 
31
 * @since 3.4
39
 * @since 3.4
32
 */
40
 */
Lines 39-44 Link Here
39
47
40
	public static final String P2_FLAVOR_DEFAULT = "tooling"; //$NON-NLS-1$
48
	public static final String P2_FLAVOR_DEFAULT = "tooling"; //$NON-NLS-1$
41
49
50
	public static final ITouchpointType TOUCHPOINT_OSGI = MetadataFactory.createTouchpointType("org.eclipse.equinox.p2.osgi", Version.createOSGi(1, 0, 0)); //$NON-NLS-1$
51
	private static final String CAPABILITY_NS_OSGI_BUNDLE = "osgi.bundle"; //$NON-NLS-1$
52
	private static final String CAPABILITY_NS_OSGI_FRAGMENT = "osgi.fragment"; //$NON-NLS-1$
53
	public static final String TYPE_ECLIPSE_BUNDLE = "bundle"; //$NON-NLS-1$
54
	public static final String NAMESPACE_ECLIPSE_TYPE = "org.eclipse.equinox.p2.eclipse.type"; //$NON-NLS-1$
55
	public static final IProvidedCapability BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_BUNDLE, Version.createOSGi(1, 0, 0));
56
	public static final String CAPABILITY_NS_JAVA_PACKAGE = "java.package"; //$NON-NLS-1$
57
42
	/**
58
	/**
43
	 * Returns bundles defined by the 'bundles.info' file in the
59
	 * Returns bundles defined by the 'bundles.info' file in the
44
	 * specified location, or <code>null</code> if none. The "bundles.info" file
60
	 * specified location, or <code>null</code> if none. The "bundles.info" file
Lines 296-299 Link Here
296
		}
312
		}
297
	}
313
	}
298
314
315
	/**
316
	 * Returns whether a profile with the given ID exists in a profile registry
317
	 * stored in the give p2 data area.
318
	 * 
319
	 * @param profileID id of the profile to check
320
	 * @param p2DataArea data area where the profile registry is
321
	 * @return whether the profile exists
322
	 */
323
	public static boolean profileExists(String profileID, File p2DataArea) {
324
		// Create a custom registry that checks the profile in the proper location
325
		File engineArea = new File(p2DataArea, EngineActivator.ID);
326
		File registryArea = new File(engineArea, SimpleProfileRegistry.DEFAULT_STORAGE_DIR);
327
		registryArea.mkdirs();
328
		SimpleProfileRegistry customRegistry = new SimpleProfileRegistry(registryArea);
329
330
		return customRegistry.containsProfile(profileID);
331
	}
332
333
	/**
334
	 * Generates a profile containing metadata for all of the bundles in the provided collection.
335
	 * The profile will have the given profile ID and will be persisted in the profile registry
336
	 * directory inside the given p2 data area.
337
	 * 
338
	 * @param profileID the ID to be used when creating the profile, if a profile with the same name exists, it will be overwritten
339
	 * @param p2DataArea the directory which contains p2 data including the profile registry, if the directory path doesn't exist it will be created
340
	 * @param bundles the collection of bundles to create metadata for and add to the profile
341
	 * 
342
	 * @throws CoreException if the profile cannot be generated
343
	 */
344
	public static void createProfile(String profileID, File p2DataArea, Collection bundles) throws CoreException {
345
		// TODO Could avoid using internal p2 code if multiple instances of the p2 servers could be run on the same vm (being looked at in 3.6)
346
347
		// Create a custom registry that stores the profile in the proper location
348
		File engineArea = new File(p2DataArea, EngineActivator.ID);
349
		File registryArea = new File(engineArea, SimpleProfileRegistry.DEFAULT_STORAGE_DIR);
350
		registryArea.mkdirs();
351
		SimpleProfileRegistry customRegistry = new SimpleProfileRegistry(registryArea);
352
353
		// Delete any previous profiles with the same ID
354
		customRegistry.removeProfile(profileID);
355
356
		// Create the profile
357
		IProfile profile = null;
358
		Properties props = new Properties();
359
		props.setProperty(IProfile.PROP_INSTALL_FOLDER, registryArea.getAbsolutePath());
360
		profile = customRegistry.addProfile(profileID, props);
361
362
		// Create metadata for the bundles
363
		Collection ius = new ArrayList(bundles.size());
364
		for (Iterator iterator = bundles.iterator(); iterator.hasNext();) {
365
			IPluginModelBase model = (IPluginModelBase) iterator.next();
366
			BundleDescription bundle = model.getBundleDescription();
367
			ius.add(createBundleIU(bundle));
368
		}
369
370
		// Create operands to install the metadata
371
		Operand[] operands = new Operand[ius.size() * 2];
372
		int i = 0;
373
		for (Iterator iter = ius.iterator(); iter.hasNext();) {
374
			IInstallableUnit iu = (IInstallableUnit) iter.next();
375
			operands[i++] = new InstallableUnitOperand(null, iu);
376
			operands[i++] = new InstallableUnitPropertyOperand(iu, "org.eclipse.equinox.p2.internal.inclusion.rules", null, PlannerHelper.createOptionalInclusionRule(iu));
377
		}
378
379
		// Add the metadata to the profile
380
		ProvisioningContext context = new ProvisioningContext();
381
		PhaseSet phaseSet = DefaultPhaseSet.createDefaultPhaseSet(DefaultPhaseSet.PHASE_CHECK_TRUST | DefaultPhaseSet.PHASE_COLLECT | DefaultPhaseSet.PHASE_CONFIGURE | DefaultPhaseSet.PHASE_UNCONFIGURE | DefaultPhaseSet.PHASE_UNINSTALL);
382
		File profileDataDirectory = customRegistry.getProfileDataDirectory(profile.getProfileId());
383
		EngineSession session = new EngineSession(profile, profileDataDirectory, context);
384
		IStatus status = phaseSet.perform(new ActionManager(), session, profile, operands, context, new NullProgressMonitor());
385
386
		if (!status.isOK() && status.getSeverity() != IStatus.CANCEL) {
387
			throw new CoreException(status);
388
		}
389
	}
390
391
	/**
392
	 * Creates an installable unit from a bundle description
393
	 * 
394
	 * @param bd bundle description to create metadata for
395
	 * @return an installable unit
396
	 */
397
	private static IInstallableUnit createBundleIU(BundleDescription bd) {
398
		InstallableUnitDescription iu = new MetadataFactory.InstallableUnitDescription();
399
		iu.setSingleton(bd.isSingleton());
400
		iu.setId(bd.getSymbolicName());
401
		iu.setVersion(Version.fromOSGiVersion(bd.getVersion()));
402
		iu.setFilter(bd.getPlatformFilter());
403
		iu.setTouchpointType(TOUCHPOINT_OSGI);
404
405
		boolean isFragment = bd.getHost() != null;
406
407
		//Process the required bundles
408
		BundleSpecification requiredBundles[] = bd.getRequiredBundles();
409
		ArrayList reqsDeps = new ArrayList();
410
		if (isFragment)
411
			reqsDeps.add(MetadataFactory.createRequiredCapability(CAPABILITY_NS_OSGI_BUNDLE, bd.getHost().getName(), VersionRange.fromOSGiVersionRange(bd.getHost().getVersionRange()), null, false, false));
412
		for (int j = 0; j < requiredBundles.length; j++)
413
			reqsDeps.add(MetadataFactory.createRequiredCapability(CAPABILITY_NS_OSGI_BUNDLE, requiredBundles[j].getName(), VersionRange.fromOSGiVersionRange(requiredBundles[j].getVersionRange()), null, requiredBundles[j].isOptional(), false));
414
415
		// Process the import packages
416
		ImportPackageSpecification osgiImports[] = bd.getImportPackages();
417
		for (int i = 0; i < osgiImports.length; i++) {
418
			// TODO we need to sort out how we want to handle wild-carded dynamic imports - for now we ignore them
419
			ImportPackageSpecification importSpec = osgiImports[i];
420
			String importPackageName = importSpec.getName();
421
			if (importPackageName.indexOf('*') != -1)
422
				continue;
423
			VersionRange versionRange = VersionRange.fromOSGiVersionRange(importSpec.getVersionRange());
424
			//TODO this needs to be refined to take into account all the attribute handled by imports
425
			reqsDeps.add(MetadataFactory.createRequiredCapability(CAPABILITY_NS_JAVA_PACKAGE, importPackageName, versionRange, null, isOptional(importSpec), false));
426
		}
427
		iu.setRequiredCapabilities((IRequiredCapability[]) reqsDeps.toArray(new IRequiredCapability[reqsDeps.size()]));
428
429
		// Create set of provided capabilities
430
		ArrayList providedCapabilities = new ArrayList();
431
		providedCapabilities.add(createSelfCapability(bd.getSymbolicName(), Version.fromOSGiVersion(bd.getVersion())));
432
		providedCapabilities.add(MetadataFactory.createProvidedCapability(CAPABILITY_NS_OSGI_BUNDLE, bd.getSymbolicName(), Version.fromOSGiVersion(bd.getVersion())));
433
434
		// Process the export package
435
		ExportPackageDescription exports[] = bd.getExportPackages();
436
		for (int i = 0; i < exports.length; i++) {
437
			//TODO make sure that we support all the refinement on the exports
438
			providedCapabilities.add(MetadataFactory.createProvidedCapability(CAPABILITY_NS_JAVA_PACKAGE, exports[i].getName(), Version.fromOSGiVersion(exports[i].getVersion())));
439
		}
440
		// Here we add a bundle capability to identify bundles
441
		providedCapabilities.add(BUNDLE_CAPABILITY);
442
		if (isFragment)
443
			providedCapabilities.add(MetadataFactory.createProvidedCapability(CAPABILITY_NS_OSGI_FRAGMENT, bd.getHost().getName(), Version.fromOSGiVersion(bd.getVersion())));
444
445
		iu.setCapabilities((IProvidedCapability[]) providedCapabilities.toArray(new IProvidedCapability[providedCapabilities.size()]));
446
		return MetadataFactory.createInstallableUnit(iu);
447
	}
448
449
	private static IProvidedCapability createSelfCapability(String installableUnitId, Version installableUnitVersion) {
450
		return MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, installableUnitId, installableUnitVersion);
451
	}
452
453
	private static boolean isOptional(ImportPackageSpecification importedPackage) {
454
		if (importedPackage.getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_DYNAMIC) || importedPackage.getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_OPTIONAL))
455
			return true;
456
		return false;
457
	}
458
299
}
459
}
(-)src/org/eclipse/pde/internal/launching/launcher/LaunchConfigurationHelper.java (-18 / +35 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.launching.launcher;
11
package org.eclipse.pde.internal.launching.launcher;
12
12
13
import org.eclipse.pde.launching.IPDELauncherConstants;
14
15
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
16
17
18
import java.io.*;
13
import java.io.*;
19
import java.net.URL;
14
import java.net.URL;
20
import java.util.*;
15
import java.util.*;
Lines 28-33 Link Here
28
import org.eclipse.pde.core.plugin.TargetPlatform;
23
import org.eclipse.pde.core.plugin.TargetPlatform;
29
import org.eclipse.pde.internal.build.IPDEBuildConstants;
24
import org.eclipse.pde.internal.build.IPDEBuildConstants;
30
import org.eclipse.pde.internal.core.*;
25
import org.eclipse.pde.internal.core.*;
26
import org.eclipse.pde.internal.launching.IPDEConstants;
27
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
28
import org.eclipse.pde.launching.IPDELauncherConstants;
31
29
32
/**
30
/**
33
 * Contains helper methods for launching an Eclipse Runtime Workbench
31
 * Contains helper methods for launching an Eclipse Runtime Workbench
Lines 37-42 Link Here
37
	private static final String PROP_OSGI_FRAMEWORK = "osgi.framework"; //$NON-NLS-1$
35
	private static final String PROP_OSGI_FRAMEWORK = "osgi.framework"; //$NON-NLS-1$
38
	private static final String PROP_OSGI_BUNDLES = "osgi.bundles"; //$NON-NLS-1$
36
	private static final String PROP_OSGI_BUNDLES = "osgi.bundles"; //$NON-NLS-1$
39
	private static final String PROP_P2_DATA_AREA = "eclipse.p2.data.area"; //$NON-NLS-1$
37
	private static final String PROP_P2_DATA_AREA = "eclipse.p2.data.area"; //$NON-NLS-1$
38
	private static final String DEFAULT_PROFILE_NAME = "SelfHostingProfile"; //$NON-NLS-1$
39
40
	/**
41
	 * The p2 data area will be set to a directory with this name inside the configuration folder
42
	 */
43
	private static final String DEFAULT_P2_DIRECTORY = ".p2"; //$NON-NLS-1$
40
44
41
	public static void synchronizeManifests(ILaunchConfiguration config, File configDir) {
45
	public static void synchronizeManifests(ILaunchConfiguration config, File configDir) {
42
		try {
46
		try {
Lines 83-89 Link Here
83
		return mgr.performStringSubstitution(text);
87
		return mgr.performStringSubstitution(text);
84
	}
88
	}
85
89
86
	public static Properties createConfigIniFile(ILaunchConfiguration configuration, String productID, Map bundles, Map bundlesWithStartLevels, File directory) throws CoreException {
90
	public static Properties createConfigIniFile(ILaunchConfiguration configuration, String productID, Map bundles, Map bundlesWithStartLevels, File configurationDirectory) throws CoreException {
87
		Properties properties = null;
91
		Properties properties = null;
88
		// if we are to generate a config.ini, start with the values in the target platform's config.ini - bug 141918
92
		// if we are to generate a config.ini, start with the values in the target platform's config.ini - bug 141918
89
		if (configuration.getAttribute(IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true)) {
93
		if (configuration.getAttribute(IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true)) {
Lines 98-109 Link Here
98
			String bundleList = properties.getProperty(PROP_OSGI_BUNDLES);
102
			String bundleList = properties.getProperty(PROP_OSGI_BUNDLES);
99
			if (bundleList != null)
103
			if (bundleList != null)
100
				properties.setProperty(PROP_OSGI_BUNDLES, computeOSGiBundles(TargetPlatformHelper.stripPathInformation(bundleList), bundles, bundlesWithStartLevels));
104
				properties.setProperty(PROP_OSGI_BUNDLES, computeOSGiBundles(TargetPlatformHelper.stripPathInformation(bundleList), bundles, bundlesWithStartLevels));
101
			String dataArea = properties.getProperty(PROP_P2_DATA_AREA);
102
			if (dataArea != null) {
103
				// Make the p2 data area in the configuration area itself, rather than a sibling of the configuration
104
				// area (which is a the root pde.core shared metadata area) @see bug 272810
105
				properties.setProperty(PROP_P2_DATA_AREA, "@config.dir/.p2"); //$NON-NLS-1$
106
			}
107
		} else {
105
		} else {
108
			String templateLoc = configuration.getAttribute(IPDELauncherConstants.CONFIG_TEMPLATE_LOCATION, (String) null);
106
			String templateLoc = configuration.getAttribute(IPDELauncherConstants.CONFIG_TEMPLATE_LOCATION, (String) null);
109
			if (templateLoc != null) {
107
			if (templateLoc != null) {
Lines 120-144 Link Here
120
		} else {
118
		} else {
121
			properties = new Properties();
119
			properties = new Properties();
122
		}
120
		}
123
		if (!directory.exists()) {
121
		if (!configurationDirectory.exists()) {
124
			directory.mkdirs();
122
			configurationDirectory.mkdirs();
125
		}
123
		}
126
		String osgiBundles = properties.getProperty(PROP_OSGI_BUNDLES);
124
		String osgiBundles = properties.getProperty(PROP_OSGI_BUNDLES);
127
		int start = configuration.getAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
125
		int start = configuration.getAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
128
		properties.put("osgi.bundles.defaultStartLevel", Integer.toString(start)); //$NON-NLS-1$
126
		properties.put("osgi.bundles.defaultStartLevel", Integer.toString(start)); //$NON-NLS-1$
129
		boolean autostart = configuration.getAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, false);
127
		boolean autostart = configuration.getAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, false);
130
128
131
		// if we are launching using P2, write out P2 files (bundles.txt) and add P2 property to config.ini
129
		// Special processing for launching with p2
132
		if (osgiBundles != null && osgiBundles.indexOf(IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR) != -1 && bundles.containsKey(IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR)) {
130
		if (osgiBundles != null && osgiBundles.indexOf(IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR) != -1 && bundles.containsKey(IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR)) {
131
132
			// Write out P2 files (bundles.txt)
133
			URL bundlesTxt = null;
133
			URL bundlesTxt = null;
134
			boolean usedefault = configuration.getAttribute(IPDELauncherConstants.USE_DEFAULT, true);
134
			boolean usedefault = configuration.getAttribute(IPDELauncherConstants.USE_DEFAULT, true);
135
			boolean useFeatures = configuration.getAttribute(IPDELauncherConstants.USEFEATURES, false);
135
			boolean useFeatures = configuration.getAttribute(IPDELauncherConstants.USEFEATURES, false);
136
			if (usedefault || useFeatures) {
136
			if (usedefault || useFeatures) {
137
				bundlesTxt = P2Utils.writeBundlesTxt(bundlesWithStartLevels, 4, false, directory, osgiBundles);
137
				bundlesTxt = P2Utils.writeBundlesTxt(bundlesWithStartLevels, 4, false, configurationDirectory, osgiBundles);
138
			} else {
138
			} else {
139
				bundlesTxt = P2Utils.writeBundlesTxt(bundlesWithStartLevels, start, autostart, directory, null);
139
				bundlesTxt = P2Utils.writeBundlesTxt(bundlesWithStartLevels, start, autostart, configurationDirectory, null);
140
			}
140
			}
141
141
142
			// Add bundles.txt as p2 config data
142
			if (bundlesTxt != null) {
143
			if (bundlesTxt != null) {
143
				properties.setProperty("org.eclipse.equinox.simpleconfigurator.configUrl", bundlesTxt.toString()); //$NON-NLS-1$
144
				properties.setProperty("org.eclipse.equinox.simpleconfigurator.configUrl", bundlesTxt.toString()); //$NON-NLS-1$
144
				// if we have simple configurator and update configurator together, ensure update doesn't reconcile
145
				// if we have simple configurator and update configurator together, ensure update doesn't reconcile
Lines 146-156 Link Here
146
					properties.setProperty("org.eclipse.update.reconcile", "false"); //$NON-NLS-1$ //$NON-NLS-2$
147
					properties.setProperty("org.eclipse.update.reconcile", "false"); //$NON-NLS-1$ //$NON-NLS-2$
147
				}
148
				}
148
			}
149
			}
150
151
			// Make the p2 data area in the configuration area itself, rather than a sibling of the configuration
152
			// area (which is a the root pde.core shared metadata area) @see bug 272810
153
			properties.setProperty(PROP_P2_DATA_AREA, "@config.dir/".concat(DEFAULT_P2_DIRECTORY)); //$NON-NLS-1$
154
155
			// Generate a profile to launch with, set the profile id as the default
156
			if (configuration.getAttribute(IPDELauncherConstants.GENERATE_PROFILE, false)) {
157
				String profileID = DEFAULT_PROFILE_NAME;
158
				File p2DataArea = new File(configurationDirectory, DEFAULT_P2_DIRECTORY);
159
160
				// Unless we are restarting an existing profile, generate/overwrite the profile
161
				if (!configuration.getAttribute(IPDEConstants.RESTART, false) || !P2Utils.profileExists(profileID, p2DataArea)) {
162
					P2Utils.createProfile(profileID, p2DataArea, bundles.values());
163
				}
164
				properties.setProperty("eclipse.p2.profile", profileID); //$NON-NLS-1$
165
			}
149
		}
166
		}
150
167
151
		setBundleLocations(bundles, properties, autostart);
168
		setBundleLocations(bundles, properties, autostart);
152
169
153
		save(new File(directory, "config.ini"), properties); //$NON-NLS-1$
170
		save(new File(configurationDirectory, "config.ini"), properties); //$NON-NLS-1$
154
		return properties;
171
		return properties;
155
	}
172
	}
156
173
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+4 lines)
Lines 2677-2682 Link Here
2677
2677
2678
	public static String ProductInfoSection_features;
2678
	public static String ProductInfoSection_features;
2679
2679
2680
	public static String ProfileBlock_0;
2681
2682
	public static String ProfileBlock_1;
2683
2680
	public static String ImportPackageSection_goToPackage;
2684
	public static String ImportPackageSection_goToPackage;
2681
2685
2682
	public static String ExportPackageSection_findReferences;
2686
	public static String ExportPackageSection_findReferences;

Return to bug 250126