[jbosstools-commits] JBoss Tools SVN: r44005 - trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Sep 25 11:29:38 EDT 2012


Author: snjeza
Date: 2012-09-25 11:29:38 -0400 (Tue, 25 Sep 2012)
New Revision: 44005

Modified:
   trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java
Log:
JBIDE-12714 - When two servers with same version are found only one is added

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-25 15:28:57 UTC (rev 44004)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java	2012-09-25 15:29:38 UTC (rev 44005)
@@ -10,6 +10,7 @@
  ************************************************************************************/
 package org.jboss.tools.runtime.ui.dialogs;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -352,22 +353,19 @@
 			boolean hideCreatedRuntimes) {
 		ArrayList<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
 		
-		// It seems the intent of this block is to increment a name on a runtime definition,
-		// however, the model it's pulling a runtime definition from the list of all definitions. 
-		// IF the items are ==, they will continue to be == even after a name change ?!
-//		List<RuntimeDefinition> allDefinitions = getAllDefinitions();
-//		for (RuntimePath runtimePath : runtimePaths) {
-//			List<RuntimeDefinition> pathDefinitions = getAllDefinitions(runtimePath);
-//			for (RuntimeDefinition runtimeDefinition : pathDefinitions) {
-//				if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
-//					String name = runtimeDefinition.getName();
-//					int i = 2;
-//					while (runtimeDefinitionsExists(runtimeDefinition, allDefinitions)) {
-//						runtimeDefinition.setName(name + " (" + i++ + ")");
-//					}
-//				}
-//			}
-//		}
+		List<RuntimeDefinition> allDefinitions = getAllDefinitions();
+		for (RuntimePath runtimePath : runtimePaths) {
+			List<RuntimeDefinition> pathDefinitions = getAllDefinitions(runtimePath);
+			for (RuntimeDefinition runtimeDefinition : pathDefinitions) {
+				if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
+					String name = runtimeDefinition.getName();
+					int i = 2;
+					while (runtimeDefinitionExists(runtimeDefinition, allDefinitions)) {
+						runtimeDefinition.setName(name + " (" + i++ + ")");
+					}
+				}
+			}
+		}
 		
 		for (RuntimePath runtimePath : runtimePaths) {
 			for (RuntimeDefinition runtimeDefinition : runtimePath.getRuntimeDefinitions()) {
@@ -389,8 +387,34 @@
 		return RuntimeModelUtil.getAllDefinitions(RuntimeUIActivator.getRuntimePaths());
 	}
 
-	private boolean runtimeDefinitionsExists(RuntimeDefinition runtimeDefinition,List<RuntimeDefinition> allRuntimeDefinitions) {
-		return RuntimeModelUtil.runtimeDefinitionsExists(runtimeDefinition, allRuntimeDefinitions);
+	private boolean runtimeDefinitionExists(RuntimeDefinition runtimeDefinition,
+			List<RuntimeDefinition> allRuntimeDefinitions) {
+		String name = runtimeDefinition.getName();
+		File location = runtimeDefinition.getLocation();
+		String type = runtimeDefinition.getType();
+		if (name == null || location == null || type == null) {
+			return false;
+		}
+		String path = location.getAbsolutePath();
+		if (path == null) {
+			return false;
+		}
+		for (RuntimeDefinition definition:allRuntimeDefinitions) {
+			if (name.equals(definition.getName()) && type.equals(definition.getType())) {
+				File loc = definition.getLocation();
+				if (loc == null) {
+					continue;
+				}
+				String dPath = loc.getAbsolutePath();
+				if (dPath == null) {
+					continue;
+				}
+				if (!path.equals(dPath)) {
+					return true;
+				}
+			}
+		}
+		return false;
 	}
 
 }



More information about the jbosstools-commits mailing list