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 240053 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/exports/ProductExportOperation.java (-253 / +5 lines)
Lines 19-35 Link Here
19
import org.eclipse.ant.core.AntRunner;
19
import org.eclipse.ant.core.AntRunner;
20
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.*;
21
import org.eclipse.core.runtime.*;
22
import org.eclipse.jdt.launching.ExecutionArguments;
22
import org.eclipse.osgi.service.resolver.BundleDescription;
23
import org.eclipse.osgi.service.resolver.*;
23
import org.eclipse.osgi.service.resolver.HostSpecification;
24
import org.eclipse.pde.core.plugin.*;
24
import org.eclipse.pde.core.plugin.TargetPlatform;
25
import org.eclipse.pde.internal.build.*;
25
import org.eclipse.pde.internal.build.*;
26
import org.eclipse.pde.internal.build.packager.PackageScriptGenerator;
26
import org.eclipse.pde.internal.build.packager.PackageScriptGenerator;
27
import org.eclipse.pde.internal.core.*;
27
import org.eclipse.pde.internal.core.*;
28
import org.eclipse.pde.internal.core.iproduct.*;
28
import org.eclipse.pde.internal.core.iproduct.*;
29
import org.eclipse.pde.internal.core.iproduct.IProduct;
29
import org.eclipse.pde.internal.core.iproduct.IProduct;
30
import org.eclipse.pde.internal.core.util.CoreUtility;
30
import org.eclipse.pde.internal.core.util.CoreUtility;
31
import org.osgi.framework.BundleContext;
32
import org.osgi.framework.InvalidSyntaxException;
33
import org.w3c.dom.Document;
31
import org.w3c.dom.Document;
34
import org.w3c.dom.Element;
32
import org.w3c.dom.Element;
35
33
Lines 63-71 Link Here
63
61
64
				createFeature(featureID, fFeatureLocation, config, true);
62
				createFeature(featureID, fFeatureLocation, config, true);
65
				createBuildPropertiesFile(fFeatureLocation, config);
63
				createBuildPropertiesFile(fFeatureLocation, config);
66
				createConfigIniFile(config);
67
				createEclipseProductFile();
68
				createLauncherIniFile(config[0]);
69
				doExport(featureID, null, fFeatureLocation, config[0], config[1], config[2], new SubProgressMonitor(monitor, 8));
64
				doExport(featureID, null, fFeatureLocation, config[0], config[1], config[2], new SubProgressMonitor(monitor, 8));
70
			} catch (IOException e) {
65
			} catch (IOException e) {
71
				PDECore.log(e);
66
				PDECore.log(e);
Lines 114-135 Link Here
114
		monitor.done();
109
		monitor.done();
115
	}
110
	}
116
111
117
	private File getCustomIniFile(String os) {
118
		IConfigurationFileInfo info = fProduct.getConfigurationFileInfo();
119
		String path = info.getPath(os);
120
		if (path == null) // if we can't find an os path, let's try the normal one
121
			path = info.getPath(null);
122
		if (info != null && path != null) {
123
			String expandedPath = getExpandedPath(path);
124
			if (expandedPath != null) {
125
				File file = new File(expandedPath);
126
				if (file.exists() && file.isFile())
127
					return file;
128
			}
129
		}
130
		return null;
131
	}
132
133
	/*
112
	/*
134
	 * (non-Javadoc)
113
	 * (non-Javadoc)
135
	 * 
114
	 * 
Lines 238-472 Link Here
238
		buffer.append(file.getAbsolutePath());
217
		buffer.append(file.getAbsolutePath());
239
	}
218
	}
240
219
241
	private void createEclipseProductFile() {
242
		File dir = new File(fFeatureLocation, "temp"); //$NON-NLS-1$
243
		if (!dir.exists() || !dir.isDirectory())
244
			dir.mkdirs();
245
		Properties properties = new Properties();
246
		IPluginModelBase model = PluginRegistry.findModel(getBrandingPlugin());
247
		if (model != null)
248
			properties.put("name", model.getResourceString(fProduct.getName())); //$NON-NLS-1$
249
		else
250
			properties.put("name", fProduct.getName()); //$NON-NLS-1$
251
		properties.put("id", fProduct.getId()); //$NON-NLS-1$
252
		if (model != null)
253
			properties.put("version", model.getPluginBase().getVersion()); //$NON-NLS-1$
254
		File product = new File(dir, ".eclipseproduct"); //$NON-NLS-1$
255
		save(product, properties, "Eclipse Product File"); //$NON-NLS-1$
256
	}
257
258
	private void createLauncherIniFile(String os) {
259
		String programArgs = getProgramArguments(os);
260
		String vmArgs = getVMArguments(os);
261
262
		if (programArgs.length() == 0 && vmArgs.length() == 0)
263
			return;
264
265
		File dir = new File(fFeatureLocation, "temp"); //$NON-NLS-1$
266
		// need to place launcher.ini file in special directory for MacOSX (bug 164762)
267
		if (Platform.OS_MACOSX.equals(os)) {
268
			dir = new File(dir, "Eclipse.app/Contents/MacOS"); //$NON-NLS-1$
269
		}
270
		if (!dir.exists() || !dir.isDirectory())
271
			dir.mkdirs();
272
273
		String lineDelimiter = Platform.OS_WIN32.equals(os) ? "\r\n" : "\n"; //$NON-NLS-1$ //$NON-NLS-2$
274
275
		PrintWriter writer = null;
276
		try {
277
			writer = new PrintWriter(new FileWriter(new File(dir, getLauncherName() + ".ini"))); //$NON-NLS-1$
278
			ExecutionArguments args = new ExecutionArguments(vmArgs, programArgs);
279
280
			// add program arguments
281
			String[] array = args.getProgramArgumentsArray();
282
			for (int i = 0; i < array.length; i++) {
283
				writer.print(array[i]);
284
				writer.print(lineDelimiter);
285
			}
286
287
			// add VM arguments
288
			array = args.getVMArgumentsArray();
289
			if (array.length > 0) {
290
				writer.print("-vmargs"); //$NON-NLS-1$
291
				writer.print(lineDelimiter);
292
				for (int i = 0; i < array.length; i++) {
293
					writer.print(array[i]);
294
					writer.print(lineDelimiter);
295
				}
296
			}
297
		} catch (IOException e) {
298
		} finally {
299
			if (writer != null) {
300
				writer.close();
301
			}
302
		}
303
	}
304
305
	private String getProgramArguments(String os) {
306
		IArgumentsInfo info = fProduct.getLauncherArguments();
307
		return info != null ? CoreUtility.normalize(info.getCompleteProgramArguments(os)) : "";//$NON-NLS-1$
308
	}
309
310
	private String getVMArguments(String os) {
311
		IArgumentsInfo info = fProduct.getLauncherArguments();
312
		return (info != null) ? CoreUtility.normalize(info.getCompleteVMArguments(os)) : ""; //$NON-NLS-1$
313
	}
314
315
	private void createConfigIniFile(String[] config) {
316
		File dir = new File(fFeatureLocation, "temp/configuration"); //$NON-NLS-1$
317
		if (!dir.exists() || !dir.isDirectory())
318
			dir.mkdirs();
319
320
		PrintWriter writer = null;
321
322
		File custom = getCustomIniFile(config[0]);
323
		if (custom != null) {
324
			BufferedReader in = null;
325
			try {
326
				in = new BufferedReader(new FileReader(custom));
327
				writer = new PrintWriter(new FileWriter(new File(dir, "config.ini"))); //$NON-NLS-1$
328
				String line;
329
				while ((line = in.readLine()) != null) {
330
					writer.println(line);
331
				}
332
			} catch (IOException e) {
333
			} finally {
334
				try {
335
					if (in != null)
336
						in.close();
337
					if (writer != null)
338
						writer.close();
339
				} catch (IOException e) {
340
				}
341
			}
342
			return;
343
		}
344
		try {
345
			writer = new PrintWriter(new FileWriter(new File(dir, "config.ini"))); //$NON-NLS-1$
346
			String location = getSplashLocation(config[0], config[1], config[2]);
347
			writer.println("#Product Runtime Configuration File"); //$NON-NLS-1$
348
			writer.println();
349
			if (location != null)
350
				writer.println("osgi.splashPath=" + location); //$NON-NLS-1$
351
			writer.println("eclipse.product=" + fProduct.getId()); //$NON-NLS-1$
352
			writer.println("osgi.bundles.defaultStartLevel=4"); //$NON-NLS-1$
353
354
			String bundleList = getPluginList(config, TargetPlatform.getBundleList());
355
			writer.println("osgi.bundles=" + bundleList); //$NON-NLS-1$
356
357
		} catch (IOException e) {
358
		} finally {
359
			if (writer != null)
360
				writer.close();
361
		}
362
	}
363
364
	private String getSplashLocation(String os, String ws, String arch) {
365
		ISplashInfo info = fProduct.getSplashInfo();
366
		String plugin = null;
367
		if (info != null) {
368
			plugin = info.getLocation();
369
		}
370
		if (plugin == null || plugin.trim().length() == 0)
371
			plugin = getBrandingPlugin();
372
373
		if (plugin == null)
374
			return null;
375
376
		StringBuffer buffer = new StringBuffer("platform:/base/plugins/"); //$NON-NLS-1$
377
		buffer.append(plugin.trim());
378
379
		State state = getState(os, ws, arch);
380
		BundleDescription bundle = state.getBundle(plugin, null);
381
		if (bundle != null) {
382
			BundleDescription[] fragments = bundle.getFragments();
383
			for (int i = 0; i < fragments.length; i++) {
384
				String id = fragments[i].getSymbolicName();
385
				if (fProduct.containsPlugin(id)) {
386
					buffer.append(",platform:/base/plugins/"); //$NON-NLS-1$
387
					buffer.append(id);
388
				}
389
			}
390
		}
391
		return buffer.toString();
392
	}
393
394
	private String getBrandingPlugin() {
395
		int dot = fProduct.getId().lastIndexOf('.');
396
		return (dot != -1) ? fProduct.getId().substring(0, dot) : null;
397
	}
398
399
	private String getPluginList(String[] config, String bundleList) {
400
		if (fProduct.useFeatures()) {
401
			// if we're using features and find simple configurator in the list, let's just default and use update configurator 
402
			if (bundleList.indexOf("org.eclipse.equinox.simpleconfigurator") != -1) { //$NON-NLS-1$
403
				return TargetPlatformHelper.getDefaultBundleList();
404
			}
405
			return bundleList;
406
		}
407
408
		StringBuffer buffer = new StringBuffer();
409
410
		// include only bundles that are actually in this product configuration
411
		Set initialBundleSet = new HashSet();
412
		StringTokenizer tokenizer = new StringTokenizer(bundleList, ","); //$NON-NLS-1$
413
		while (tokenizer.hasMoreTokens()) {
414
			String token = tokenizer.nextToken();
415
			int index = token.indexOf('@');
416
			String id = index != -1 ? token.substring(0, index) : token;
417
			if (fProduct.containsPlugin(id)) {
418
				if (buffer.length() > 0)
419
					buffer.append(',');
420
				buffer.append(id);
421
				if (index != -1 && index < token.length() - 1)
422
					buffer.append(token.substring(index));
423
				initialBundleSet.add(id);
424
			}
425
		}
426
427
		if (!fProduct.containsPlugin("org.eclipse.update.configurator")) { //$NON-NLS-1$
428
			initialBundleSet.add("org.eclipse.osgi"); //$NON-NLS-1$
429
430
			Dictionary environment = new Hashtable(4);
431
			environment.put("osgi.os", config[0]); //$NON-NLS-1$
432
			environment.put("osgi.ws", config[1]); //$NON-NLS-1$
433
			environment.put("osgi.arch", config[2]); //$NON-NLS-1$
434
			environment.put("osgi.nl", config[3]); //$NON-NLS-1$
435
436
			BundleContext context = PDECore.getDefault().getBundleContext();
437
			for (int i = 0; i < fInfo.items.length; i++) {
438
				BundleDescription bundle = (BundleDescription) fInfo.items[i];
439
				String filterSpec = bundle.getPlatformFilter();
440
				try {
441
					if (filterSpec == null || context.createFilter(filterSpec).match(environment)) {
442
						String id = ((BundleDescription) fInfo.items[i]).getSymbolicName();
443
						if (!initialBundleSet.contains(id)) {
444
							if (buffer.length() > 0)
445
								buffer.append(","); //$NON-NLS-1$
446
							buffer.append(id);
447
448
							// ensure core.runtime is always started
449
							if ("org.eclipse.core.runtime".equals(id)) { //$NON-NLS-1$
450
								buffer.append("@start"); //$NON-NLS-1$
451
							}
452
						}
453
					}
454
				} catch (InvalidSyntaxException e) {
455
				}
456
			}
457
		}
458
459
		// something horribly went wrong if we get there
460
		if (buffer.length() == 0)
461
			return TargetPlatformHelper.getDefaultBundleList();
462
463
		// if we have both, prefer update.configurator for now
464
		if (fProduct.containsPlugin("org.eclipse.update.configurator") && fProduct.containsPlugin("org.eclipse.equinox.simpleconfigurator")) //$NON-NLS-1$//$NON-NLS-2$
465
			return TargetPlatformHelper.getDefaultBundleList();
466
467
		return buffer.toString();
468
	}
469
470
	protected HashMap createAntBuildProperties(String os, String ws, String arch) {
220
	protected HashMap createAntBuildProperties(String os, String ws, String arch) {
471
		HashMap properties = super.createAntBuildProperties(os, ws, arch);
221
		HashMap properties = super.createAntBuildProperties(os, ws, arch);
472
		properties.put(IXMLConstants.PROPERTY_LAUNCHER_NAME, getLauncherName());
222
		properties.put(IXMLConstants.PROPERTY_LAUNCHER_NAME, getLauncherName());
Lines 584-589 Link Here
584
		generator.setGenerateVersionsList(true);
334
		generator.setGenerateVersionsList(true);
585
		if (fProduct != null)
335
		if (fProduct != null)
586
			generator.setProduct(fProduct.getModel().getInstallLocation());
336
			generator.setProduct(fProduct.getModel().getInstallLocation());
337
338
		ProductGenerator productGenerator = new ProductGenerator();
587
	}
339
	}
588
340
589
	private void createMacScript(String[] config, IProgressMonitor monitor) {
341
	private void createMacScript(String[] config, IProgressMonitor monitor) {

Return to bug 240053