Skip to content

Commit

Permalink
Merge pull request #2793 from DamnClin/get-existing-project-properties
Browse files Browse the repository at this point in the history
Get existing project properties
  • Loading branch information
pascalgrimaud authored Jul 27, 2022
2 parents ca87a00 + 19a002f commit e112595
Show file tree
Hide file tree
Showing 117 changed files with 1,021 additions and 2,163 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ sonar.issue.ignore.multicriteria.S4036.resourceKey=src/main/java/tech/jhipster/l
sonar.issue.ignore.multicriteria.S4036.ruleKey=java:S4036

# Rule: Allow temp files writting for downloads
sonar.issue.ignore.multicriteria.S5443.resourceKey=src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
sonar.issue.ignore.multicriteria.S5443.resourceKey=src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectDownloader.java
sonar.issue.ignore.multicriteria.S5443.ruleKey=java:S5443
20 changes: 0 additions & 20 deletions src/main/java/tech/jhipster/lite/common/domain/JsonUtils.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.lite.generator.client.angular.security.jwt.application.AngularJwtApplicationService;
import tech.jhipster.lite.generator.project.domain.GeneratorAction;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO;
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep;

@RestController
@RequestMapping("/api/clients/angular/jwt")
Expand All @@ -27,7 +25,6 @@ public AngularJwtResource(AngularJwtApplicationService angularJwtApplicationServ
@Operation(summary = "Add Angular with authentication JWT")
@ApiResponse(responseCode = "500", description = "An error occurred while adding Angular with authentication JWT")
@PostMapping
@GeneratorStep(id = GeneratorAction.ANGULAR_JWT)
public void addJwtAngular(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
angularJwtApplicationService.addJwtAngular(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.lite.generator.client.angular.security.oauth2.application.AngularOauth2ApplicationService;
import tech.jhipster.lite.generator.project.domain.GeneratorAction;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO;
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep;

@RestController
@RequestMapping("/api/clients/angular/oauth2")
Expand All @@ -27,7 +25,6 @@ public AngularOauth2Resource(AngularOauth2ApplicationService angularOauth2Applic
@Operation(summary = "Add OAuth2 authentication")
@ApiResponse(responseCode = "500", description = "An error occurred while adding OAuth2 authentication")
@PostMapping
@GeneratorStep(id = GeneratorAction.ANGULAR_OAUTH2)
public void addJwtAngular(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
angularOauth2ApplicationService.addOauth2(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.lite.generator.client.svelte.core.application.SvelteApplicationService;
import tech.jhipster.lite.generator.project.domain.GeneratorAction;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO;
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep;

@RestController
@RequestMapping("/api/clients/svelte")
Expand All @@ -27,7 +25,6 @@ public SvelteResource(SvelteApplicationService svelteApplicationService) {
@Operation(summary = "Add Svelte", description = "Add Svelte")
@ApiResponse(responseCode = "500", description = "An error occurred while adding Svelte")
@PostMapping
@GeneratorStep(id = GeneratorAction.SVELTE)
public void addSvelte(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
svelteApplicationService.addSvelte(project);
Expand All @@ -36,7 +33,6 @@ public void addSvelte(@RequestBody ProjectDTO projectDTO) {
@Operation(summary = "Add SvelteKit with minimal CSS")
@ApiResponse(responseCode = "500", description = "An error occurred while adding SvelteKit with minimal CSS")
@PostMapping("/styles")
@GeneratorStep(id = GeneratorAction.SVEKTEKIT_STYLE)
public void addStyledSvelteKit(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
svelteApplicationService.addStyledSvelteKit(project);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package tech.jhipster.lite.generator.packagemanager.npm.domain;

import static tech.jhipster.lite.common.domain.FileUtils.getPath;
import static tech.jhipster.lite.common.domain.WordUtils.CB;
import static tech.jhipster.lite.common.domain.WordUtils.DQ;
import static tech.jhipster.lite.common.domain.WordUtils.LF;
import static tech.jhipster.lite.common.domain.WordUtils.OB;
import static tech.jhipster.lite.common.domain.WordUtils.indent;
import static tech.jhipster.lite.generator.project.domain.Constants.DEPENDENCIES_FOLDER;
import static tech.jhipster.lite.generator.project.domain.Constants.PACKAGE_JSON;
import static tech.jhipster.lite.generator.project.domain.Constants.TEMPLATE_FOLDER;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PRETTIER_DEFAULT_INDENT;
import static tech.jhipster.lite.common.domain.FileUtils.*;
import static tech.jhipster.lite.common.domain.WordUtils.*;
import static tech.jhipster.lite.generator.project.domain.Constants.*;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*;

import java.util.Optional;
import java.util.function.Function;
import tech.jhipster.lite.common.domain.FileUtils;
import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.generator.project.domain.Project;
Expand Down Expand Up @@ -78,36 +73,21 @@ public void prettify(Project project) {
this.npmRepository.npmPrettierFormat(project);
}

@Override
public Optional<String> getVersionInCommon(String name) {
return getVersion("common", name);
}

@Override
public Optional<String> getVersion(String folder, String name) {
assertFolder(folder);
Assert.notBlank("name", name);
return FileUtils
.readLineInClasspath(getPath(TEMPLATE_FOLDER, DEPENDENCIES_FOLDER, folder, PACKAGE_JSON), DQ + name + DQ)
.map(readValue -> {
String[] result = readValue.split(":");
if (result.length == 2) {
return result[1].replace(",", "").replace(DQ, "").replace(" ", "");
}
return null;
});
.map(toProperty());
}

@Override
public Optional<String> getName(String folder) {
assertFolder(folder);
return FileUtils.getValueBetween(getPath(folder, PACKAGE_JSON), NAME + ": " + DQ, DQ);
}
private Function<String, String> toProperty() {
return readValue -> {
String[] result = readValue.split(":");

@Override
public Optional<String> getDescription(String folder) {
assertFolder(folder);
return FileUtils.getValueBetween(getPath(folder, PACKAGE_JSON), DESCRIPTION + ": " + DQ, DQ);
return result[1].replace(",", "").replace(DQ, "").replace(" ", "");
};
}

private void assertFolder(String folder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ public interface NpmService {
void prettify(Project project);

Optional<String> getVersion(String folder, String name);
Optional<String> getVersionInCommon(String name);

Optional<String> getName(String folder);
Optional<String> getDescription(String folder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.lite.generator.packagemanager.npm.application.NpmApplicationService;
import tech.jhipster.lite.generator.project.domain.GeneratorAction;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO;
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep;

@RestController
@RequestMapping("/api/package-managers/npm")
Expand All @@ -27,7 +25,6 @@ public NpmResource(NpmApplicationService npmApplicationService) {
@Operation(summary = "Run: npm install")
@ApiResponse(responseCode = "500", description = "An error occurred while installing project")
@PostMapping("/install")
@GeneratorStep(id = GeneratorAction.NPM_INSTALL)
public void install(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
npmApplicationService.install(project);
Expand All @@ -36,7 +33,6 @@ public void install(@RequestBody ProjectDTO projectDTO) {
@Operation(summary = "Run: npm run prettier:format")
@ApiResponse(responseCode = "500", description = "An error occurred while prettifying project")
@PostMapping("/prettier-format")
@GeneratorStep(id = GeneratorAction.NPM_PRETTIFY)
public void prettify(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
npmApplicationService.prettify(project);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ private Constants() {}
public static final String PACKAGE_JSON = "package.json";
public static final String DOCKERFILE = "Dockerfile";
public static final String INTEGRATION_TEST = "IntegrationTest.java";
public static final String JHIPSTER_FOLDER = ".jhipster";
public static final String HISTORY_JSON = "history.json";
public static final String TSCONFIG_JSON = "tsconfig.json";
public static final String README_MD = "README.md";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private Project(ProjectBuilder builder) {
Assert.notNull("config", builder.config);

this.folder = builder.folder;
this.endOfLine = Optional.ofNullable(builder.endOfLine).orElseGet(this::detectEndOfLineOrDefault);
this.endOfLine = detectEndOfLineOrDefault();
this.config = builder.config;
this.remoteUrl = Optional.ofNullable(builder.remoteUrl);
this.language = Optional.ofNullable(builder.language);
Expand Down Expand Up @@ -197,7 +197,7 @@ public int getServerPort() {
* @return "\r\n" if found or "\n" otherwise
* @see FileUtils#detectEndOfLine(String)
*/
public String detectEndOfLineOrDefault() {
private String detectEndOfLineOrDefault() {
Optional<String> eol = Optional.empty();
try (Stream<Path> paths = Files.list(Path.of(this.folder)).filter(Files::isRegularFile)) {
List<String> filenames = paths.map(Path::toString).toList();
Expand All @@ -216,7 +216,6 @@ public String detectEndOfLineOrDefault() {
public static class ProjectBuilder {

private String folder;
private String endOfLine;
private Map<String, Object> config = new HashMap<>();
private String remoteUrl;
private LanguageType language;
Expand All @@ -237,11 +236,6 @@ public ProjectBuilder folder(String folder) {
return this;
}

public ProjectBuilder endOfLine(String endOfLine) {
this.endOfLine = endOfLine;
return this;
}

public ProjectBuilder config(Map<String, Object> config) {
if (config != null) {
this.config = config;
Expand Down
Loading

0 comments on commit e112595

Please sign in to comment.