Fix shared configuration for a case without a local configuration
Fix extensions processing

Change-Id: Ifa90ab3f57503ee971f292140ab91fe43a3f2ca4
Signed-off-by: Alexander Dudaev <aleksandr.dudayev@xored.com>
diff --git a/launching/org.eclipse.rcptt.launching.ext/META-INF/MANIFEST.MF b/launching/org.eclipse.rcptt.launching.ext/META-INF/MANIFEST.MF
index ac86cd1..90e8944 100644
--- a/launching/org.eclipse.rcptt.launching.ext/META-INF/MANIFEST.MF
+++ b/launching/org.eclipse.rcptt.launching.ext/META-INF/MANIFEST.MF
@@ -35,7 +35,8 @@
  org.eclipse.core.commands,
  org.eclipse.rcptt.core.launching;bundle-version="[2.4.0,3.0.0)",
  org.apache.felix.scr,
- org.eclipse.equinox.launcher
+ org.eclipse.equinox.launcher,
+ org.eclipse.core.filesystem
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.eclipse.rcptt.internal.launching.ext,
diff --git a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/PDELocationUtils.java b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/PDELocationUtils.java
index e672a77..ebdab1a 100644
--- a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/PDELocationUtils.java
+++ b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/PDELocationUtils.java
@@ -17,6 +17,7 @@
 
 import java.io.File;
 
+import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
@@ -98,8 +99,8 @@
 
 	private static IStatus validateDirectoryPath(File file) {
 		if (file == null || !file.exists()) {
-			return new Status(IStatus.ERROR, PLUGIN_ID,
-					"Directory \"" + (file != null ? file.getPath() : "null") + "\" does not exist."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+			return new Status(IStatus.ERROR, PLUGIN_ID, EFS.ERROR_NOT_EXISTS,
+					"Directory \"" + (file != null ? file.getPath() : "null") + "\" does not exist.", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		}
 
 		if (!file.isDirectory()) {
diff --git a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/UpdateVMArgs.java b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/UpdateVMArgs.java
index f0a4499..99d462b 100644
--- a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/UpdateVMArgs.java
+++ b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/UpdateVMArgs.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2015 Xored Software Inc and others.
+ * Copyright (c) 2009, 2019 Xored Software Inc and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -91,7 +91,7 @@
 		StringBuilder result = new StringBuilder();
 
 		for (String extension : extensions.split(",")) {
-			if (extensions.contains(AJConstants.HOOK)) {
+			if (extension.contains(AJConstants.HOOK)) {
 				continue;
 			}
 			if (!extension.isEmpty())
diff --git a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/Q7Target.java b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/Q7Target.java
index 831f833..603f0f2 100644
--- a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/Q7Target.java
+++ b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/Q7Target.java
@@ -76,7 +76,7 @@
 	 */
 	public static class AutInstall {
 		private static final String OSGI_BUNDLES = "osgi.bundles";
-		private OriginalOrderProperties config;
+		private final OriginalOrderProperties config;
 		public final ProfileBundleContainer container;
 		public String userArea;
 
@@ -129,7 +129,8 @@
 
 		public URL getInstallLocationURL() {
 			try {
-				return TargetPlatformHelper.buildURL(container.getLocation(true), true, getInstallLocation().getAbsolutePath());
+				return TargetPlatformHelper.buildURL(container.getLocation(true), true,
+						getInstallLocation().getAbsolutePath());
 			} catch (CoreException e) {
 				log(status("Can't get AUT location", e));
 				return null;
diff --git a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/TargetPlatformHelper.java b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/TargetPlatformHelper.java
index 3cf4ec2..a65f9d6 100644
--- a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/TargetPlatformHelper.java
+++ b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/TargetPlatformHelper.java
@@ -105,9 +105,9 @@
 @SuppressWarnings("restriction")
 public class TargetPlatformHelper implements ITargetPlatformHelper {
 	private static final boolean DEBUG = "true"
-		.equals(Platform.getDebugOption("org.eclipse.rcptt.launching.ext/debug"));
+			.equals(Platform.getDebugOption("org.eclipse.rcptt.launching.ext/debug"));
 	private static final boolean DEBUG_BUNDLES = "true"
-		.equals(Platform.getDebugOption("org.eclipse.rcptt.launching.ext/debug/bundles"));
+			.equals(Platform.getDebugOption("org.eclipse.rcptt.launching.ext/debug/bundles"));
 	public static final String IDE_APPLICATION = "org.eclipse.ui.ide.workbench";
 	public static final String APPLICATION_PROPERTY = "eclipse.application"; //$NON-NLS-1$
 	public static final String PRODUCT_PROPERTY = "eclipse.product"; //$NON-NLS-1$
@@ -301,7 +301,7 @@
 
 	private void initialize() {
 		extra.clear();
-        q7target = new Q7Target();
+		q7target = new Q7Target();
 		if (this.target != null && this.target.getTargetLocations() != null) {
 			ITargetLocation[] containers = this.target.getTargetLocations();
 			for (ITargetLocation iUBundleContainer : containers) {
@@ -419,7 +419,7 @@
 
 		if (DEBUG_BUNDLES) {
 			final List<String> targetModelsLocations = new ArrayList<String>();
-			for(final IPluginModelBase model : targetModels) {
+			for (final IPluginModelBase model : targetModels) {
 				targetModelsLocations.add(model.getInstallLocation());
 			}
 			debug("Bundles: " + targetModelsLocations);
@@ -539,8 +539,8 @@
 			if (elements.length != 1)
 				continue;
 			String visiblity = elements[0].getAttribute("visible"); //$NON-NLS-1$
-			boolean visible = visiblity == null ? true : Boolean.valueOf(
-					visiblity).booleanValue();
+			boolean visible = visiblity == null ? true
+					: Boolean.valueOf(visiblity).booleanValue();
 			if (id != null && visible) {
 				result.add(id);
 			}
@@ -979,8 +979,8 @@
 	private String getVmArg(File eclipseIniFile) {
 		List<String> lines = parseIniFile(eclipseIniFile);
 		int vmIndex = lines.indexOf("-vm") + 1;
-		return vmIndex == 0 || vmIndex == lines.size() ? null : lines
-				.get(vmIndex);
+		return vmIndex == 0 || vmIndex == lines.size() ? null
+				: lines.get(vmIndex);
 	}
 
 	public String getVmFromIniFile() {
@@ -1379,55 +1379,60 @@
 	private static final String USER_DIR = "@user.dir"; //$NON-NLS-1$
 	private static final String PROP_USER_HOME = "user.home"; //$NON-NLS-1$
 	private static final String PROP_USER_DIR = "user.dir"; //$NON-NLS-1$
-	private static final String FILE_SCHEME = "file:"; //$NON-NLS-1$    
+	private static final String FILE_SCHEME = "file:"; //$NON-NLS-1$
 
 	public static OriginalOrderProperties processConfiguration(AutInstall autInstall) {
 		URL baseConfigurationLocation = null;
 		OriginalOrderProperties baseConfiguration = null;
 		String location = null;
-			if (baseConfigurationLocation == null)
-				try {
-					baseConfigurationLocation = new URL(autInstall.getInstallLocationURL(), CONFIG_DIR);
-				} catch (MalformedURLException e) {
-					// leave baseConfigurationLocation null
-				}
-			baseConfiguration = loadConfiguration(baseConfigurationLocation);
-			if (baseConfiguration != null) {
-				// if the base sets the install area then use that value if the property.  We know the 
-				// property is not already set.
-				location = baseConfiguration.getProperty(PROP_CONFIG_AREA);
+		if (baseConfigurationLocation == null)
+			try {
+				baseConfigurationLocation = new URL(autInstall.getInstallLocationURL(), CONFIG_DIR);
+			} catch (MalformedURLException e) {
+				// leave baseConfigurationLocation null
 			}
+		baseConfiguration = loadConfiguration(baseConfigurationLocation);
+		if (baseConfiguration != null) {
+			// if the base sets the install area then use that value if the property. We know the
+			// property is not already set.
+			location = baseConfiguration.getProperty(PROP_CONFIG_AREA);
+		}
 
-		// Now we know where the base configuration is supposed to be.  Go ahead and load
-		// it and merge into the System properties.  Then, if cascaded, read the parent configuration.
-		// Note that in a cascaded situation, the user configuration may be ignored if the parent 
-		// configuration has changed since the user configuration has been written. 
-		// Note that the parent may or may not be the same parent as we read above since the 
-		// base can define its parent.  The first parent we read was either defined by the user
-		// on the command line or was the one in the install dir.  
+		// Now we know where the base configuration is supposed to be. Go ahead and load
+		// it and merge into the System properties. Then, if cascaded, read the parent configuration.
+		// Note that in a cascaded situation, the user configuration may be ignored if the parent
+		// configuration has changed since the user configuration has been written.
+		// Note that the parent may or may not be the same parent as we read above since the
+		// base can define its parent. The first parent we read was either defined by the user
+		// on the command line or was the one in the install dir.
 		// if the config or parent we are about to read is the same as the base config we read above,
 		// just reuse the base
 		OriginalOrderProperties configuration = baseConfiguration;
 		final URL configUrl = getConfigurationLocation(location, autInstall.getInstallLocation());
 
-		String configurationArea = configUrl.getFile();
-    	int index = configurationArea.lastIndexOf("/");
-    	if (index == configurationArea.length() - 1) {
-    		configurationArea = configurationArea.substring(0, index);
-			index = configurationArea.lastIndexOf("/");
-		}
-    	autInstall.userArea = configurationArea.substring(0, index + 1);
-
 		if (configuration == null || !configUrl.equals(baseConfigurationLocation))
 			configuration = loadConfiguration(configUrl);
 
-		if (configuration != null && "false".equalsIgnoreCase(configuration.getProperty(PROP_CONFIG_CASCADED))) { //$NON-NLS-1$
+		if (configuration == null) {
+			Q7ExtLaunchingPlugin.getDefault().info("File config.ini from folder \"" + configUrl + "\" was not read");
+			return baseConfiguration;
+		}
+
+		String configurationArea = configUrl.getFile();
+		int index = configurationArea.lastIndexOf("/");
+		if (index == configurationArea.length() - 1) {
+			configurationArea = configurationArea.substring(0, index);
+			index = configurationArea.lastIndexOf("/");
+		}
+		autInstall.userArea = configurationArea.substring(0, index + 1);
+
+		if ("false".equalsIgnoreCase(configuration.getProperty(PROP_CONFIG_CASCADED))) { //$NON-NLS-1$
 			configuration.remove(PROP_SHARED_CONFIG_AREA);
 			return configuration;
 		} else {
-			if (configuration == null)
-				throw new RuntimeException("File config.ini from folder \"" + configUrl + "\" was not read");
-			URL sharedConfigURL = buildLocation(configuration.getProperty(PROP_SHARED_CONFIG_AREA), null, "", autInstall.getInstallLocation().getAbsolutePath()); //$NON-NLS-1$
+
+			URL sharedConfigURL = buildLocation(configuration.getProperty(PROP_SHARED_CONFIG_AREA), null, "", //$NON-NLS-1$
+					autInstall.getInstallLocation().getAbsolutePath());
 			if (sharedConfigURL == null)
 				try {
 					// there is no shared config value so compute one
@@ -1438,9 +1443,9 @@
 			// if the parent location is different from the config location, read it too.
 			if (sharedConfigURL != null) {
 				if (sharedConfigURL.equals(configUrl)) {
-					//After all we are not in a shared configuration setup.
-					// - remove the property to show that we do not have a parent 
-					// - merge configuration with the system properties 
+					// After all we are not in a shared configuration setup.
+					// - remove the property to show that we do not have a parent
+					// - merge configuration with the system properties
 					return configuration;
 				} else {
 					// if the parent we are about to read is the same as the base config we read above,
@@ -1475,7 +1480,7 @@
 
 	private static OriginalOrderProperties substituteVars(OriginalOrderProperties result) {
 		if (result == null) {
-			//nothing todo.
+			// nothing todo.
 			return null;
 		}
 		for (Enumeration<?> eKeys = result.keys(); eKeys.hasMoreElements();) {
@@ -1509,10 +1514,10 @@
 					if (prop == null) {
 						try {
 							// try using the System.getenv method if it exists (bug 126921)
-							Method getenv = System.class.getMethod("getenv", new Class[] {String.class}); //$NON-NLS-1$
-							prop = (String) getenv.invoke(null, new Object[] {var});
+							Method getenv = System.class.getMethod("getenv", new Class[] { String.class }); //$NON-NLS-1$
+							prop = (String) getenv.invoke(null, new Object[] { var });
 						} catch (Throwable t) {
-							// do nothing; 
+							// do nothing;
 							// on 1.4 VMs this throws an error
 							// on J2ME this method does not exist
 						}
@@ -1541,18 +1546,20 @@
 			buf.append(VARIABLE_DELIM_CHAR).append(var);
 		return buf.toString();
 	}
-	
+
 	private static URL getConfigurationLocation(String configurationArea, File installLocation) {
 		URL configurationLocation = buildLocation(configurationArea, null, "", installLocation.getAbsolutePath()); //$NON-NLS-1$
 		if (configurationLocation == null)
-			configurationLocation = buildURL(computeDefaultConfigurationLocation(installLocation), true, installLocation.getAbsolutePath());
+			configurationLocation = buildURL(computeDefaultConfigurationLocation(installLocation), true,
+					installLocation.getAbsolutePath());
 
 		return configurationLocation;
 	}
 
-	private static URL buildLocation(String location, URL defaultLocation, String userDefaultAppendage, String installArea) {
+	private static URL buildLocation(String location, URL defaultLocation, String userDefaultAppendage,
+			String installArea) {
 		URL result = null;
-		// if the instance location is not set, predict where the workspace will be and 
+		// if the instance location is not set, predict where the workspace will be and
 		// put the instance area inside the workspace meta area.
 		if (location == null)
 			result = defaultLocation;
@@ -1620,7 +1627,7 @@
 		}
 		return toAdjust;
 	}
-	
+
 	private static URL adjustTrailingSlash(URL url, boolean trailingSlash) throws MalformedURLException {
 		String file = url.getFile();
 		if (trailingSlash == (file.endsWith("/"))) //$NON-NLS-1$
@@ -1631,19 +1638,19 @@
 
 	private static String computeDefaultConfigurationLocation(File installLocation) {
 		// 1) We store the config state relative to the 'eclipse' directory if possible
-		// 2) If this directory is read-only 
-		//    we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home> 
-		//    is unique for each local user, and <application-id> is the one 
-		//    defined in .eclipseproduct marker file. If .eclipseproduct does not
-		//    exist, use "eclipse" as the application-id.
+		// 2) If this directory is read-only
+		// we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home>
+		// is unique for each local user, and <application-id> is the one
+		// defined in .eclipseproduct marker file. If .eclipseproduct does not
+		// exist, use "eclipse" as the application-id.
 
-		String configurationLocation = null; 
+		String configurationLocation = null;
 		if (canWrite(installLocation))
 			configurationLocation = installLocation.getAbsolutePath();
-		else 
-		// We can't write in the eclipse install dir so try for some place in the user's home dir
+		else
+			// We can't write in the eclipse install dir so try for some place in the user's home dir
 			configurationLocation = computeDefaultUserAreaLocation(installLocation);
-		
+
 		return configurationLocation + File.separator + CONFIG_DIR;
 	}
 
@@ -1669,10 +1676,10 @@
 	}
 
 	private static String computeDefaultUserAreaLocation(File installDir) {
-		//    we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home> 
-		//    is unique for each local user, and <application-id> is the one 
-		//    defined in .eclipseproduct marker file. If .eclipseproduct does not
-		//    exist, use "eclipse" as the application-id.
+		// we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home>
+		// is unique for each local user, and <application-id> is the one
+		// defined in .eclipseproduct marker file. If .eclipseproduct does not
+		// exist, use "eclipse" as the application-id.
 		String installDirHash = getInstallDirHash(installDir);
 
 		String appName = "." + ECLIPSE; //$NON-NLS-1$
@@ -1689,7 +1696,7 @@
 					appVersion = ""; //$NON-NLS-1$
 				appName += File.separator + appId + "_" + appVersion + "_" + installDirHash; //$NON-NLS-1$ //$NON-NLS-2$
 			} catch (IOException e) {
-				// Do nothing if we get an exception.  We will default to a standard location 
+				// Do nothing if we get an exception. We will default to a standard location
 				// in the user's home dir.
 				// add the hash to help prevent collisions
 				appName += File.separator + installDirHash;
@@ -1700,7 +1707,7 @@
 		}
 		appName += '_' + OS_WS_ARCHToString();
 		String userHome = System.getProperty(PROP_USER_HOME);
-		return new File(userHome, appName).getAbsolutePath(); //$NON-NLS-1$
+		return new File(userHome, appName).getAbsolutePath(); // $NON-NLS-1$
 	}
 
 	private static String OS_WS_ARCHToString() {
@@ -1789,7 +1796,8 @@
 		return installDirHash;
 	}
 
-	private static OriginalOrderProperties mergeProperties(OriginalOrderProperties source, OriginalOrderProperties userConfiguration) {
+	private static OriginalOrderProperties mergeProperties(OriginalOrderProperties source,
+			OriginalOrderProperties userConfiguration) {
 		if (userConfiguration != null) {
 			source.setBeginAdd(true);
 			source.putAll(userConfiguration);
diff --git a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/target/TargetPlatformManager.java b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/target/TargetPlatformManager.java
index 11a4f46..1dc40d1 100644
--- a/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/target/TargetPlatformManager.java
+++ b/launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/target/TargetPlatformManager.java
@@ -17,6 +17,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -79,16 +80,23 @@
 			final String localLocation = info.getUserArea();
 			if (localLocation != null) {
 				/*
-				final File localProductDir = PDELocationUtils.getProductLocation(location);
-				final ITargetLocation localInstallationContainer = service
-						.newProfileLocation(localProductDir.getAbsolutePath(), null);
-				containers.add(localInstallationContainer);
-				*/
+				 * final File localProductDir = PDELocationUtils.getProductLocation(location);
+				 * final ITargetLocation localInstallationContainer = service
+				 * .newProfileLocation(localProductDir.getAbsolutePath(), null);
+				 * containers.add(localInstallationContainer);
+				 */
 
-				final File localPluginsDir = PDELocationUtils.getPluginFolder(localLocation);
-				final ITargetLocation localPluginsContainer = service
-						.newDirectoryLocation(localPluginsDir.getAbsolutePath());
-				containers.add(localPluginsContainer);
+				try {
+					final File localPluginsDir = PDELocationUtils.getPluginFolder(localLocation);
+					final ITargetLocation localPluginsContainer = service
+							.newDirectoryLocation(localPluginsDir.getAbsolutePath());
+					containers.add(localPluginsContainer);
+				} catch (CoreException e) {
+					if(e.getStatus().getCode() == EFS.ERROR_NOT_EXISTS) {
+						Q7ExtLaunchingPlugin.log(new Status(IStatus.INFO, PLUGIN_ID, EFS.ERROR_NOT_EXISTS, localLocation + " does not have plugins.", e));
+					} else
+						throw e;
+				}
 			}
 
 			info.setBundleContainers(containers
@@ -286,8 +294,6 @@
 		return null;
 	}
 
-
-
 	private static CoreException createErrorProductLocationException(String location, Throwable e)
 			throws CoreException {
 		return new CoreException(
diff --git a/rcpttTests/pom.xml b/rcpttTests/pom.xml
index b885f5d..6825cc9 100644
--- a/rcpttTests/pom.xml
+++ b/rcpttTests/pom.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (c) 2009, 2016 Xored Software Inc and others.
+    Copyright (c) 2009, 2019 Xored Software Inc and others.
     All rights reserved. This program and the accompanying materials
     are made available under the terms of the Eclipse Public License v1.0
     which accompanies this distribution, and is available at
@@ -51,7 +51,7 @@
             <tag>skipExecution</tag>
           </skipTags>
           <testOptions>
-            <execTimeout>18000</execTimeout>
+            <execTimeout>25000</execTimeout>
           </testOptions>
         </configuration>
       </plugin>