Skip to content

Commit

Permalink
[NETBEANS-5668] Fix slipping <br/>-s in the Project Problem Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed May 12, 2021
1 parent 07a82fa commit 99e1b1c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html>");
String[] lines = details.split("\n");
sb.append("<html>"); //NOI18N
String[] lines = details.split("\n"); //NOI18N
for (String line : lines) {
sb.append(line).append("<br/>");
sb.append(line).append("<br/>"); //NOI18N
}
Notification ntn = NotificationDisplayer.getDefault().notify(title,
NbGradleProject.getWarningIcon(),
Expand All @@ -59,22 +59,39 @@ public synchronized void clear() {

public static String bulletedList(Collection<? extends Object> elements) {
StringBuilder sb = new StringBuilder();
sb.append("<ul>");
sb.append("<ul>"); //NOI18N
for (Object element : elements) {
sb.append("<li>");
String[] lines = element.toString().split("\n");
sb.append("<li>"); //NOI18N
String[] lines = element.toString().split("\n"); //NOI18N
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
sb.append(line);
sb.append(lineWrap(line, 78));
if (i < lines.length - 1) {
sb.append("<br/>");
sb.append("<br/>"); //NOI18N
}
}
sb.append("</li>");
sb.append("</li>"); //NOI18N
}
sb.append("</ul>");
sb.append("</ul>"); //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("<br/>").append(part); //NOI18N
col = part.length();
} else {
sb.append(delim).append(part);
col += delim.length() + part.length();
delim = " "; //NOI18N
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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 = "<br/>";
}
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();
}
Expand Down

0 comments on commit 99e1b1c

Please sign in to comment.