-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from murdos/poc-npm-version-source
feat: new modules (prettier/status-reporter) to demonstrate how to add npm and java dependencies
- Loading branch information
Showing
26 changed files
with
700 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...xtension/generator/prettier/properties/application/PrettierPluginsApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ter/lite/extension/generator/prettier/properties/domain/PrettierPluginsModuleFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/tech/jhipster/lite/extension/generator/prettier/properties/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
26 changes: 26 additions & 0 deletions
26
...e/extension/generator/prettier/properties/primary/PrettierPluginsModuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...erver/springboot/startupreport/application/SpringBootStartupReportApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...enerator/server/springboot/startupreport/domain/SpringBootStartupReportModuleFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...boot/startupreport/infrastructure/primary/SpringBootStartupReportModuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
.../tech/jhipster/lite/extension/generator/server/springboot/startupreport/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
19 changes: 19 additions & 0 deletions
19
...ster/lite/extension/shared/dependencies/domain/JhliteExtensionSampleNpmVersionSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...d/dependencies/infrastructure/secondary/JhliteExtensionSampleMavenDependenciesReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...n/shared/dependencies/infrastructure/secondary/JhliteExtensionSampleNpmVersionReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/tech/jhipster/lite/extension/shared/dependencies/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...urces/generator/jhlite-extension-sample-dependencies/jhlite-extension-sample/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"prettier-plugin-properties": "0.3.0" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/resources/generator/jhlite-extension-sample-dependencies/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...lite/extension/generator/prettier/properties/domain/PrettierPluginsModuleFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.