Skip to content

Commit

Permalink
feat: sample module that add a maven dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
murdos committed Oct 14, 2024
1 parent 1c659b9 commit 123f126
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.jhipster.lite.extension.generator.server.springboot.startupreport.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.extension.generator.server.springboot.startupreport.domain.SpringBootStartupReportModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class SpringBootStartupReportApplicationService {

private final SpringBootStartupReportModuleFactory factory;

public SpringBootStartupReportApplicationService() {
this.factory = new SpringBootStartupReportModuleFactory();
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tech.jhipster.lite.extension.generator.server.springboot.startupreport.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.javaDependency;
import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.javadependency.JavaDependency;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

public class SpringBootStartupReportModuleFactory {

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);
return moduleBuilder(properties).javaDependencies().addDependency(startupReportDependency()).and().build();
}

private JavaDependency startupReportDependency() {
return javaDependency()
.groupId("com.maciejwalkowiak.spring")
.artifactId("spring-boot-startup-report")
.versionSlug("spring-boot-startup-report")
.optional()
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tech.jhipster.lite.extension.generator.server.springboot.startupreport.infrastructure.primary;

import static tech.jhipster.lite.extension.shared.slug.domain.JhliteExtensionSampleModuleSlug.*;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.SPRING_BOOT;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.extension.generator.server.springboot.startupreport.application.SpringBootStartupReportApplicationService;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;

@Configuration
class SpringBootStartupReportModuleConfiguration {

@Bean
JHipsterModuleResource springBootStartupReportResource(SpringBootStartupReportApplicationService springBootStartupReport) {
return JHipsterModuleResource.builder()
.slug(SPRING_BOOT_STARTUP_REPORT)
.withoutProperties()
.apiDoc(
"Spring Boot",
"Generates an interactive Spring Boot application startup report that lets you understand what contributes to the application startup time and perhaps helps to optimize it"
)
.organization(JHipsterModuleOrganization.builder().addDependency(SPRING_BOOT).build())
.tags("server", "spring", "spring-boot")
.factory(springBootStartupReport::buildModule);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tech.jhipster.lite.BusinessContext
package tech.jhipster.lite.extension.generator.server.springboot.startupreport;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public enum JhliteExtensionSampleModuleSlug implements JHipsterModuleSlugFactory
BANNER_JHIPSTER_V7("banner-jhipster-v7"),
BANNER_JHIPSTER_V7_REACT("banner-jhipster-v7-react"),
BANNER_JHIPSTER_V7_VUE("banner-jhipster-v7-vue"),
PRETTIER_PLUGIN_PROPERTIES("prettier-plugin-properties");
PRETTIER_PLUGIN_PROPERTIES("prettier-plugin-properties"),
SPRING_BOOT_STARTUP_REPORT("spring-boot-startup-report");

private final String slug;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@

<properties>
<!-- Version slugs of dependencies added by jhipster-lite modules should be declared here -->
<spring-boot-startup-report.version>0.2.0</spring-boot-startup-report.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- Dependencies that will be added by jhipster-lite modules should be declared here -->
<dependency>
<groupId>com.maciejwalkowiak.spring</groupId>
<artifactId>spring-boot-startup-report</artifactId>
<version>${spring-boot-startup-report.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>
</project>
5 changes: 5 additions & 0 deletions src/test/features/spring-boot-startup-report.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Prettier Plugins

Scenario: Should apply properties plugin
When I apply "spring-boot-startup-report" module to default project with maven file without parameters
Then I should have "spring-boot-startup-report" in "pom.xml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tech.jhipster.lite.extension.generator.server.springboot.startupreport.domain;

import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.jhipster.lite.TestFileUtils;
import tech.jhipster.lite.extension.UnitTest;
import tech.jhipster.lite.extension.shared.dependencies.infrastructure.secondary.JhliteExtensionSampleMavenDependenciesReader;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterModulesFixture;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles;
import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions;
import tech.jhipster.lite.module.infrastructure.secondary.TestJHipsterModules;

@UnitTest
class SpringBootStartupReportModuleFactoryTest {

private final SpringBootStartupReportModuleFactory factory = new SpringBootStartupReportModuleFactory();

@BeforeEach
void setup() {
TestJHipsterModules.register(new JhliteExtensionSampleMavenDependenciesReader(new FileSystemProjectFiles()));
}

@AfterEach
void tearDown() {
TestJHipsterModules.unregisterReaders();
}

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

JHipsterModule module = factory.buildModule(properties);

assertThatModuleWithFiles(module, pomFile()).hasFile("pom.xml").containing("spring-boot-startup-report");
}

public static JHipsterModulesAssertions.ModuleFile pomFile() {
return file("src/test/resources/projects/init-maven/pom.xml", "pom.xml");
}
}
196 changes: 196 additions & 0 deletions src/test/resources/projects/init-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>

<groupId>tech.jhipster.jhlitest</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>myapp</name>
<description>My App</description>
<packaging>jar</packaging>

<!-- jhipster-needle-maven-parent -->

<repositories>
<!-- jhipster-needle-maven-repository -->
</repositories>

<pluginRepositories>
<!-- jhipster-needle-maven-plugin-repository -->
</pluginRepositories>

<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.version>3.6.3</maven.version>
<maven-enforcer-plugin.version>3.0.0</maven-enforcer-plugin.version>

<junit-jupiter.version>5.8.2</junit-jupiter.version>
<assertj.version>3.22.0</assertj.version>
<mockito.version>4.2.0</mockito.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<!-- jhipster-needle-maven-property -->
</properties>

<dependencyManagement>
<dependencies>
<!-- jhipster-needle-maven-add-dependency-management -->
</dependencies>
</dependencyManagement>

<dependencies>
<!-- jhipster-needle-maven-add-dependency -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- jhipster-needle-maven-add-dependency-test -->
</dependencies>

<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>config/*.properties</include>
<include>config/*.yml</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>config/*.properties</exclude>
<exclude>config/*.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
<excludes>
<exclude>**/*IT*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<!-- Due to spring-boot repackage, without adding this property test classes are not found
See https://github.com/spring-projects/spring-boot/issues/6254 -->
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
<includes>
<include>**/*IT*</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- jhipster-needle-maven-add-plugin -->
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
<execution>
<id>enforce-dependencyConvergence</id>
<configuration>
<rules>
<DependencyConvergence />
</rules>
<fail>false</fail>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<requireMavenVersion>
<message>You are running an older version of Maven. JHipster requires at least Maven ${maven.version}</message>
<version>[${maven.version},)</version>
</requireMavenVersion>
<requireJavaVersion>
<message>You are running an incompatible version of Java. JHipster engine supports JDK 21+.</message>
<version>[21,22)</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
<!-- jhipster-needle-maven-add-plugin-management -->
</plugins>
</pluginManagement>
</build>
</project>
1 change: 1 addition & 0 deletions tests-ci/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ if [[ $application == 'fullapp' ]]; then
"banner-jhipster-v7" \
"prettier" \
"prettier-plugin-properties" \
"spring-boot-startup-report" \

else
echo "*** Unknown configuration..."
Expand Down

0 comments on commit 123f126

Please sign in to comment.