Skip to content

Commit

Permalink
Merge pull request #42485 from Thevakumar-Luheerathan/fix-ballerina-l…
Browse files Browse the repository at this point in the history
…ang-iss-42483

[Master] Exit RunBuildToolsTask upon tool error
  • Loading branch information
LakshanWeerasinghe committed Apr 5, 2024
2 parents 66ab6b6 + c956cef commit fa2ff30
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.ballerina.projects.ProjectException;
import io.ballerina.projects.ProjectKind;
import io.ballerina.projects.SemanticVersion;
import io.ballerina.projects.buildtools.ToolContext;
import io.ballerina.projects.directory.SingleFileProject;
import io.ballerina.projects.environment.ResolutionOptions;
import io.ballerina.projects.internal.PackageDiagnostic;
Expand Down Expand Up @@ -230,12 +229,6 @@ public void execute(Project project) {
});
// Add tool resolution diagnostics to diagnostics
diagnostics.addAll(project.currentPackage().getBuildToolResolution().getDiagnosticList());
// Report build tool execution diagnostics
if (project.getToolContextMap() != null) {
for (ToolContext tool : project.getToolContextMap().values()) {
diagnostics.addAll(tool.diagnostics());
}
}
boolean hasErrors = false;
for (Diagnostic d : diagnostics) {
if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -103,6 +104,7 @@ public void execute(Project project) {
.diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code()
.startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX)).toList();
toolManifestDiagnostics.forEach(outStream::println);
List<Diagnostic> toolDiagnostics = new ArrayList<>(toolManifestDiagnostics);

// Read the build tool entries specified the Ballerina.toml
List<Tool> toolEntries = project.currentPackage().manifest().tools();
Expand All @@ -126,6 +128,7 @@ public void execute(Project project) {
return;
}
buildToolResolution.getDiagnosticList().forEach(outStream::println);
toolDiagnostics.addAll(buildToolResolution.getDiagnosticList());
List<BuildTool> resolvedTools = buildToolResolution.getResolvedTools();
List<BuildTool> centralDeliveredResolvedTools = resolvedTools.stream().filter(tool -> !DEFAULT_VERSION
.equals(tool.version().toString())).toList();
Expand Down Expand Up @@ -196,6 +199,7 @@ public void execute(Project project) {
try {
this.outStream.printf("\t%s(%s)%n", toolEntry.type().value(), toolEntry.id().value());
targetTool.get().execute(toolContext);
toolDiagnostics.addAll(toolContext.diagnostics());
for (Diagnostic d : toolContext.diagnostics()) {
if (d.toString().contains("(1:1,1:1)")) {
outStream.println(new PackageDiagnostic(d.diagnosticInfo(), toolContext.toolId()));
Expand All @@ -207,6 +211,13 @@ public void execute(Project project) {
throw createLauncherException(e.getMessage());
}
}

// Exit if there is any error diagnostic
boolean hasErrors = toolDiagnostics.stream()
.anyMatch(d -> d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR));
if (hasErrors) {
throw createLauncherException("build tool execution contains errors");
}
// Reload the project to load the generated code
reloadProject(project);
this.outStream.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ public Object[][] provideToolPropertiesDiagnostics() {
{
"build-tool-with-invalid-missing-toml-properties",
"build-tool-with-invalid-missing-toml-properties.txt",
"error: compilation contains errors"
"error: build tool execution contains errors"
},
{
"build-tool-with-invalid-missing-optional-toml-properties",
Expand All @@ -1207,12 +1207,12 @@ public Object[][] provideToolPropertiesDiagnostics() {
{
"build-tool-with-diagnostics",
"build-tool-with-diagnostics.txt",
"error: compilation contains errors"
"error: build tool execution contains errors"
},
{
"build-tool-with-recurring-tool-properties",
"build-tool-with-recurring-tool-properties.txt",
"error: compilation contains errors"
"error: build tool execution contains errors"
}
};
}
Expand Down Expand Up @@ -1259,7 +1259,7 @@ public void testBuildProjectWithBuildToolNotFound() throws IOException {
String buildLog = readOutput(true);
Assert.assertEquals(buildLog.replaceAll("\r", ""),
getOutput("build-bal-project-with-build-tool-not-found.txt"));
Assert.assertEquals("error: compilation contains errors", e.getDetailedMessages().get(0));
Assert.assertEquals("error: build tool execution contains errors", e.getDetailedMessages().get(0));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,9:26)] Build tool 'grpc' cannot be resolved

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
Executing Build Tools
openapi(generate-delivery-client)
ERROR [generate-delivery-client] The provided filePath does not exist

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ ERROR [Ballerina.toml:(12:1,14:24)] missing key '[filePath]' in table '[tool.ope
Executing Build Tools
WARNING: Execution of 'openapi:generate-delivery-client' is skipped due to errors
WARNING: Execution of 'openapi:generate-client' is skipped due to errors

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client'
Executing Build Tools
openapi(generate-delivery-client)
WARNING: Execution of 'openapi:generate-delivery-client' is skipped due to errors

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,9:26)] Build tool 'grpc' cannot be resolved

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
Executing Build Tools
openapi(generate-delivery-client)
ERROR [generate-delivery-client] The provided filePath does not exist

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ ERROR [Ballerina.toml:(12:1,14:24)] missing key '[filePath]' in table '[tool.ope
Executing Build Tools
WARNING: Execution of 'openapi:generate-delivery-client' is skipped due to errors
WARNING: Execution of 'openapi:generate-client' is skipped due to errors

Compiling source
foo/winery:0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client'
Executing Build Tools
openapi(generate-delivery-client)
WARNING: Execution of 'openapi:generate-delivery-client' is skipped due to errors

Compiling source
foo/winery:0.1.0

0 comments on commit fa2ff30

Please sign in to comment.