Bug 304505 - org.eclipse.update.configurator performs duplicate work even when off
diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java
index c16f331..e5df17d 100644
--- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java
+++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java
@@ -76,11 +76,19 @@
Utils.debug("Starting update configurator..."); //$NON-NLS-1$
- String reconcile = ctx.getProperty("org.eclipse.update.reconcile"); //$NON-NLS-1$
- if (reconcile == null || reconcile.equalsIgnoreCase("true")) //$NON-NLS-1$
+ if (isReconciling())
installBundles();
registerBundleGroupProvider();
}
+
+ /**
+ * Returns whether the update configurator should be doing its own reconciling work
+ */
+ public static boolean isReconciling() {
+ String reconcile = context.getProperty("org.eclipse.update.reconcile"); //$NON-NLS-1$
+ return reconcile == null || reconcile.equalsIgnoreCase("true"); //$NON-NLS-1$
+
+ }
private void registerBundleGroupProvider() {
final String serviceName = IBundleGroupProvider.class.getName();
@@ -253,7 +261,7 @@
if (activationPolicy != null) {
ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_ACTIVATIONPOLICY, activationPolicy);
if (elements != null && elements.length > 0) {
- // if the value is "lazy" then it has a lazy activation poliyc
+ // if the value is "lazy" then it has a lazy activation policy
if (Constants.ACTIVATION_LAZY.equals(elements[0].getValue()))
return true;
}
diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
index 691dfbe..3331300 100644
--- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
+++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
@@ -60,7 +60,7 @@
private static PlatformConfiguration currentPlatformConfiguration = null;
//private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
-// private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ // private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();
private static final String XML_ENCODING = "UTF-8"; //$NON-NLS-1$
private Configuration config;
@@ -86,7 +86,7 @@
private static final String CONFIG_FILE_LOCK_SUFFIX = ".lock"; //$NON-NLS-1$
private static final String CONFIG_FILE_TEMP_SUFFIX = ".tmp"; //$NON-NLS-1$
private static final String LINKS = "links"; //$NON-NLS-1$
- private static final String[] BOOTSTRAP_PLUGINS = {};
+ private static final String[] BOOTSTRAP_PLUGINS = {};
private static final String DEFAULT_FEATURE_APPLICATION = "org.eclipse.ui.ide.workbench"; //$NON-NLS-1$
@@ -94,44 +94,45 @@
private static final String LINK_READ = "r"; //$NON-NLS-1$
private static final String LINK_READ_WRITE = "rw"; //$NON-NLS-1$
private static URL installURL;
-
+
private PlatformConfiguration(Location platformConfigLocation) throws CoreException, IOException {
this.externalLinkSites = new HashMap();
this.config = null;
-
+
// initialize configuration
initializeCurrent(platformConfigLocation);
- if(config != null)
+ if (config != null)
setDefaultPolicy();
// Detect external links. These are "soft link" to additional sites. The link
// files are usually provided by external installation programs. They are located
// relative to this configuration URL.
- // Note: don't do it for self hosting
- if (!isTransient())
- configureExternalLinks();
+ // Note: don't do it for self hosting or if update reconciler is disabled
+ if (ConfigurationActivator.isReconciling()) {
+ if (!isTransient())
+ configureExternalLinks();
- // Validate sites in the configuration. Causes any sites that do not exist to
- // be removed from the configuration
- validateSites();
+ // Validate sites in the configuration. Causes any sites that do not exist to
+ // be removed from the configuration
+ validateSites();
+ }
// compute differences between configuration and actual content of the sites
// (base sites and link sites)
// Note: when the config is transient (generated by PDE, etc.) we don't reconcile
if (isTransient())
return;
-
+
// for 'osgi.clean' or osgi.checkConfiguration', force a refresh
boolean osgiClean = "true".equals(ConfigurationActivator.getBundleContext().getProperty("osgi.clean")); //$NON-NLS-1$ //$NON-NLS-2$
boolean osgiCheckConfiguration = "true".equals(ConfigurationActivator.getBundleContext().getProperty("osgi.checkConfiguration")); //$NON-NLS-1$ //$NON-NLS-2$
-
+
if (osgiClean || osgiCheckConfiguration) {
// We have to call refresh() for features to be rescanned correctly
refresh();
reconcile();
- }
- else {
+ } else {
changeStamp = computeChangeStamp();
if (changeStamp > config.getDate().getTime())
reconcile();
@@ -148,11 +149,11 @@
installLocation = new Path(url.getPath()).removeLastSegments(3).toFile().toURL();
}
} catch (Exception e) {
- //
+ //
}
- initialize(url, installLocation);
+ initialize(url, installLocation);
}
-
+
public PlatformConfiguration(URL url, URL installLocation) throws Exception {
this.externalLinkSites = new HashMap();
initialize(url, installLocation);
@@ -163,15 +164,15 @@
// has a MANAGED_ONLY policy, then all sites should have default policy
// of MANAGED_ONLY.
ISiteEntry[] sentries = getConfiguredSites();
- if(sentries != null && sentries.length >0){
+ if (sentries != null && sentries.length > 0) {
int policyType = sentries[0].getSitePolicy().getType();
- if(policyType == ISitePolicy.MANAGED_ONLY){
+ if (policyType == ISitePolicy.MANAGED_ONLY) {
defaultPolicy = policyType;
}
}
}
- public static int getDefaultPolicy(){
+ public static int getDefaultPolicy() {
return defaultPolicy;
}
@@ -218,7 +219,7 @@
if (entry == null)
return;
-
+
URL url = entry.getURL();
if (url == null)
return;
@@ -226,9 +227,9 @@
String key = url.toExternalForm();
if (config.getSiteEntry(key) != null && !replace)
return;
-
+
if (entry instanceof SiteEntry)
- config.addSiteEntry(key, (SiteEntry)entry);
+ config.addSiteEntry(key, (SiteEntry) entry);
}
/*
@@ -241,8 +242,8 @@
URL url = entry.getURL();
if (url == null)
return;
-
- String key = url.toExternalForm();
+
+ String key = url.toExternalForm();
if (entry instanceof SiteEntry)
config.removeSiteEntry(key);
}
@@ -253,14 +254,14 @@
public ISiteEntry[] getConfiguredSites() {
if (config == null)
return new ISiteEntry[0];
-
+
SiteEntry[] sites = config.getSites();
ArrayList enabledSites = new ArrayList(sites.length);
- for (int i=0; i<sites.length; i++) {
+ for (int i = 0; i < sites.length; i++) {
if (sites[i].isEnabled())
enabledSites.add(sites[i]);
}
- return (ISiteEntry[])enabledSites.toArray(new ISiteEntry[enabledSites.size()]);
+ return (ISiteEntry[]) enabledSites.toArray(new ISiteEntry[enabledSites.size()]);
}
/*
@@ -269,7 +270,7 @@
public ISiteEntry findConfiguredSite(URL url) {
return findConfiguredSite(url, true);
}
-
+
/**
*
* @param url site url
@@ -281,7 +282,7 @@
return null;
String key = url.toExternalForm();
- SiteEntry result = config.getSiteEntry(key);
+ SiteEntry result = config.getSiteEntry(key);
if (result == null) { // retry with decoded URL string
try {
//PAL foundation
@@ -292,7 +293,7 @@
}
result = config.getSiteEntry(key);
}
-
+
if (result == null && checkPlatformURL) {
try {
result = findConfiguredSite(config.asPlatformURL(url), false);
@@ -320,17 +321,17 @@
config = new Configuration();
SiteEntry[] sites = config.getSites();
- for (int i=0; i<sites.length; i++) {
+ for (int i = 0; i < sites.length; i++) {
// find out what site contains the feature and configure it
try {
- URL url = new URL(sites[i].getURL(), FEATURES + "/" + entry.getFeatureIdentifier()+ "_" + entry.getFeatureVersion() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ URL url = new URL(sites[i].getURL(), FEATURES + "/" + entry.getFeatureIdentifier() + "_" + entry.getFeatureVersion() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
try {
url = resolvePlatformURL(url, getBasePathLocation(url, config.getInstallURL(), config.getURL()));
} catch (IOException e) {
}
if (new File(url.getFile()).exists())
sites[i].addFeatureEntry(entry);
- else {
+ else {
url = new URL(sites[i].getURL(), FEATURES + "/" + entry.getFeatureIdentifier() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
if (new File(url.getFile()).exists())
sites[i].addFeatureEntry(entry);
@@ -360,12 +361,12 @@
public IFeatureEntry[] getConfiguredFeatureEntries() {
ArrayList configFeatures = new ArrayList();
SiteEntry[] sites = config.getSites();
- for (int i=0; i<sites.length; i++) {
+ for (int i = 0; i < sites.length; i++) {
FeatureEntry[] features = sites[i].getFeatureEntries();
- for (int j=0; j<features.length; j++)
+ for (int j = 0; j < features.length; j++)
configFeatures.add(features[j]);
}
- return (IFeatureEntry[])configFeatures.toArray(new FeatureEntry[configFeatures.size()]);
+ return (IFeatureEntry[]) configFeatures.toArray(new FeatureEntry[configFeatures.size()]);
}
/*
@@ -376,7 +377,7 @@
return null;
SiteEntry[] sites = config.getSites();
- for (int i=0; i<sites.length; i++) {
+ for (int i = 0; i < sites.length; i++) {
FeatureEntry f = sites[i].getFeatureEntry(id);
if (f != null)
return f;
@@ -416,7 +417,6 @@
return 0;
}
-
public String getApplicationIdentifier() {
// Return the app if defined in system properties
String application = ConfigurationActivator.getBundleContext().getProperty(ECLIPSE_APPLICATION);
@@ -478,22 +478,21 @@
}
return (URL[]) path.toArray(new URL[0]);
}
-
+
public Set getPluginPaths() {
-
+
HashSet paths = new HashSet();
ISiteEntry[] sites = getConfiguredSites();
for (int i = 0; i < sites.length; i++) {
String[] plugins = sites[i].getPlugins();
for (int j = 0; j < plugins.length; j++) {
- paths.add(plugins[j]);
+ paths.add(plugins[j]);
}
}
-
+
return paths;
}
-
/*
* A variation of the getPluginPath, but it returns the actual plugin entries
@@ -508,7 +507,7 @@
Utils.debug("Site " + sites[i].getURL() + " is not a SiteEntry"); //$NON-NLS-1$ //$NON-NLS-2$
continue;
}
- PluginEntry[] plugins = ((SiteEntry)sites[i]).getPluginEntries();
+ PluginEntry[] plugins = ((SiteEntry) sites[i]).getPluginEntries();
for (int j = 0; j < plugins.length; j++) {
allPlugins.add(plugins[j]);
Utils.debug(" " + plugins[j].getURL()); //$NON-NLS-1$
@@ -516,7 +515,6 @@
}
return (PluginEntry[]) allPlugins.toArray(new PluginEntry[0]);
}
-
/*
* @see IPlatformConfiguration#getBootstrapPluginIdentifiers()
@@ -581,7 +579,7 @@
*/
public synchronized void save(URL url) throws IOException {
if (url == null)
- throw new IOException(Messages.cfig_unableToSave_noURL);
+ throw new IOException(Messages.cfig_unableToSave_noURL);
OutputStream os = null;
if (!url.getProtocol().equals("file")) { //$NON-NLS-1$
@@ -595,7 +593,7 @@
} catch (CoreException e) {
Utils.log(e.getMessage());
Utils.log(e.getStatus());
- throw new IOException(NLS.bind(Messages.cfig_unableToSave, (new String[] { url.toExternalForm() })));
+ throw new IOException(NLS.bind(Messages.cfig_unableToSave, (new String[] {url.toExternalForm()})));
} finally {
os.close();
}
@@ -604,7 +602,7 @@
File cfigFile = new File(url.getFile().replace('/', File.separatorChar));
if (!cfigFile.getName().equals(PLATFORM_XML)) {
if (cfigFile.exists() && cfigFile.isFile()) {
- Utils.log(Messages.PlatformConfiguration_expectingPlatformXMLorDirectory + cfigFile.getName());
+ Utils.log(Messages.PlatformConfiguration_expectingPlatformXMLorDirectory + cfigFile.getName());
cfigFile = cfigFile.getParentFile();
}
cfigFile = new File(cfigFile, CONFIG_NAME);
@@ -619,35 +617,35 @@
// - rename the temp file to platform.xml
File cfigFileOriginal = new File(cfigFile.getAbsolutePath());
File cfigTmp = new File(cfigFile.getAbsolutePath() + CONFIG_FILE_TEMP_SUFFIX);
-
+
// Backup old file
- if (cfigFile.exists()){
+ if (cfigFile.exists()) {
File backupDir = new File(workingDir, CONFIG_HISTORY);
if (!backupDir.exists())
backupDir.mkdir();
long timestamp = cfigFile.lastModified();
- File preservedFile = new File(backupDir, String.valueOf(timestamp)+".xml"); //$NON-NLS-1$
+ File preservedFile = new File(backupDir, String.valueOf(timestamp) + ".xml"); //$NON-NLS-1$
// If the target file exists, increment the timestamp. Try at most 100 times.
long increment = 1;
- while (preservedFile.exists() && increment < 100){
- preservedFile = new File(backupDir, String.valueOf(timestamp+increment++)+".xml"); //$NON-NLS-1$
+ while (preservedFile.exists() && increment < 100) {
+ preservedFile = new File(backupDir, String.valueOf(timestamp + increment++) + ".xml"); //$NON-NLS-1$
}
if (!preservedFile.exists()) {
// try renaming current config to backup copy
if (!cfigFile.renameTo(preservedFile))
- Utils.log(Messages.PlatformConfiguration_cannotBackupConfig);
+ Utils.log(Messages.PlatformConfiguration_cannotBackupConfig);
}
}
// first save the file as temp
os = new FileOutputStream(cfigTmp);
-
+
try {
saveAsXML(os);
// Try flushing any internal buffers, and synchronize with the disk
try {
os.flush();
- ((FileOutputStream)os).getFD().sync();
+ ((FileOutputStream) os).getFD().sync();
} catch (SyncFailedException e2) {
Utils.log(e2.getMessage());
} catch (IOException e2) {
@@ -657,7 +655,7 @@
os.close();
os = null;
} catch (IOException e1) {
- Utils.log(Messages.PlatformConfiguration_cannotCloseStream + cfigTmp);
+ Utils.log(Messages.PlatformConfiguration_cannotCloseStream + cfigTmp);
Utils.log(e1.getMessage());
}
// set file time stamp to match that of the config element
@@ -668,13 +666,13 @@
changeStamp = config.getDate().getTime();
config.setDirty(false);
} catch (CoreException e) {
- throw new IOException(NLS.bind(Messages.cfig_unableToSave, (new String[] { cfigTmp.getAbsolutePath() })));
+ throw new IOException(NLS.bind(Messages.cfig_unableToSave, (new String[] {cfigTmp.getAbsolutePath()})));
} finally {
if (os != null)
try {
os.close();
} catch (IOException e1) {
- Utils.log(Messages.PlatformConfiguration_cannotCloseTempFile + cfigTmp);
+ Utils.log(Messages.PlatformConfiguration_cannotCloseTempFile + cfigTmp);
}
}
@@ -687,14 +685,13 @@
// with "tmp" (latest), then "bak" (the previous). We can also end up
// here if we failed to rename the current config to "bak". In that
// case we will restart with the previous state.
- Utils.log(Messages.PlatformConfiguration_cannotRenameTempFile);
-
- throw new IOException(NLS.bind(Messages.cfig_unableToSave, (new String[] { cfigTmp.getAbsolutePath() })));
+ Utils.log(Messages.PlatformConfiguration_cannotRenameTempFile);
+
+ throw new IOException(NLS.bind(Messages.cfig_unableToSave, (new String[] {cfigTmp.getAbsolutePath()})));
}
}
}
-
public static PlatformConfiguration getCurrent() {
return currentPlatformConfiguration;
}
@@ -704,12 +701,12 @@
*/
public static synchronized void startup(URL installURL, Location platformConfigLocation) throws Exception {
PlatformConfiguration.installURL = installURL;
-
+
// create current configuration
if (currentPlatformConfiguration == null) {
currentPlatformConfiguration = new PlatformConfiguration(platformConfigLocation);
if (currentPlatformConfiguration.config == null)
- throw new Exception(Messages.PlatformConfiguration_cannotLoadConfig + platformConfigLocation.getURL());
+ throw new Exception(Messages.PlatformConfiguration_cannotLoadConfig + platformConfigLocation.getURL());
if (currentPlatformConfiguration.config.isDirty())
// If this is a transient config (generated by PDE),do nothing
// otherwise, save the configuration with proper date
@@ -735,7 +732,6 @@
}
}
-
private synchronized void initializeCurrent(Location platformConfigLocation) throws IOException {
// Configuration URL was is specified by the OSGi layer.
@@ -747,7 +743,7 @@
// configuration is written into the specified configuration area.
URL configFileURL = new URL(platformConfigLocation.getURL(), CONFIG_NAME);
- try {
+ try {
// check concurrent use lock
getConfigurationLock(platformConfigLocation.getURL());
@@ -761,10 +757,10 @@
Location parentLocation = platformConfigLocation.getParentLocation();
if (parentLocation == null)
throw new IOException(); // no platform.xml found, need to create default site
-
+
URL sharedConfigFileURL = new URL(parentLocation.getURL(), CONFIG_NAME);
config = loadConfig(sharedConfigFileURL, installURL);
-
+
// pre-initialized config loaded OK ... copy any remaining update metadata
// Only copy if the default config location is not the install location
if (!sharedConfigFileURL.equals(configFileURL)) {
@@ -781,26 +777,25 @@
// if config == null an unhandled exception has been thrown and we allow it to propagate
if (config != null) {
configLocation = configFileURL;
- if (config.getURL() == null)
+ if (config.getURL() == null)
config.setURL(configFileURL);
- verifyPath(configLocation, config.getInstallURL());
+ verifyPath(configLocation, config.getInstallURL());
Utils.debug("Creating configuration " + configFileURL.toString()); //$NON-NLS-1$
}
}
- } finally {
+ } finally {
// releaes concurrent use lock
clearConfigurationLock();
}
}
-
private synchronized void initialize(URL url, URL installLocation) throws Exception {
if (url != null) {
- config = loadConfig(url, installLocation);
+ config = loadConfig(url, installLocation);
Utils.debug("Using configuration " + url.toString()); //$NON-NLS-1$
}
if (config == null) {
- config = new Configuration();
+ config = new Configuration();
Utils.debug("Creating empty configuration object"); //$NON-NLS-1$
}
config.setURL(url);
@@ -808,21 +803,22 @@
configLocation = url;
}
- private void createDefaultConfiguration(URL url, URL installLocation)throws IOException{
+ private void createDefaultConfiguration(URL url, URL installLocation) throws IOException {
// we are creating new configuration
config = new Configuration();
config.setURL(url);
config.setInstallLocation(installLocation);
- SiteEntry defaultSite = (SiteEntry)getRootSite();
+ SiteEntry defaultSite = (SiteEntry) getRootSite();
configureSite(defaultSite);
try {
// parse the site directory to discover features
defaultSite.loadFromDisk(0);
} catch (CoreException e1) {
- Utils.log(Messages.PlatformConfiguration_cannotLoadDefaultSite + defaultSite.getResolvedURL());
+ Utils.log(Messages.PlatformConfiguration_cannotLoadDefaultSite + defaultSite.getResolvedURL());
return;
}
}
+
private ISiteEntry getRootSite() {
// create default site entry for the root
ISitePolicy defaultPolicy = createSitePolicy(getDefaultPolicy(), DEFAULT_POLICY_LIST);
@@ -835,7 +831,7 @@
ISiteEntry defaultSite = createSiteEntry(siteURL, defaultPolicy);
return defaultSite;
}
-
+
/**
* Gets the configuration lock
* @param url configuration directory
@@ -844,24 +840,24 @@
if (!url.getProtocol().equals("file")) //$NON-NLS-1$
return;
- File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE+ File.separator+CONFIG_FILE_LOCK_SUFFIX);
+ File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE + File.separator + CONFIG_FILE_LOCK_SUFFIX);
verifyPath(url, config == null ? null : config.getInstallURL());
// PAL nio optional
- lock = createLocker(lockFile);
+ lock = createLocker(lockFile);
try {
lock.lock();
} catch (IOException ioe) {
lock = null;
- }
+ }
}
-
+
private void clearConfigurationLock() {
// PAL nio optional
if (lock != null) {
lock.release();
}
}
-
+
/**
* Create a locker using java new I/O or regular I/O
* depending whether we run in J2SE or cdcFoundation
@@ -871,23 +867,23 @@
if (!checkNio) {
useNio = true;
try {
- Class.forName("java.nio.channels.FileLock"); //$NON-NLS-1$
+ Class.forName("java.nio.channels.FileLock"); //$NON-NLS-1$
} catch (ClassNotFoundException e) {
useNio = false;
}
}
if (useNio)
return new Locker_JavaNio(lock);
-
+
return new Locker_JavaIo(lock);
}
-
+
private long computeChangeStamp() {
featuresChangeStamp = computeFeaturesChangeStamp();
pluginsChangeStamp = computePluginsChangeStamp();
changeStamp = Math.max(featuresChangeStamp, pluginsChangeStamp);
// round off to seconds
- changeStamp = (changeStamp/1000)*1000;
+ changeStamp = (changeStamp / 1000) * 1000;
return changeStamp;
}
@@ -999,7 +995,7 @@
Utils.debug(" bad URL " + e); //$NON-NLS-1$
return;
}
-
+
// process the link
SiteEntry linkSite = (SiteEntry) externalLinkSites.get(siteURL);
if (linkSite == null) {
@@ -1033,7 +1029,7 @@
unconfigureSite(list[i]);
Utils.debug("Site " + siteURL + " does not exist ... removing from configuration"); //$NON-NLS-1$ //$NON-NLS-2$
}
-
+
// If multiple paths are defined in the same link file
// or if the path changes, the old site will still be kept.
// A better algorithm could be implemented by keeping track
@@ -1042,7 +1038,7 @@
String linkName = list[i].getLinkFileName();
if (linkName != null) {
File linkFile = new File(linkName);
- if (!linkFile.exists()) {
+ if (!linkFile.exists()) {
unconfigureSite(list[i]);
config.setDirty(true);
Utils.debug("Site " + siteURL + " is no longer linked ... removing from configuration"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1050,7 +1046,7 @@
}
}
}
-
+
private void linkInitializedState(Configuration sharedConfig, Location sharedConfigLocation, Location newConfigLocation) {
try {
URL newConfigIniURL = new URL(newConfigLocation.getURL(), CONFIG_INI);
@@ -1063,7 +1059,7 @@
String externalForm = Utils.makeRelative(config.getInstallURL(), sharedConfigLocation.getURL()).toExternalForm();
props.put("osgi.sharedConfiguration.area", externalForm); //$NON-NLS-1$
props.store(new FileOutputStream(configIni), "Linked configuration"); //$NON-NLS-1$
-
+
config = new Configuration(new Date());
config.setURL(new URL(newConfigLocation.getURL(), CONFIG_NAME));
config.setLinkedConfig(sharedConfig);
@@ -1074,31 +1070,31 @@
System.out.println(e);
}
}
-
+
private Configuration loadConfig(URL url, URL installLocation) throws Exception {
if (url == null)
- throw new IOException(Messages.cfig_unableToLoad_noURL);
+ throw new IOException(Messages.cfig_unableToLoad_noURL);
// try to load saved configuration file (watch for failed prior save())
ConfigurationParser parser = null;
try {
parser = new ConfigurationParser();
} catch (InvocationTargetException e) {
- throw (Exception)e.getTargetException();
+ throw (Exception) e.getTargetException();
}
-
+
config = null;
Exception originalException = null;
try {
config = parser.parse(url, installLocation);
if (config == null)
- throw new Exception(Messages.PlatformConfiguration_cannotFindConfigFile);
+ throw new Exception(Messages.PlatformConfiguration_cannotFindConfigFile);
} catch (Exception e1) {
// check for save failures, so open temp and backup configurations
originalException = e1;
try {
- URL tempURL = new URL(url.toExternalForm()+CONFIG_FILE_TEMP_SUFFIX);
- config = parser.parse(tempURL, installLocation);
+ URL tempURL = new URL(url.toExternalForm() + CONFIG_FILE_TEMP_SUFFIX);
+ config = parser.parse(tempURL, installLocation);
if (config == null)
throw new Exception();
config.setDirty(true); // force saving to platform.xml
@@ -1109,12 +1105,13 @@
File cfigFile = new File(url.getFile().replace('/', File.separatorChar));
File workingDir = cfigFile.getParentFile();
if (workingDir != null && workingDir.exists()) {
- File[] backups = workingDir.listFiles(new FileFilter(){
+ File[] backups = workingDir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".xml"); //$NON-NLS-1$
- }});
+ }
+ });
if (backups != null && backups.length > 0) {
- URL backupUrl = backups[backups.length-1].toURL();
+ URL backupUrl = backups[backups.length - 1].toURL();
config = parser.parse(backupUrl, installLocation);
}
}
@@ -1170,8 +1167,7 @@
}
}
- public static URL resolvePlatformURL(URL url, URL base_path_Location)
- throws IOException {
+ public static URL resolvePlatformURL(URL url, URL base_path_Location) throws IOException {
if (url.getProtocol().equals("platform")) { //$NON-NLS-1$
if (base_path_Location == null) {
url = FileLocator.toFileURL(url);
@@ -1181,27 +1177,24 @@
final String BASE = "platform:/base/";
final String CONFIG = "platform:/config/";
String toResolve = url.toExternalForm();
- if (toResolve.startsWith(BASE))
- url = new URL(base_path_Location, toResolve.substring(BASE
- .length()));
+ if (toResolve.startsWith(BASE))
+ url = new URL(base_path_Location, toResolve.substring(BASE.length()));
else if (toResolve.startsWith(CONFIG)) {
- url = new URL(base_path_Location, toResolve.substring(CONFIG
- .length()));
- }
- else
+ url = new URL(base_path_Location, toResolve.substring(CONFIG.length()));
+ } else
url = base_path_Location;
}
}
return url;
}
-
- private URL getBasePathLocation(URL url, URL installLocation, URL configLocation) {
+
+ private URL getBasePathLocation(URL url, URL installLocation, URL configLocation) {
final String BASE = "platform:/base/";
final String CONFIG = "platform:/config/";
String toResolve = url.toExternalForm();
- if(toResolve.startsWith(BASE)) {
+ if (toResolve.startsWith(BASE)) {
return installLocation;
- }else if(toResolve.startsWith(CONFIG)){
+ } else if (toResolve.startsWith(CONFIG)) {
URL config_loc;
try {
config_loc = new URL(configLocation, "..");
@@ -1212,13 +1205,13 @@
}
return url;
}
-
+
public static URL getInstallURL() {
return installURL;
}
-
- private void saveAsXML(OutputStream stream) throws CoreException,IOException {
- BufferedWriter xmlWriter = new BufferedWriter(new OutputStreamWriter(stream,XML_ENCODING));
+
+ private void saveAsXML(OutputStream stream) throws CoreException, IOException {
+ BufferedWriter xmlWriter = new BufferedWriter(new OutputStreamWriter(stream, XML_ENCODING));
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setExpandEntityReferences(false);
@@ -1226,18 +1219,18 @@
factory.setIgnoringComments(true);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
-
+
if (config == null)
- throw Utils.newCoreException(Messages.PlatformConfiguration_cannotSaveNonExistingConfig,null);
-
+ throw Utils.newCoreException(Messages.PlatformConfiguration_cannotSaveNonExistingConfig, null);
+
config.setDate(new Date());
Element configElement = config.toXML(doc);
doc.appendChild(configElement);
-
+
// This is not DBCS friendly... PAL
//XMLPrintHandler.printComment(xmlWriter,"Created on " + config.getDate().toString());
- XMLPrintHandler.printNode(xmlWriter,doc,XML_ENCODING);
-
+ XMLPrintHandler.printNode(xmlWriter, doc, XML_ENCODING);
+
} catch (Exception e) {
throw Utils.newCoreException("", e); //$NON-NLS-1$
} finally {
@@ -1245,8 +1238,8 @@
// will close the stream in the caller
//xmlWriter.close();
}
- }
-
+ }
+
private void reconcile() throws CoreException {
long lastChange = config.getDate().getTime();
SiteEntry[] sites = config.getSites();
@@ -1259,7 +1252,7 @@
}
config.setDirty(true);
}
-
+
public Configuration getConfiguration() {
return config;
}