Skip to content

Commit

Permalink
Merge pull request #488 from pascalgrimaud/init-prettier-xml
Browse files Browse the repository at this point in the history
Init prettier xml
  • Loading branch information
pascalgrimaud authored Jan 5, 2022
2 parents f91c2ac + 2e3f4f1 commit bfd88c2
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ overrides:
tabWidth: 2

# xml rules:
xmlWhitespaceSensitivity: ignore
xmlWhitespaceSensitivity: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static String getParent(Parent parent, int indentation) {
.append(VERSION_END)
.append(System.lineSeparator())
.append(indent(2, indentation))
.append("<relativePath/>")
.append("<relativePath />")
.append(System.lineSeparator())
.append(indent(1, indentation))
.append(PARENT_END);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void addLoggerToConfiguration(
String needleLogger
) {
String loggerWithNeedle =
String.format("<logger name=\"%s\" level=\"%s\"/>", packageName, level.toString()) + System.lineSeparator() + needleLogger;
String.format("<logger name=\"%s\" level=\"%s\" />", packageName, level.toString()) + System.lineSeparator() + " " + needleLogger;
projectRepository.replaceText(project, getPath(folderConfig), fileLoggingConfig, needleLogger, loggerWithNeedle);
}
}
18 changes: 9 additions & 9 deletions src/main/resources/generator/buildtool/maven/pom.xml.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?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">
<?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>{{packageName}}{{^packageName}}com.mycompany.myapp{{/packageName}}</groupId>
Expand Down Expand Up @@ -190,8 +192,7 @@
</goals>
<configuration>
<fileSets>
<fileSet
implementation="org.apache.maven.shared.model.fileset.FileSet">
<fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
<directory>${project.basedir}</directory>
<includes>
<include>**/*.exec</include>
Expand Down Expand Up @@ -229,7 +230,7 @@
<id>enforce-dependencyConvergence</id>
<configuration>
<rules>
<DependencyConvergence/>
<DependencyConvergence />
</rules>
<fail>false</fail>
</configuration>
Expand All @@ -241,8 +242,7 @@
<configuration>
<rules>
<requireMavenVersion>
<message>You are running an older version of Maven. JHipster requires at least Maven ${maven.version}
</message>
<message>You are running an older version of Maven. JHipster requires at least Maven ${maven.version}</message>
<version>[${maven.version},)</version>
</requireMavenVersion>
<requireJavaVersion>
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/generator/init/.prettierrc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ overrides:
- files: "*.java"
options:
tabWidth: {{prettierDefaultIndent}}{{^prettierDefaultIndent}}2{{/prettierDefaultIndent}}

# xml rules:
xmlWhitespaceSensitivity: ignore
5 changes: 3 additions & 2 deletions src/main/resources/generator/init/package.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"license": "UNLICENSED",
"scripts": {
"prepare": "husky install",
"prettier:check": "prettier --check \"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java}\"",
"prettier:format": "prettier --write \"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java}\""
"prettier:check": "prettier --check \"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\"",
"prettier:format": "prettier --write \"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\""
},
"devDependencies": {
"@prettier/plugin-xml": "1.2.0",
"husky": "7.0.4",
"lint-staged": "12.1.5",
"prettier": "2.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,3 @@ public class {{mainClass}}App {
return hostAddress;
}
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<include resource="org/springframework/boot/logging/logback/base.xml" />

<!-- The FILE and ASYNC appenders are here as examples for a production configuration -->
<!--
Expand All @@ -27,18 +26,17 @@
</root>
-->

<logger name="{{packageName}}" level="INFO"/>
<logger name="{{packageName}}" level="INFO" />

<logger name="ch.qos.logback" level="WARN"/>
<logger name="com.sun" level="WARN"/>
<logger name="org.springframework" level="WARN"/>
<logger name="ch.qos.logback" level="WARN" />
<logger name="com.sun" level="WARN" />
<logger name="org.springframework" level="WARN" />
<!-- jhipster-needle-logback-add-log -->

<!-- https://logback.qos.ch/manual/configuration.html#shutdownHook and https://jira.qos.ch/browse/LOGBACK-1090 -->
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

</configuration>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<include resource="org/springframework/boot/logging/logback/base.xml" />

<!-- The FILE and ASYNC appenders are here as examples for a production configuration -->
<!--
Expand All @@ -27,16 +26,15 @@
</root>
-->

<logger name="{{packageName}}" level="INFO"/>
<logger name="{{packageName}}" level="INFO" />

<logger name="ch.qos.logback" level="WARN"/>
<logger name="com.sun" level="WARN"/>
<logger name="org.springframework" level="WARN"/>
<logger name="ch.qos.logback" level="WARN" />
<logger name="com.sun" level="WARN" />
<logger name="org.springframework" level="WARN" />
<!-- jhipster-needle-logback-add-log -->

<root>
<level>WARN</level>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="CONSOLE" />
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void shouldAddParent() {
"<groupId>org.springframework.boot</groupId>",
"<artifactId>spring-boot-starter-parent</artifactId>",
"<version>2.5.3</version>",
"<relativePath/>",
"<relativePath />",
"</parent>"
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void shouldGetParent() {
" <groupId>org.springframework.boot</groupId>" + System.lineSeparator() +
" <artifactId>spring-boot-starter-parent</artifactId>" + System.lineSeparator() +
" <version>2.5.3</version>" + System.lineSeparator() +
" <relativePath/>" + System.lineSeparator() +
" <relativePath />" + System.lineSeparator() +
" </parent>";
// @formatter:on
Parent parent = Parent.builder().groupId("org.springframework.boot").artifactId("spring-boot-starter-parent").version("2.5.3").build();
Expand All @@ -37,7 +37,7 @@ void shouldGetParentWith4Indentations() {
" <groupId>org.springframework.boot</groupId>" + System.lineSeparator() +
" <artifactId>spring-boot-starter-parent</artifactId>" + System.lineSeparator() +
" <version>2.5.3</version>" + System.lineSeparator() +
" <relativePath/>" + System.lineSeparator() +
" <relativePath />" + System.lineSeparator() +
" </parent>";
// @formatter:on
Parent parent = Parent.builder().groupId("org.springframework.boot").artifactId("spring-boot-starter-parent").version("2.5.3").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ private void assertLoggerInConfig(Project project) {
project,
getPath(MAIN_RESOURCES, LOGGING_CONFIGURATION),
List.of(
"<logger name=\"org.hibernate.validator\" level=\"WARN\"/>",
"<logger name=\"org.hibernate\" level=\"WARN\"/>",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\"/>"
"<logger name=\"org.hibernate.validator\" level=\"WARN\" />",
"<logger name=\"org.hibernate\" level=\"WARN\" />",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\" />"
)
);

assertFileContent(
project,
getPath(TEST_RESOURCES, LOGGING_TEST_CONFIGURATION),
List.of(
"<logger name=\"org.hibernate.validator\" level=\"WARN\"/>",
"<logger name=\"org.hibernate\" level=\"WARN\"/>",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\"/>",
"<logger name=\"com.github.dockerjava\" level=\"WARN\"/>",
"<logger name=\"org.testcontainers\" level=\"WARN\"/>"
"<logger name=\"org.hibernate.validator\" level=\"WARN\" />",
"<logger name=\"org.hibernate\" level=\"WARN\" />",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\" />",
"<logger name=\"com.github.dockerjava\" level=\"WARN\" />",
"<logger name=\"org.testcontainers\" level=\"WARN\" />"
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,23 @@ private void assertLoggerInConfig(Project project) {
project,
getPath(MAIN_RESOURCES, LOGGING_CONFIGURATION),
List.of(
"<logger name=\"org.hibernate.validator\" level=\"WARN\"/>",
"<logger name=\"org.hibernate\" level=\"WARN\"/>",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\"/>",
"<logger name=\"org.postgresql\" level=\"WARN\"/>"
"<logger name=\"org.hibernate.validator\" level=\"WARN\" />",
"<logger name=\"org.hibernate\" level=\"WARN\" />",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\" />",
"<logger name=\"org.postgresql\" level=\"WARN\" />"
)
);

assertFileContent(
project,
getPath(TEST_RESOURCES, LOGGING_TEST_CONFIGURATION),
List.of(
"<logger name=\"org.hibernate.validator\" level=\"WARN\"/>",
"<logger name=\"org.hibernate\" level=\"WARN\"/>",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\"/>",
"<logger name=\"org.postgresql\" level=\"WARN\"/>",
"<logger name=\"com.github.dockerjava\" level=\"WARN\"/>",
"<logger name=\"org.testcontainers\" level=\"WARN\"/>"
"<logger name=\"org.hibernate.validator\" level=\"WARN\" />",
"<logger name=\"org.hibernate\" level=\"WARN\" />",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\" />",
"<logger name=\"org.postgresql\" level=\"WARN\" />",
"<logger name=\"com.github.dockerjava\" level=\"WARN\" />",
"<logger name=\"org.testcontainers\" level=\"WARN\" />"
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ private void assertLoggerInConfig(Project project) {
assertFileContent(
project,
getPath(MAIN_RESOURCES, LOGGING_CONFIGURATION),
List.of("<logger name=\"liquibase\" level=\"WARN\"/>", "<logger name=\"LiquibaseSchemaResolver\" level=\"INFO\"/>")
List.of("<logger name=\"liquibase\" level=\"WARN\" />", "<logger name=\"LiquibaseSchemaResolver\" level=\"INFO\" />")
);

assertFileContent(
project,
getPath(TEST_RESOURCES, LOGGING_TEST_CONFIGURATION),
List.of(
"<logger name=\"org.hibernate.validator\" level=\"WARN\"/>",
"<logger name=\"org.hibernate\" level=\"WARN\"/>",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\"/>"
"<logger name=\"org.hibernate.validator\" level=\"WARN\" />",
"<logger name=\"org.hibernate\" level=\"WARN\" />",
"<logger name=\"org.hibernate.ejb.HibernatePersistence\" level=\"OFF\" />"
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void shouldAddLoggerWithLevel() {
service.addLogger(project, "tech.jhipster.web", Level.DEBUG);

String applicationProperties = getPath(MAIN_RESOURCES, "logback-spring.xml");
assertFileContent(project, applicationProperties, "<logger name=\"tech.jhipster.web\" level=\"DEBUG\"/>");
assertFileContent(project, applicationProperties, "<logger name=\"tech.jhipster.web\" level=\"DEBUG\" />");
assertFileContent(project, applicationProperties, "<!-- jhipster-needle-logback-add-log -->");
}
}
Expand All @@ -60,7 +60,7 @@ void shouldAddLoggerWithLevel() {
service.addLoggerTest(project, "tech.jhipster.web", Level.DEBUG);

String applicationProperties = getPath(TEST_RESOURCES, "logback.xml");
assertFileContent(project, applicationProperties, "<logger name=\"tech.jhipster.web\" level=\"DEBUG\"/>");
assertFileContent(project, applicationProperties, "<logger name=\"tech.jhipster.web\" level=\"DEBUG\" />");
assertFileContent(project, applicationProperties, "<!-- jhipster-needle-logback-add-log -->");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void shouldInit() {

assertFileContent(project, getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=8080");
assertFileContent(project, getPath(TEST_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=0");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\"/>");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\" />");

assertTestUtil(project);
assertExceptionHandler(project);
Expand All @@ -62,7 +62,7 @@ void shouldAddSpringBootMvc() {

assertFileContent(project, getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=8080");
assertFileContent(project, getPath(TEST_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=0");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\"/>");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\" />");

assertTestUtil(project);
assertExceptionHandler(project);
Expand All @@ -82,7 +82,7 @@ void shouldAddSpringBootMvcWithServerPort() {

assertFileContent(project, getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=7419");
assertFileContent(project, getPath(TEST_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=0");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\"/>");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\" />");

assertTestUtil(project);
assertExceptionHandler(project);
Expand All @@ -102,7 +102,7 @@ void shouldAddSpringBootMvcWithInvalidServerPort() {

assertFileContent(project, getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=8080");
assertFileContent(project, getPath(TEST_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=0");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\"/>");
assertLoggingConfiguration(project, "<logger name=\"org.springframework.web\" level=\"WARN\" />");

assertTestUtil(project);
assertExceptionHandler(project);
Expand All @@ -121,7 +121,7 @@ void shouldAddSpringBootUndertow() {

assertFileContent(project, getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=8080");
assertFileContent(project, getPath(TEST_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=0");
assertLoggingConfiguration(project, "<logger name=\"io.undertow\" level=\"WARN\"/>");
assertLoggingConfiguration(project, "<logger name=\"io.undertow\" level=\"WARN\" />");

assertTestUtil(project);
assertExceptionHandler(project);
Expand All @@ -141,7 +141,7 @@ void shouldAddSpringBootUndertowWithServerPort() {

assertFileContent(project, getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=1664");
assertFileContent(project, getPath(TEST_RESOURCES, "config", APPLICATION_PROPERTIES), "server.port=0");
assertLoggingConfiguration(project, "<logger name=\"io.undertow\" level=\"WARN\"/>");
assertLoggingConfiguration(project, "<logger name=\"io.undertow\" level=\"WARN\" />");

assertTestUtil(project);
assertExceptionHandler(project);
Expand Down

0 comments on commit bfd88c2

Please sign in to comment.