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: new modules (prettier/status-reporter) to demonstrate how to add npm and java dependencies #85

Merged
merged 3 commits into from
Oct 15, 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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<version>${approvaltests.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand All @@ -100,6 +106,7 @@
<jacoco.version>0.8.12</jacoco.version>
<properties-maven-plugin.version>1.2.1</properties-maven-plugin.version>
<sonar-maven-plugin.version>4.0.0.4121</sonar-maven-plugin.version>
<approvaltests.version>24.4.0</approvaltests.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.jhipster.lite.extension.generator.prettier.properties.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.extension.generator.prettier.properties.domain.PrettierPluginsModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class PrettierPluginsApplicationService {

private final PrettierPluginsModuleFactory factory;

public PrettierPluginsApplicationService() {
factory = new PrettierPluginsModuleFactory();
}

public JHipsterModule buildPropertiesPluginModule(JHipsterModuleProperties properties) {
return factory.buildPropertiesPluginModule(properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tech.jhipster.lite.extension.generator.prettier.properties.domain;

import static tech.jhipster.lite.extension.shared.dependencies.domain.JhliteExtensionSampleNpmVersionSource.JHLITE_EXTENSION_SAMPLE;
import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

public class PrettierPluginsModuleFactory {

public JHipsterModule buildPropertiesPluginModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
.packageJson()
.addDevDependency(packageName("prettier-plugin-properties"), JHLITE_EXTENSION_SAMPLE)
.and()
.preCommitActions(stagedFilesFilter("*.properties"), preCommitCommands("prettier --write"))
.build();
//@formatter:on
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tech.jhipster.lite.BusinessContext
package tech.jhipster.lite.extension.generator.prettier.properties;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tech.jhipster.lite.extension.generator.prettier.properties.primary;

import static tech.jhipster.lite.extension.shared.slug.domain.JhliteExtensionSampleModuleSlug.PRETTIER_PLUGIN_PROPERTIES;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.PRETTIER;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.extension.generator.prettier.properties.application.PrettierPluginsApplicationService;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;

@Configuration
class PrettierPluginsModuleConfiguration {

@Bean
JHipsterModuleResource prettierPropertiesModule(PrettierPluginsApplicationService prettierPlugins) {
return JHipsterModuleResource.builder()
.slug(PRETTIER_PLUGIN_PROPERTIES)
.propertiesDefinition(JHipsterModulePropertiesDefinition.EMPTY)
.apiDoc("Prettier", "Format .properties files with prettier")
.organization(JHipsterModuleOrganization.builder().addDependency(PRETTIER).build())
.tags("prettier")
.factory(prettierPlugins::buildPropertiesPluginModule);
}
}
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
@@ -0,0 +1,19 @@
package tech.jhipster.lite.extension.shared.dependencies.domain;

import tech.jhipster.lite.module.domain.npm.NpmVersionSource;
import tech.jhipster.lite.module.domain.npm.NpmVersionSourceFactory;

public enum JhliteExtensionSampleNpmVersionSource implements NpmVersionSourceFactory {
JHLITE_EXTENSION_SAMPLE("jhlite-extension-sample");

private final String source;

JhliteExtensionSampleNpmVersionSource(String source) {
this.source = source;
}

@Override
public NpmVersionSource build() {
return new NpmVersionSource(source);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tech.jhipster.lite.extension.shared.dependencies.infrastructure.secondary;

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.module.domain.ProjectFiles;
import tech.jhipster.lite.module.domain.javadependency.JavaDependenciesVersions;
import tech.jhipster.lite.module.infrastructure.secondary.javadependency.FileSystemMavenDependenciesReader;
import tech.jhipster.lite.module.infrastructure.secondary.javadependency.JavaDependenciesReader;

@Repository
@Order(Ordered.HIGHEST_PRECEDENCE)
public class JhliteExtensionSampleMavenDependenciesReader implements JavaDependenciesReader {

private static final String CURRENT_VERSIONS_FILE = "/generator/jhlite-extension-sample-dependencies/pom.xml";

private final FileSystemMavenDependenciesReader reader;

public JhliteExtensionSampleMavenDependenciesReader(ProjectFiles files) {
this.reader = new FileSystemMavenDependenciesReader(files, CURRENT_VERSIONS_FILE);
}

@Override
public JavaDependenciesVersions get() {
return reader.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tech.jhipster.lite.extension.shared.dependencies.infrastructure.secondary;

import java.util.List;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.extension.shared.dependencies.domain.JhliteExtensionSampleNpmVersionSource;
import tech.jhipster.lite.module.domain.ProjectFiles;
import tech.jhipster.lite.module.domain.npm.NpmPackagesVersions;
import tech.jhipster.lite.module.infrastructure.secondary.npm.FileSystemNpmVersionReader;
import tech.jhipster.lite.module.infrastructure.secondary.npm.NpmVersionsReader;

@Repository
@Order(Ordered.HIGHEST_PRECEDENCE)
public class JhliteExtensionSampleNpmVersionReader implements NpmVersionsReader {

private static final String PARENT_FOLDER = "/generator/jhlite-extension-sample-dependencies/";

private final FileSystemNpmVersionReader reader;

public JhliteExtensionSampleNpmVersionReader(ProjectFiles projectFiles) {
reader = new FileSystemNpmVersionReader(projectFiles, List.of(JhliteExtensionSampleNpmVersionSource.values()), PARENT_FOLDER);
}

@Override
public NpmPackagesVersions get() {
return reader.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tech.jhipster.lite.extension.SharedKernel
package tech.jhipster.lite.extension.shared.dependencies;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public enum JhliteExtensionSampleModuleSlug implements JHipsterModuleSlugFactory
BANNER_JHIPSTER_V3("banner-jhipster-v3"),
BANNER_JHIPSTER_V7("banner-jhipster-v7"),
BANNER_JHIPSTER_V7_REACT("banner-jhipster-v7-react"),
BANNER_JHIPSTER_V7_VUE("banner-jhipster-v7-vue");
BANNER_JHIPSTER_V7_VUE("banner-jhipster-v7-vue"),
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
@@ -0,0 +1,5 @@
{
"dependencies": {
"prettier-plugin-properties": "0.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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>

<artifactId>jhlite-extension-sample-dependencies</artifactId>
<version>0.0.7-SNAPSHOT</version>
<name>JHLite Extension Sample dependencies</name>
<description>JHLite Extension Sample dependencies list</description>
<packaging>pom</packaging>

<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>
8 changes: 8 additions & 0 deletions src/test/features/prettier-plugins.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Prettier Plugins

Scenario: Should apply properties plugin
When I apply modules to default project
| init |
| prettier |
| prettier-plugin-properties |
Then I should have "prettier-plugin-properties" in "package.json"
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
Expand Up @@ -11,7 +11,10 @@
@ComponentTest
@IncludeEngines("cucumber")
@SuppressWarnings("java:S2187")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "tech.jhipster.lite.extension, tech.jhipster.lite.module.infrastructure.primary")
@ConfigurationParameter(
key = GLUE_PROPERTY_NAME,
value = "tech.jhipster.lite.extension, tech.jhipster.lite.module.infrastructure.primary, tech.jhipster.lite.project.infrastructure.primary"
)
@ConfigurationParameter(
key = PLUGIN_PROPERTY_NAME,
value = "pretty, json:target/cucumber/cucumber.json, html:target/cucumber/cucumber.htm, junit:target/cucumber/TEST-cucumber.xml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tech.jhipster.lite.extension.generator.prettier.properties.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.JhliteExtensionSampleNpmVersionReader;
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.TestJHipsterModules;

@UnitTest
class PrettierPluginsModuleFactoryTest {

private final PrettierPluginsModuleFactory factory = new PrettierPluginsModuleFactory();

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

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

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

JHipsterModule module = factory.buildPropertiesPluginModule(properties);

assertThatModuleWithFiles(module, packageJsonFile())
.hasFile("package.json")
.containing(
"""
"prettier-plugin-properties": "\
"""
);
}

public static ModuleFile packageJsonFile() {
return file("src/test/resources/projects/empty-node/package.json", "package.json");
}
}
Loading