Skip to content

Commit

Permalink
Ensured exit status is set on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jul 10, 2024
1 parent c901065 commit c952b98
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To compile the source code located in `src/main/kotlin` and `src/test/kotlin` fr

```java
@BuildCommand(summary = "Compiles the Kotlin project")
public void compile() throws IOException {
public void compile() throws Exception {
new CompileKotlinOperation()
.fromProject(this)
.execute();
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bld/java/com/example/ExampleBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void main(String[] args) {

@BuildCommand(summary = "Compiles the Kotlin project")
@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
new CompileKotlinOperation()
.fromProject(this)
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/rife/bld/extension/CompileKotlinOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.extension.kotlin.CompilerPlugin;
import rife.bld.operations.AbstractOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.FileUtils;

import java.io.File;
Expand Down Expand Up @@ -214,10 +215,12 @@ public Collection<String> compileTestClasspath() {
*/
@Override
@SuppressWarnings("PMD.SystemPrintln")
public void execute()
throws IOException {
public void execute() throws Exception {
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();
Expand All @@ -232,11 +235,10 @@ public void execute()
/**
* 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")
protected void executeBuildMainSources()
throws IOException {
protected void executeBuildMainSources() throws ExitStatusException {
if (!silent()) {
System.out.println("Compiling Kotlin main sources.");
}
Expand All @@ -255,11 +257,11 @@ protected void executeBuildMainSources()
* @param sources the source files to compile
* @param destination the destination directory
* @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,
File friendPaths)
throws IOException {
throws ExitStatusException {
if (sources.isEmpty() || destination == null) {
return;
}
Expand Down Expand Up @@ -299,18 +301,17 @@ protected void executeBuildSources(Collection<String> classpath, Collection<File

var exitCode = k2.exec(System.err, args.toArray(String[]::new));
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.
*
* @throws IOException if an error occurs
* @throws ExitStatusException if an error occurs
*/
@SuppressWarnings("PMD.SystemPrintln")
protected void executeBuildTestSources()
throws IOException {
protected void executeBuildTestSources() throws ExitStatusException {
if (!silent()) {
System.out.println("Compiling Kotlin test sources.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import rife.tools.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -93,7 +92,7 @@ void testCollections() {
}

@Test
void testExecute() throws IOException {
void testExecute() throws Exception {
var tmpDir = Files.createTempDirectory("bld-kotlin").toFile();

try {
Expand Down

0 comments on commit c952b98

Please sign in to comment.