Blob Blame History Raw
From 5ca45e97b527b5a4d4ed4ce92e32720859911968 Mon Sep 17 00:00:00 2001
From: Stephan Herrmann
Date: Sat, 15 Jun 2019 20:47:45 +0200
Subject: Bug 548211 - "Remove" in the Module dependencies tab does not remove
 system modules

Change-Id: I633fa86e5911c50b17a1c7ef188805902942e1db
---
 .../jdt/internal/ui/wizards/NewWizardMessages.java |  1 +
 .../ui/wizards/NewWizardMessages.properties        |  1 +
 .../wizards/buildpaths/ModuleDependenciesPage.java | 22 ++++++++++++++++++----
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java
index 3a66ae56ed..961aa63bba 100644
--- a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java
+++ b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java
@@ -564,6 +564,7 @@ public final class NewWizardMessages extends NLS {
 	public static String ModuleDependenciesPage_removeCurrentModule_error;
 	public static String ModuleDependenciesPage_removeModule_error_with_hint;
 	public static String ModuleDependenciesPage_removeSystemModule_error_hint;
+	public static String ModuleDependenciesPage_moduleIsRequired_error_hint;
 
 	public static String ModuleDependenciesAdapter_patchConflict_title;
 	public static String ModuleDependenciesAdapter_patchConflict_message;
diff --git a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties
index feb30bc627..a3d8a04624 100644
--- a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties
+++ b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties
@@ -605,6 +605,7 @@ ModuleDependenciesPage_removeCurrentModule_error=Cannot remove the current modul
 ModuleDependenciesPage_removeModule_error_with_hint=Cannot remove module ''{0}''{1}
 ModuleDependenciesPage_removeSystemModule_error_hint=\nOnly system modules can be removed here.\n\
 To remove other modules please remove them from the Modulepath (Projects or Libraries tab).
+ModuleDependenciesPage_moduleIsRequired_error_hint=\nIt is required along the path {0}
 
 ModuleDependenciesAdapter_patchConflict_title=Patch module conflict
 ModuleDependenciesAdapter_patchConflict_message=The {0} {1} was declared to patch module ''{2}''.\n\
diff --git a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java
index ccc5c3317a..b813d22956 100644
--- a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java
+++ b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java
@@ -614,7 +614,16 @@ public class ModuleDependenciesPage extends BuildPathBasePage {
 				return;
 			}
 			selectedModuleNames.add(moduleName);
-			collectModulesToRemove(moduleName, allModulesToRemove);
+			String problemModule= collectModulesToRemove(moduleName, allModulesToRemove);
+			if (problemModule != null) {
+				int lastArrow= problemModule.lastIndexOf("->"); //$NON-NLS-1$
+				String leafMod= lastArrow == -1 ? problemModule : problemModule.substring(lastArrow+2);
+				MessageDialog.openError(getShell(), NewWizardMessages.ModuleDependenciesPage_removeModule_dialog_title,
+						MessageFormat.format(NewWizardMessages.ModuleDependenciesPage_removeModule_error_with_hint,
+								leafMod, 
+								MessageFormat.format(NewWizardMessages.ModuleDependenciesPage_moduleIsRequired_error_hint, problemModule)));
+				return;
+			}
 		}
 		String seedModules= String.join(", ", selectedModuleNames); //$NON-NLS-1$
 		if (allModulesToRemove.size() == selectedModuleNames.size()) {
@@ -664,15 +673,20 @@ public class ModuleDependenciesPage extends BuildPathBasePage {
 		}
 	}
 
-	private void collectModulesToRemove(String mod, Set<String> modulesToRemove) {
+	private String collectModulesToRemove(String mod, Set<String> modulesToRemove) {
 		if (fModuleList.fNames.contains(mod) && modulesToRemove.add(mod)) {
 			List<String> requireds= fModuleRequiredByModules.get(mod);
 			if (requireds != null) {
 				for (String required : requireds) {
-					collectModulesToRemove(required, modulesToRemove);
+					if (fModuleList.getModuleKind(required) == ModuleKind.Focus)
+						return required + "->" + mod; //$NON-NLS-1$
+					String problemModule= collectModulesToRemove(required, modulesToRemove);
+					if (problemModule != null)
+						return problemModule + "->" + mod; //$NON-NLS-1$
 				}
 			}
 		}
+		return null;
 	}
 	
 	private boolean confirmRemoveModule(String message) {
@@ -741,7 +755,7 @@ public class ModuleDependenciesPage extends BuildPathBasePage {
 				List<String> dominators= fModuleRequiredByModules.get(name);
 				if (dominators != null) {
 					for (String dominator : dominators) {
-						if (names.contains(dominator)) {
+						if (names.contains(dominator) && fModuleList.getModuleKind(dominator) == ModuleKind.System) {
 							continue outer;
 						}
 					}
-- 
cgit v1.2.1