Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ plugins {
id "com.github.ben-manes.versions" version "0.53.0"
}

def isNonStable = { String version ->
def normalizedVersion = version.toUpperCase()
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { normalizedVersion.contains(it) }
def stableVersion = version ==~ /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !stableVersion
}

group 'com.formkiq.gradle'
version '1.0.9'
version '1.0.10'

allprojects {
apply plugin: 'com.diffplug.spotless'

tasks.matching { it.name == 'dependencyUpdates' }.configureEach {
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
}

repositories {
Expand Down
45 changes: 27 additions & 18 deletions src/main/java/com/formkiq/gradle/JavaBasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.owasp.dependencycheck.gradle.extension.AnalyzerExtension;
import org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* {@link Plugin} for FormKiQ Gradle Conventions.
Expand All @@ -26,9 +26,24 @@ public class JavaBasePlugin implements Plugin<Project> {

/** Checkstyle Version. */
private static final String CHECKSTYLE_TOOL_VERSION = "10.12.4";
/** Maximum number of parent directories to search for shared config files. */
private static final int MAX_CONFIG_PARENT_DEPTH = 3;
/** Java version. */
private static final int JAVA_VERSION = 17;

private static File findConfigFile(final Project project, final String fileName) {
File directory = project.getProjectDir();
for (int depth = 0; depth <= MAX_CONFIG_PARENT_DEPTH && directory != null; depth++) {
File candidate = new File(directory, fileName);
if (candidate.isFile()) {
return candidate;
}
directory = directory.getParentFile();
}

return project.file(fileName);
}

@Override
public void apply(Project root) {
root.getRepositories().mavenCentral();
Expand Down Expand Up @@ -59,11 +74,11 @@ public void apply(Project root) {
p.getExtensions().configure(SpotlessExtension.class, (SpotlessExtension s) -> {
s.java(j -> {
j.eclipse().sortMembersEnabled(true)
.configFile(p.getRootProject().file("spotless.eclipseformat.xml"));
.configFile(findConfigFile(p, "spotless.eclipseformat.xml"));
j.removeUnusedImports();
j.removeWildcardImports();
j.forbidWildcardImports();

j.licenseHeaderFile(p.getRootProject().file("LICENSE"));
j.licenseHeaderFile(findConfigFile(p, "LICENSE"));
});
s.groovyGradle(g -> {
g.target("*.gradle");
Expand All @@ -86,8 +101,8 @@ public void apply(Project root) {
});

// SpotBugs
p.getExtensions().configure(SpotBugsExtension.class, sb -> sb.getExcludeFilter()
.set(p.file(p.getRootDir() + "/config/gradle/spotbugs-exclude.xml")));
p.getExtensions().configure(SpotBugsExtension.class,
sb -> sb.getExcludeFilter().set(findConfigFile(p, "config/gradle/spotbugs-exclude.xml")));

p.getTasks().withType(com.github.spotbugs.snom.SpotBugsTask.class).configureEach(t -> {
if (t.getReports().findByName("html") == null) {
Expand All @@ -103,9 +118,11 @@ public void apply(Project root) {
// Checkstyle
p.getExtensions().configure(CheckstyleExtension.class, cs -> {
cs.setToolVersion(CHECKSTYLE_TOOL_VERSION);
cs.setConfigFile(p.file("config/checkstyle/checkstyle.xml"));
cs.setConfigFile(findConfigFile(p, "config/checkstyle/checkstyle.xml"));
Map<String, Object> props = new LinkedHashMap<>();
props.put("project_loc", p.getProjectDir());
props.put("suppressions_file",
findConfigFile(p, "config/checkstyle/mysuppressions.xml").getAbsolutePath());
cs.setConfigProperties(props);
cs.setMaxWarnings(0);
cs.setMaxErrors(0);
Expand All @@ -115,14 +132,12 @@ public void apply(Project root) {
p.getExtensions().configure(DependencyCheckExtension.class, dc -> {
dc.setFormats(Arrays.asList("HTML", "JSON", "SARIF"));
dc.setFailBuildOnCVSS(7.0f);
dc.setScanConfigurations(Arrays.asList("runtimeClasspath"));
dc.setScanConfigurations(List.of("runtimeClasspath"));
dc.setSkipTestGroups(true);
Object skipProjects = p.findProperty("dependencyCheckSkipProjects");
if (skipProjects != null) {
List<String> projectPaths = Arrays.stream(skipProjects.toString().split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
.map(String::trim).filter(s -> !s.isEmpty()).toList();
dc.setSkipProjects(projectPaths);
}
dc.analyzers((AnalyzerExtension analyzers) -> {
Expand Down Expand Up @@ -157,12 +172,6 @@ public void apply(Project root) {
t.setMinHeapSize("1g");
t.setMaxHeapSize("2g");
});

p.afterEvaluate(prj -> {
if (!prj.file("config/checkstyle/checkstyle.xml").exists()) {
prj.getLogger().warn("Checkstyle config not found at config/checkstyle/checkstyle.xml");
}
});
});

}
Expand Down
Loading