Skip to content

Commit b819362

Browse files
authored
CLI refactoring using Picocli (#20)
1 parent 0489e36 commit b819362

26 files changed

+1122
-832
lines changed

.editorconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# File generated by jbang setup@jabrena
4+
5+
# top-most EditorConfig file
6+
root = true
7+
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.html]
15+
indent_style = space
16+
indent_size = 4
17+
18+
[*.json]
19+
indent_style = space
20+
indent_size = 4
21+
22+
[*.xml]
23+
indent_style = space
24+
indent_size = 4
25+
26+
[*.java]
27+
indent_style = space
28+
indent_size = 4
29+
30+
[*.yml,*.yaml]
31+
indent_style = space
32+
indent_size = 2
33+
34+
[*.dsl]
35+
indent_style = space
36+
indent_size = 4

.github/workflows/build_standard.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 0
17-
- name: Set up JDK 11
18-
uses: actions/setup-java@v1
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
1919
with:
20-
java-version: 11
20+
distribution: 'temurin' # See 'Supported distributions' for available options
21+
java-version: 17
2122
- name: Install Graphviz
2223
run: sudo apt-get -y install graphviz
2324
- name: Gradle caches
@@ -44,7 +45,7 @@ jobs:
4445
path: ./out
4546
if-no-files-found: error
4647

47-
validate_java_11:
48+
validate_java_17:
4849
runs-on: ubuntu-latest
4950
needs:
5051
- build
@@ -56,14 +57,15 @@ jobs:
5657
path: ./out
5758
- name: Grant execute permission for cm
5859
run: chmod +x ./out/bin/cm
59-
- name: Set up JDK 11
60-
uses: actions/setup-java@v1
60+
- name: Set up JDK 17
61+
uses: actions/setup-java@v4
6162
with:
62-
java-version: 11
63+
distribution: 'temurin' # See 'Supported distributions' for available options
64+
java-version: 17
6365
- name: Execute to check if Java version is compatible
6466
run: ./out/bin/cm
6567

66-
validate_java_17:
68+
validate_java_21:
6769
runs-on: ubuntu-latest
6870
needs:
6971
- build
@@ -75,14 +77,15 @@ jobs:
7577
path: ./out
7678
- name: Grant execute permission for cm
7779
run: chmod +x ./out/bin/cm
78-
- name: Set up JDK 17
79-
uses: actions/setup-java@v1
80+
- name: Set up JDK 21
81+
uses: actions/setup-java@v4
8082
with:
81-
java-version: 17
83+
distribution: 'temurin' # See 'Supported distributions' for available options
84+
java-version: '21'
8285
- name: Execute to check if Java version is compatible
8386
run: ./out/bin/cm
8487

85-
validate_java_21:
88+
validate_java_24:
8689
runs-on: ubuntu-latest
8790
needs:
8891
- build
@@ -94,9 +97,10 @@ jobs:
9497
path: ./out
9598
- name: Grant execute permission for cm
9699
run: chmod +x ./out/bin/cm
97-
- name: Set up JDK 21
98-
uses: actions/setup-java@v1
100+
- name: Set up JDK 24
101+
uses: actions/setup-java@v4
99102
with:
100-
java-version: 21
103+
distribution: 'temurin' # See 'Supported distributions' for available options
104+
java-version: '24'
101105
- name: Execute to check if Java version is compatible
102106
run: ./out/bin/cm

.gitignore

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
1-
# Compiled class file
2-
*.class
3-
**/target
4-
**/out
5-
6-
# Build
7-
/build
1+
build/
82
.gradle/
9-
10-
# Log file
11-
*.log
12-
13-
# BlueJ files
14-
*.ctxt
15-
16-
# Mobile Tools for Java (J2ME)
17-
.mtj.tmp/
18-
19-
# Package Files #
20-
*.jar
21-
*.war
22-
*.nar
23-
*.ear
24-
*.zip
25-
*.tar.gz
26-
*.rar
27-
28-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
29-
hs_err_pid*
30-
31-
# IntelliJ
32-
/.idea
3+
.cursor/
4+
.DS_Store

.sdkmanrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java=17.0.9-graalce

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ The following examples illustrate the CLI usage.
8989
If you want to contribute to this project you can create a fork and a pull request. The project is built with Gradle, so you can import it as Gradle project within Eclipse or IntelliJ IDEA (or any other IDE supporting Gradle).
9090
9191
```bash
92+
# Use sdkman or install manually JDK 17
93+
sdk env install
94+
9295
./gradlew clean build
96+
./gradlew clean build jacocoTestReport
97+
jwebserver -p 9000 -d "$(pwd)/build/reports/"
98+
./gradlew clean build snapshot
99+
java -jar build/libs/context-mapper-cli-0.1.0-SNAPSHOT.jar
93100
```
94101
95102
## Contributing
@@ -100,4 +107,3 @@ Contribution is always welcome! Here are some ways how you can contribute:
100107
101108
## Licence
102109
ContextMapper is released under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
103-

build.gradle

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,38 @@ plugins {
77
id 'nebula.release' version '19.0.10'
88
}
99

10-
group 'org.contextmapper'
10+
group = 'org.contextmapper'
1111

12-
sourceCompatibility = '11'
13-
targetCompatibility = '11'
12+
java {
13+
sourceCompatibility = JavaVersion.VERSION_17
14+
targetCompatibility = JavaVersion.VERSION_17
15+
}
1416

1517
repositories {
1618
mavenCentral()
1719
}
1820

1921
dependencies {
20-
implementation "commons-cli:commons-cli:${commonsCliVersion}"
2122
implementation "org.contextmapper:context-mapper-dsl:${cmlVersion}"
23+
implementation "info.picocli:picocli:${picocliVersion}"
2224

2325
testImplementation "org.junit.jupiter:junit-jupiter-api:${jUnitVersion}"
2426
testImplementation "org.junit.jupiter:junit-jupiter-params:${jUnitVersion}"
2527
testImplementation "org.assertj:assertj-core:${assertJVersion}"
2628
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
2729
testImplementation "org.mockito:mockito-junit-jupiter:${mockitoVersion}"
28-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jUnitVersion}"
2930
}
3031

3132
application {
32-
mainClassName = 'org.contextmapper.cli.ContextMapperCLI'
33-
applicationName = 'context-mapper-cli'
34-
}
35-
startScripts {
33+
mainClass = 'org.contextmapper.cli.ContextMapperCLI'
3634
applicationName = 'cm'
3735
}
36+
37+
javadoc {
38+
options.addStringOption('Xdoclint:none', '-quiet')
39+
failOnError false
40+
}
41+
3842
jar {
3943
manifest {
4044
attributes (
@@ -43,21 +47,25 @@ jar {
4347
'Main-Class': 'org.contextmapper.cli.ContextMapperCLI'
4448
)
4549
}
50+
from {
51+
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
52+
}
53+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
54+
exclude('META-INF/LICENSE.txt', 'META-INF/NOTICE.txt', 'META-INF/DEPENDENCIES')
55+
exclude('META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/services/**')
4656
}
4757

4858
if (!project.hasProperty('signing.secretKeyRingFile')) {
4959
project.ext.'signing.secretKeyRingFile' = "${rootDir}/secret-key.gpg"
5060
}
5161

5262
test {
53-
useJUnitPlatform()
54-
5563
testLogging {
56-
showExceptions true
57-
exceptionFormat "full"
64+
showExceptions = true
65+
exceptionFormat = "full"
5866

59-
showCauses true
60-
showStackTraces true
67+
showCauses = true
68+
showStackTraces = true
6169
}
6270
}
6371

@@ -146,14 +154,22 @@ signing {
146154
sign(publishing.publications)
147155
}
148156

157+
testing {
158+
suites {
159+
test(JvmTestSuite) {
160+
useJUnitJupiter(jUnitVersion)
161+
}
162+
}
163+
}
164+
149165
tasks.withType(GenerateModuleMetadata) {
150166
enabled = false
151167
}
152168

153-
tasks.withType(CreateStartScripts).each { task ->
154-
task.doLast {
155-
String text = task.windowsScript.text
169+
tasks.withType(CreateStartScripts).configureEach {
170+
doLast {
171+
String text = windowsScript.text
156172
text = text.replaceFirst(/(set CLASSPATH=%APP_HOME%\\lib\\).*/, { "${it[1]}*" })
157-
task.windowsScript.write text
173+
windowsScript.text = text
158174
}
159175
}

context_mapper_cli.feature

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Feature: Context Mapper CLI Usage
2+
As a user of the Context Mapper CLI
3+
I want to be able to validate CML files and generate various outputs
4+
So that I can effectively use the tool for my Domain-Driven Design modeling.
5+
6+
Background:
7+
Given the Context Mapper CLI is installed
8+
9+
Scenario: Display help for the validate command
10+
When I run the command `./cm validate -h`
11+
Then the output should contain:
12+
"""
13+
Context Mapper CLI
14+
usage: cm validate
15+
-h,--help Prints this message.
16+
-i,--input <arg> Path to the CML file which you want to validate.
17+
"""
18+
19+
Scenario: Validate a CML file
20+
Given a CML file named "DDD-Sample.cml" exists
21+
When I run the command `./cm validate -i DDD-Sample.cml`
22+
Then the CLI should validate "DDD-Sample.cml" successfully
23+
24+
Scenario: Display help for the generate command
25+
When I run the command `./cm generate -h`
26+
Then the output should contain:
27+
"""
28+
Context Mapper CLI
29+
usage: cm generate
30+
-f,--outputFile <arg> The name of the file that shall be generated
31+
(only used by Freemarker generator, as we cannot
32+
know the file extension).
33+
-g,--generator <arg> The generator you want to call. Use one of the
34+
following values: context-map (Graphical DDD
35+
Context Map), plantuml (PlantUML class-,
36+
component-, and state diagrams.), generic
37+
(Generate generic text with Freemarker template)
38+
-h,--help Prints this message.
39+
-i,--input <arg> Path to the CML file for which you want to
40+
generate output.
41+
-o,--outputDir <arg> Path to the directory into which you want to
42+
generate.
43+
-t,--template <arg> Path to the Freemarker template you want to use.
44+
This parameter is only used if you pass 'generic'
45+
to the 'generator' (-g) parameter.
46+
"""
47+
48+
Scenario: Generate PlantUML output
49+
Given a CML file named "DDD-Sample.cml" exists
50+
And an output directory named "output-directory"
51+
When I run the command `./cm generate -i DDD-Sample.cml -g plantuml -o ./output-directory`
52+
Then PlantUML diagrams should be generated in "./output-directory" from "DDD-Sample.cml"
53+
54+
Scenario: Generate Context Map output
55+
Given a CML file named "DDD-Sample.cml" exists
56+
And an output directory named "output-directory"
57+
When I run the command `./cm generate -i DDD-Sample.cml -g context-map -o ./output-directory`
58+
Then a Context Map should be generated in "./output-directory" from "DDD-Sample.cml"
59+
60+
Scenario: Generate arbitrary text file with Freemarker template
61+
Given a CML file named "DDD-Sample.cml" exists
62+
And an output directory named "output-directory"
63+
And a Freemarker template file named "template.md.ftl"
64+
When I run the command `./cm generate -i DDD-Sample.cml -g generic -o ./output-directory -t template.md.ftl -f glossary.md`
65+
Then a file named "glossary.md" should be generated in "./output-directory" using "template.md.ftl" and "DDD-Sample.cml"

gradle.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ ossSnapshotRepository=https://oss.sonatype.org/content/repositories/snapshots/
33
ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deploy/maven2/
44

55
# dependency versions
6-
jUnitVersion=5.9.1
7-
assertJVersion=3.19.0
8-
mockitoVersion=3.9.0
6+
jUnitVersion=5.12.2
7+
assertJVersion=3.27.3
8+
mockitoVersion=5.17.0
99

10-
commonsCliVersion=1.4
1110
cmlVersion=6.12.0
12-
11+
picocliVersion=4.7.7

0 commit comments

Comments
 (0)