[jbosstools-commits] JBoss Tools SVN: r43494 - in trunk/runtime: plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/internal and 7 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Sep 6 22:11:25 EDT 2012
Author: rob.stryker at jboss.com
Date: 2012-09-06 22:11:25 -0400 (Thu, 06 Sep 2012)
New Revision: 43494
Added:
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimePathUtilTest.java
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/RuntimeCoreActivator.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/internal/RuntimeExtensionManager.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimeDetectorDelegate.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/handlers/TestHandler1.java
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionAllTests.java
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java
Log:
JBIDE-12559 JBIDE-12549 to trunk more runtime re-org
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/RuntimeCoreActivator.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/RuntimeCoreActivator.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/RuntimeCoreActivator.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -35,7 +35,6 @@
private static RuntimeCoreActivator plugin;
// Member variables
- private Set<IRuntimeDetector> declaredRuntimeDetectors;
private Set<IRuntimeDetector> runtimeDetectors;
private Map<String, DownloadRuntime> downloadRuntimes;
@@ -95,7 +94,7 @@
}
public IRuntimeDetector findRuntimeDetector(String id) {
- for (IRuntimeDetector detector:getDeclaredRuntimeDetectors()) {
+ for (IRuntimeDetector detector:getRuntimeDetectors()) {
if (id.equals(detector.getId())) {
return detector;
}
@@ -103,24 +102,13 @@
return null;
}
- /*
- * Is this really necessary??
- *
- * getDeclaredRuntimeDetectors and getRuntimeDetectors
- * does almost exactly the same thing, except getRuntimeDetectors
- * sets the enablement and getDeclared... does not.
- *
- * Why would anyone require uninitialized detectors?
- * Couldn't they simply ignore the enabled flag?
- */
+ /* Please use getRuntimeDetectors */
+ @Deprecated
public Set<IRuntimeDetector> getDeclaredRuntimeDetectors() {
- if( declaredRuntimeDetectors == null) {
- declaredRuntimeDetectors = RuntimeExtensionManager.getDefault().loadDeclaredRuntimeDetectors();
- }
- return declaredRuntimeDetectors;
+ return getRuntimeDetectors();
}
- public Set<IRuntimeDetector> getRuntimeDetectors() {
+ public synchronized Set<IRuntimeDetector> getRuntimeDetectors() {
if (runtimeDetectors == null) {
runtimeDetectors = RuntimeExtensionManager.getDefault().loadInitializedRuntimeDetectors();
}
@@ -128,7 +116,7 @@
}
public void saveEnabledDetectors() {
- saveEnabledDetectors(getDeclaredRuntimeDetectors());
+ saveEnabledDetectors(getRuntimeDetectors());
}
public void saveEnabledDetectors(Set<IRuntimeDetector> allDetectors) {
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/internal/RuntimeExtensionManager.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/internal/RuntimeExtensionManager.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/internal/RuntimeExtensionManager.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -82,7 +82,9 @@
boolean allEnabled = false;
if (enabledDetectors == null) {
allEnabled = true;
- }
+ }
+
+ enabledDetectors = (enabledDetectors == null ? new String[0] : enabledDetectors);
List<String> enabled = Arrays.asList(enabledDetectors);
for (IRuntimeDetector detector : set) {
boolean enableVal = allEnabled || enabled.contains(detector.getId());
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimeDetectorDelegate.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimeDetectorDelegate.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimeDetectorDelegate.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -5,6 +5,14 @@
import org.eclipse.core.runtime.IProgressMonitor;
+/**
+ * Runtime detectors and their delegates are *NOT* expected to maintain state.
+ * They are instantiated only once and may be given several requests,
+ * possibly concurrently.
+ *
+ * @author rob stryker
+ *
+ */
public interface IRuntimeDetectorDelegate {
/**
* The framework is asking you to create or otherwise initialize
Added: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -0,0 +1,50 @@
+package org.jboss.tools.runtime.core.util;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.runtime.core.JBossRuntimeLocator;
+import org.jboss.tools.runtime.core.RuntimeCoreActivator;
+import org.jboss.tools.runtime.core.model.IRuntimeDetector;
+import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
+
+public class RuntimeInitializerUtil {
+ public static void initializeRuntimesFromFolder(File directory, IProgressMonitor monitor) {
+ if( directory != null && directory.isDirectory()) {
+ RuntimePath runtimePath = new RuntimePath(directory.getAbsolutePath());
+ List<RuntimeDefinition> runtimeDefinitions = createRuntimeDefinitions(runtimePath, monitor);
+ initializeRuntimes(runtimeDefinitions);
+ }
+ }
+
+ public static void initializeRuntimes(List<RuntimeDefinition> runtimeDefinitions) {
+ Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
+ for( IRuntimeDetector detector:detectors) {
+ if (detector.isEnabled()) {
+ detector.initializeRuntimes(runtimeDefinitions);
+ }
+ }
+ }
+
+ public static void createRuntimeDefinitions(Set<RuntimePath> runtimePaths, IProgressMonitor monitor) {
+ for (RuntimePath runtimePath : runtimePaths) {
+ // TODO sub monitors
+ createRuntimeDefinitions(runtimePath, monitor);
+ }
+ }
+
+ public static List<RuntimeDefinition> createRuntimeDefinitions(RuntimePath runtimePath, IProgressMonitor monitor) {
+ JBossRuntimeLocator locator = new JBossRuntimeLocator();
+ List<RuntimeDefinition> runtimeDefinitions = locator
+ .searchForRuntimes(runtimePath.getPath(), monitor);
+ runtimePath.getRuntimeDefinitions().clear();
+ for (RuntimeDefinition runtimeDefinition : runtimeDefinitions) {
+ runtimeDefinition.setRuntimePath(runtimePath);
+ }
+ runtimePath.getRuntimeDefinitions().addAll(runtimeDefinitions);
+ return runtimeDefinitions;
+ }
+}
Added: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -0,0 +1,137 @@
+package org.jboss.tools.runtime.core.util;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+import org.jboss.tools.runtime.core.RuntimeCoreActivator;
+import org.jboss.tools.runtime.core.model.IRuntimeDetector;
+import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
+
+public class RuntimeModelUtil {
+ public static final String LINE_DELIMITER = "\n\r\f";//$NON-NLS-1$
+ public static final String IN_LINE_DELIMITER = ",";//$NON-NLS-1$
+
+ /**
+ * This class will read a properties file of the format:
+ * pathName=/some/path/to/jboss,true
+ *
+ * Where the path is a path to be scanned, and the
+ * following boolean is whether this should be scanned
+ * on every startup.
+ *
+ * @param file
+ * @return
+ */
+ public static Set<RuntimePath> parseRuntimeFile(File file) {
+ try {
+ return parseRuntimeFile(new BufferedInputStream(new FileInputStream(file)), false);
+ } catch(IOException ioe) {
+ RuntimeCoreActivator.getDefault().logError(ioe);
+ }
+ return new TreeSet<RuntimePath>();
+ }
+
+ /**
+ * This class will read an input stream of the format:
+ * pathName=/some/path/to/jboss,true
+ *
+ * Where the path is a path to be scanned, and the
+ * following boolean is whether this should be scanned
+ * on every startup.
+ *
+ * @param file
+ * @return
+ */
+ public static Set<RuntimePath> parseRuntimeFile(InputStream is, boolean includeMissing) {
+ final Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
+ try {
+ Properties servers = new Properties();
+ servers.load(is);
+ Enumeration<Object> elements = servers.elements();
+ while (elements.hasMoreElements()) {
+ String str = (String) elements.nextElement();
+ StringTokenizer lineTokenizer =
+ new StringTokenizer(str,LINE_DELIMITER);
+ while (lineTokenizer.hasMoreTokens()) {
+ String lineToken = lineTokenizer.nextToken();
+ StringTokenizer tokenizer = new StringTokenizer(
+ lineToken, IN_LINE_DELIMITER);
+ if (tokenizer.countTokens() == 2) {
+ String location = tokenizer.nextToken();
+ boolean scan = Boolean.parseBoolean(tokenizer.nextToken());
+ File locationFile = new File(location);
+ if (locationFile.isDirectory() || (includeMissing && !locationFile.exists())) {
+ RuntimePath tempLocation = new RuntimePath(location);
+ tempLocation.setScanOnEveryStartup(scan);
+ runtimePaths.add(tempLocation);
+ }
+ }
+ }
+ }
+ } catch (IOException e) {
+ RuntimeCoreActivator.getDefault().logError(e);
+ }
+ return runtimePaths;
+ }
+
+ public static void updateTimestamps(Set<RuntimePath> runtimePaths2) {
+ for (RuntimePath runtimePath : runtimePaths2) {
+ String path = runtimePath.getPath();
+ if (path != null && !path.isEmpty()) {
+ File directory = new File(path);
+ if (directory.isDirectory()) {
+ runtimePath.setTimestamp(directory.lastModified());
+ }
+ }
+ }
+ }
+
+
+ public static boolean verifyRuntimeDefinitionCreated(RuntimeDefinition runtimeDefinition) {
+ return verifyRuntimeDefinitionCreated(runtimeDefinition, true);
+ }
+ public static boolean verifyRuntimeDefinitionCreated(RuntimeDefinition runtimeDefinition, boolean checkNested) {
+ Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
+ return verifyRuntimeDefinitionCreated(runtimeDefinition, detectors, checkNested);
+ }
+ public static boolean verifyRuntimeDefinitionCreated(RuntimeDefinition runtimeDefinition,
+ Set<IRuntimeDetector> detectors, boolean checkNested) {
+ boolean created = false;
+ for (IRuntimeDetector detector:detectors) {
+ if (!detector.isEnabled()) {
+ continue;
+ }
+ if (detector.exists(runtimeDefinition)) {
+ if( !checkNested ) {
+ created = true;
+ } else {
+ List<RuntimeDefinition> includedDefinitions = runtimeDefinition.getIncludedRuntimeDefinitions();
+ boolean includedCreated = true;
+ for (RuntimeDefinition includedDefinition:includedDefinitions) {
+ if (!verifyRuntimeDefinitionCreated(includedDefinition)) {
+ includedCreated = false;
+ break;
+ }
+ }
+ if (includedCreated) {
+ created = true;
+ break;
+ }
+ }
+ }
+ }
+ return (created);
+ }
+
+}
Added: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -0,0 +1,180 @@
+package org.jboss.tools.runtime.core.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.tools.common.xml.IMemento;
+import org.jboss.tools.common.xml.XMLMemento;
+import org.jboss.tools.runtime.core.RuntimeCoreActivator;
+import org.jboss.tools.runtime.core.model.IRuntimeDetector;
+import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
+
+public class RuntimePathPreferenceIO {
+ private static final String RUNTIME_PATHS = "runtimePaths";
+ private static final String PATH = "path";
+ private static final String RUNTIME_PATH = "runtimePath";
+ private static final String SCAN_ON_EVERY_STAERTUP = "scanOnEveryStartup";
+ private static final String TIMESTAMP = "timestamp";
+ private static final String SERVER_DEFINITIONS = "serverDefinitions";
+ private static final String SERVER_DEFINITION = "serverDefinition";
+ private static final String NAME = "name";
+ private static final String INCLUDED_DEFINITION = "included";
+ private static final String VERSION = "version";
+ private static final String TYPE = "type";
+ private static final String LOCATION = "location";
+ private static final String DESCRIPTION = "description";
+ private static final String ENABLED = "enabled";
+ public static final String FIRST_START = "firstStart"; //$NON-NLS-1$
+ public static final String PREFERENCES_VERSION = "version"; //$NON-NLS-1$
+ private static final String RUNTIME_PREFERENCES_VERSION = "2"; //$NON-NLS-1$
+
+ public static String getPreferenceOutputString(Set<RuntimePath> runtimePaths) throws IOException {
+ XMLMemento memento = XMLMemento.createWriteRoot(RUNTIME_PATHS);
+ memento.putString(PREFERENCES_VERSION, RUNTIME_PREFERENCES_VERSION);
+ for (RuntimePath runtimePath:runtimePaths) {
+ IMemento runtimePathNode = memento.createChild(RUNTIME_PATH);
+ runtimePathNode.putString(PATH, runtimePath.getPath());
+ runtimePathNode.putBoolean(SCAN_ON_EVERY_STAERTUP, runtimePath.isScanOnEveryStartup());
+ runtimePathNode.putString(TIMESTAMP, String.valueOf(runtimePath.getTimestamp()));
+ IMemento serverDefinitionsNode = runtimePathNode.createChild(SERVER_DEFINITIONS);
+ List<RuntimeDefinition> definitions = runtimePath.getRuntimeDefinitions();
+ putDefinitions(serverDefinitionsNode, definitions);
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BufferedOutputStream os = new BufferedOutputStream(baos);
+ try {
+ memento.save(os);
+ os.flush();
+ String runtimes = baos.toString();
+ return runtimes;
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ private static void putDefinitions(IMemento runtimeDefintionsNode,
+ List<RuntimeDefinition> definitions) {
+ for (RuntimeDefinition runtimeDefinition:definitions) {
+ IMemento sdNode = runtimeDefintionsNode.createChild(SERVER_DEFINITION);
+ putRuntimeDefinition(runtimeDefinition, sdNode);
+ IMemento includedNodes = sdNode.createChild(INCLUDED_DEFINITION);
+ for (RuntimeDefinition included:runtimeDefinition.getIncludedRuntimeDefinitions()) {
+ IMemento includedNode = includedNodes.createChild(SERVER_DEFINITION);
+ putRuntimeDefinition(included, includedNode);
+ }
+ }
+ }
+
+ private static void putRuntimeDefinition(RuntimeDefinition runtimeDefinition,
+ IMemento node) {
+ node.putString(NAME, runtimeDefinition.getName());
+ node.putString(VERSION, runtimeDefinition.getVersion());
+ node.putString(TYPE, runtimeDefinition.getType());
+ node.putString(LOCATION, runtimeDefinition.getLocation().getAbsolutePath());
+ node.putString(DESCRIPTION, runtimeDefinition.getDescription());
+ node.putBoolean(ENABLED, runtimeDefinition.isEnabled());
+ }
+
+ public static Set<RuntimePath> loadRuntimePathsFromPreferenceString(String preferenceString) {
+ HashSet<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
+ if (preferenceString == null || preferenceString.isEmpty()) {
+ return runtimePaths;
+ }
+ InputStream is = new BufferedInputStream(new ByteArrayInputStream(preferenceString.getBytes()));
+ XMLMemento memento = XMLMemento.createReadRoot(is);
+
+ // If there's no preference version declared, it's version 1,
+ // which requires computing the nested runtimes, since
+ // they are not stored in the model
+ String preferencesVersion = memento.getString(PREFERENCES_VERSION);
+ boolean computeIncluded = preferencesVersion == null;
+
+
+ IMemento[] nodes = memento.getChildren(RUNTIME_PATH);
+ for (IMemento node:nodes) {
+ String path = node.getString(PATH);
+ boolean scanOnEveryStartup = node.getBoolean(SCAN_ON_EVERY_STAERTUP);
+ String tsString = node.getString(TIMESTAMP);
+ Long timestamp = null;
+ try {
+ timestamp = new Long(tsString);
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ RuntimePath runtimePath = new RuntimePath(path);
+ runtimePath.setScanOnEveryStartup(scanOnEveryStartup);
+ if (timestamp != null) {
+ runtimePath.setTimestamp(timestamp);
+ }
+ IMemento serverDefinitionsNode = node.getChild(SERVER_DEFINITIONS);
+ IMemento[] sdNodes = serverDefinitionsNode.getChildren(SERVER_DEFINITION);
+ for (IMemento sdNode:sdNodes) {
+ RuntimeDefinition serverDefinition = createRuntimeDefinition(sdNode);
+ serverDefinition.setRuntimePath(runtimePath);
+ IMemento includedDefinition = sdNode.getChild(INCLUDED_DEFINITION);
+ if (includedDefinition != null) {
+ IMemento[] includedNodes = includedDefinition
+ .getChildren(SERVER_DEFINITION);
+ for (IMemento includedNode : includedNodes) {
+ RuntimeDefinition included = createRuntimeDefinition(includedNode);
+ included.setRuntimePath(runtimePath);
+ included.setParent(serverDefinition);
+ serverDefinition.getIncludedRuntimeDefinitions().add(
+ included);
+ }
+ }
+ runtimePath.getRuntimeDefinitions().add(serverDefinition);
+ }
+ runtimePaths.add(runtimePath);
+ }
+ if (computeIncluded) {
+ for(RuntimeDefinition definition:getAllRuntimeDefinitions(runtimePaths)) {
+ Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
+ for (IRuntimeDetector detector:detectors) {
+ detector.computeIncludedRuntimeDefinition(definition);
+ }
+ }
+ }
+ return runtimePaths;
+ }
+
+ private static RuntimeDefinition createRuntimeDefinition(IMemento node) {
+ String name = node.getString(NAME);
+ String version = node.getString(VERSION);
+ String type = node.getString(TYPE);
+ String location = node.getString(LOCATION);
+ String description = node.getString(DESCRIPTION);
+ boolean enabled = node.getBoolean(ENABLED);
+ RuntimeDefinition runtimeDefinition =
+ new RuntimeDefinition(name, version, type, new File(location));
+ runtimeDefinition.setDescription(description);
+ runtimeDefinition.setEnabled(enabled);
+ return runtimeDefinition;
+ }
+
+ private static List<RuntimeDefinition> getAllRuntimeDefinitions(Set<RuntimePath> paths) {
+ List<RuntimeDefinition> defs = new ArrayList<RuntimeDefinition>();
+ for( Iterator<RuntimePath> i = paths.iterator(); i.hasNext(); ) {
+ defs.addAll(i.next().getRuntimeDefinitions());
+ }
+ return defs;
+ }
+}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -10,18 +10,11 @@
******************************************************************************/
package org.jboss.tools.runtime.ui;
-import java.io.BufferedInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.TreeSet;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -31,12 +24,13 @@
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonNavigator;
-import org.jboss.tools.runtime.core.JBossRuntimeLocator;
-import org.jboss.tools.runtime.core.RuntimeCoreActivator;
-import org.jboss.tools.runtime.core.model.IRuntimeDetector;
-import org.jboss.tools.runtime.core.model.RuntimeDefinition;
import org.jboss.tools.runtime.core.model.RuntimePath;
+import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
+import org.jboss.tools.runtime.core.util.RuntimeModelUtil;
+/**
+ * This class is only run on the first start of the product
+ */
public class JBossRuntimeStartup {
private static final String JBOSS_EAP_HOME = "../../runtimes/jboss-eap"; // JBoss EAP home directory (relative to plugin)- <RHDS_HOME>/jbossas. //$NON-NLS-1$
@@ -45,71 +39,44 @@
private static final String LOCATIONS_FILE_CONFIGURATION = "../../studio/" + LOCATIONS_FILE_NAME; //$NON-NLS-1$
public static void initializeRuntimes(IProgressMonitor monitor) {
- JBossRuntimeLocator locator = new JBossRuntimeLocator();
- try {
- String configuration = getConfiguration();
- File directory = new File(configuration, JBOSS_EAP_HOME);
- if (directory.isDirectory()) {
- RuntimePath runtimePath = new RuntimePath(
- directory.getAbsolutePath());
- List<RuntimeDefinition> runtimeDefinitions = locator
- .searchForRuntimes(runtimePath.getPath(), monitor);
- runtimePath.getRuntimeDefinitions().clear();
- for (RuntimeDefinition serverDefinition : runtimeDefinitions) {
- serverDefinition.setRuntimePath(runtimePath);
- }
- initializeRuntimes(runtimeDefinitions);
- }
- } catch (IOException e) {
- RuntimeUIActivator.log(e);
- }
+ initializeEAPRuntimes(monitor);
+ initializeRuntimesFromDefinitionFile(monitor);
+ }
+
+ private static void initializeEAPRuntimes(IProgressMonitor monitor) {
+ File directory = getEAPDirectory();
+ RuntimeInitializerUtil.initializeRuntimesFromFolder(directory, monitor);
+ RuntimeWorkbenchUtils.refreshServersView(); // ?!?!
+ }
+
+ private static void initializeRuntimesFromDefinitionFile(IProgressMonitor monitor) {
final Set<RuntimePath> runtimePaths = parseRuntimeLocationsFile();
for (RuntimePath runtimePath : runtimePaths) {
- List<RuntimeDefinition> serverDefinitions = locator
- .searchForRuntimes(runtimePath.getPath(), monitor);
- runtimePath.getRuntimeDefinitions().clear();
- for (RuntimeDefinition serverDefinition : serverDefinitions) {
- serverDefinition.setRuntimePath(runtimePath);
- }
- runtimePath.getRuntimeDefinitions().addAll(serverDefinitions);
+ RuntimeInitializerUtil.createRuntimeDefinitions(runtimePath, monitor);
}
+
if (runtimePaths.size() > 0) {
- RuntimeUIActivator.getDefault().getRuntimePaths()
- .addAll(runtimePaths);
+ RuntimeUIActivator.getDefault().getRuntimePaths().addAll(runtimePaths);
RuntimeUIActivator.getDefault().saveRuntimePaths();
}
}
- public static void initializeRuntimes(List<RuntimeDefinition> serverDefinitions) {
- Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
- for( IRuntimeDetector detector:detectors) {
- if (detector.isEnabled()) {
- detector.initializeRuntimes(serverDefinitions);
- }
+ private static File getEAPDirectory() {
+ try {
+ String configuration = getConfiguration();
+ File directory = new File(configuration, JBOSS_EAP_HOME);
+ return directory;
+ } catch( IOException ioe) {
+ RuntimeUIActivator.log(ioe);
}
- refreshCommonNavigator();
+ return null;
}
- private static void refreshCommonNavigator() {
- // https://jira.jboss.org/jira/browse/JBDS-1091
- Display.getDefault().asyncExec(new Runnable() {
-
- public void run() {
- IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.wst.server.ui.ServersView");
- if (view instanceof CommonNavigator) {
- CommonNavigator navigator = (CommonNavigator) view;
- navigator.getCommonViewer().refresh();
- }
- }
- });
- }
-
- private static Set<RuntimePath> parseRuntimeLocationsFile() {
- final Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
+ private static File findRuntimeFile() {
try {
String pluginLocation = FileLocator.resolve(RuntimeUIActivator.getDefault().getBundle().getEntry("/")).getPath(); //$NON-NLS-1$
File serversFile = new File(pluginLocation, LOCATIONS_FILE);
-
+
if (!serversFile.isFile()) {
String configuration = getConfiguration();
serversFile = new File(configuration, LOCATIONS_FILE_CONFIGURATION).getCanonicalFile();
@@ -120,39 +87,22 @@
serversFile = new File(pluginLocation,LOCATIONS_FILE_NAME);
}
if (serversFile.isFile()) {
- //String str = FileUtil.readFile(serversFile);
- Properties servers = new Properties();
- servers.load(new BufferedInputStream(new FileInputStream(serversFile)));
- Enumeration<Object> elements = servers.elements();
- while (elements.hasMoreElements()) {
- String str = (String) elements.nextElement();
- StringTokenizer lineTokenizer = new StringTokenizer(str,
- "\n\r\f"); //$NON-NLS-1$
- while (lineTokenizer.hasMoreTokens()) {
- String lineToken = lineTokenizer.nextToken();
- StringTokenizer tokenizer = new StringTokenizer(
- lineToken, ","); //$NON-NLS-1$
- if (tokenizer.countTokens() == 2) {
- String location = tokenizer.nextToken();
- boolean scan = Boolean.parseBoolean(tokenizer.nextToken());
- File locationFile = new File(location);
- if (locationFile.isDirectory()) {
- RuntimePath tempLocation = new RuntimePath(location);
- tempLocation.setScanOnEveryStartup(scan);
- runtimePaths.add(tempLocation);
- }
- }
- }
- }
+ return serversFile;
}
- } catch (FileNotFoundException e) {
- RuntimeUIActivator.log(e);
- } catch (IOException e) {
- RuntimeUIActivator.log(e);
+ } catch(IOException ioe) {
+ RuntimeUIActivator.log(ioe);
}
- return runtimePaths;
+ return null;
}
-
+
+ private static Set<RuntimePath> parseRuntimeLocationsFile() {
+ File runtimeFile = findRuntimeFile();
+ if( runtimeFile != null && runtimeFile.isFile()) {
+ return RuntimeModelUtil.parseRuntimeFile(runtimeFile);
+ }
+ return new TreeSet<RuntimePath>();
+ }
+
private static String getConfiguration() throws IOException {
Location configLocation = Platform.getConfigurationLocation();
URL configURL = configLocation.getURL();
Added: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -0,0 +1,54 @@
+package org.jboss.tools.runtime.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
+
+public class RuntimeCheckboxTreeViewer extends CheckboxTreeViewer {
+ public RuntimeCheckboxTreeViewer(Composite parent, final Set<RuntimePath> runtimePaths2, int heightHint) {
+ super(parent, SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
+
+ GridData gd;
+ Tree tree = getTree();
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ GC gc = new GC( parent);
+ FontMetrics fontMetrics = gc.getFontMetrics( );
+ gc.dispose( );
+ gd.minimumHeight = Dialog.convertHeightInCharsToPixels(fontMetrics, heightHint);
+ tree.setLayoutData(gd);
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
+
+ String[] columnNames = new String[] { "Name", "Version", "Type", "Location"};
+ int[] columnWidths = new int[] {300, 100, 50, 200};
+
+ for (int i = 0; i < columnNames.length; i++) {
+ TreeViewerColumn tc = new TreeViewerColumn(this, SWT.NONE);
+ tc.getColumn().setText(columnNames[i]);
+ tc.getColumn().setWidth(columnWidths[i]);
+ }
+
+ setLabelProvider(new RuntimeLabelProvider());
+ List<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
+ for (RuntimePath runtimePath:runtimePaths2) {
+ runtimeDefinitions.addAll(runtimePath.getRuntimeDefinitions());
+ }
+ setContentProvider(new RuntimeContentProvider(runtimeDefinitions));
+ setInput(runtimeDefinitions);
+ for (RuntimeDefinition definition:runtimeDefinitions) {
+ setChecked(definition, definition.isEnabled());
+ }
+ }
+}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -24,9 +24,9 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.PlatformUI;
-import org.jboss.tools.runtime.core.JBossRuntimeLocator;
+import org.jboss.tools.runtime.core.model.RuntimeDefinition;
import org.jboss.tools.runtime.core.model.RuntimePath;
-import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
/**
* @author snjeza
@@ -36,15 +36,10 @@
@Override
public void earlyStartup() {
- String skipRuntimeScanner = System.getProperty("skip.runtime.scanner", "false");
- if ("true".equals(skipRuntimeScanner)) {
+ if( Boolean.getBoolean("skip.runtime.scanner"))
return;
- }
- boolean firstStartWorkspace = RuntimeUIActivator.getDefault().
- getPreferenceStore().getBoolean(RuntimeUIActivator.FIRST_START);
- IEclipsePreferences configurationNode = ConfigurationScope.INSTANCE.getNode(RuntimeUIActivator.PLUGIN_ID);
- boolean firstStartConfiguration = configurationNode.getBoolean(RuntimeUIActivator.FIRST_START, true);
- final boolean firstStart = firstStartWorkspace || firstStartConfiguration;
+
+ final boolean firstStart = isFirstStart();
Job runtimeJob = new Job("Searching runtimes...") {
@Override
@@ -81,10 +76,25 @@
runtimeJob.setPriority(Job.LONG);
runtimeJob.schedule(1000);
+ setFirstStartFalse();
+ }
+
+
+ private boolean isFirstStart() {
+ boolean firstStartWorkspace = RuntimeUIActivator.getDefault().
+ getPreferenceStore().getBoolean(RuntimeUIActivator.FIRST_START);
+ IEclipsePreferences configurationNode = ConfigurationScope.INSTANCE.getNode(RuntimeUIActivator.PLUGIN_ID);
+ boolean firstStartConfiguration = configurationNode.getBoolean(RuntimeUIActivator.FIRST_START, true);
+ final boolean firstStart = firstStartWorkspace || firstStartConfiguration;
+ return firstStart;
+ }
+
+ private void setFirstStartFalse() {
+ IEclipsePreferences configurationNode = ConfigurationScope.INSTANCE.getNode(RuntimeUIActivator.PLUGIN_ID);
+ configurationNode.putBoolean(RuntimeUIActivator.FIRST_START, false);
RuntimeUIActivator.getDefault().getPreferenceStore().setValue(RuntimeUIActivator.FIRST_START, false);
- configurationNode.putBoolean(RuntimeUIActivator.FIRST_START, false);
}
-
+
private boolean runtimeExists(boolean firstStart, IProgressMonitor monitor) {
Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
for (RuntimePath runtimePath:runtimePaths) {
@@ -95,29 +105,20 @@
return false;
}
if (runtimePath.isModified()) {
- JBossRuntimeLocator locator = new JBossRuntimeLocator();
- List<RuntimeDefinition> serverDefinitions = locator.searchForRuntimes(runtimePath.getPath(), monitor);
- if (monitor.isCanceled()) {
- return false;
- }
- runtimePath.getRuntimeDefinitions().clear();
- for (RuntimeDefinition serverDefinition:serverDefinitions) {
- serverDefinition.setRuntimePath(runtimePath);
- }
- runtimePath.getRuntimeDefinitions().addAll(serverDefinitions);
+ RuntimeInitializerUtil.createRuntimeDefinitions(runtimePath, monitor);
RuntimeUIActivator.setTimestamp(runtimePaths);
}
monitor.setTaskName("JBoss Runtime Detector: checking " + runtimePath.getPath());
- List<RuntimeDefinition> serverDefinitions = runtimePath.getRuntimeDefinitions();
- for (RuntimeDefinition serverDefinition:serverDefinitions) {
+ List<RuntimeDefinition> runtimeDefinitions = runtimePath.getRuntimeDefinitions();
+ for (RuntimeDefinition runtimeDefinition:runtimeDefinitions) {
if (monitor.isCanceled()) {
return false;
}
- if (!serverDefinition.isEnabled()) {
+ if (!runtimeDefinition.isEnabled()) {
continue;
}
- monitor.setTaskName("JBoss Runtime Detector: checking " + serverDefinition.getLocation());
- if (!RuntimeUIActivator.runtimeCreated(serverDefinition)) {
+ monitor.setTaskName("JBoss Runtime Detector: checking " + runtimeDefinition.getLocation());
+ if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
return true;
}
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -10,12 +10,6 @@
************************************************************************************/
package org.jboss.tools.runtime.ui;
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
@@ -28,35 +22,23 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.TreeViewerColumn;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
-import org.eclipse.ui.XMLMemento;
-import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.jboss.tools.runtime.core.JBossRuntimeLocator;
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
import org.jboss.tools.runtime.core.model.RuntimePath;
+import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
+import org.jboss.tools.runtime.core.util.RuntimeModelUtil;
+import org.jboss.tools.runtime.core.util.RuntimePathPreferenceIO;
import org.jboss.tools.runtime.ui.dialogs.SearchRuntimePathDialog;
import org.jboss.tools.runtime.ui.download.DownloadRuntimes;
-import org.jboss.tools.runtime.ui.preferences.RuntimePreferencePage;
import org.osgi.framework.BundleContext;
/**
@@ -84,38 +66,16 @@
public static final String RUNTIME_PATH = "runtimePath";
public static final String SCAN_ON_EVERY_STAERTUP = "scanOnEveryStartup";
-
- public static final String TIMESTAMP = "timestamp";
- private static final String SERVER_DEFINITIONS = "serverDefinitions";
-
- private static final String SERVER_DEFINITION = "serverDefinition";
-
- private static final String NAME = "name";
-
- private static final String INCLUDED_DEFINITION = "included";
-
- private static final String VERSION = "version";
-
- private static final String TYPE = "type";
-
- private static final String LOCATION = "location";
-
- private static final String DESCRIPTION = "description";
-
- private static final String ENABLED = "enabled";
-
public static final String FIRST_START = "firstStart"; //$NON-NLS-1$
public static final String PREFERENCES_VERSION = "version"; //$NON-NLS-1$
-
- private static final String RUNTIME_PREFERENCES_VERSION = "2"; //$NON-NLS-1$
private BundleContext context;
private Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
- private List<RuntimeDefinition> serverDefinitions;
+ private List<RuntimeDefinition> runtimeDefinitions;
private ListenerList runtimePathChangeChangeListeners;
@@ -174,59 +134,14 @@
}
public static CheckboxTreeViewer createRuntimeViewer(final Set<RuntimePath> runtimePaths2, Composite composite, int heightHint) {
- GridData gd;
- CheckboxTreeViewer viewer = new CheckboxTreeViewer(composite, SWT.V_SCROLL
- | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
-
- Tree tree = viewer.getTree();
- gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- GC gc = new GC( composite);
- FontMetrics fontMetrics = gc.getFontMetrics( );
- gc.dispose( );
- gd.minimumHeight = Dialog.convertHeightInCharsToPixels(fontMetrics, heightHint);
- tree.setLayoutData(gd);
- tree.setHeaderVisible(true);
- tree.setLinesVisible(true);
-
- String[] columnNames = new String[] { "Name", "Version", "Type", "Location"};
- int[] columnWidths = new int[] {300, 100, 50, 200};
-
- for (int i = 0; i < columnNames.length; i++) {
- TreeViewerColumn tc = new TreeViewerColumn(viewer, SWT.NONE);
- tc.getColumn().setText(columnNames[i]);
- tc.getColumn().setWidth(columnWidths[i]);
- }
-
- viewer.setLabelProvider(new RuntimeLabelProvider());
- List<RuntimeDefinition> serverDefinitions = new ArrayList<RuntimeDefinition>();
- for (RuntimePath runtimePath:runtimePaths2) {
- serverDefinitions.addAll(runtimePath.getRuntimeDefinitions());
- }
- viewer.setContentProvider(new RuntimeContentProvider(serverDefinitions));
- viewer.setInput(serverDefinitions);
- for (RuntimeDefinition definition:serverDefinitions) {
- viewer.setChecked(definition, definition.isEnabled());
- }
- return viewer;
+ return new RuntimeCheckboxTreeViewer(composite, runtimePaths2, heightHint);
}
public static void refreshRuntimes(Shell shell, final Set<RuntimePath> runtimePaths, final CheckboxTreeViewer viewer, boolean needRefresh, int heightHint) {
IRunnableWithProgress op = new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- JBossRuntimeLocator locator = new JBossRuntimeLocator();
- for (RuntimePath runtimePath : runtimePaths) {
- List<RuntimeDefinition> serverDefinitions = locator
- .searchForRuntimes(runtimePath.getPath(), monitor);
- runtimePath.getRuntimeDefinitions().clear();
- for (RuntimeDefinition serverDefinition : serverDefinitions) {
- serverDefinition.setRuntimePath(runtimePath);
- }
- runtimePath.getRuntimeDefinitions()
- .addAll(serverDefinitions);
- }
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ RuntimeInitializerUtil.createRuntimeDefinitions(runtimePaths, monitor);
}
};
try {
@@ -238,12 +153,12 @@
@Override
public void widgetDisposed(DisposeEvent e) {
viewer.setInput(null);
- List<RuntimeDefinition> serverDefinitions = new ArrayList<RuntimeDefinition>();
+ List<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
for (RuntimePath runtimePath : runtimePaths) {
- serverDefinitions.addAll(runtimePath
+ runtimeDefinitions.addAll(runtimePath
.getRuntimeDefinitions());
- viewer.setInput(serverDefinitions);
- for (RuntimeDefinition serverDefinition : serverDefinitions) {
+ viewer.setInput(runtimeDefinitions);
+ for (RuntimeDefinition serverDefinition : runtimeDefinitions) {
runtimeExists(serverDefinition);
viewer.setChecked(serverDefinition,
serverDefinition.isEnabled());
@@ -259,109 +174,23 @@
}
}
- public static boolean runtimeExists(RuntimeDefinition serverDefinition) {
- Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
- for (IRuntimeDetector detector:detectors) {
- if (detector.isEnabled() && detector.exists(serverDefinition)) {
- return true;
- }
- }
- return false;
+ public static boolean runtimeExists(RuntimeDefinition runtimeDefinition) {
+ return RuntimeModelUtil.verifyRuntimeDefinitionCreated(runtimeDefinition, false);
}
- public static void refreshPreferencePage(Shell shell) {
- Shell mainShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getShell();
- if (shell != null && !shell.isDisposed()) {
- shell.close();
- }
- shell = Display.getCurrent().getActiveShell();
- if (shell != mainShell && shell != null) {
- shell.close();
- }
- PreferenceDialog preferenceDialog = PreferencesUtil
- .createPreferenceDialogOn(PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getShell(),
- RuntimePreferencePage.ID, null, null);
- preferenceDialog.open();
- }
-
public void saveRuntimePreferences() {
saveRuntimePaths();
RuntimeCoreActivator.getDefault().saveEnabledDetectors();
}
private void initRuntimePaths() throws WorkbenchException {
- runtimePaths = new HashSet<RuntimePath>();
String runtimes = getPreferences().get(RUNTIME_PATHS, null);
if (runtimes == null || runtimes.isEmpty()) {
return;
}
- Reader reader = new StringReader(runtimes);
- XMLMemento memento = XMLMemento.createReadRoot(reader);
- String preferencesVersion = memento.getString(PREFERENCES_VERSION);
- boolean computeIncluded = preferencesVersion == null;
- IMemento[] nodes = memento.getChildren(RUNTIME_PATH);
- for (IMemento node:nodes) {
- String path = node.getString(PATH);
- boolean scanOnEveryStartup = node.getBoolean(SCAN_ON_EVERY_STAERTUP);
- String tsString = node.getString(TIMESTAMP);
- Long timestamp = null;
- try {
- timestamp = new Long(tsString);
- } catch (NumberFormatException e) {
- // ignore
- }
- RuntimePath runtimePath = new RuntimePath(path);
- runtimePath.setScanOnEveryStartup(scanOnEveryStartup);
- if (timestamp != null) {
- runtimePath.setTimestamp(timestamp);
- }
- IMemento serverDefinitionsNode = node.getChild(SERVER_DEFINITIONS);
- IMemento[] sdNodes = serverDefinitionsNode.getChildren(SERVER_DEFINITION);
- for (IMemento sdNode:sdNodes) {
- RuntimeDefinition serverDefinition = createServerDefinition(sdNode);
- serverDefinition.setRuntimePath(runtimePath);
- IMemento includedDefinition = sdNode.getChild(INCLUDED_DEFINITION);
- if (includedDefinition != null) {
- IMemento[] includedNodes = includedDefinition
- .getChildren(SERVER_DEFINITION);
- for (IMemento includedNode : includedNodes) {
- RuntimeDefinition included = createServerDefinition(includedNode);
- included.setRuntimePath(runtimePath);
- included.setParent(serverDefinition);
- serverDefinition.getIncludedRuntimeDefinitions().add(
- included);
- }
- }
- runtimePath.getRuntimeDefinitions().add(serverDefinition);
- }
- runtimePaths.add(runtimePath);
- }
- if (computeIncluded) {
- for(RuntimeDefinition definition:getServerDefinitions()) {
- Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
- for (IRuntimeDetector detector:detectors) {
- detector.computeIncludedRuntimeDefinition(definition);
- }
- }
- }
+ runtimePaths = RuntimePathPreferenceIO.loadRuntimePathsFromPreferenceString(runtimes);
}
- private RuntimeDefinition createServerDefinition(IMemento node) {
- String name = node.getString(NAME);
- String version = node.getString(VERSION);
- String type = node.getString(TYPE);
- String location = node.getString(LOCATION);
- String description = node.getString(DESCRIPTION);
- boolean enabled = node.getBoolean(ENABLED);
- RuntimeDefinition serverDefinition =
- new RuntimeDefinition(name, version, type, new File(location));
- serverDefinition.setDescription(description);
- serverDefinition.setEnabled(enabled);
- return serverDefinition;
- }
-
private static IEclipsePreferences getPreferences() {
if (prefs == null) {
prefs = ConfigurationScope.INSTANCE.getNode(PLUGIN_ID);
@@ -370,71 +199,29 @@
}
public void saveRuntimePaths() {
- if (runtimePaths == null) {
+ if (runtimePaths == null)
return;
- }
- XMLMemento memento = XMLMemento.createWriteRoot(RUNTIME_PATHS);
- Writer writer = null;
+
try {
- memento.putString(PREFERENCES_VERSION, RUNTIME_PREFERENCES_VERSION);
- for (RuntimePath runtimePath:runtimePaths) {
- IMemento runtimePathNode = memento.createChild(RUNTIME_PATH);
- runtimePathNode.putString(PATH, runtimePath.getPath());
- runtimePathNode.putBoolean(SCAN_ON_EVERY_STAERTUP, runtimePath.isScanOnEveryStartup());
- runtimePathNode.putString(TIMESTAMP, String.valueOf(runtimePath.getTimestamp()));
- IMemento serverDefinitionsNode = runtimePathNode.createChild(SERVER_DEFINITIONS);
- List<RuntimeDefinition> definitions = runtimePath.getRuntimeDefinitions();
- putDefinitions(serverDefinitionsNode, definitions);
- }
- writer = new StringWriter();
- memento.save(writer);
- writer.flush();
- String runtimes = writer.toString();
+ String runtimes = RuntimePathPreferenceIO.getPreferenceOutputString(runtimePaths);
getPreferences().put(RUNTIME_PATHS, runtimes);
getPreferences().flush();
- if (runtimePathChangeChangeListeners != null) {
- Object[] listeners = runtimePathChangeChangeListeners.getListeners();
- for (Object listener:listeners ) {
- IRuntimePathChangeListener runtimePathChangeChangeListener = (IRuntimePathChangeListener) listener;
- runtimePathChangeChangeListener.changed();
- }
- }
+ fireRuntimePathsChanged();
} catch (Exception e) {
log(e);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- // ignore
- }
- }
}
}
- private void putDefinitions(IMemento serverDefintionsNode,
- List<RuntimeDefinition> definitions) {
- for (RuntimeDefinition serverDefinition:definitions) {
- IMemento sdNode = serverDefintionsNode.createChild(SERVER_DEFINITION);
- putServerDefinition(serverDefinition, sdNode);
- IMemento includedNodes = sdNode.createChild(INCLUDED_DEFINITION);
- for (RuntimeDefinition included:serverDefinition.getIncludedRuntimeDefinitions()) {
- IMemento includedNode = includedNodes.createChild(SERVER_DEFINITION);
- putServerDefinition(included, includedNode);
+ private void fireRuntimePathsChanged() {
+ if (runtimePathChangeChangeListeners != null) {
+ Object[] listeners = runtimePathChangeChangeListeners.getListeners();
+ for (Object listener:listeners ) {
+ IRuntimePathChangeListener runtimePathChangeChangeListener = (IRuntimePathChangeListener) listener;
+ runtimePathChangeChangeListener.changed();
}
}
}
- private void putServerDefinition(RuntimeDefinition serverDefinition,
- IMemento node) {
- node.putString(NAME, serverDefinition.getName());
- node.putString(VERSION, serverDefinition.getVersion());
- node.putString(TYPE, serverDefinition.getType());
- node.putString(LOCATION, serverDefinition.getLocation().getAbsolutePath());
- node.putString(DESCRIPTION, serverDefinition.getDescription());
- node.putBoolean(ENABLED, serverDefinition.isEnabled());
- }
-
public Set<RuntimePath> getRuntimePaths() {
if (runtimePaths == null) {
try {
@@ -448,15 +235,15 @@
}
public List<RuntimeDefinition> getServerDefinitions() {
- if (serverDefinitions == null) {
- serverDefinitions = new ArrayList<RuntimeDefinition>();
+ if (runtimeDefinitions == null) {
+ runtimeDefinitions = new ArrayList<RuntimeDefinition>();
} else {
- serverDefinitions.clear();
+ runtimeDefinitions.clear();
}
for (RuntimePath runtimePath:getRuntimePaths()) {
- serverDefinitions.addAll(runtimePath.getRuntimeDefinitions());
+ runtimeDefinitions.addAll(runtimePath.getRuntimeDefinitions());
}
- return serverDefinitions;
+ return runtimeDefinitions;
}
public Set<IRuntimeDetector> getRuntimeDetectors() {
@@ -468,44 +255,15 @@
}
public static void setTimestamp(Set<RuntimePath> runtimePaths2) {
- for (RuntimePath runtimePath : runtimePaths2) {
- String path = runtimePath.getPath();
- if (path != null && !path.isEmpty()) {
- File directory = new File(path);
- if (directory.isDirectory()) {
- runtimePath.setTimestamp(directory.lastModified());
- }
- }
- }
+ RuntimeModelUtil.updateTimestamps(runtimePaths2);
}
public void refreshRuntimePreferences() {
runtimePaths = null;
}
- public static boolean runtimeCreated(RuntimeDefinition serverDefinition) {
- Set<IRuntimeDetector> detectors = getDefault().getRuntimeDetectors();
- boolean created = false;
- for (IRuntimeDetector detector:detectors) {
- if (!detector.isEnabled()) {
- continue;
- }
- if (detector.exists(serverDefinition)) {
- List<RuntimeDefinition> includedDefinitions = serverDefinition.getIncludedRuntimeDefinitions();
- boolean includedCreated = true;
- for (RuntimeDefinition includedDefinition:includedDefinitions) {
- if (!runtimeCreated(includedDefinition)) {
- includedCreated = false;
- break;
- }
- }
- if (includedCreated) {
- created = true;
- break;
- }
- }
- }
- return (created);
+ public static boolean runtimeCreated(RuntimeDefinition runtimeDefinition) {
+ return RuntimeModelUtil.verifyRuntimeDefinitionCreated(runtimeDefinition);
}
public void addRuntimePathChangeListener(IRuntimePathChangeListener listener) {
Added: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -0,0 +1,51 @@
+package org.jboss.tools.runtime.ui;
+
+import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.jboss.tools.runtime.ui.preferences.RuntimePreferencePage;
+
+public class RuntimeWorkbenchUtils {
+ public static void refreshServersView() {
+ // https://jira.jboss.org/jira/browse/JBDS-1091
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.wst.server.ui.ServersView");
+ if (view instanceof CommonNavigator) {
+ CommonNavigator navigator = (CommonNavigator) view;
+ navigator.getCommonViewer().refresh();
+ }
+ }
+ });
+ }
+
+ public static void refreshPreferencePage(final Shell shell) {
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ refreshPreferencePageUIThread(shell);
+ }
+ });
+ }
+
+ public static void refreshPreferencePageUIThread(Shell shell) {
+ Shell mainShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getShell();
+ if (shell != null && !shell.isDisposed()) {
+ shell.close();
+ }
+ shell = Display.getCurrent().getActiveShell();
+ if (shell != mainShell && shell != null) {
+ shell.close();
+ }
+ PreferenceDialog preferenceDialog = PreferencesUtil
+ .createPreferenceDialogOn(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getShell(),
+ RuntimePreferencePage.ID, null, null);
+ preferenceDialog.open();
+ }
+
+}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -43,9 +43,10 @@
import org.eclipse.swt.widgets.TreeItem;
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
-import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
+import org.jboss.tools.runtime.ui.RuntimeWorkbenchUtils;
/**
* @author snjeza
@@ -267,13 +268,7 @@
setReturnCode(OK);
close();
if (needRefresh) {
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- RuntimeUIActivator.refreshPreferencePage(getShell());
- }
- });
-
+ RuntimeWorkbenchUtils.refreshPreferencePage(getShell());
}
}
@@ -340,13 +335,12 @@
List<RuntimeDefinition> allDefinitions = getAllDefinitions();
for (RuntimePath runtimePath : runtimePaths) {
List<RuntimeDefinition> pathDefinitions = getAllDefinitions(runtimePath);
- for (RuntimeDefinition serverDefinition : pathDefinitions) {
- if (!RuntimeUIActivator.runtimeCreated(serverDefinition)) {
-
- String name = serverDefinition.getName();
+ for (RuntimeDefinition runtimeDefinition : pathDefinitions) {
+ if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
+ String name = runtimeDefinition.getName();
int i = 2;
- while (serverDefinitionsExists(serverDefinition, allDefinitions)) {
- serverDefinition.setName(name + " (" + i++ + ")");
+ while (runtimeDefinitionsExists(runtimeDefinition, allDefinitions)) {
+ runtimeDefinition.setName(name + " (" + i++ + ")");
}
}
}
@@ -382,7 +376,7 @@
return allServerDefinitions;
}
- private boolean serverDefinitionsExists(RuntimeDefinition serverDefinition,
+ private boolean runtimeDefinitionsExists(RuntimeDefinition serverDefinition,
List<RuntimeDefinition> allServerDefinitions) {
String name = serverDefinition.getName();
File location = serverDefinition.getLocation();
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -78,6 +78,7 @@
import org.jboss.tools.runtime.ui.IRuntimePathChangeListener;
import org.jboss.tools.runtime.ui.RuntimeSharedImages;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
+import org.jboss.tools.runtime.ui.RuntimeWorkbenchUtils;
import org.jboss.tools.runtime.ui.dialogs.AutoResizeTableLayout;
import org.jboss.tools.runtime.ui.dialogs.EditRuntimePathDialog;
import org.jboss.tools.runtime.ui.dialogs.RuntimePathEditingSupport;
@@ -383,7 +384,7 @@
}
}
if (!getControl().isDisposed()) {
- RuntimeUIActivator.refreshPreferencePage(getShell());
+ RuntimeWorkbenchUtils.refreshPreferencePageUIThread(getShell());
}
}
@@ -535,7 +536,7 @@
}
- class RuntimePathLabelProvider extends ColumnLabelProvider {
+ public static class RuntimePathLabelProvider extends ColumnLabelProvider {
private int columnIndex;
@@ -576,7 +577,7 @@
}
}
- private class RuntimeDetectorContentProvider implements IStructuredContentProvider {
+ private static class RuntimeDetectorContentProvider implements IStructuredContentProvider {
private Set<IRuntimeDetector> detectors;
@@ -597,7 +598,7 @@
}
}
- private class RuntimeDetectorLabelProvider extends LabelProvider implements
+ private static class RuntimeDetectorLabelProvider extends LabelProvider implements
ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {
Modified: trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/handlers/TestHandler1.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/handlers/TestHandler1.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/handlers/TestHandler1.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -4,9 +4,12 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.jboss.tools.runtime.core.model.AbstractRuntimeDetectorDelegate;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.test.RuntimeTestActivator;
public class TestHandler1 extends AbstractRuntimeDetectorDelegate {
@@ -18,6 +21,12 @@
public TestHandler1() {
ME = this;
+ System.out.println("Inside TestHandler constructor: " + this.toString());
+ try {
+ throw new Exception();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
}
private ArrayList<String> initialized = new ArrayList<String>();
@@ -25,20 +34,26 @@
initialized.clear();
}
private void addInit(String s) {
+ System.out.println("__ Adding s: " + s);
initialized.add(s);
}
public String[] getInited() {
+ System.out.println("__ getting inited: " + initialized);
return (String[]) initialized.toArray(new String[initialized.size()]);
}
@Override
public RuntimeDefinition getRuntimeDefinition(File root,
IProgressMonitor monitor) {
- if( root.isDirectory() && root.list().length == 0 ) {
- RuntimeDefinition def = new RuntimeDefinition(
- "Handler1 Folder " + root.getName(), "1.0",
- "testHandler", root);
- return def;
+ IPath rootPath = new Path(root.getAbsolutePath());
+ IPath stateLoc = RuntimeTestActivator.getDefault().getStateLocation();
+ if( stateLoc.isPrefixOf(rootPath)) {
+ if( root.isDirectory() && root.list().length == 0 ) {
+ RuntimeDefinition def = new RuntimeDefinition(
+ "Handler1 Folder " + root.getName(), "1.0",
+ "testHandler", root);
+ return def;
+ }
}
return null;
}
Modified: trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionAllTests.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionAllTests.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionAllTests.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -15,7 +15,8 @@
@Suite.SuiteClasses({
- RuntimeDetectionFrameworkTest.class
+ RuntimeDetectionFrameworkTest.class,
+ RuntimePathUtilTest.class
})
@RunWith(Suite.class)
Modified: trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java 2012-09-07 01:01:45 UTC (rev 43493)
+++ trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -131,11 +131,16 @@
Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
for( IRuntimeDetector detector:detectors) {
if (detector.isEnabled()) {
+ System.out.println("initializing for detector " + detector.getId());
detector.initializeRuntimes(runtimeDefinitions);
}
}
-
- String[] initialized = TestHandler1.getInstance().getInited();
+ TestHandler1 handler = TestHandler1.getInstance();
+ String[] initialized = handler.getInited();
+ if( initialized.length == 0 ) {
+ // debug
+ System.out.println("HERE inspecting handler " + handler.toString());
+ }
assertEquals(3, initialized.length);
}
Added: trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimePathUtilTest.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimePathUtilTest.java (rev 0)
+++ trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimePathUtilTest.java 2012-09-07 02:11:25 UTC (rev 43494)
@@ -0,0 +1,48 @@
+package org.jboss.tools.runtime.test;
+
+import static org.jboss.tools.runtime.core.util.RuntimeModelUtil.IN_LINE_DELIMITER;
+import static org.jboss.tools.runtime.core.util.RuntimeModelUtil.LINE_DELIMITER;
+
+import java.io.ByteArrayInputStream;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.tools.runtime.core.model.RuntimePath;
+import org.jboss.tools.runtime.core.util.RuntimeModelUtil;
+import org.junit.Test;
+
+public class RuntimePathUtilTest extends TestCase {
+ @Test
+ public void testSimplePropertyFile() {
+ String twoLine =
+ "name1=/home/some/path" + IN_LINE_DELIMITER
+ + "true" + LINE_DELIMITER
+ + "name2=/home/some/path2" + IN_LINE_DELIMITER
+ + "false" + LINE_DELIMITER;
+ byte[] asBytes = twoLine.getBytes();
+ ByteArrayInputStream is = new ByteArrayInputStream(asBytes);
+ Set<RuntimePath> paths = RuntimeModelUtil.parseRuntimeFile(is, true);
+ assertEquals(2, paths.size());
+
+ is = new ByteArrayInputStream(asBytes);
+ paths = RuntimeModelUtil.parseRuntimeFile(is, false);
+ assertEquals(0, paths.size());
+ }
+
+ @Test
+ public void testDuplicatePathDifferentNameRescan() {
+ String twoLine =
+ "name1=/home/some/path" + IN_LINE_DELIMITER
+ + "true" + LINE_DELIMITER
+ + "name2=/home/some/path" + IN_LINE_DELIMITER
+ + "false" + LINE_DELIMITER;
+ ByteArrayInputStream is = new ByteArrayInputStream(twoLine.getBytes());
+ Set<RuntimePath> paths = RuntimeModelUtil.parseRuntimeFile(is, true);
+ assertEquals(1, paths.size());
+
+ is = new ByteArrayInputStream(twoLine.getBytes());
+ paths = RuntimeModelUtil.parseRuntimeFile(is, false);
+ assertEquals(0, paths.size());
+ }
+}
More information about the jbosstools-commits
mailing list