Compare commits
5 commits
7d5b50641c
...
5526cfdcf4
Author | SHA1 | Date | |
---|---|---|---|
5526cfdcf4 | |||
5a2824507f | |||
3e350e617a | |||
432e5ffed1 | |||
e6d5c6c38f |
6 changed files with 55 additions and 24 deletions
4
.github/workflows/bld.yml
vendored
4
.github/workflows/bld.yml
vendored
|
@ -28,9 +28,9 @@ jobs:
|
|||
working-directory: examples
|
||||
run: ./bld download
|
||||
|
||||
- name: Run tests [examples]
|
||||
- name: Run Detekt [examples]
|
||||
working-directory: examples
|
||||
run: ./bld compile test
|
||||
run: ./bld compile detekt
|
||||
|
||||
- name: Download dependencies
|
||||
run: ./bld download
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.downloadLocation=
|
||||
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.9
|
||||
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT
|
||||
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0-SNAPSHOT
|
||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.sourceDirectories=
|
||||
|
|
|
@ -46,14 +46,14 @@ public class ExampleBuild extends Project {
|
|||
|
||||
public static void main(String[] args) {
|
||||
// Enable detailed logging
|
||||
// var level = Level.ALL;
|
||||
// var logger = Logger.getLogger("rife.bld.extension");
|
||||
// var consoleHandler = new ConsoleHandler();
|
||||
//
|
||||
// consoleHandler.setLevel(level);
|
||||
// logger.addHandler(consoleHandler);
|
||||
// logger.setLevel(level);
|
||||
// logger.setUseParentHandlers(false);
|
||||
var level = Level.ALL;
|
||||
var logger = Logger.getLogger("rife.bld.extension");
|
||||
var consoleHandler = new ConsoleHandler();
|
||||
|
||||
consoleHandler.setLevel(level);
|
||||
logger.addHandler(consoleHandler);
|
||||
logger.setLevel(level);
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
new ExampleBuild().start(args);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.nio.file.Path;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -55,6 +56,8 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
"snakeyaml-engine-",
|
||||
"trove4j-");
|
||||
private static final Logger LOGGER = Logger.getLogger(DetektOperation.class.getName());
|
||||
private static final String OS_NAME =
|
||||
System.getProperty("os.name") != null ? System.getProperty("os.name").toLowerCase(Locale.US) : null;
|
||||
private final Collection<File> classpath_ = new ArrayList<>();
|
||||
private final Collection<File> config_ = new ArrayList<>();
|
||||
private final Collection<String> excludes_ = new ArrayList<>();
|
||||
|
@ -290,6 +293,17 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
return classPath(paths.stream().map(File::new).toList());
|
||||
}
|
||||
|
||||
private String cleanPath(File path) {
|
||||
return cleanPath(path.getAbsolutePath());
|
||||
}
|
||||
|
||||
private String cleanPath(String path) {
|
||||
if (isWindows()) {
|
||||
return path.replaceAll("\\\\", "\\\\\\\\");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paths to the config files ({@code path/to/config.yml}).
|
||||
*
|
||||
|
@ -323,7 +337,6 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
return configStrings(List.of(configs));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Paths to the config files ({@code path/to/config.yml}).
|
||||
*
|
||||
|
@ -525,13 +538,13 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
// base-path
|
||||
if (isNotBlank(basePath_)) {
|
||||
args.add("--base-path");
|
||||
args.add(basePath_);
|
||||
args.add(cleanPath(basePath_));
|
||||
}
|
||||
|
||||
// baseline
|
||||
if (isNotBlank(baseline_)) {
|
||||
args.add("--baseline");
|
||||
args.add(baseline_);
|
||||
args.add(cleanPath(baseline_));
|
||||
}
|
||||
|
||||
// build-upon-default-config
|
||||
|
@ -542,19 +555,19 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
// classpath
|
||||
if (!classpath_.isEmpty()) {
|
||||
args.add("--classpath");
|
||||
args.add(String.join(File.pathSeparator, classpath_.stream().map(File::getAbsolutePath).toList()));
|
||||
args.add(String.join(File.pathSeparator, classpath_.stream().map(this::cleanPath).toList()));
|
||||
}
|
||||
|
||||
// config
|
||||
if (!config_.isEmpty()) {
|
||||
args.add("-config");
|
||||
args.add(String.join(";", config_.stream().map(File::getAbsolutePath).toList()));
|
||||
args.add(String.join(";", config_.stream().map(this::cleanPath).toList()));
|
||||
}
|
||||
|
||||
// config-resource
|
||||
if (isNotBlank(configResource_)) {
|
||||
args.add("--config-resource");
|
||||
args.add(configResource_);
|
||||
args.add(cleanPath(configResource_));
|
||||
}
|
||||
|
||||
// create-baseline
|
||||
|
@ -575,7 +588,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
// excludes
|
||||
if (!excludes_.isEmpty()) {
|
||||
args.add("--excludes");
|
||||
args.add(String.join(",", excludes_));
|
||||
args.add(String.join(",", excludes_.stream().map(this::cleanPath).toList()));
|
||||
}
|
||||
|
||||
// generate-config
|
||||
|
@ -586,19 +599,19 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
// includes
|
||||
if (!includes_.isEmpty()) {
|
||||
args.add("--includes");
|
||||
args.add(String.join(",", includes_));
|
||||
args.add(String.join(",", includes_.stream().map(this::cleanPath).toList()));
|
||||
}
|
||||
|
||||
// input
|
||||
if (!input_.isEmpty()) {
|
||||
args.add("--input");
|
||||
args.add(String.join(",", input_.stream().map(File::getAbsolutePath).toList()));
|
||||
args.add(String.join(",", input_.stream().map(this::cleanPath).toList()));
|
||||
}
|
||||
|
||||
// jdk-home
|
||||
if (isNotBlank(jdkHome_)) {
|
||||
args.add("--jdk-home");
|
||||
args.add(jdkHome_);
|
||||
args.add(cleanPath(jdkHome_));
|
||||
}
|
||||
|
||||
// jvm-target
|
||||
|
@ -627,14 +640,14 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
// plugins
|
||||
if (!plugins_.isEmpty()) {
|
||||
args.add("--plugins");
|
||||
args.add(String.join(",", plugins_.stream().map(File::getAbsolutePath).toList()));
|
||||
args.add(String.join(",", plugins_.stream().map(this::cleanPath).toList()));
|
||||
}
|
||||
|
||||
// report
|
||||
if (!report_.isEmpty()) {
|
||||
report_.forEach(it -> {
|
||||
args.add("--report");
|
||||
args.add(it.id().name().toLowerCase() + ":" + it.path());
|
||||
args.add(it.id().name().toLowerCase() + ":" + cleanPath(it.path()));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -693,7 +706,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
if (!f.getName().endsWith("-sources.jar") && !f.getName().endsWith("-javadoc.jar")) {
|
||||
for (var m : DETEKT_JARS) {
|
||||
if (f.getName().startsWith(m)) {
|
||||
jars.add(f.getAbsolutePath());
|
||||
jars.add(cleanPath(f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -819,6 +832,15 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
|
|||
return s != null && !s.isBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current operating system is Windows.
|
||||
*
|
||||
* @return true if the operating system is Windows, false otherwise.
|
||||
*/
|
||||
private boolean isWindows() {
|
||||
return OS_NAME != null && OS_NAME.contains("win");
|
||||
}
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL: Use a custom JDK home directory to include into the
|
||||
* classpath.
|
||||
|
|
|
@ -264,6 +264,7 @@ class DetektOperationTest {
|
|||
var op = new DetektOperation()
|
||||
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
|
||||
"example", "Example"))
|
||||
.baseline("src/test/resources/detekt-baseline.xml")
|
||||
.maxIssues(8);
|
||||
assertThatNoException().isThrownBy(op::execute);
|
||||
}
|
||||
|
@ -281,6 +282,7 @@ class DetektOperationTest {
|
|||
var op = new DetektOperation()
|
||||
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
|
||||
"example", "Example"))
|
||||
.baseline("src/test/resources/detekt-baseline.xml")
|
||||
.report(new Report(ReportId.HTML, html.getAbsolutePath()))
|
||||
.report(new Report(ReportId.XML, xml.getAbsolutePath()))
|
||||
.report(new Report(ReportId.TXT, txt.getAbsolutePath()))
|
||||
|
@ -299,6 +301,7 @@ class DetektOperationTest {
|
|||
var op = new DetektOperation()
|
||||
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
|
||||
"example", "Example"))
|
||||
.baseline("src/test/resources/detekt-baseline.xml")
|
||||
.debug(true);
|
||||
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
|
||||
}
|
||||
|
|
6
src/test/resources/detekt-baseline.xml
Normal file
6
src/test/resources/detekt-baseline.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" ?>
|
||||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
Loading…
Add table
Add a link
Reference in a new issue