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

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java (-11 / +65 lines)
Lines 246-261 Link Here
246
		//Start figuring out stuffs 
246
		//Start figuring out stuffs 
247
		URL rootURL = launcherData.getLauncher() != null ? launcherData.getLauncher().getParentFile().toURL() : null;
247
		URL rootURL = launcherData.getLauncher() != null ? launcherData.getLauncher().getParentFile().toURL() : null;
248
248
249
		// look for shared configuration to merge
249
		Properties sharedConfigProperties = getSharedConfiguration(props.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), getOSGiInstallArea(manipulator.getLauncherData()));
250
		String sharedConfigurationArea = props.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA);
250
		if (sharedConfigProperties != null) {
251
		if (sharedConfigurationArea != null) {
251
			sharedConfigProperties.putAll(props);
252
			File sharedConfigIni = findSharedConfigIniFile(rootURL, sharedConfigurationArea);
252
			props = sharedConfigProperties;
253
			if (sharedConfigIni != null && sharedConfigIni.exists()) {
254
				Properties sharedProps = loadProperties(sharedConfigIni);
255
				// merge: shared properties are over-written by user customizations
256
				sharedProps.putAll(props);
257
				props = sharedProps;
258
			}
259
		}
253
		}
260
254
261
		//Extracting fwkJar location needs to be done first 
255
		//Extracting fwkJar location needs to be done first 
Lines 333-339 Link Here
333
327
334
		// check for a relative URL
328
		// check for a relative URL
335
		if (!sharedConfigurationURL.getPath().startsWith("/")) { //$NON-NLS-1$
329
		if (!sharedConfigurationURL.getPath().startsWith("/")) { //$NON-NLS-1$
336
337
			if (!rootURL.getProtocol().equals(sharedConfigurationURL.getProtocol())) {
330
			if (!rootURL.getProtocol().equals(sharedConfigurationURL.getProtocol())) {
338
				Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_relative_url, rootURL.toExternalForm(), sharedConfigurationArea));
331
				Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_relative_url, rootURL.toExternalForm(), sharedConfigurationArea));
339
				return null;
332
				return null;
Lines 496-501 Link Here
496
		try {
489
		try {
497
			out = new FileOutputStream(outputFile);
490
			out = new FileOutputStream(outputFile);
498
			configProps = makeRelative(configProps, launcherData.getLauncher().getParentFile().toURL(), fwJar, outputFile.getParentFile(), getOSGiInstallArea(manipulator.getLauncherData()));
491
			configProps = makeRelative(configProps, launcherData.getLauncher().getParentFile().toURL(), fwJar, outputFile.getParentFile(), getOSGiInstallArea(manipulator.getLauncherData()));
492
			filterPropertiesFromSharedArea(configProps, launcherData);
499
			configProps.store(out, header);
493
			configProps.store(out, header);
500
			Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_fwConfigSave, outputFile));
494
			Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_fwConfigSave, outputFile));
501
		} finally {
495
		} finally {
Lines 508-511 Link Here
508
			out = null;
502
			out = null;
509
		}
503
		}
510
	}
504
	}
505
506
	private void filterPropertiesFromSharedArea(Properties configProps, LauncherData launcherData) {
507
		//Remove from the config file that we are about to write the properties that are unchanged compared to what is in the base 
508
		Properties sharedConfigProperties = getSharedConfiguration(configProps.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), getOSGiInstallArea(launcherData));
509
		if (sharedConfigProperties == null)
510
			return;
511
		Enumeration keys = configProps.propertyNames();
512
		while (keys.hasMoreElements()) {
513
			String key = (String) keys.nextElement();
514
			String sharedValue = sharedConfigProperties.getProperty(key);
515
			if (sharedValue == null)
516
				continue;
517
			if (equalsIgnoringSeparators(sharedValue, configProps.getProperty(key)))
518
				configProps.remove(key);
519
		}
520
	}
521
522
	private boolean equalsIgnoringSeparators(String s1, String s2) {
523
		if (s1 == null && s2 == null)
524
			return true;
525
		if (s1 == null || s2 == null)
526
			return false;
527
		StringBuffer sb1 = new StringBuffer(s1);
528
		StringBuffer sb2 = new StringBuffer(s2);
529
		canonicalizePathsForComparison(sb1);
530
		canonicalizePathsForComparison(sb2);
531
		return sb1.toString().equals(sb2.toString());
532
	}
533
534
	private void canonicalizePathsForComparison(StringBuffer s) {
535
		final String[] tokens = new String[] {"\\\\", "\\", "//", "/"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
536
		for (int t = 0; t < tokens.length; t++) {
537
			int idx = s.length();
538
			for (int i = s.length(); i != 0 && idx != -1; i--) {
539
				idx = s.lastIndexOf(tokens[t], idx);
540
				if (idx != -1)
541
					s.replace(idx, idx + tokens[t].length(), "^"); //$NON-NLS-1$
542
			}
543
		}
544
	}
545
546
	private Properties getSharedConfiguration(String sharedConfigurationArea, File baseFile) {
547
		if (sharedConfigurationArea == null)
548
			return null;
549
		File sharedConfigIni;
550
		try {
551
			sharedConfigIni = findSharedConfigIniFile(baseFile.toURL(), sharedConfigurationArea);
552
		} catch (MalformedURLException e) {
553
			return null;
554
		}
555
		if (sharedConfigIni != null && sharedConfigIni.exists())
556
			try {
557
				return loadProperties(sharedConfigIni);
558
			} catch (FileNotFoundException e) {
559
				return null;
560
			} catch (IOException e) {
561
				return null;
562
			}
563
		return null;
564
	}
511
}
565
}

Return to bug 229342