You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2022/02/03 17:16:33 UTC
[netbeans] 01/03: Form a single problem from the exception.
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 9b9d3fff59dcd0c6df493e78673b315dc860fc88
Author: Svata Dedic <sv...@oracle.com>
AuthorDate: Wed Feb 2 11:27:35 2022 +0100
Form a single problem from the exception.
---
.../gradle/GradleProjectProblemProvider.java | 10 ++-
.../gradle/loaders/GradleProjectLoaderImpl.java | 6 +-
.../gradle/loaders/LegacyProjectLoader.java | 84 ++++++++++++++++++++--
3 files changed, 90 insertions(+), 10 deletions(-)
diff --git a/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectProblemProvider.java b/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectProblemProvider.java
index 2b53729..b12edc8 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectProblemProvider.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectProblemProvider.java
@@ -80,12 +80,16 @@ public class GradleProjectProblemProvider implements ProjectProblemsProvider {
public Collection<? extends ProjectProblem> getProblems() {
List<ProjectProblem> ret = new ArrayList<>();
GradleProject gp = project.getLookup().lookup(NbGradleProjectImpl.class).getGradleProject();
- if (gp.getQuality().notBetterThan(EVALUATED)) {
- ret.add(ProjectProblem.createError(Bundle.LBL_PrimingRequired(), Bundle.TXT_PrimingRequired(), resolver));
+ // untrusted project can't have 'real' problems: the execution could not happen
+ boolean trusted = ProjectTrust.getDefault().isTrusted(project);
+ if (!trusted || gp.getProblems().isEmpty()) {
+ if (gp.getQuality().notBetterThan(EVALUATED)) {
+ ret.add(ProjectProblem.createError(Bundle.LBL_PrimingRequired(), Bundle.TXT_PrimingRequired(), resolver));
+ }
} else {
for (String problem : gp.getProblems()) {
String[] lines = problem.split("\\n"); //NOI18N
- ret.add(ProjectProblem.createWarning(lines[0], problem.replaceAll("\\n", "<br/>"), resolver)); //NOI18N
+ ret.add(ProjectProblem.createWarning(lines[0], problem.replaceAll("\\n", "<br/>"), null)); //NOI18N
}
}
return ret;
diff --git a/extide/gradle/src/org/netbeans/modules/gradle/loaders/GradleProjectLoaderImpl.java b/extide/gradle/src/org/netbeans/modules/gradle/loaders/GradleProjectLoaderImpl.java
index 070bf2a..833ee1c 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/loaders/GradleProjectLoaderImpl.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/loaders/GradleProjectLoaderImpl.java
@@ -30,6 +30,7 @@ import org.netbeans.modules.gradle.api.NbGradleProject;
import org.netbeans.modules.gradle.api.execute.GradleCommandLine;
import org.netbeans.modules.gradle.api.execute.RunUtils;
import org.netbeans.modules.gradle.options.GradleExperimentalSettings;
+import org.openide.util.NbBundle;
/**
*
@@ -45,6 +46,9 @@ public class GradleProjectLoaderImpl implements GradleProjectLoader {
}
@Override
+ @NbBundle.Messages({
+ "ERR_ProjectNotTrusted=Gradle execution is not trusted on this project."
+ })
public GradleProject loadProject(NbGradleProject.Quality aim, String descriptionOpt, boolean ignoreCache, boolean interactive, String... args) {
LOGGER.info("Load aiming " +aim + " for "+ project);
GradleCommandLine cmd = new GradleCommandLine(args);
@@ -76,7 +80,7 @@ public class GradleProjectLoaderImpl implements GradleProjectLoader {
} else {
ret = ctx.getPrevious();
if (ret != null) {
- ret = ret.invalidate("Gradle execution is not trusted on this project.");
+ ret = ret.invalidate(Bundle.ERR_ProjectNotTrusted());
}
LOGGER.log(Level.FINER, "Execution not allowed, invalidated {0}", ret);
}
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 488b94d..2520aa7 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java
@@ -20,6 +20,7 @@ package org.netbeans.modules.gradle.loaders;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -174,12 +175,7 @@ public class LegacyProjectLoader extends AbstractProjectLoader {
}
} catch (GradleConnectionException | IllegalStateException ex) {
LOG.log(FINE, "Failed to retrieve project information for: " + base.getProjectDir(), ex);
- List<String> problems = new ArrayList<>();
- Throwable th = ex;
- while (th != null) {
- problems.add(th.getMessage());
- th = th.getCause();
- }
+ List<String> problems = exceptionsToProblems(ex);
errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir()), ex.getMessage(), GradleProjectErrorNotifications.bulletedList(problems));
return ctx.previous.invalidate(problems.toArray(new String[0]));
} finally {
@@ -201,6 +197,82 @@ public class LegacyProjectLoader extends AbstractProjectLoader {
}
return ret;
}
+
+ private static List<String> causesToProblems(Throwable ex) {
+ List<String> problems = new ArrayList<>();
+ Throwable th = ex;
+ while (th != null) {
+ problems.add(th.getMessage());
+ }
+ return problems;
+ }
+
+ @NbBundle.Messages({
+ "# {0} - previous part",
+ "# {1} - appended part",
+ "FMT_AppendMessage={0} {1}",
+ "# {0} - the error message",
+ "# {1} - the file / line",
+ "FMT_MessageWithLocation={0} ({1})"
+ })
+ /**
+ * Rearranges the exception stack messages to be more readable. A typical Gradle build exception is a
+ * {@link GradleConnectionException} that wraps the actual exception. The message of this exception
+ * is completely useless except possibly for gradle wrapper/distribution path.
+ *
+ * The next to rearrange is the positional information - the message should come first as it
+ * often appears in the title. The positional information holder is not a part of oficial tooling API
+ * so a little hack is used to extract the information from the exception chain.
+ *
+ * The rest of messages is coalesced into one text. Location, if present, is appended at the end.
+ */
+ private static List<String> exceptionsToProblems(Throwable t) {
+ if (!(t instanceof GradleConnectionException)) {
+ return causesToProblems(t);
+ }
+ // skip Connection exception no useful info there.
+ Throwable cause = t.getCause();
+ if (cause == null || cause == t) {
+ // no cause - use exception message.
+ return Collections.singletonList(t.getMessage());
+ }
+ String msg = "";
+ String appendLocation = null;
+ // LocationAwareException is not part of APIs:
+ if (cause.getClass().getName().endsWith("LocationAwareException")) { // NOI18N
+ Throwable next = cause.getCause();
+ appendLocation = cause.getMessage();
+ if (next != null) {
+ String m = next.getMessage();
+ int i = appendLocation.indexOf(m);
+ if (i >= 0) {
+ // the LocationAwareException may include the immediately nested exception's message.
+ appendLocation = appendLocation.substring(0, i).trim();
+ }
+ }
+ cause = next;
+ }
+ while (cause != null) {
+ if (!msg.isEmpty()) {
+ msg = Bundle.FMT_AppendMessage(msg, cause.getMessage());
+ } else {
+ msg = cause.getMessage();
+ }
+ Throwable next = cause.getCause();
+ if (next == cause) {
+ break;
+ }
+ cause = next;
+ }
+ if (appendLocation != null) {
+ // if the message itself is multi-line, add the location info on a separate line:
+ if (msg.contains("\n")) { // NOI18N
+ msg = msg + "\n"; // NOI18N
+ }
+ msg = Bundle.FMT_MessageWithLocation(msg, appendLocation);
+ }
+ return Collections.singletonList(msg);
+ }
private static BuildActionExecuter<NbProjectInfo> createInfoAction(ProjectConnection pconn, GradleCommandLine cmd, CancellationToken token, ProgressListener pl) {
BuildActionExecuter<NbProjectInfo> ret = pconn.action(new NbProjectInfoAction());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists