Skip to content

Commit

Permalink
Cleaned up API to match bld operations and options APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 28, 2024
1 parent c630757 commit 324fc48
Show file tree
Hide file tree
Showing 3 changed files with 371 additions and 26 deletions.
4 changes: 2 additions & 2 deletions examples/lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.5
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.0
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.6-SNAPSHOT
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.1-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories=
bld.version=2.0.1
228 changes: 204 additions & 24 deletions src/main/java/rife/bld/extension/DetektOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -55,7 +55,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
"sarif4k-jvm-",
"snakeyaml-engine-",
"trove4j-");
private static final Logger LOGGER = Logger.getLogger(Report.class.getName());
private static final Logger LOGGER = Logger.getLogger(DetektOperation.class.getName());
private final Collection<File> classpath_ = new ArrayList<>();
private final Collection<File> config_ = new ArrayList<>();
private final Collection<String> excludes_ = new ArrayList<>();
Expand Down Expand Up @@ -128,8 +128,28 @@ public DetektOperation basePath(String path) {
* @return this operation instance
*/
public DetektOperation basePath(File path) {
basePath_ = path.getAbsolutePath();
return this;
return basePath(path.getAbsolutePath());
}

/**
* Retrieves the base path.
*
* @return the directory path
*/
public String basePath() {
return basePath_;
}

/**
* Specifies a directory as the base path. Currently, it impacts all file
* paths in the formatted reports. File paths in console output and txt
* report are not affected and remain as absolute paths.
*
* @param path the directory path
* @return this operation instance
*/
public DetektOperation basePath(Path path) {
return basePath(path.toFile());
}

/**
Expand All @@ -152,8 +172,27 @@ public DetektOperation baseline(String baseline) {
* @return this operation instance
*/
public DetektOperation baseline(File baseline) {
baseline_ = baseline.getAbsolutePath();
return this;
return baseline(baseline.getAbsolutePath());
}

/**
* If a baseline xml file is passed in, only new code smells not in the
* baseline are printed in the console.
*
* @param baseline the baseline xml file
* @return this operation instance
*/
public DetektOperation baseline(Path baseline) {
return baseline(baseline.toFile());
}

/**
* Retrieves the baseline xml file.
*
* @return the baseline xml file
*/
public String baseline() {
return baseline_;
}

/**
Expand All @@ -177,8 +216,18 @@ public DetektOperation buildUponDefaultConfig(boolean buildUponDefaultConfig) {
* @return this operation instance
*/
public DetektOperation classPath(File... paths) {
classpath_.addAll(List.of(paths));
return this;
return classPath(List.of(paths));
}

/**
* EXPERIMENTAL: Paths where to find user class files and jar dependencies.
* Used for type resolution.
*
* @param paths one or more files
* @return this operation instance
*/
public DetektOperation classPath(Path... paths) {
return classPathPaths(List.of(paths));
}

/**
Expand All @@ -189,8 +238,7 @@ public DetektOperation classPath(File... paths) {
* @return this operation instance
*/
public DetektOperation classPath(String... paths) {
classpath_.addAll(Arrays.stream(paths).map(File::new).toList());
return this;
return classPathStrings(List.of(paths));
}


Expand All @@ -215,15 +263,48 @@ public Collection<File> classPath() {
return classpath_;
}

/**
* EXPERIMENTAL: Paths where to find user class files and jar dependencies.
* Used for type resolution.
*
* @param paths the paths
* @return this operation instance
*/
public DetektOperation classPathPaths(Collection<Path> paths) {
classpath_.addAll(paths.stream().map(Path::toFile).toList());
return this;
}

/**
* EXPERIMENTAL: Paths where to find user class files and jar dependencies.
* Used for type resolution.
*
* @param paths the paths
* @return this operation instance
*/
public DetektOperation classPathStrings(Collection<String> paths) {
classpath_.addAll(paths.stream().map(File::new).toList());
return this;
}

/**
* Paths to the config files ({@code path/to/config.yml}).
*
* @param configs one or more config files
* @return this operation instance
*/
public DetektOperation config(File... configs) {
config_.addAll(List.of(configs));
return this;
return config(List.of(configs));
}

/**
* Paths to the config files ({@code path/to/config.yml}).
*
* @param configs one or more config files
* @return this operation instance
*/
public DetektOperation config(Path... configs) {
return configPaths(List.of(configs));
}

/**
Expand All @@ -233,10 +314,10 @@ public DetektOperation config(File... configs) {
* @return this operation instance
*/
public DetektOperation config(String... configs) {
config_.addAll(Arrays.stream(configs).map(File::new).toList());
return this;
return configStrings(List.of(configs));
}


/**
* Paths to the config files ({@code path/to/config.yml}).
*
Expand All @@ -257,6 +338,17 @@ public Collection<File> config() {
return config_;
}

/**
* Paths to the config files ({@code path/to/config.yml}).
*
* @param configs the config files
* @return this operation instance
*/
public DetektOperation configPaths(Collection<Path> configs) {
config_.addAll(configs.stream().map(Path::toFile).toList());
return this;
}

/**
* Path to the config resource on detekt's classpath ({@code path/to/config.yml}).
*
Expand All @@ -275,7 +367,36 @@ public DetektOperation configResource(String resource) {
* @return this operation instance
*/
public DetektOperation configResource(File resource) {
configResource_ = resource.getAbsolutePath();
return configResource(resource.getAbsolutePath());
}

/**
* Path to the config resource on detekt's classpath ({@code path/to/config.yml}).
*
* @param resource the config resource path
* @return this operation instance
*/
public DetektOperation configResource(Path resource) {
return configResource(resource.toFile());
}

/**
* Retrieves the path of the config resource.
*
* @return the config resource path
*/
public String configResource() {
return configResource_;
}

/**
* Paths to the config files ({@code path/to/config.yml}).
*
* @param configs the config files
* @return this operation instance
*/
public DetektOperation configStrings(Collection<String> configs) {
config_.addAll(configs.stream().map(File::new).toList());
return this;
}

Expand Down Expand Up @@ -360,7 +481,7 @@ public void execute() throws IOException, InterruptedException, ExitStatusExcept
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
} else {
super.execute();
if (successful_ && LOGGER.isLoggable(Level.INFO) && !silent()){
if (successful_ && LOGGER.isLoggable(Level.INFO) && !silent()) {
if (createBaseline_) {
LOGGER.info("Detekt baseline generated successfully: "
+ "file://" + new File(baseline_).toURI().getPath());
Expand Down Expand Up @@ -627,8 +748,7 @@ public DetektOperation input(Collection<File> paths) {
* @return this operation instance
*/
public DetektOperation input(String... paths) {
input_.addAll(Arrays.stream(paths).map(File::new).toList());
return this;
return inputStrings(List.of(paths));
}

/**
Expand All @@ -638,10 +758,18 @@ public DetektOperation input(String... paths) {
* @return this operation instance
*/
public DetektOperation input(File... paths) {
input_.addAll(List.of(paths));
return this;
return input(List.of(paths));
}

/**
* Input paths to analyze. If not specified the current working directory is used.
*
* @param paths one or more paths
* @return this operation instance
*/
public DetektOperation input(Path... paths) {
return inputPaths(List.of(paths));
}

/**
* Returns the input paths to analyze.
Expand All @@ -652,6 +780,28 @@ public Collection<File> input() {
return input_;
}

/**
* Input paths to analyze. If not specified the current working directory is used.
*
* @param paths the paths
* @return this operation instance
*/
public DetektOperation inputPaths(Collection<Path> paths) {
input_.addAll(paths.stream().map(Path::toFile).toList());
return this;
}

/**
* Input paths to analyze. If not specified the current working directory is used.
*
* @param paths the paths
* @return this operation instance
*/
public DetektOperation inputStrings(Collection<String> paths) {
input_.addAll(paths.stream().map(File::new).toList());
return this;
}

/*
* Determines if a string is not blank.
*/
Expand Down Expand Up @@ -731,8 +881,7 @@ public DetektOperation parallel(boolean parallel) {
* @return this operation instance
*/
public DetektOperation plugins(String... jars) {
plugins_.addAll(Arrays.stream(jars).map(File::new).toList());
return this;
return pluginsStrings(List.of(jars));
}

/**
Expand All @@ -742,8 +891,17 @@ public DetektOperation plugins(String... jars) {
* @return this operation instance
*/
public DetektOperation plugins(File... jars) {
plugins_.addAll(List.of(jars));
return this;
return plugins(List.of(jars));
}

/**
* Extra paths to plugin jars.
*
* @param jars one or more jars
* @return this operation instance
*/
public DetektOperation plugins(Path... jars) {
return pluginsPaths(List.of(jars));
}

/**
Expand All @@ -766,6 +924,28 @@ public Collection<File> plugins() {
return plugins_;
}

/**
* Extra paths to plugin jars.
*
* @param jars the jars paths
* @return this operation instance
*/
public DetektOperation pluginsPaths(Collection<Path> jars) {
plugins_.addAll(jars.stream().map(Path::toFile).toList());
return this;
}

/**
* Extra paths to plugin jars.
*
* @param jars the jars paths
* @return this operation instance
*/
public DetektOperation pluginsStrings(Collection<String> jars) {
plugins_.addAll(jars.stream().map(File::new).toList());
return this;
}

/**
* Generates a report for given {@link ReportId report-id} and stores it on given 'path'.
*
Expand Down
Loading

0 comments on commit 324fc48

Please sign in to comment.