Skip to content

Commit

Permalink
Merge pull request #11600 from murdos/liquibase-linter
Browse files Browse the repository at this point in the history
feat(liquibase): new module for configuring a liquibase linter executed as a maven plugin
  • Loading branch information
pascalgrimaud authored Dec 19, 2024
2 parents e80ac1b + 474417c commit 9e7c8c4
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export default {
'*.{js,cjs,ts,tsx,vue}': ['eslint --fix', 'prettier --write'],
'*.{css,scss}': ['stylelint --fix --allow-empty-input', 'prettier --write'],
'*.pug': ['eslint --fix', 'prettier --write'],
'*.{md,json,yml,html,java,xml,feature,sh}': ['prettier --write'],
'*.{md,json*,yml,html,java,xml,feature,sh}': ['prettier --write'],
};
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ bracketSameLine: false

# xml rules:
xmlWhitespaceSensitivity: ignore

# https://github.com/prettier/prettier/issues/15956
overrides:
- files: ['*.jsonc']
options:
trailingComma: none
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.postActions()
.add(context -> npmLazyInstaller.runInstallIn(context.projectFolder()))
.and()
.preCommitActions(stagedFilesFilter("*.{md,json,yml,html,css,scss,java,xml,feature}"), preCommitCommands("['prettier --write']"))
.preCommitActions(stagedFilesFilter("*.{md,json*,yml,html,css,scss,java,xml,feature}"), preCommitCommands("['prettier --write']"))
.build();
//@formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
public JHipsterModule buildAsyncModule(JHipsterModuleProperties properties) {
return factory.buildAsyncModule(properties);
}

public JHipsterModule buildLinterModule(JHipsterModuleProperties properties) {
return factory.buildLinterModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
import static tech.jhipster.lite.module.domain.JHipsterModule.artifactId;
import static tech.jhipster.lite.module.domain.JHipsterModule.from;
import static tech.jhipster.lite.module.domain.JHipsterModule.groupId;
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;
import static tech.jhipster.lite.module.domain.JHipsterModule.propertyKey;
import static tech.jhipster.lite.module.domain.JHipsterModule.propertyValue;
import static tech.jhipster.lite.module.domain.JHipsterModule.to;
import static tech.jhipster.lite.module.domain.JHipsterModule.toSrcMainJava;
import static tech.jhipster.lite.module.domain.JHipsterModule.toSrcTestJava;
import static tech.jhipster.lite.module.domain.JHipsterModule.toSrcTestResources;
import static tech.jhipster.lite.module.domain.JHipsterModule.versionSlug;
import static tech.jhipster.lite.module.domain.properties.SpringConfigurationFormat.PROPERTIES;
import static tech.jhipster.lite.module.domain.properties.SpringConfigurationFormat.YAML;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.LogLevel;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin.MavenPluginOptionalBuilder;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

Expand Down Expand Up @@ -76,4 +81,35 @@ public JHipsterModule buildAsyncModule(JHipsterModuleProperties properties) {
.build();
//@formatter:on
}

public JHipsterModule buildLinterModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
.mavenPlugins()
.plugin(liquibaseLinterMavenPlugin().build())
.pluginManagement(liquibaseLinterMavenPluginManagement())
.and()
.files()
.add(SOURCE.append("liquibase-linter.jsonc"), toSrcTestResources().append("liquibase-linter.jsonc"))
.and()
.build();
//@formatter:on
}

private MavenPlugin liquibaseLinterMavenPluginManagement() {
return liquibaseLinterMavenPlugin()
.versionSlug("liquibase-linter-maven-plugin")
.configuration(
"""
<changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
<configurationFile>src/test/resources/liquibase-linter.jsonc</configurationFile>
"""
)
.addExecution(pluginExecution().goals("lint"))
.build();
}

private static MavenPluginOptionalBuilder liquibaseLinterMavenPlugin() {
return mavenPlugin().groupId("io.github.liquibase-linter").artifactId("liquibase-linter-maven-plugin");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static tech.jhipster.lite.shared.slug.domain.JHLiteFeatureSlug.JPA_PERSISTENCE;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.LIQUIBASE;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.LIQUIBASE_ASYNC;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.LIQUIBASE_LINTER;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.LOGS_SPY;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.MAVEN_JAVA;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -16,29 +18,46 @@
@Configuration
class LiquibaseModuleConfiguration {

private static final String SPRING_BOOT_DATABASE_MIGRATION = "Spring Boot - Database Migration";

@Bean
JHipsterModuleResource liquibaseModule(LiquibaseApplicationService liquibase) {
return JHipsterModuleResource.builder()
.slug(LIQUIBASE)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addIndentation().addSpringConfigurationFormat().build())
.apiDoc("Spring Boot - Database Migration", "Add Liquibase")
.apiDoc(SPRING_BOOT_DATABASE_MIGRATION, "Add Liquibase")
.organization(
JHipsterModuleOrganization.builder().feature(DATABASE_MIGRATION).addDependency(JPA_PERSISTENCE).addDependency(LOGS_SPY).build()
)
.tags("server", "spring", "spring-boot", "database", "migration", "liquibase")
.tags(liquibaseTags())
.factory(liquibase::buildModule);
}

private String[] liquibaseTags() {
return new String[] { "liquibase", "database", "migration", "spring", "spring-boot" };
}

@Bean
JHipsterModuleResource liquibaseAsyncModule(LiquibaseApplicationService liquibase) {
return JHipsterModuleResource.builder()
.slug(LIQUIBASE_ASYNC)
.propertiesDefinition(
JHipsterModulePropertiesDefinition.builder().addIndentation().addBasePackage().addSpringConfigurationFormat().build()
)
.apiDoc("Spring Boot - Database Migration", "Support updating the database asynchronously with Liquibase")
.apiDoc(SPRING_BOOT_DATABASE_MIGRATION, "Support updating the database asynchronously with Liquibase")
.organization(JHipsterModuleOrganization.builder().addDependency(LIQUIBASE).build())
.tags("server", "spring", "spring-boot", "database", "migration", "liquibase")
.tags(liquibaseTags())
.factory(liquibase::buildAsyncModule);
}

@Bean
JHipsterModuleResource liquibaseLinterModule(LiquibaseApplicationService liquibase) {
return JHipsterModuleResource.builder()
.slug(LIQUIBASE_LINTER)
.propertiesDefinition(JHipsterModulePropertiesDefinition.EMPTY)
.apiDoc(SPRING_BOOT_DATABASE_MIGRATION, "Configure a linter for the Liquibase migration scripts")
.organization(JHipsterModuleOrganization.builder().addDependency(LIQUIBASE).addDependency(MAVEN_JAVA).build())
.tags("server", "database", "migration", "liquibase", "linter")
.factory(liquibase::buildLinterModule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public static JHipsterDestination toSrcMainResources() {
return JHipsterDestination.SRC_MAIN_RESOURCES;
}

public static JHipsterDestination toSrcTestResources() {
return JHipsterDestination.SRC_TEST_RESOURCES;
}

public static JHipsterFileMatcher filesWithExtension(String extension) {
return path -> StringUtils.endsWithIgnoreCase(path.get(), "." + extension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class JHipsterDestination {
public static final JHipsterDestination SRC_TEST_JAVA = new JHipsterDestination("src/test/java");
public static final JHipsterDestination SRC_MAIN_DOCKER = new JHipsterDestination("src/main/docker");
public static final JHipsterDestination SRC_MAIN_RESOURCES = new JHipsterDestination("src/main/resources");
public static final JHipsterDestination SRC_TEST_RESOURCES = new JHipsterDestination("src/test/resources");

private static final String MUSTACHE_EXTENSION = ".mustache";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
LICENSE_MIT("license-mit"),
LIQUIBASE("liquibase"),
LIQUIBASE_ASYNC("liquibase-async"),
LIQUIBASE_LINTER("liquibase-linter"),
LOGSTASH("logstash"),
LOGS_SPY("logs-spy"),
MAVEN_JAVA("maven-java"),
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<jqassistant-context-mapper-plugin.version>2.1.0-M2</jqassistant-context-mapper-plugin.version>
<jqassistant-jmolecules-plugin.version>2.1.0-M4</jqassistant-jmolecules-plugin.version>
<jqassistant-spring-plugin.version>2.2.1</jqassistant-spring-plugin.version>
<langchain4j.version>0.36.2</langchain4j.version>
<jooq.version>3.19.16</jooq.version>
<!-- Test dependencies -->
<junit-jupiter.version>5.11.4</junit-jupiter.version>
<assertj.version>3.26.3</assertj.version>
Expand Down Expand Up @@ -69,8 +71,7 @@
<asciidoctor-maven-plugin.version>3.1.1</asciidoctor-maven-plugin.version>
<openapi-maven-plugin.version>0.0.21</openapi-maven-plugin.version>
<openapi-backwards-compat-maven-plugin.version>1.0.3</openapi-backwards-compat-maven-plugin.version>
<langchain4j.version>0.36.2</langchain4j.version>
<jooq.version>3.19.16</jooq.version>
<liquibase-linter-maven-plugin.version>0.8.0</liquibase-linter-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -416,6 +417,11 @@
<artifactId>langchain4j-open-ai-spring-boot-starter</artifactId>
<version>${langchain4j.version}</version>
</dependency>
<dependency>
<groupId>io.github.liquibase-linter</groupId>
<artifactId>liquibase-linter-maven-plugin</artifactId>
<version>${liquibase-linter-maven-plugin.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
6 changes: 6 additions & 0 deletions src/main/resources/generator/prettier/.prettierrc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ bracketSameLine: false

# xml rules:
xmlWhitespaceSensitivity: ignore

# https://github.com/prettier/prettier/issues/15956
overrides:
- files: ['*.jsonc']
options:
trailingComma: none
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"isolate-ddl-changes": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ Feature: Liquibase module
| packageName | tech.jhipster.chips |
Then I should have files in "src/main/java/tech/jhipster/chips/wire/liquibase/infrastructure/secondary"
| AsyncSpringLiquibase.java |

Scenario: Should apply liquibase-linter module
When I apply "liquibase-linter" module to default project with maven file
| packageName | tech.jhipster.chips |
Then I should have "<artifactId>liquibase-linter-maven-plugin</artifactId>" in "pom.xml"
Then I should have files in "src/test/resources/"
| liquibase-linter.jsonc |
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void shouldBuildModuleWithoutPrettierLintStaged() {
.containing(
"""
module.exports = {
'*.{md,json,yml,html,css,scss,java,xml,feature}': ['prettier --write'],
'*.{md,json*,yml,html,css,scss,java,xml,feature}': ['prettier --write'],
'*.pug': ['eslint --fix', 'prettier --write'],
};
"""
Expand Down Expand Up @@ -83,7 +83,7 @@ void shouldBuildModuleWithEmptyLintStaged() {
.containing(
"""
module.exports = {
'*.{md,json,yml,html,css,scss,java,xml,feature}': ['prettier --write'],
'*.{md,json*,yml,html,css,scss,java,xml,feature}': ['prettier --write'],
};
"""
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,50 @@ void shouldBuildModuleWithPropertiesSpringConfigurationFormat() {
.notContaining("YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();");
}
}

@Nested
class LiquibaseLinterModule {

@Test
void shouldBuildModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(tmpDirForTest())
.basePackage("tech.jhipster.jhlitest")
.build();

JHipsterModule module = factory.buildLinterModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
.containing(
"""
<plugin>
<groupId>io.github.liquibase-linter</groupId>
<artifactId>liquibase-linter-maven-plugin</artifactId>
</plugin>
"""
)
.containing(
"""
<plugin>
<groupId>io.github.liquibase-linter</groupId>
<artifactId>liquibase-linter-maven-plugin</artifactId>
<version>${liquibase-linter-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>lint</goal>
</goals>
</execution>
</executions>
<configuration>
<changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
<configurationFile>src/test/resources/liquibase-linter.jsonc</configurationFile>
</configuration>
</plugin>
"""
)
.and()
.hasFile("src/test/resources/liquibase-linter.jsonc");
}
}
}
1 change: 1 addition & 0 deletions tests-ci/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ elif [[ $application == 'fullapp' ]]; then
apply_modules \
"jpa-postgresql" \
"liquibase" \
"liquibase-linter" \
"liquibase-async"

apply_modules \
Expand Down

0 comments on commit 9e7c8c4

Please sign in to comment.