Skip to content

Commit 073b68b

Browse files
committed
jooby-cli: improvements
- upgrade gradle generator to use the new plugin usage fix #1583 - add --openapi option #1584
1 parent 3477b47 commit 073b68b

File tree

10 files changed

+127
-36
lines changed

10 files changed

+127
-36
lines changed

modules/jooby-cli/build.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<project default="dependencies">
3+
<target name="dependencies">
4+
<property name="buildDir" value="${basedir}${file.separator}target${file.separator}classes" />
5+
<property name="file" value="${buildDir}${file.separator}dependencies.properties" />
6+
7+
<echo file="${file}" append="false">kotlinVersion=${kotlin.version}${line.separator}</echo>
8+
<echo file="${file}" append="true">mavenCompilerPluginVersion=${maven-compiler-plugin.version}${line.separator}</echo>
9+
<echo file="${file}" append="true">mavenSurefirePluginVersion=${maven-surefire-plugin.version}${line.separator}</echo>
10+
<echo file="${file}" append="true">mavenShadePluginVersion=${maven-shade-plugin.version}${line.separator}</echo>
11+
<echo file="${file}" append="true">storkMavenPluginVersion=${stork-maven-plugin.version}${line.separator}</echo>
12+
</target>
13+
</project>

modules/jooby-cli/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@
6868

6969
<build>
7070
<plugins>
71+
<plugin>
72+
<artifactId>maven-antrun-plugin</artifactId>
73+
<executions>
74+
<execution>
75+
<phase>generate-resources</phase>
76+
<configuration>
77+
<target>
78+
<ant antfile="${project.basedir}/build.xml"></ant>
79+
</target>
80+
</configuration>
81+
<goals>
82+
<goal>run</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
7187
<plugin>
7288
<groupId>org.apache.maven.plugins</groupId>
7389
<artifactId>maven-compiler-plugin</artifactId>

modules/jooby-cli/src/main/java/io/jooby/cli/Cli.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public class Cli extends Cmd {
6767
} else {
6868
ctx.println(
6969
"Unknown command or option(s): " + args.stream().collect(Collectors.joining(" ")));
70+
ctx.println(spec.commandLine().getUsageMessage());
7071
}
72+
} else {
73+
ctx.println(spec.commandLine().getUsageMessage());
7174
}
7275
}
7376

modules/jooby-cli/src/main/java/io/jooby/cli/Context.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.nio.file.Path;
1111
import java.nio.file.attribute.PosixFilePermission;
12+
import java.util.Map;
1213
import java.util.Set;
1314

1415
/**
@@ -56,6 +57,18 @@ void writeTemplate(@Nonnull String template, @Nonnull Object model, @Nonnull Pat
5657
void copyResource(@Nonnull String source, @Nonnull Path dest,
5758
@Nonnull Set<PosixFilePermission> permissions) throws IOException;
5859

60+
/**
61+
* List all dependencies and their version. Like:
62+
*
63+
* <pre>
64+
* kotlin.version = 1.2.3
65+
* </pre>
66+
*
67+
* @return Dependency map.
68+
* @throws IOException If something goes wrong.
69+
*/
70+
Map<String, String> getDependencyMap() throws IOException;
71+
5972
/**
6073
* Ask user for input.
6174
*

modules/jooby-cli/src/main/java/io/jooby/cli/CreateCmd.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class CreateCmd extends Cmd {
6363
private boolean kotlin;
6464

6565
@CommandLine.Option(
66-
names = {"-s", "--stork"},
66+
names = {"--stork"},
6767
description = "Add Stork Maven plugin to build (Maven only)"
6868
)
6969
private boolean stork;
@@ -81,7 +81,7 @@ public class CreateCmd extends Cmd {
8181
private String server;
8282

8383
@CommandLine.Option(
84-
names = {"-d", "--docker"},
84+
names = {"--docker"},
8585
description = "Generates a Dockerfile"
8686
)
8787
private boolean docker;
@@ -92,6 +92,12 @@ public class CreateCmd extends Cmd {
9292
)
9393
private boolean mvc;
9494

95+
@CommandLine.Option(
96+
names = {"--openapi"},
97+
description = "Configure build to generate OpenAPI files"
98+
)
99+
private boolean openapi;
100+
95101
@Override public void run(@Nonnull Context ctx) throws Exception {
96102
Path projectDir = ctx.getWorkspace().resolve(name);
97103
if (Files.exists(projectDir)) {
@@ -116,6 +122,8 @@ public class CreateCmd extends Cmd {
116122

117123
mvc = yesNo(ctx.readLine("Use MVC (yes/No): "));
118124

125+
openapi = yesNo(ctx.readLine("Configure OpenAPI (yes/No): "));
126+
119127
server = server(ctx.readLine("Choose a server (jetty, netty or undertow): "));
120128

121129
if (!gradle) {
@@ -157,6 +165,8 @@ public class CreateCmd extends Cmd {
157165
}
158166

159167
Map<String, Object> model = new HashMap<>();
168+
model.putAll(ctx.getDependencyMap());
169+
160170
model.put("package", packageName);
161171
model.put("groupId", packageName);
162172
model.put("artifactId", name);
@@ -171,6 +181,7 @@ public class CreateCmd extends Cmd {
171181
model.put("maven", !gradle);
172182
model.put("docker", docker);
173183
model.put("mvc", mvc);
184+
model.put("openapi", openapi);
174185
model.put("kapt", mvc && kotlin);
175186
model.put("apt", mvc && !kotlin);
176187
model.put("finalArtifactId", finalArtifactId);

modules/jooby-cli/src/main/java/io/jooby/internal/cli/CommandContextImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import java.nio.file.Paths;
2626
import java.nio.file.attribute.PosixFilePermission;
2727
import java.util.Collections;
28+
import java.util.LinkedHashMap;
29+
import java.util.Map;
30+
import java.util.Properties;
2831
import java.util.Set;
2932

3033
public class CommandContextImpl implements Context {
@@ -39,6 +42,8 @@ public class CommandContextImpl implements Context {
3942

4043
private JSONObject configuration;
4144

45+
private Properties versions;
46+
4247
public CommandContextImpl(LineReader reader, String version) throws IOException {
4348
this.reader = reader;
4449
this.out = reader.getTerminal().writer();
@@ -124,4 +129,16 @@ private void writeTemplate(String template, Object model, Writer writer)
124129
Files.setPosixFilePermissions(dest, permissions);
125130
}
126131
}
132+
133+
public Map<String, String> getDependencyMap() throws IOException {
134+
if (versions == null) {
135+
versions = new Properties();
136+
try (InputStream in = getClass().getResourceAsStream("/dependencies.properties")) {
137+
versions.load(in);
138+
}
139+
}
140+
Map result = new LinkedHashMap<>();
141+
result.putAll(versions);
142+
return result;
143+
}
127144
}

modules/jooby-cli/src/main/resources/cli/App.java.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package {{package}};
22

33
import io.jooby.Jooby;
4+
import io.jooby.OpenAPIModule;
45

56
public class App extends Jooby {
67

78
{
9+
{{#if openapi}}
10+
install(new OpenAPIModule());
11+
{{/if}}
12+
813
{{#if mvc}}
914
mvc(new Controller());
1015
{{else}}

modules/jooby-cli/src/main/resources/cli/App.kt.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package {{package}}
22

33
import io.jooby.Kooby
4+
import io.jooby.OpenAPIModule
45
import io.jooby.runApp
56

67
class App: Kooby({
8+
{{#if openapi}}
9+
install(OpenAPIModule())
10+
{{/if}}
11+
712
{{#if mvc}}
813
mvc(Controller())
914
{{else}}
Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
buildscript {
22
ext {
3-
kotlinVersion = "1.3.50"
3+
{{#if kotlin}}kotlinVersion = "{{kotlinVersion}}"{{/if}}
44
joobyVersion = "{{joobyVersion}}"
55
}
6+
}
67

7-
repositories {
8-
mavenLocal()
9-
jcenter()
10-
mavenCentral()
11-
}
12-
13-
dependencies {
14-
{{#kapt}}
15-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
16-
{{/kapt}}
17-
classpath "com.google.gradle:osdetector-gradle-plugin:1.4.0"
18-
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
19-
{{#if kotlin}}classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"{{/if}}
20-
classpath "io.jooby:jooby-gradle-plugin:$joobyVersion"
21-
classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
22-
}
8+
plugins {
9+
id "application"
10+
{{#if kotlin}}
11+
id "org.jetbrains.kotlin.jvm" version "{{kotlinVersion}}"
12+
{{/if}}
13+
{{#if kapt}}
14+
id "org.jetbrains.kotlin.kapt" version "{{kotlinVersion}}"
15+
{{/if}}
16+
{{#if openapi}}
17+
id "io.jooby.openAPI" version "${joobyVersion}"
18+
{{/if}}
19+
id "io.jooby.run" version "${joobyVersion}"
20+
id "io.spring.dependency-management" version "1.0.9.RELEASE"
21+
id "com.google.osdetector" version "1.6.2"
22+
id "com.github.johnrengelman.shadow" version "5.2.0"
2323
}
24-
apply plugin: "io.spring.dependency-management"
25-
apply plugin: "com.google.osdetector"
26-
apply plugin: "com.github.johnrengelman.shadow"
27-
apply plugin: "application"
28-
{{#kapt}}
29-
apply plugin: "org.jetbrains.kotlin.kapt"
30-
{{/kapt}}
31-
{{#if kotlin}}apply plugin: "kotlin"{{/if}}
32-
apply plugin: "jooby"
3324

3425
group "{{groupId}}"
3526
version "{{version}}"
@@ -38,8 +29,8 @@ sourceCompatibility = 1.8
3829

3930
repositories {
4031
mavenLocal()
41-
jcenter()
4232
mavenCentral()
33+
jcenter()
4334
}
4435

4536
dependencyManagement {
@@ -55,11 +46,11 @@ dependencies {
5546
annotationProcessor "io.jooby:jooby-apt"
5647
{{/if}}
5748
{{#each dependencies}}
58-
compile "{{this}}"
49+
implementation "{{this}}"
5950
{{/each}}
6051

6152
{{#each testDependencies}}
62-
testCompile "{{this}}"
53+
testImplementation "{{this}}"
6354
{{/each}}
6455
}
6556

@@ -83,3 +74,9 @@ tasks.withType(JavaCompile) {
8374
shadowJar {
8475
mergeServiceFiles()
8576
}
77+
78+
{{#openapi}}
79+
joobyRun.dependsOn openAPI
80+
81+
jar.dependsOn openAPI
82+
{{/openapi}}

modules/jooby-cli/src/main/resources/cli/pom.xml.hbs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<jooby.version>{{joobyVersion}}</jooby.version>
1919

2020
{{#if kotlin}}
21-
<kotlin.version>1.3.50</kotlin.version>
21+
<kotlin.version>{{kotlinVersion}}</kotlin.version>
2222
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
2323
{{/if}}
2424
<maven.compiler.source>1.8</maven.compiler.source>
@@ -101,7 +101,7 @@
101101
{{else}}
102102
<plugin>
103103
<artifactId>maven-compiler-plugin</artifactId>
104-
<version>3.8.1</version>
104+
<version>{{mavenCompilerPluginVersion}}</version>
105105
{{#if apt}}
106106
<configuration>
107107
<annotationProcessorPaths>
@@ -117,19 +117,30 @@
117117
{{/if}}
118118
<plugin>
119119
<artifactId>maven-surefire-plugin</artifactId>
120-
<version>3.0.0-M3</version>
120+
<version>{{mavenSurefirePluginVersion}}</version>
121121
</plugin>
122122
<!-- jooby:run -->
123123
<plugin>
124124
<groupId>io.jooby</groupId>
125125
<artifactId>jooby-maven-plugin</artifactId>
126126
<version>${jooby.version}</version>
127+
{{#if openapi}}
128+
<executions>
129+
<execution>
130+
<goals>
131+
<goal>openapi</goal>
132+
</goals>
133+
<configuration>
134+
</configuration>
135+
</execution>
136+
</executions>
137+
{{/if}}
127138
</plugin>
128139
{{#if stork}}
129140
<plugin>
130141
<groupId>com.fizzed</groupId>
131142
<artifactId>stork-maven-plugin</artifactId>
132-
<version>3.0.0</version>
143+
<version>{{storkMavenPluginVersion}}</version>
133144
<executions>
134145
<execution>
135146
<id>stork-launcher</id>
@@ -155,7 +166,7 @@
155166
<!-- Build uber jar -->
156167
<plugin>
157168
<artifactId>maven-shade-plugin</artifactId>
158-
<version>3.2.1</version>
169+
<version>{{mavenShadePluginVersion}}</version>
159170
<executions>
160171
<execution>
161172
<id>uber-jar</id>

0 commit comments

Comments
 (0)