Ensured exit status is set on failure
This commit is contained in:
parent
b26240df76
commit
8b02e1e45a
3 changed files with 147 additions and 135 deletions
|
@ -45,3 +45,7 @@ public void detektBaseline() throws ExitStatusException, IOException, Interrupte
|
|||
- [View Examples Project](https://github.com/rife2/bld-detekt/tree/main/examples)
|
||||
|
||||
Please check the [DetektOperation documentation](https://rife2.github.io/bld-detekt/rife/bld/extension/DetektOperation.html#method-summary) for all available configuration options.
|
||||
|
||||
## Template Project
|
||||
|
||||
There is also a [Kotlin Template Project](https://github.com/rife2/kotlin-bld-example) with support for [Dokka](https://github.com/rife2/bld-dokka) and the Detekt extensions.
|
||||
|
|
|
@ -21,7 +21,6 @@ import rife.bld.extension.detekt.Report;
|
|||
import rife.bld.extension.detekt.ReportId;
|
||||
import rife.bld.operations.AbstractProcessOperation;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -60,6 +59,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
private final Collection<File> classpath_ = new ArrayList<>();
|
||||
private final Collection<File> config_ = new ArrayList<>();
|
||||
private final Collection<String> excludes_ = new ArrayList<>();
|
||||
private final Collection<String> includes_ = new ArrayList<>();
|
||||
private final Collection<File> input_ = new ArrayList<>();
|
||||
private final Collection<File> plugins_ = new ArrayList<>();
|
||||
private final Collection<Report> report_ = new ArrayList<>();
|
||||
|
@ -73,7 +73,6 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
private boolean debug_;
|
||||
private boolean disableDefaultRuleSets_;
|
||||
private boolean generateConfig_;
|
||||
private final Collection<String> includes_ = new ArrayList<>();
|
||||
private String jdkHome_;
|
||||
private String jvmTarget_;
|
||||
private String languageVersion_;
|
||||
|
@ -350,13 +349,18 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
*
|
||||
* @throws InterruptedException when the operation was interrupted
|
||||
* @throws IOException when an exception occurred during the execution of the process
|
||||
* @throws FileUtilsErrorException when an exception occurred during the retrieval of the operation output
|
||||
* @throws ExitStatusException when the exit status was changed during the operation
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws IOException, FileUtilsErrorException, InterruptedException, ExitStatusException {
|
||||
public void execute() throws IOException, InterruptedException, ExitStatusException {
|
||||
if (project_ == null) {
|
||||
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||
LOGGER.severe("A project must be specified.");
|
||||
}
|
||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
} else {
|
||||
super.execute();
|
||||
if (successful_ && LOGGER.isLoggable(Level.INFO)) {
|
||||
if (successful_ && LOGGER.isLoggable(Level.INFO) && !silent()){
|
||||
if (createBaseline_) {
|
||||
LOGGER.info("Detekt baseline generated successfully: "
|
||||
+ "file://" + new File(baseline_).toURI().getPath());
|
||||
|
@ -365,6 +369,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the {@link #execute} operation, constructs the command list
|
||||
|
@ -372,11 +377,8 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
*/
|
||||
@Override
|
||||
protected List<String> executeConstructProcessCommandList() {
|
||||
if (project_ == null) {
|
||||
LOGGER.severe("A project must be specified.");
|
||||
}
|
||||
|
||||
final List<String> args = new ArrayList<>();
|
||||
if (project_ != null) {
|
||||
args.add(javaTool());
|
||||
args.add("-cp");
|
||||
args.add(getDetektJarList(project_.libBldDirectory()));
|
||||
|
@ -508,9 +510,10 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
});
|
||||
}
|
||||
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
if (LOGGER.isLoggable(Level.FINE) && !silent()) {
|
||||
LOGGER.fine(String.join(" ", args.stream().filter(this::isNotBlank).toList()));
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
@ -551,9 +554,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves the matching JARs files from the given directory.
|
||||
*/
|
||||
// Retrieves the matching JARs files from the given directory.
|
||||
private String getDetektJarList(File directory) {
|
||||
var jars = new ArrayList<String>();
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ class DetektOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
void testCheckAllParameters() throws IOException {
|
||||
var args = Files.readAllLines(Paths.get("src", "test", "resources", "detekt-args.txt"));
|
||||
|
||||
|
@ -190,4 +191,10 @@ class DetektOperationTest {
|
|||
.debug(true);
|
||||
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteNoProject() {
|
||||
var op = new DetektOperation();
|
||||
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue