From 99e1b1ca22b744e88c85bd0989cce112d61ae0e5 Mon Sep 17 00:00:00 2001 From: Laszlo Kishalmi Date: Mon, 10 May 2021 09:21:59 -0700 Subject: [PATCH] [NETBEANS-5668] Fix slipping
-s in the Project Problem Dialog --- .../gradle/tooling/NetBeansToolingPlugin.java | 14 ++++++- .../GradleProjectErrorNotifications.java | 37 +++++++++++++----- .../gradle/loaders/LegacyProjectLoader.java | 38 ++++++++++--------- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/extide/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NetBeansToolingPlugin.java b/extide/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NetBeansToolingPlugin.java index 15e84591b9e7..9b1da3717e9e 100644 --- a/extide/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NetBeansToolingPlugin.java +++ b/extide/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NetBeansToolingPlugin.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import javax.inject.Inject; +import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.tooling.provider.model.ToolingModelBuilder; @@ -97,12 +98,21 @@ public Object buildAll(String modelName, Project prj) { pw.println(ex.toString()); ex.printStackTrace(pw); - BaseModel ret = new NbProjectInfoModel(); + NbProjectInfoModel ret = new NbProjectInfoModel(); ret.setGradleException(sw.toString()); + + Throwable cause = ex; + while ((cause != null) || (cause.getCause() != cause)) { + if (cause instanceof GradleException) { + ret.noteProblem((GradleException) cause); + break; + } + cause = cause.getCause(); + } return ret; } } - + } } diff --git a/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectErrorNotifications.java b/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectErrorNotifications.java index 7ec2df50071d..d284d43eecec 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectErrorNotifications.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectErrorNotifications.java @@ -36,10 +36,10 @@ public class GradleProjectErrorNotifications { public synchronized void openNotification(String title, String problem, String details) { StringBuilder sb = new StringBuilder(details.length()); - sb.append(""); - String[] lines = details.split("\n"); + sb.append(""); //NOI18N + String[] lines = details.split("\n"); //NOI18N for (String line : lines) { - sb.append(line).append("
"); + sb.append(line).append("
"); //NOI18N } Notification ntn = NotificationDisplayer.getDefault().notify(title, NbGradleProject.getWarningIcon(), @@ -59,22 +59,39 @@ public synchronized void clear() { public static String bulletedList(Collection elements) { StringBuilder sb = new StringBuilder(); - sb.append(""); //NOI18N return sb.toString(); } + private static String lineWrap(String line, int maxCol) { + StringBuilder sb = new StringBuilder(line.length()); + String[] parts = line.split(" "); //NOI18N + int col = 0; + String delim = ""; //NOI18N + for (String part : parts) { + if ((sb.length() > 0) && (col + part.length() > maxCol)) { + sb.append("
").append(part); //NOI18N + col = part.length(); + } else { + sb.append(delim).append(part); + col += delim.length() + part.length(); + delim = " "; //NOI18N + } + } + return sb.toString(); + } } diff --git a/extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java b/extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java index 96e422a4203e..6845c5024d23 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java @@ -19,6 +19,8 @@ package org.netbeans.modules.gradle.loaders; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; @@ -142,38 +144,40 @@ private static GradleProject loadGradleProject(ReloadContext ctx, CancellationTo errors.clear(); info = retrieveProjectInfo(goOnline, pconn, cmd, token, pl); + if (!info.getProblems().isEmpty()) { + errors.openNotification( + TIT_LOAD_ISSUES(base.getProjectDir().getName()), + TIT_LOAD_ISSUES(base.getProjectDir().getName()), + GradleProjectErrorNotifications.bulletedList(info.getProblems())); + } if (!info.hasException()) { if (!info.getProblems().isEmpty()) { // If we do not have exception, but seen some problems the we mark the quality as SIMPLE quality = SIMPLE; - errors.openNotification( - TIT_LOAD_ISSUES(base.getProjectDir().getName()), - TIT_LOAD_ISSUES(base.getProjectDir().getName()), - GradleProjectErrorNotifications.bulletedList(info.getProblems())); - } else { quality = ctx.aim; } } else { - String problem = info.getGradleException(); - String[] lines = problem.split("\n"); - LOG.log(INFO, "Failed to retrieve project information for: {0}\nReason: {1}", new Object[] {base.getProjectDir(), problem}); //NOI18N - errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir().getName()), lines[0], problem); - return ctx.previous.invalidate(problem); + if (info.getProblems().isEmpty()) { + String problem = info.getGradleException(); + String[] lines = problem.split("\n"); + LOG.log(INFO, "Failed to retrieve project information for: {0}\nReason: {1}", new Object[] {base.getProjectDir(), problem}); //NOI18N + errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir().getName()), lines[0], problem); + return ctx.previous.invalidate(problem); + } else { + return ctx.previous.invalidate(info.getProblems().toArray(new String[0])); + } } } catch (GradleConnectionException | IllegalStateException ex) { LOG.log(FINE, "Failed to retrieve project information for: " + base.getProjectDir(), ex); - StringBuilder sb = new StringBuilder(); + List problems = new ArrayList<>(); Throwable th = ex; - String separator = ""; while (th != null) { - sb.insert(0, separator); - sb.insert(0, th.getMessage()); + problems.add(th.getMessage()); th = th.getCause(); - separator = "
"; } - errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir()), ex.getMessage(), sb.toString()); - return ctx.previous.invalidate(sb.toString()); + errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir()), ex.getMessage(), GradleProjectErrorNotifications.bulletedList(problems)); + return ctx.previous.invalidate(problems.toArray(new String[0])); } finally { loadedProjects.incrementAndGet(); }