Skip to content

Commit

Permalink
Merge pull request #42131 from ShammiL/lifecycle-plugin-diag
Browse files Browse the repository at this point in the history
Fix lifecycle plugin diagnostics being ignored during executable generation
  • Loading branch information
ShammiL authored Feb 15, 2024
2 parents c4919f8 + f5263f5 commit 45ab4cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.ballerina.projects.ProjectException;
import io.ballerina.projects.ProjectKind;
import io.ballerina.projects.internal.model.Target;
import io.ballerina.tools.diagnostics.Diagnostic;
import org.ballerinalang.compiler.plugins.CompilerPlugin;

import java.io.File;
Expand All @@ -38,10 +37,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Collectors;

import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException;
import static io.ballerina.cli.utils.FileUtils.getFileNameWithoutExtension;
Expand Down Expand Up @@ -127,16 +123,9 @@ public void execute(Project project) {
}
}

List<Diagnostic> diagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics());
if (!diagnostics.isEmpty()) {
// TODO: When deprecating the lifecycle compiler plugin, we can remove this check for duplicates
// in JBallerinaBackend diagnostics and the diagnostics added to EmitResult.
diagnostics = diagnostics.stream()
.filter(diagnostic -> !jBallerinaBackend.diagnosticResult().diagnostics().contains(diagnostic))
.collect(Collectors.toList());
if (!diagnostics.isEmpty()) {
diagnostics.forEach(d -> out.println("\n" + d.toString()));
}
// Print diagnostics found during emit executable
if (!emitResult.diagnostics().diagnostics().isEmpty()) {
emitResult.diagnostics().diagnostics().forEach(d -> out.println("\n" + d.toString()));
}

} catch (ProjectException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,11 @@ public DiagnosticResult diagnosticResult() {
return diagnosticResult;
}

// TODO EmitResult should not contain compilation diagnostics.
public EmitResult emit(OutputType outputType, Path filePath) {
Path generatedArtifact = null;

if (diagnosticResult.hasErrors()) {
return new EmitResult(false, diagnosticResult, generatedArtifact);
return new EmitResult(false, new DefaultDiagnosticResult(new ArrayList<>()), generatedArtifact);
}

switch (outputType) {
Expand All @@ -227,19 +226,23 @@ public EmitResult emit(OutputType outputType, Path filePath) {
throw new RuntimeException("Unexpected output type: " + outputType);
}

ArrayList<Diagnostic> diagnostics = new ArrayList<>(diagnosticResult.allDiagnostics);
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(diagnosticResult.allDiagnostics);
List<Diagnostic> emitResultDiagnostics = new ArrayList<>();
// Add lifecycle plugin diagnostics.
List<Diagnostic> pluginDiagnostics = packageCompilation.notifyCompilationCompletion(filePath);
if (!pluginDiagnostics.isEmpty()) {
diagnostics.addAll(pluginDiagnostics);
emitResultDiagnostics.addAll(pluginDiagnostics);
}
diagnosticResult = new DefaultDiagnosticResult(diagnostics);

List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
// Add jar resolver diagnostics.
jarResolver().diagnosticResult().diagnostics().stream().forEach(
diagnostic -> allDiagnostics.add(diagnostic));
diagnostic -> emitResultDiagnostics.add(diagnostic));
allDiagnostics.addAll(emitResultDiagnostics);
// JBallerinaBackend diagnostics contains all diagnostics.
// EmitResult will only contain diagnostics related to emitting the executable.
diagnosticResult = new DefaultDiagnosticResult(allDiagnostics);

// TODO handle the EmitResult properly
return new EmitResult(true, new DefaultDiagnosticResult(allDiagnostics), generatedArtifact);
return new EmitResult(true, new DefaultDiagnosticResult(emitResultDiagnostics), generatedArtifact);
}

private Path emitBala(Path filePath) {
Expand Down

0 comments on commit 45ab4cd

Please sign in to comment.