Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2010-03-03 14:38:10 -0500
committerAndrew Niefer2010-03-03 14:38:10 -0500
commit6b6821baaa0a7499eab380741b862b33c6413ce0 (patch)
tree9f2541188a79f859df889e271fa9034d612b6a6c
parent2823d9e5edf97ea81143d99d4524dcc769416f74 (diff)
downloadrt.equinox.framework-6b6821baaa0a7499eab380741b862b33c6413ce0.tar.gz
rt.equinox.framework-6b6821baaa0a7499eab380741b862b33c6413ce0.tar.xz
rt.equinox.framework-6b6821baaa0a7499eab380741b862b33c6413ce0.zip
bug 301226 - Improve error handling in case of unusable configuration areav20100304
-rw-r--r--bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
index df507e5fb..4e083955a 100644
--- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
+++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Anton Leherbauer (Wind River Systems) - bug 301226
*******************************************************************************/
package org.eclipse.equinox.launcher;
@@ -202,6 +203,9 @@ public class Main {
private static final String PROP_COMMANDS = "eclipse.commands"; //$NON-NLS-1$
private static final String PROP_ECLIPSESECURITY = "eclipse.security"; //$NON-NLS-1$
+ // Suffix for location properties - see LocationManager.
+ private static final String READ_ONLY_AREA_SUFFIX = ".readOnly"; //$NON-NLS-1$
+
// Data mode constants for user, configuration and data locations.
private static final String NONE = "@none"; //$NON-NLS-1$
private static final String NO_DEFAULT = "@noDefault"; //$NON-NLS-1$
@@ -557,6 +561,10 @@ public class Main {
if (!checkVersion(System.getProperty("java.version"), System.getProperty(PROP_REQUIRED_JAVA_VERSION))) //$NON-NLS-1$
return;
+ // verify configuration location is writable
+ if (!checkConfigurationLocation(configurationLocation))
+ return;
+
setSecurityPolicy(bootPath);
// splash handling is done here, because the default case needs to know
// the location of the boot plugin we are going to use
@@ -652,6 +660,41 @@ public class Main {
}
/**
+ * Checks whether the given location can be created and is writable.
+ * If the system property "osgi.configuration.area.readOnly" is set
+ * the check always succeeds.
+ * <p>Will set PROP_EXITCODE/PROP_EXITDATA accordingly if check fails.</p>
+ *
+ * @param locationUrl configuration area URL, may be <code>null</code>
+ * @return a boolean indicating whether the checking passed
+ */
+ private boolean checkConfigurationLocation(URL locationUrl) {
+ if (locationUrl == null || !"file".equals(locationUrl.getProtocol())) //$NON-NLS-1$
+ return true;
+ if (Boolean.valueOf(System.getProperty(PROP_CONFIG_AREA + READ_ONLY_AREA_SUFFIX)).booleanValue()) {
+ // user wants readonly config area
+ return true;
+ }
+ File configDir = new File(locationUrl.getFile()).getAbsoluteFile();
+ if (!configDir.exists()) {
+ configDir.mkdirs();
+ if (!configDir.exists()) {
+ System.getProperties().put(PROP_EXITCODE, "15"); //$NON-NLS-1$
+ System.getProperties().put(PROP_EXITDATA, "<title>Invalid Configuration Location</title>The configuration area at '" + configDir + //$NON-NLS-1$
+ "' could not be created. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$
+ return false;
+ }
+ }
+ if (!canWrite(configDir)) {
+ System.getProperties().put(PROP_EXITCODE, "15"); //$NON-NLS-1$
+ System.getProperties().put(PROP_EXITDATA, "<title>Invalid Configuration Location</title>The configuration area at '" + configDir + //$NON-NLS-1$
+ "' is not writable. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$
+ return false;
+ }
+ return true;
+ }
+
+ /**
* Returns a string representation of the given URL String. This converts
* escaped sequences (%..) in the URL into the appropriate characters.
* NOTE: due to class visibility there is a copy of this method

Back to the top