Skip to content

Commit 57a4f70

Browse files
committed
formatter-maven-plugin
1 parent ff90612 commit 57a4f70

File tree

7 files changed

+80
-52
lines changed

7 files changed

+80
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- formatter-maven-plugin
1213
- startup doc initialization
1314

1415
### Changed

pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
1919
<base-native-build-args>-H:IncludeResources=graalkus/fm-doc-process-config.xml,-H:IncludeResources=graalkus/template/document.ftl</base-native-build-args>
2020
<quarkus.native.additional-build-args>${base-native-build-args}</quarkus.native.additional-build-args>
21+
<!-- formatter plugin -->
22+
<mvn-formatter-plugin-version>2.24.1</mvn-formatter-plugin-version>
23+
<fugerit-code-rules-version>0.1.1</fugerit-code-rules-version>
24+
<format.skip>false</format.skip>
2125
</properties>
2226
<dependencyManagement>
2327
<dependencies>
@@ -201,6 +205,31 @@
201205
<reportOutputFolder>${project.build.directory}/freemarker-syntax-verify-report</reportOutputFolder>
202206
</configuration>
203207
</plugin>
208+
<plugin>
209+
<groupId>net.revelc.code.formatter</groupId>
210+
<artifactId>formatter-maven-plugin</artifactId>
211+
<version>${mvn-formatter-plugin-version}</version>
212+
<dependencies>
213+
<dependency>
214+
<groupId>org.fugerit.java</groupId>
215+
<artifactId>fugerit-code-rules</artifactId>
216+
<version>${fugerit-code-rules-version}</version>
217+
</dependency>
218+
</dependencies>
219+
<configuration>
220+
<configFile>org/fugerit/java/coderules/eclipse-format.xml</configFile>
221+
<skip>${format.skip}</skip>
222+
</configuration>
223+
<executions>
224+
<execution>
225+
<id>format-sources</id>
226+
<phase>process-sources</phase>
227+
<goals>
228+
<goal>format</goal>
229+
</goals>
230+
</execution>
231+
</executions>
232+
</plugin>
204233
</plugins>
205234
</build>
206235
<profiles>

src/main/java/org/fugerit/java/demo/graalkus/AppInit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class AppInit {
1313
DocHelper docHelper;
1414

1515
void onStart(@Observes StartupEvent ev) {
16-
InitHandler.initDocAllAsync( docHelper.getDocProcessConfig().getFacade().handlers() );
16+
InitHandler.initDocAllAsync(docHelper.getDocProcessConfig().getFacade().handlers());
1717
}
1818

1919
}

src/main/java/org/fugerit/java/demo/graalkus/DocHelper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
@ApplicationScoped
1111
public class DocHelper {
1212

13-
private FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://graalkus/fm-doc-process-config.xml" );
13+
private FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade
14+
.loadConfigSafe("cl://graalkus/fm-doc-process-config.xml");
1415

15-
public FreemarkerDocProcessConfig getDocProcessConfig() { return this.docProcessConfig; }
16+
public FreemarkerDocProcessConfig getDocProcessConfig() {
17+
return this.docProcessConfig;
18+
}
1619

1720
}

src/main/java/org/fugerit/java/demo/graalkus/DocResource.java

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import jakarta.ws.rs.Path;
77
import jakarta.ws.rs.Produces;
88
import jakarta.ws.rs.WebApplicationException;
9-
import jakarta.ws.rs.core.MediaType;
109
import lombok.extern.slf4j.Slf4j;
1110
import org.fugerit.java.doc.base.config.DocConfig;
1211
import org.fugerit.java.doc.base.process.DocProcessContext;
@@ -32,12 +31,14 @@ byte[] processDocument(String handlerId) {
3231
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
3332
// creates the doc helper
3433
// create custom data for the fremarker template 'document.ftl'
35-
List<People> listPeople = Arrays.asList(new People("Luthien", "Tinuviel", "Queen"), new People("Thorin", "Oakshield", "King"));
34+
List<People> listPeople = Arrays.asList(new People("Luthien", "Tinuviel", "Queen"),
35+
new People("Thorin", "Oakshield", "King"));
3636
String chainId = "document";
3737
// output generation
38-
docHelper.getDocProcessConfig().fullProcess(chainId, DocProcessContext.newContext("listPeople", listPeople), handlerId, baos);
38+
docHelper.getDocProcessConfig().fullProcess(chainId, DocProcessContext.newContext("listPeople", listPeople),
39+
handlerId, baos);
3940
// return the output
40-
log.info( "processDocument handlerId:{}", handlerId );
41+
log.info("processDocument handlerId:{}", handlerId);
4142
return baos.toByteArray();
4243
} catch (Exception e) {
4344
String message = String.format("Error processing %s, error:%s", handlerId, e);
@@ -46,71 +47,64 @@ byte[] processDocument(String handlerId) {
4647
}
4748
}
4849

49-
@APIResponse(responseCode = "200", description = "The Markdown document content" )
50-
@APIResponse(responseCode = "500", description = "In case of an unexpected error" )
51-
@Tag( name = "document" )
52-
@Tag( name = "markdown" )
53-
@Operation( operationId = "MarkdownExample", summary = "Example Markdown generation",
54-
description = "Generates an example Markdown document using Fugerit Venus Doc handler" )
50+
@APIResponse(responseCode = "200", description = "The Markdown document content")
51+
@APIResponse(responseCode = "500", description = "In case of an unexpected error")
52+
@Tag(name = "document")
53+
@Tag(name = "markdown")
54+
@Operation(operationId = "MarkdownExample", summary = "Example Markdown generation", description = "Generates an example Markdown document using Fugerit Venus Doc handler")
5555
@GET
5656
@Produces("text/markdown")
5757
@Path("/example.md")
5858
public byte[] markdownExample() {
5959
return processDocument(DocConfig.TYPE_MD);
6060
}
6161

62-
@APIResponse(responseCode = "200", description = "The HTML document content" )
63-
@APIResponse(responseCode = "500", description = "In case of an unexpected error" )
64-
@Tag( name = "document" )
65-
@Tag( name = "html" )
66-
@Operation( operationId = "HTMLExample", summary = "Example HTML generation",
67-
description = "Generates an example HTML document using Fugerit Venus Doc handler" )
62+
@APIResponse(responseCode = "200", description = "The HTML document content")
63+
@APIResponse(responseCode = "500", description = "In case of an unexpected error")
64+
@Tag(name = "document")
65+
@Tag(name = "html")
66+
@Operation(operationId = "HTMLExample", summary = "Example HTML generation", description = "Generates an example HTML document using Fugerit Venus Doc handler")
6867
@GET
6968
@Produces("text/html")
7069
@Path("/example.html")
7170
public byte[] htmlExample() {
7271
return processDocument(DocConfig.TYPE_HTML);
7372
}
7473

75-
@APIResponse(responseCode = "200", description = "The AsciiDoc document content" )
76-
@APIResponse(responseCode = "500", description = "In case of an unexpected error" )
77-
@Tag( name = "document" )
78-
@Tag( name = "asciidoc" )
79-
@Operation( operationId = "AsciiDocExample", summary = "Example AsciiDoc generation",
80-
description = "Generates an example AsciiDoc document using Fugerit Venus Doc handler" )
74+
@APIResponse(responseCode = "200", description = "The AsciiDoc document content")
75+
@APIResponse(responseCode = "500", description = "In case of an unexpected error")
76+
@Tag(name = "document")
77+
@Tag(name = "asciidoc")
78+
@Operation(operationId = "AsciiDocExample", summary = "Example AsciiDoc generation", description = "Generates an example AsciiDoc document using Fugerit Venus Doc handler")
8179
@GET
8280
@Produces("text/asciidoc")
8381
@Path("/example.adoc")
8482
public byte[] asciidocExample() {
8583
return processDocument(DocConfig.TYPE_ADOC);
8684
}
8785

88-
@APIResponse(responseCode = "200", description = "The PDF document content" )
89-
@APIResponse(responseCode = "500", description = "In case of an unexpected error" )
90-
@Tag( name = "document" )
91-
@Tag( name = "pdf" )
92-
@Operation( operationId = "PDFExample", summary = "Example PDF generation",
93-
description = "Generates an example PDF document using Fugerit Venus Doc handler" )
86+
@APIResponse(responseCode = "200", description = "The PDF document content")
87+
@APIResponse(responseCode = "500", description = "In case of an unexpected error")
88+
@Tag(name = "document")
89+
@Tag(name = "pdf")
90+
@Operation(operationId = "PDFExample", summary = "Example PDF generation", description = "Generates an example PDF document using Fugerit Venus Doc handler")
9491
@GET
9592
@Produces("application/pdf")
9693
@Path("/example.pdf")
9794
public byte[] pdfExample() {
9895
return processDocument(DocConfig.TYPE_PDF);
9996
}
10097

101-
102-
@APIResponse(responseCode = "200", description = "The CSV document content" )
103-
@APIResponse(responseCode = "500", description = "In case of an unexpected error" )
104-
@Tag( name = "document" )
105-
@Tag( name = "csv" )
106-
@Operation( operationId = "CSVExample", summary = "Example CSV generation",
107-
description = "Generates an example CSV document using Fugerit Venus Doc handler" )
98+
@APIResponse(responseCode = "200", description = "The CSV document content")
99+
@APIResponse(responseCode = "500", description = "In case of an unexpected error")
100+
@Tag(name = "document")
101+
@Tag(name = "csv")
102+
@Operation(operationId = "CSVExample", summary = "Example CSV generation", description = "Generates an example CSV document using Fugerit Venus Doc handler")
108103
@GET
109104
@Produces("text/csv")
110105
@Path("/example.csv")
111106
public byte[] csvExample() {
112107
return processDocument(DocConfig.TYPE_CSV);
113108
}
114109

115-
116110
}

src/test/java/test/org/fugerit/java/demo/graalkus/DocHelperTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,31 @@
2929
* https://github.com/fugerit-org/fj-doc
3030
*
3131
* NOTE: This is a 'Hello World' style example, adapt it to your scenario, especially :
32-
* - change the doc handler and the output mode (here a ByteArrayOutputStream buffer is used)
32+
* - change the doc handler and the output mode (here a ByteArrayOutputStream buffer is used)
3333
*/
3434
@Slf4j
3535
class DocHelperTest {
3636

3737
@Test
3838
void testDocProcess() {
39-
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
39+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
4040
// creates the doc helper
4141
DocHelper docHelper = new DocHelper();
4242
// create custom data for the fremarker template 'document.ftl'
43-
List<People> listPeople = Arrays.asList( new People( "Luthien", "Tinuviel", "Queen" ), new People( "Thorin", "Oakshield", "King" ) );
44-
45-
43+
List<People> listPeople = Arrays.asList(new People("Luthien", "Tinuviel", "Queen"),
44+
new People("Thorin", "Oakshield", "King"));
45+
4646
String chainId = "document";
4747
// handler id
4848
String handlerId = DocConfig.TYPE_MD;
4949
// output generation
50-
docHelper.getDocProcessConfig().fullProcess( chainId, DocProcessContext.newContext( "listPeople", listPeople ), handlerId, baos );
50+
docHelper.getDocProcessConfig().fullProcess(chainId, DocProcessContext.newContext("listPeople", listPeople),
51+
handlerId, baos);
5152
// print the output
52-
log.info( "html output : \n{}", new String( baos.toByteArray(), StandardCharsets.UTF_8 ) );
53-
Assertions.assertNotEquals( 0, baos.size() );
53+
log.info("html output : \n{}", new String(baos.toByteArray(), StandardCharsets.UTF_8));
54+
Assertions.assertNotEquals(0, baos.size());
5455
} catch (Exception e) {
55-
log.error( String.format( "Error : %s", e.toString() ), e );
56+
log.error(String.format("Error : %s", e.toString()), e);
5657
}
5758
}
5859

src/test/java/test/org/fugerit/java/demo/graalkus/GreetingResourceTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class GreetingResourceTest {
1111
@Test
1212
void testHelloEndpoint() {
1313
given()
14-
.when().get("/hello")
15-
.then()
16-
.statusCode(200)
17-
.body(is("Hello from Quarkus REST"));
14+
.when().get("/hello")
15+
.then()
16+
.statusCode(200)
17+
.body(is("Hello from Quarkus REST"));
1818
}
1919

2020
}

0 commit comments

Comments
 (0)