Skip to content

Commit

Permalink
Merge pull request #3840 from AnneJacquet/mvn-wrapper-module
Browse files Browse the repository at this point in the history
maven wrapper module
  • Loading branch information
pascalgrimaud authored Oct 7, 2022
2 parents 2d0bd5a + ea157eb commit b9d33f1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public MavenApplicationService() {
factory = new MavenModuleFactory();
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
public JHipsterModule buildMavenModule(JHipsterModuleProperties properties) {
return factory.buildMavenModule(properties);
}

public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties properties) {
return factory.buildMavenWrapperModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,15 @@ public class MavenModuleFactory {
private static final ArtifactId JACOCO_ARTIFACT_ID = artifactId("jacoco-maven-plugin");
private static final VersionSlug JACOCO_VERSION = versionSlug("jacoco");

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

public JHipsterModule buildMavenModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
return mavenWrapperModulesFiles(properties)
.context()
.put("dasherizedBaseName", properties.projectBaseName().kebabCase())
.and()
.startupCommand("./mvnw")
.files()
.add(SOURCE.template("pom.xml"), to("pom.xml"))
.addExecutable(SOURCE.file("mvnw"), to("mvnw"))
.addExecutable(SOURCE.file("mvnw.cmd"), to("mvnw.cmd"))
.batch(SOURCE.append(".mvn/wrapper"), to(".mvn/wrapper"))
.addFile("maven-wrapper.jar")
.addFile("maven-wrapper.properties")
.and()
.and()
.javaBuildPlugins()
.plugin(mavenCompilerPlugin())
Expand All @@ -51,6 +43,26 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
//@formatter:on
}

public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties properties) {
return mavenWrapperModulesFiles(properties).build();
}

private JHipsterModuleBuilder mavenWrapperModulesFiles(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return moduleBuilder(properties)
.files()
.addExecutable(SOURCE.file("mvnw"), to("mvnw"))
.addExecutable(SOURCE.file("mvnw.cmd"), to("mvnw.cmd"))
.batch(SOURCE.append(".mvn/wrapper"), to(".mvn/wrapper"))
.addFile("maven-wrapper.jar")
.addFile("maven-wrapper.properties")
.and()
.and();
//@formatter:on
}

private JavaBuildPlugin mavenCompilerPlugin() {
return javaBuildPlugin()
.groupId(APACHE_PLUGINS_GROUP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ JHipsterModuleResource mavenModule(MavenApplicationService maven) {
.apiDoc("Build Tool", "Init Maven project with pom.xml and wrapper")
.organization(JHipsterModuleOrganization.builder().feature("java-build-tool").addModuleDependency("init").build())
.tags("buildtool", "test")
.factory(maven::buildModule);
.factory(maven::buildMavenModule);
}

@Bean
JHipsterModuleResource mavenWrapperModule(MavenApplicationService maven) {
return JHipsterModuleResource
.builder()
.slug("maven-wrapper")
.withoutProperties()
.apiDoc("Build Tool", "Add maven wrapper")
.standalone()
.tags("buildtool", "test")
.factory(maven::buildMavenWrapperModule);
}
}
9 changes: 9 additions & 0 deletions src/test/features/maven.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ Feature: Maven module
| projectNmae | Jhipster |
Then I should have files in "."
| pom.xml |

Scenario: Should apply maven wrapper module
When I apply "maven-wrapper" module to default project without parameters
Then I should have files in ".mvn/wrapper"
| maven-wrapper.jar |
| maven-wrapper.properties |
Then I should have files in ""
| mvnw.cmd |
| mvnw |
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class MavenModuleFactoryTest {
private static final MavenModuleFactory factory = new MavenModuleFactory();

@Test
void shouldBuildModule() {
void shouldBuildMavenModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.basePackage("com.jhipster.test")
.projectBaseName("myApp")
.projectName("JHipster test")
.build();

JHipsterModule module = factory.buildModule(properties);
JHipsterModule module = factory.buildMavenModule(properties);

assertThatModuleWithFiles(module, readmeFile())
.hasFile("pom.xml")
Expand Down Expand Up @@ -178,4 +178,15 @@ void shouldBuildModule() {
.hasFile("README.md")
.containing("./mvnw");
}

@Test
void shouldBuildMavenWrapperModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).build();

JHipsterModule module = factory.buildMavenWrapperModule(properties);

assertThatModuleWithFiles(module)
.hasExecutableFiles("mvnw", "mvnw.cmd")
.hasPrefixedFiles(".mvn/wrapper", "maven-wrapper.jar", "maven-wrapper.properties");
}
}

0 comments on commit b9d33f1

Please sign in to comment.