Ensured exit status is set on failure

This commit is contained in:
Erik C. Thauvin 2024-06-24 20:13:27 -07:00
parent c901065b3a
commit c952b980bb
Signed by: erik
GPG key ID: 776702A6A2DA330E
4 changed files with 16 additions and 16 deletions

View file

@ -17,7 +17,7 @@ To compile the source code located in `src/main/kotlin` and `src/test/kotlin` fr
```java ```java
@BuildCommand(summary = "Compiles the Kotlin project") @BuildCommand(summary = "Compiles the Kotlin project")
public void compile() throws IOException { public void compile() throws Exception {
new CompileKotlinOperation() new CompileKotlinOperation()
.fromProject(this) .fromProject(this)
.execute(); .execute();

View file

@ -57,7 +57,7 @@ public class ExampleBuild extends Project {
@BuildCommand(summary = "Compiles the Kotlin project") @BuildCommand(summary = "Compiles the Kotlin project")
@Override @Override
public void compile() throws IOException { public void compile() throws Exception {
// The source code located in src/main/kotlin and src/test/kotlin will be compiled // The source code located in src/main/kotlin and src/test/kotlin will be compiled
new CompileKotlinOperation() new CompileKotlinOperation()
.fromProject(this) .fromProject(this)

View file

@ -21,6 +21,7 @@ import rife.bld.BaseProject;
import rife.bld.extension.kotlin.CompileOptions; import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.extension.kotlin.CompilerPlugin; import rife.bld.extension.kotlin.CompilerPlugin;
import rife.bld.operations.AbstractOperation; import rife.bld.operations.AbstractOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import java.io.File; import java.io.File;
@ -214,10 +215,12 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
*/ */
@Override @Override
@SuppressWarnings("PMD.SystemPrintln") @SuppressWarnings("PMD.SystemPrintln")
public void execute() public void execute() throws Exception {
throws IOException {
if (project_ == null) { if (project_ == null) {
throw new IllegalArgumentException("A project must be specified."); if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
LOGGER.severe("A project must be specified.");
}
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
} }
executeCreateBuildDirectories(); executeCreateBuildDirectories();
@ -232,11 +235,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Part of the {@link #execute execute} operation, builds the main sources. * Part of the {@link #execute execute} operation, builds the main sources.
* *
* @throws IOException if an error occurs * @throws ExitStatusException if an error occurs
*/ */
@SuppressWarnings("PMD.SystemPrintln") @SuppressWarnings("PMD.SystemPrintln")
protected void executeBuildMainSources() protected void executeBuildMainSources() throws ExitStatusException {
throws IOException {
if (!silent()) { if (!silent()) {
System.out.println("Compiling Kotlin main sources."); System.out.println("Compiling Kotlin main sources.");
} }
@ -255,11 +257,11 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @param sources the source files to compile * @param sources the source files to compile
* @param destination the destination directory * @param destination the destination directory
* @param friendPaths the output directory for friendly modules * @param friendPaths the output directory for friendly modules
* @throws IOException if an error occurs * @throws ExitStatusException if an error occurs
*/ */
protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination, protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination,
File friendPaths) File friendPaths)
throws IOException { throws ExitStatusException {
if (sources.isEmpty() || destination == null) { if (sources.isEmpty() || destination == null) {
return; return;
} }
@ -299,18 +301,17 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
var exitCode = k2.exec(System.err, args.toArray(String[]::new)); var exitCode = k2.exec(System.err, args.toArray(String[]::new));
if (exitCode.getCode() != 0) { if (exitCode.getCode() != 0) {
throw new IOException("Kotlin compilation failed."); throw new ExitStatusException(exitCode.getCode());
} }
} }
/** /**
* Part of the {@link #execute execute} operation, builds the test sources. * Part of the {@link #execute execute} operation, builds the test sources.
* *
* @throws IOException if an error occurs * @throws ExitStatusException if an error occurs
*/ */
@SuppressWarnings("PMD.SystemPrintln") @SuppressWarnings("PMD.SystemPrintln")
protected void executeBuildTestSources() protected void executeBuildTestSources() throws ExitStatusException {
throws IOException {
if (!silent()) { if (!silent()) {
System.out.println("Compiling Kotlin test sources."); System.out.println("Compiling Kotlin test sources.");
} }

View file

@ -25,7 +25,6 @@ import rife.bld.extension.kotlin.CompilerPlugin;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@ -93,7 +92,7 @@ class CompileKotlinOperationTest {
} }
@Test @Test
void testExecute() throws IOException { void testExecute() throws Exception {
var tmpDir = Files.createTempDirectory("bld-kotlin").toFile(); var tmpDir = Files.createTempDirectory("bld-kotlin").toFile();
try { try {