Skip to content

Commit

Permalink
feat(frontend-maven-plugin): extract cache logic (checksum computatio…
Browse files Browse the repository at this point in the history
…n of resources) into a dedicated module

See #10612
  • Loading branch information
murdos committed Sep 18, 2024
1 parent ae7731c commit da521b3
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public JHipsterModule buildFrontendMavenModule(JHipsterModuleProperties properti
public JHipsterModule buildFrontendGradleModule(JHipsterModuleProperties properties) {
return factory.buildFrontendGradleModule(properties);
}

public JHipsterModule buildFrontendMavenCacheModule(JHipsterModuleProperties properties) {
return factory.buildFrontendMavenCacheModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,29 @@ public FrontendJavaBuildToolModuleFactory(NpmVersions npmVersions) {
}

public JHipsterModule buildFrontendMavenModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return commonModuleFiles(properties)
.javaBuildProperties()
.set(buildPropertyKey("node.version"), buildPropertyValue("v" + npmVersions.nodeVersion().get()))
.set(buildPropertyKey("npm.version"), buildPropertyValue(npmVersions.get("npm", NpmVersionSource.COMMON).get()))
.and()
.mavenPlugins()
.plugin(frontendMavenPlugin())
.and()
.build();
//@formatter:on
}

public JHipsterModule buildFrontendMavenCacheModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return moduleBuilder(properties)
.mavenPlugins()
.plugin(checksumPlugin())
.plugin(antrunPlugin())
.plugin(frontendMavenPlugin())
.and()
.build();
//@formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.server.javatool.frontendmaven.application.FrontendJavaBuildToolApplicationService;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;
import tech.jhipster.lite.module.domain.resource.*;

@Configuration
class FrontendJavaBuildToolModuleConfiguration {

private static final String[] TAGS = { "server", "tools" };
private static final String FRONTEND_JAVA_PLUGIN = "Frontend Java Plugin";

@Bean
JHipsterModuleResource frontendMavenModule(FrontendJavaBuildToolApplicationService frontendJavaBuildTool) {
return JHipsterModuleResource.builder()
.slug(FRONTEND_MAVEN_PLUGIN)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addIndentation().build())
.apiDoc("Frontend Java Plugin", "Add Frontend Maven Plugin")
.apiDoc(FRONTEND_JAVA_PLUGIN, "Add Frontend Maven Plugin")
.organization(
JHipsterModuleOrganization.builder()
.feature(FRONTEND_JAVA_BUILD_TOOL_PLUGIN)
Expand All @@ -27,16 +28,27 @@ JHipsterModuleResource frontendMavenModule(FrontendJavaBuildToolApplicationServi
.addDependency(MAVEN_JAVA)
.build()
)
.tags("server", "tools")
.tags(TAGS)
.factory(frontendJavaBuildTool::buildFrontendMavenModule);
}

@Bean
JHipsterModuleResource frontendMavenCacheModule(FrontendJavaBuildToolApplicationService frontendJavaBuildTool) {
return JHipsterModuleResource.builder()
.slug(FRONTEND_MAVEN_PLUGIN_CACHE)
.propertiesDefinition(JHipsterModulePropertiesDefinition.EMPTY)
.apiDoc(FRONTEND_JAVA_PLUGIN, "Add cache - by computing resources checksum - to avoid rebuilding frontend on successive maven builds")
.organization(JHipsterModuleOrganization.builder().addDependency(FRONTEND_MAVEN_PLUGIN).build())
.tags(TAGS)
.factory(frontendJavaBuildTool::buildFrontendMavenCacheModule);
}

@Bean
JHipsterModuleResource frontendGradleModule(FrontendJavaBuildToolApplicationService frontendJavaBuildTool) {
return JHipsterModuleResource.builder()
.slug(NODE_GRADLE_PLUGIN)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addIndentation().build())
.apiDoc("Frontend Java Plugin", "Add node-gradle plugin for building frontend with Gradle")
.apiDoc(FRONTEND_JAVA_PLUGIN, "Add node-gradle plugin for building frontend with Gradle")
.organization(
JHipsterModuleOrganization.builder()
.feature(FRONTEND_JAVA_BUILD_TOOL_PLUGIN)
Expand All @@ -45,7 +57,7 @@ JHipsterModuleResource frontendGradleModule(FrontendJavaBuildToolApplicationServ
.addDependency(GRADLE_JAVA)
.build()
)
.tags("server", "tools")
.tags(TAGS)
.factory(frontendJavaBuildTool::buildFrontendGradleModule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
FLYWAY_MYSQL("flyway-mysql"),
FLYWAY_POSTGRESQL("flyway-postgresql"),
FRONTEND_MAVEN_PLUGIN("frontend-maven-plugin"),
FRONTEND_MAVEN_PLUGIN_CACHE("frontend-maven-plugin-cache"),
FRONT_HEXAGONAL_ARCHITECTURE("front-hexagonal-architecture"),
NODE_GRADLE_PLUGIN("node-gradle-plugin"),
GATEWAY("gateway"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Feature: Frontend server module
Then I should have files in "src/main/java/tech/jhipster/chips/wire/frontend/infrastructure/primary"
| RedirectionResource.java |

Scenario: Should apply frontend-maven-plugin-cache module
When I apply "frontend-maven-plugin-cache" module to default project with maven file
| packageName | tech.jhipster.chips |
Then I should have "checksum-maven-plugin" in "pom.xml"

Scenario: Should apply frontend server gradle module
When I apply "node-gradle-plugin" module to default project with gradle build
| packageName | tech.jhipster.chips |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,76 @@ void shouldBuildFrontendMavenModule() {
.hasFile("pom.xml")
.containing(" <node.version>v16.0.0</node.version>")
.containing(" <npm.version>4.0.0</npm.version>")
.notContaining("<artifactId>checksum-maven-plugin</artifactId>")
.containing(
"""
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>install-node-and-npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>build front</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
<environmentVariables>
<APP_VERSION>${project.version}</APP_VERSION>
</environmentVariables>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
</configuration>
</execution>
<execution>
<id>front test</id>
<phase>test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run test:coverage</arguments>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
</configuration>
</execution>
</executions>
<configuration>
<installDirectory>${project.build.directory}</installDirectory>
</configuration>
</plugin>
"""
)
.and()
.hasPrefixedFiles(
"src/main/java/tech/jhipster/jhlitest/wire/frontend",
"infrastructure/primary/RedirectionResource.java",
"package-info.java"
);
}

@Test
void shouldBuildFrontendMavenCacheModule() {
JHipsterModule module = factory.buildFrontendMavenCacheModule(getProperties());

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
.containing(
"""
<plugin>
Expand Down Expand Up @@ -118,67 +188,6 @@ void shouldBuildFrontendMavenModule() {
</executions>
</plugin>
"""
)
.containing(
"""
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>install-node-and-npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>build front</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
<environmentVariables>
<APP_VERSION>${project.version}</APP_VERSION>
</environmentVariables>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
</configuration>
</execution>
<execution>
<id>front test</id>
<phase>test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run test:coverage</arguments>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
</configuration>
</execution>
</executions>
<configuration>
<installDirectory>${project.build.directory}</installDirectory>
</configuration>
</plugin>
"""
)
.and()
.hasPrefixedFiles(
"src/main/java/tech/jhipster/jhlitest/wire/frontend",
"infrastructure/primary/RedirectionResource.java",
"package-info.java"
);
}
}
Expand Down

0 comments on commit da521b3

Please sign in to comment.