Skip to content

Commit

Permalink
gradle 8.5 & code quality fixes (via #2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Jan 18, 2024
1 parent 5f9d071 commit 2386ea6
Show file tree
Hide file tree
Showing 19 changed files with 291 additions and 427 deletions.
4 changes: 2 additions & 2 deletions allure-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ plugins {
description = "Allure Report Generator"

node {
// enforce https
distBaseUrl.set("https://nodejs.org/dist")
// repository is declared in root settings.gradle.kts
distBaseUrl.set(null as String?)
version.set("16.18.0")
download.set(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@
* @since 2.0
*/
@SuppressWarnings({
"PMD.ExcessiveImports",
"ClassDataAbstractionCoupling",
"ClassFanOutComplexity"
"ClassFanOutComplexity",
"PMD.ExcessiveImports",
"PMD.TooManyMethods",
})
public class Allure2Plugin implements Reader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected static TreeWidgetItem toWidgetItem(final TestResultTreeGroup group) {
/**
* Adds categories info to test results.
*/
private static class EnrichDataAggregator implements Aggregator2 {
private static final class EnrichDataAggregator implements Aggregator2 {

@Override
public void aggregate(final Configuration configuration,
Expand All @@ -192,7 +192,7 @@ public void aggregate(final Configuration configuration,
/**
* Generates tree data.
*/
private static class JsonAggregator extends CommonJsonAggregator2 {
private static final class JsonAggregator extends CommonJsonAggregator2 {

JsonAggregator() {
super(JSON_FILE_NAME);
Expand All @@ -207,7 +207,7 @@ protected Tree<TestResult> getData(final List<LaunchResults> launches) {
/**
* Generates export data.
*/
private static class CsvExportAggregator extends CommonCsvExportAggregator2<CsvExportCategory> {
private static final class CsvExportAggregator extends CommonCsvExportAggregator2<CsvExportCategory> {

CsvExportAggregator() {
super(CSV_FILE_NAME, CsvExportCategory.class);
Expand All @@ -231,7 +231,7 @@ protected List<CsvExportCategory> getData(final List<LaunchResults> launchesResu
/**
* Generates widget data.
*/
private static class WidgetAggregator extends CommonJsonAggregator2 {
private static final class WidgetAggregator extends CommonJsonAggregator2 {

WidgetAggregator() {
super(Constants.WIDGETS_DIR, JSON_FILE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/**
* @author charlie (Dmitry Baev).
*/
@SuppressWarnings("PMD.CognitiveComplexity")
public class ReportWebGenerator {

private static final String FAVICON_ICO = "favicon.ico";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SeverityPlugin() {
/**
* Adds severity to test results.
*/
private static class SeverityAggregator implements Aggregator2 {
private static final class SeverityAggregator implements Aggregator2 {

@Override
public void aggregate(final Configuration configuration,
Expand All @@ -75,7 +75,7 @@ private void setSeverityLevel(final TestResult result) {
/**
* Generates widget data.
*/
private static class WidgetAggregator extends CommonJsonAggregator2 {
private static final class WidgetAggregator extends CommonJsonAggregator2 {

WidgetAggregator() {
super("widgets", JSON_FILE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ default <T extends Extension> List<T> getExtensions(final Class<T> extensionType
* @param <T> the java type of context's type.
* @return resolved context.
*/
default <T, S extends Context<T>> Optional<S> getContext(Class<S> contextType) {
default <T, S extends Context<T>> Optional<S> getContext(final Class<S> contextType) {
return getExtensions(contextType).stream()
.findFirst();
}
Expand All @@ -111,7 +111,7 @@ default <T, S extends Context<T>> Optional<S> getContext(Class<S> contextType) {
* @return resolved context.
* @throws ContextNotFoundException if no such context present.
*/
default <T, S extends Context<T>> S requireContext(Class<S> contextType) {
default <T, S extends Context<T>> S requireContext(final Class<S> contextType) {
return getContext(contextType).orElseThrow(() -> new ContextNotFoundException(contextType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ default Set<TestResult> getResults() {
* @param <T> the java type of extra block.
* @return the found block or default value.
*/
default <T> T getExtra(String name, Supplier<T> defaultValue) {
default <T> T getExtra(final String name, final Supplier<T> defaultValue) {
final Optional<T> extra = getExtra(name);
return extra.orElseGet(defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ default boolean shouldDisplayMessage() {
.noneMatch(step -> step.hasMessage(message.get()));
}

default boolean hasMessage(String message) {
default boolean hasMessage(final String message) {
final Optional<String> current = Optional.ofNullable(getStatusMessage())
.filter(s -> Objects.equals(s, message));
return current.isPresent() || getSteps().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public interface WithGroupTime {

void setTime(GroupTime time);

default void updateTime(GroupTime groupTime) {
default void updateTime(final GroupTime groupTime) {
getTimeSafe().merge(groupTime);
}

default void updateTime(Timeable timed) {
default void updateTime(final Timeable timed) {
getTimeSafe().update(timed.getTime());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,41 @@ public interface WithLabels {

void setLabels(List<Label> labels);

default <T> T findAll(LabelName name, Collector<String, ?, T> collector) {
default <T> T findAll(final LabelName name, final Collector<String, ?, T> collector) {
return findAll(name.value(), collector);
}

default <T> T findAll(String name, Collector<String, ?, T> collector) {
default <T> T findAll(final String name, final Collector<String, ?, T> collector) {
return getLabels().stream()
.filter(label -> name.equals(label.getName()))
.map(Label::getValue)
.collect(collector);
}

default List<String> findAll(LabelName name) {
default List<String> findAll(final LabelName name) {
return findAll(name, Collectors.toList());
}

default List<String> findAll(String name) {
default List<String> findAll(final String name) {
return findAll(name, Collectors.toList());
}

default Optional<String> findOne(LabelName name) {
default Optional<String> findOne(final LabelName name) {
return findOne(name.value());
}

default Optional<String> findOne(String name) {
default Optional<String> findOne(final String name) {
return getLabels().stream()
.filter(label -> name.equals(label.getName()))
.map(Label::getValue)
.findAny();
}

default void addLabelIfNotExists(LabelName name, String value) {
default void addLabelIfNotExists(final LabelName name, final String value) {
addLabelIfNotExists(name.value(), value);
}

default void addLabelIfNotExists(String name, String value) {
default void addLabelIfNotExists(final String name, final String value) {
if (value == null || name == null) {
return;
}
Expand All @@ -77,7 +77,7 @@ default void addLabelIfNotExists(String name, String value) {
}
}

default void addLabel(String name, String value) {
default void addLabel(final String name, final String value) {
getLabels().add(new Label().setName(name).setValue(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public interface WithStatistic {

void setStatistic(Statistic statistic);

default void updateStatistic(Statistic other) {
default void updateStatistic(final Statistic other) {
getStatistic().setFailed(other.getFailed() + getStatistic().getFailed());
getStatistic().setBroken(other.getBroken() + getStatistic().getBroken());
getStatistic().setPassed(other.getPassed() + getStatistic().getPassed());
getStatistic().setSkipped(other.getSkipped() + getStatistic().getSkipped());
getStatistic().setUnknown(other.getUnknown() + getStatistic().getUnknown());
}

default void updateStatistic(Statusable statusable) {
default void updateStatistic(final Statusable statusable) {
if (statusable == null) {
return;
}
Expand Down
110 changes: 63 additions & 47 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.github.spotbugs.snom.SpotBugsTask
import java.nio.charset.StandardCharsets.UTF_8

val linkHomepage by extra("https://allurereport.org/")
Expand All @@ -13,20 +14,22 @@ val qualityConfigsDir by extra("$gradleScriptDir/quality-configs")
val spotlessDtr by extra("$qualityConfigsDir/spotless")

tasks.wrapper {
gradleVersion = "8.1.1"
gradleVersion = "8.5"
}

plugins {
java
`java-library`
`maven-publish`
signing
checkstyle
pmd
id("com.github.spotbugs")
id("com.bmuschko.docker-remote-api")
id("io.github.gradle-nexus.publish-plugin")
id("com.diffplug.spotless")
id("com.gorylenko.gradle-git-properties")
id("io.spring.dependency-management")
id("ru.vyarus.quality")
id("org.owasp.dependencycheck")
}

Expand Down Expand Up @@ -62,25 +65,37 @@ subprojects {
apply(plugin = "java")
apply(plugin = "signing")
apply(plugin = "maven-publish")
apply(plugin = "ru.vyarus.quality")
apply(plugin = "checkstyle")
apply(plugin = "pmd")
apply(plugin = "com.github.spotbugs")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "io.spring.dependency-management")

val orgSlf4jVersion = "2.0.9"
val comSquareupRetrofit2Version = "2.9.0"

dependencyManagement {
imports {
mavenBom("com.fasterxml.jackson:jackson-bom:2.16.1")
mavenBom("org.junit:junit-bom:5.10.1")
mavenBom("io.qameta.allure:allure-bom:2.25.0")
mavenBom("com.squareup.okhttp3:okhttp-bom:4.12.0")
// latest version that supports java 8
mavenBom("com.vladsch.flexmark:flexmark-all:0.62.2")
mavenBom("io.qameta.allure:allure-bom:2.25.0")
mavenBom("org.junit:junit-bom:5.10.1")
}
dependencies {
dependency("ch.qos.logback:logback-classic:1.3.14")
dependency("com.beust:jcommander:1.82")
dependency("com.github.spotbugs:spotbugs-annotations:4.8.3")
dependency("com.github.spotbugs:spotbugs:4.8.3")
dependency("com.opencsv:opencsv:4.6")
dependency("com.puppycrawl.tools:checkstyle:10.12.7")
dependency("com.squareup.retrofit2:converter-jackson:${comSquareupRetrofit2Version}")
dependency("com.squareup.retrofit2:retrofit:${comSquareupRetrofit2Version}")
dependency("commons-beanutils:commons-beanutils:1.9.4")
dependency("commons-io:commons-io:2.15.1")
dependency("javax.xml.bind:jaxb-api:2.3.1")
dependency("net.sourceforge.pmd:pmd-java:6.55.0")
dependency("org.allurefw:allure1-model:1.0")
dependency("org.apache.commons:commons-lang3:3.14.0")
dependency("org.apache.httpcomponents:httpclient:4.5.14")
Expand All @@ -91,20 +106,10 @@ subprojects {
dependency("org.junit-pioneer:junit-pioneer:2.2.0")
dependency("org.mockito:mockito-core:5.9.0")
dependency("org.projectlombok:lombok:1.18.30")
dependency("org.slf4j:slf4j-api:${orgSlf4jVersion}")
dependency("org.slf4j:slf4j-nop:${orgSlf4jVersion}")
dependency("org.slf4j:slf4j-simple:${orgSlf4jVersion}")
dependency("org.zeroturnaround:zt-zip:1.16")
dependencySet("org.slf4j:2.0.7") {
entry("slf4j-api")
entry("slf4j-nop")
entry("slf4j-simple")
}
dependencySet("com.squareup.retrofit2:2.9.0") {
entry("converter-jackson")
entry("retrofit")
}
dependencySet("com.vladsch.flexmark:0.62.2") {
entry("flexmark")
entry("flexmark-ext-tables")
}
}
}

Expand Down Expand Up @@ -149,29 +154,45 @@ subprojects {
}
}

quality {
configDir = "$gradleScriptDir/quality-configs"
excludeSources = fileTree("build/generated-sources")
exclude("**/*.json")
checkstyleVersion = "8.36.1"
pmdVersion = "6.28.0"
spotbugsVersion = "4.1.2"
codenarcVersion = "1.6"
spotbugs = true
codenarc = true
pmd = true
checkstyle = true
htmlReports = false

afterEvaluate {
val spotbugs = configurations.findByName("spotbugs")
if (spotbugs != null) {
dependencies {
spotbugs("org.slf4j:slf4j-simple")
spotbugs("com.github.spotbugs:spotbugs:4.8.2")
}
}
}
fun excludeGeneratedSources(source: FileTree): FileTree = (source - fileTree("build/generated-sources")).asFileTree

checkstyle {
toolVersion = dependencyManagement.managedVersions["com.puppycrawl.tools:checkstyle"]!!
configDirectory = rootProject.layout.projectDirectory.dir("gradle/quality-configs/checkstyle")
}

pmd {
toolVersion = dependencyManagement.managedVersions["net.sourceforge.pmd:pmd-java"]!!
ruleSets = listOf()
ruleSetFiles = rootProject.files("gradle/quality-configs/pmd/pmd.xml")
}

spotbugs {
toolVersion = dependencyManagement.managedVersions["com.github.spotbugs:spotbugs"]!!
excludeFilter = rootProject.file("gradle/quality-configs/spotbugs/exclude.xml")
}

tasks.withType(Checkstyle::class) {
source = excludeGeneratedSources(source)
}

tasks.withType(Pmd::class) {
source = excludeGeneratedSources(source)
}

tasks.withType(SpotBugsTask::class) {
}

tasks.checkstyleTest {
enabled = false
}

tasks.pmdTest {
enabled = false
}

tasks.spotbugsTest {
enabled = false
}

spotless {
Expand Down Expand Up @@ -292,7 +313,7 @@ subprojects {
}
}

val pluginsDir = "$buildDir/plugins/"
val pluginsDir = layout.buildDirectory.dir("plugins")
val copyPlugins by tasks.creating(Sync::class) {
group = "Build"
dependsOn(allurePlugin)
Expand All @@ -304,11 +325,6 @@ subprojects {
}
includeEmptyDirs = false
}

repositories {
mavenLocal()
mavenCentral()
}
}

apply(plugin = "com.bmuschko.docker-remote-api")
Expand Down
Loading

0 comments on commit 2386ea6

Please sign in to comment.