Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkstyle): use latest checkstyle version when using checkstyle maven plugin #11606

Merged
merged 2 commits into from
Dec 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static tech.jhipster.lite.module.domain.JHipsterModule.from;
import static tech.jhipster.lite.module.domain.JHipsterModule.gradleCorePlugin;
import static tech.jhipster.lite.module.domain.JHipsterModule.javaDependency;
import static tech.jhipster.lite.module.domain.JHipsterModule.mavenPlugin;
import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;
import static tech.jhipster.lite.module.domain.JHipsterModule.pluginExecution;
Expand All @@ -12,13 +13,15 @@
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.gradleplugin.GradleMainBuildPlugin;
import tech.jhipster.lite.module.domain.javabuild.VersionSlug;
import tech.jhipster.lite.module.domain.javadependency.JavaDependency;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

public class CheckstyleModuleFactory {

private static final JHipsterSource TEMPLATES_SOURCE = from("server/javatool/checkstyle/main");
private static final String CHECKSTYLE = "checkstyle";

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);
Expand Down Expand Up @@ -51,14 +54,19 @@ private MavenPlugin checkstyleMavenPlugin() {
<failsOnError>true</failsOnError>
"""
)
.addDependency(checkstyleDependency())
.addExecution(pluginExecution().goals("check").id("validate").phase(VALIDATE))
.build();
}

private JavaDependency checkstyleDependency() {
return javaDependency().groupId("com.puppycrawl.tools").artifactId(CHECKSTYLE).versionSlug(CHECKSTYLE).build();
}

private GradleMainBuildPlugin checkstyleGradlePlugin() {
VersionSlug toolVersionSlug = new VersionSlug("checkstyle");
VersionSlug toolVersionSlug = new VersionSlug(CHECKSTYLE);
return gradleCorePlugin()
.id("checkstyle")
.id(CHECKSTYLE)
.toolVersionSlug(toolVersionSlug)
.configuration(
"""
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/generator/dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
java
checkstyle
alias(libs.plugins.jib)
alias(libs.plugins.protobuf)
// jhipster-needle-gradle-plugin
Expand All @@ -12,10 +11,6 @@ java {
}
}

checkstyle {
toolVersion = libs.versions.checkstyle.get()
}

// jhipster-needle-gradle-project-extension-plugin-configuration

repositories {
Expand All @@ -29,7 +24,6 @@ version = "0.0.1-SNAPSHOT"
// jhipster-needle-profile-activation

dependencies {
implementation(libs.checkstyle)
// jhipster-needle-gradle-implementation-dependencies
// jhipster-needle-gradle-compile-dependencies
// jhipster-needle-gradle-runtime-dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ jacoco = "0.8.11"
sonarqube = "4.4.1.3373"
node-gradle = "7.0.2"

[libraries]
[libraries.checkstyle]
group = "com.puppycrawl.tools"
name = "checkstyle"
version.ref = "checkstyle"

[plugins]
[plugins.jib]
id = "com.google.cloud.tools.jib"
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<protobuf-maven-plugin.version>2.7.3</protobuf-maven-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<checkstyle.version>10.21.0</checkstyle.version>
<maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
<git-commit-id-plugin.version>9.0.1</git-commit-id-plugin.version>
<frontend-maven-plugin.version>1.15.1</frontend-maven-plugin.version>
Expand Down Expand Up @@ -422,6 +423,11 @@
<artifactId>liquibase-linter-maven-plugin</artifactId>
<version>${liquibase-linter-maven-plugin.version}</version>
</dependency>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class RestAccount {
return roles;
}

private static class RestAccountBuilder {
private static final class RestAccountBuilder {

private String username;
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CustomClaimConverter implements Converter<Map<String, Object>, Map<String,
}
}

private static class NameClaimAppender implements ClaimAppender {
private static final class NameClaimAppender implements ClaimAppender {

@Override
public void append(Map<String, Object> claim, ObjectNode user) {
Expand All @@ -140,7 +140,7 @@ class CustomClaimConverter implements Converter<Map<String, Object>, Map<String,
}
}

private static class GroupClaimAppender implements ClaimAppender {
private static final class GroupClaimAppender implements ClaimAppender {

@Override
public void append(Map<String, Object> claim, ObjectNode user) {
Expand All @@ -152,7 +152,7 @@ class CustomClaimConverter implements Converter<Map<String, Object>, Map<String,
}
}

private static class RolesClaimAppender implements ClaimAppender {
private static final class RolesClaimAppender implements ClaimAppender {

@Override
public void append(Map<String, Object> claim, ObjectNode user) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package tech.jhipster.lite.generator.server.javatool.checkstyle.domain;

import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.gradleBuildFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.gradleLibsVersionFile;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.pomFile;

import org.junit.jupiter.api.Test;
import tech.jhipster.lite.TestFileUtils;
Expand Down Expand Up @@ -37,6 +40,13 @@ void shouldBuildModuleForMaven() {
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
Expand All @@ -46,6 +56,7 @@ void shouldBuildModuleForMaven() {
</plugin>
"""
)
.containing("<checkstyle.version>")
.and()
.hasFile("checkstyle.xml")
.containing("<module name=\"IllegalImport\">")
Expand Down
Loading