Skip to content

Commit ee42987

Browse files
authored
Merge pull request #941 from swagger-api/java-11-support
added java 11 support to java generators
2 parents a48fc03 + 6e7f175 commit ee42987

File tree

24 files changed

+234
-52
lines changed

24 files changed

+234
-52
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/AbstractJavaCodegen.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ public abstract class AbstractJavaCodegen extends DefaultCodegenConfig {
5454
public static final String DEFAULT_LIBRARY = "<default>";
5555
public static final String DATE_LIBRARY = "dateLibrary";
5656
public static final String JAVA8_MODE = "java8";
57+
public static final String JAVA11_MODE = "java11";
5758
public static final String WITH_XML = "withXml";
5859
public static final String SUPPORT_JAVA6 = "supportJava6";
5960
public static final String ERROR_ON_UNKNOWN_ENUM = "errorOnUnknownEnum";
6061
public static final String CHECK_DUPLICATED_MODEL_NAME = "checkDuplicatedModelName";
6162

6263
protected String dateLibrary = "threetenbp";
6364
protected boolean java8Mode = false;
65+
protected boolean java11Mode = false;
6466
protected boolean withXml = false;
6567
protected String invokerPackage = "io.swagger";
6668
protected String groupId = "io.swagger";
@@ -165,6 +167,7 @@ public AbstractJavaCodegen() {
165167
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
166168
Map<String, String> dateOptions = new HashMap<String, String>();
167169
dateOptions.put("java8", "Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets \"" + JAVA8_MODE + "\" to true");
170+
dateOptions.put("java11", "Java 11 native JSR384 (preferred for jdk 11+) - note: this also sets \"" + JAVA11_MODE + "\" to true");
168171
dateOptions.put("threetenbp", "Backport of JSR310 (preferred for jdk < 1.8)");
169172
dateOptions.put("java8-localdatetime", "Java 8 using LocalDateTime (for legacy app only)");
170173
dateOptions.put("joda", "Joda (for legacy app only)");
@@ -424,12 +427,10 @@ public void processOpts() {
424427
// used later in recursive import in postProcessingModels
425428
importMapping.put("com.fasterxml.jackson.annotation.JsonProperty", "com.fasterxml.jackson.annotation.JsonCreator");
426429

427-
if(additionalProperties.containsKey(JAVA8_MODE)) {
428-
setJava8Mode(Boolean.parseBoolean(additionalProperties.get(JAVA8_MODE).toString()));
429-
if ( java8Mode ) {
430-
additionalProperties.put("java8", true);
431-
}
432-
}
430+
setJava8Mode(Boolean.parseBoolean(String.valueOf(additionalProperties.get(JAVA8_MODE))));
431+
additionalProperties.put(JAVA8_MODE, java8Mode);
432+
setJava11Mode(Boolean.parseBoolean(String.valueOf(additionalProperties.get(JAVA11_MODE))));
433+
additionalProperties.put(JAVA11_MODE, java11Mode);
433434

434435
if(additionalProperties.containsKey(WITH_XML)) {
435436
setWithXml(Boolean.parseBoolean(additionalProperties.get(WITH_XML).toString()));
@@ -1538,6 +1539,10 @@ public void setJava8Mode(boolean enabled) {
15381539
this.java8Mode = enabled;
15391540
}
15401541

1542+
public void setJava11Mode(boolean java11Mode) {
1543+
this.java11Mode = java11Mode;
1544+
}
1545+
15411546
@Override
15421547
public String escapeQuotationMark(String input) {
15431548
// remove " to avoid code injection

src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
6868
protected boolean delegateMethod = false;
6969
protected boolean singleContentTypes = false;
7070
protected boolean java8 = false;
71+
protected boolean java11 = false;
7172
protected boolean async = false;
7273
protected String responseWrapper = "";
7374
protected boolean useTags = false;
@@ -181,10 +182,19 @@ public void processOpts() {
181182
if (!additionalProperties.containsKey(DATE_LIBRARY)) {
182183
setDateLibrary("java8");
183184
}
184-
} else {
185-
this.defaultInterfaces = false;
186185
}
187186

187+
if (additionalProperties.containsKey(JAVA11_MODE)) {
188+
this.setJava11(Boolean.valueOf(additionalProperties.get(JAVA11_MODE).toString()));
189+
}
190+
if (this.java11) {
191+
additionalProperties.put("javaVersion", "11");
192+
additionalProperties.put("jdk11", "true");
193+
}
194+
195+
additionalProperties.put("isJava8or11", this.java8 || this.java11);
196+
this.defaultInterfaces = !(this.java8 || this.java11);
197+
188198
// set invokerPackage as basePackage
189199
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
190200
this.setBasePackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
@@ -383,7 +393,7 @@ public void processOpts() {
383393
}
384394
}
385395

386-
if ((!this.delegatePattern && this.java8) || this.delegateMethod) {
396+
if ((!this.delegatePattern && (this.java8 || this.java11)) || this.delegateMethod) {
387397
additionalProperties.put("jdk8-no-delegate", true);
388398
}
389399

@@ -800,6 +810,8 @@ public void setSingleContentTypes(boolean singleContentTypes) {
800810

801811
public void setJava8(boolean java8) { this.java8 = java8; }
802812

813+
public void setJava11(boolean java11) { this.java11 = java11; }
814+
803815
public void setAsync(boolean async) { this.async = async; }
804816

805817
public void setResponseWrapper(String responseWrapper) { this.responseWrapper = responseWrapper; }

src/main/resources/handlebars/Java/libraries/feign/auth/OAuth.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ public class OAuth implements RequestInterceptor {
8787
}
8888
// If first time, get the token
8989
if (expirationTimeMillis == null || System.currentTimeMillis() >= expirationTimeMillis) {
90-
updateAccessToken();
90+
updateAccessToken(template);
9191
}
9292
if (getAccessToken() != null) {
9393
template.header("Authorization", "Bearer " + getAccessToken());
9494
}
9595
}
9696

97-
public synchronized void updateAccessToken() {
97+
public synchronized void updateAccessToken(RequestTemplate template) {
9898
OAuthJSONAccessTokenResponse accessTokenResponse;
9999
try {
100100
accessTokenResponse = oauthClient.accessToken(tokenRequestBuilder.buildBodyMessage());
101101
} catch (Exception e) {
102-
throw new RetryableException(e.getMessage(), e,null);
102+
throw new RetryableException(400, e.getMessage(), template.request().httpMethod(), e, null, template.request());
103103
}
104104
if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) {
105105
setAccessToken(accessTokenResponse.getAccessToken(), accessTokenResponse.getExpiresIn());

src/main/resources/handlebars/Java/libraries/feign/pom.mustache

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@
165165
</plugins>
166166
</build>
167167
</profile>
168+
{{#java11}}
169+
<profile>
170+
<id>jdk11</id>
171+
<activation>
172+
<jdk>[11,)</jdk>
173+
</activation>
174+
<dependencies>
175+
<dependency>
176+
<groupId>com.sun.xml.ws</groupId>
177+
<artifactId>jaxws-rt</artifactId>
178+
<version>2.3.3</version>
179+
<type>pom</type>
180+
</dependency>
181+
</dependencies>
182+
</profile>
183+
{{/java11}}
168184
</profiles>
169185

170186
<dependencies>
@@ -279,7 +295,7 @@
279295
</dependency>
280296
</dependencies>
281297
<properties>
282-
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
298+
<java.version>{{#java11}}11{{/java11}}{{^java11}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/java11}}</java.version>
283299
<maven.compiler.source>${java.version}</maven.compiler.source>
284300
<maven.compiler.target>${java.version}</maven.compiler.target>
285301
{{#useOas2}}
@@ -288,8 +304,8 @@
288304
{{^useOas2}}
289305
<swagger-core-version>2.0.0</swagger-core-version>
290306
{{/useOas2}}
291-
<feign-version>9.4.0</feign-version>
292-
<feign-form-version>2.1.0</feign-form-version>
307+
<feign-version>11.6</feign-version>
308+
<feign-form-version>3.8.0</feign-form-version>
293309
<jackson-version>2.10.1</jackson-version>
294310
{{#threetenbp}}
295311
<jackson-threetenbp-version>2.6.4</jackson-threetenbp-version>

src/main/resources/handlebars/Java/libraries/okhttp-gson/pom.mustache

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@
166166
</plugins>
167167
</build>
168168
</profile>
169+
{{#java11}}
170+
<profile>
171+
<id>jdk11</id>
172+
<activation>
173+
<jdk>[11,)</jdk>
174+
</activation>
175+
<dependencies>
176+
<dependency>
177+
<groupId>com.sun.xml.ws</groupId>
178+
<artifactId>jaxws-rt</artifactId>
179+
<version>2.3.3</version>
180+
<type>pom</type>
181+
</dependency>
182+
</dependencies>
183+
</profile>
184+
{{/java11}}
169185
</profiles>
170186

171187
<dependencies>
@@ -276,7 +292,7 @@
276292
</dependency>
277293
</dependencies>
278294
<properties>
279-
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
295+
<java.version>{{#java11}}11{{/java11}}{{^java11}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/java11}}</java.version>
280296
<maven.compiler.source>${java.version}</maven.compiler.source>
281297
<maven.compiler.target>${java.version}</maven.compiler.target>
282298
{{#useOas2}}

src/main/resources/handlebars/Java/libraries/resttemplate/pom.mustache

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,22 @@
181181
</plugins>
182182
</build>
183183
</profile>
184+
{{#java11}}
185+
<profile>
186+
<id>jdk11</id>
187+
<activation>
188+
<jdk>[11,)</jdk>
189+
</activation>
190+
<dependencies>
191+
<dependency>
192+
<groupId>com.sun.xml.ws</groupId>
193+
<artifactId>jaxws-rt</artifactId>
194+
<version>2.3.3</version>
195+
<type>pom</type>
196+
</dependency>
197+
</dependencies>
198+
</profile>
199+
{{/java11}}
184200
</profiles>
185201

186202
<dependencies>

src/main/resources/handlebars/Java/libraries/retrofit/pom.mustache

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@
174174
</plugins>
175175
</build>
176176
</profile>
177+
{{#java11}}
178+
<profile>
179+
<id>jdk11</id>
180+
<activation>
181+
<jdk>[11,)</jdk>
182+
</activation>
183+
<dependencies>
184+
<dependency>
185+
<groupId>com.sun.xml.ws</groupId>
186+
<artifactId>jaxws-rt</artifactId>
187+
<version>2.3.3</version>
188+
<type>pom</type>
189+
</dependency>
190+
</dependencies>
191+
</profile>
192+
{{/java11}}
177193
</profiles>
178194

179195
<dependencies>

src/main/resources/handlebars/Java/libraries/retrofit2/pom.mustache

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@
166166
</plugins>
167167
</build>
168168
</profile>
169+
{{#java11}}
170+
<profile>
171+
<id>jdk11</id>
172+
<activation>
173+
<jdk>[11,)</jdk>
174+
</activation>
175+
<dependencies>
176+
<dependency>
177+
<groupId>com.sun.xml.ws</groupId>
178+
<artifactId>jaxws-rt</artifactId>
179+
<version>2.3.3</version>
180+
<type>pom</type>
181+
</dependency>
182+
</dependencies>
183+
</profile>
184+
{{/java11}}
169185
</profiles>
170186

171187
<dependencies>
@@ -323,7 +339,7 @@
323339
</dependencies>
324340
<properties>
325341
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
326-
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
342+
<java.version>{{#java11}}11{{/java11}}{{^java11}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/java11}}</java.version>
327343
<maven.compiler.source>${java.version}</maven.compiler.source>
328344
<maven.compiler.target>${java.version}</maven.compiler.target>
329345
<gson-fire-version>1.8.0</gson-fire-version>

src/main/resources/handlebars/Java/pom.mustache

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,22 @@
181181
</plugins>
182182
</build>
183183
</profile>
184+
{{#java11}}
185+
<profile>
186+
<id>jdk11</id>
187+
<activation>
188+
<jdk>[11,)</jdk>
189+
</activation>
190+
<dependencies>
191+
<dependency>
192+
<groupId>com.sun.xml.ws</groupId>
193+
<artifactId>jaxws-rt</artifactId>
194+
<version>2.3.3</version>
195+
<type>pom</type>
196+
</dependency>
197+
</dependencies>
198+
</profile>
199+
{{/java11}}
184200
</profiles>
185201

186202
<dependencies>

src/main/resources/handlebars/JavaInflector/pom.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@
117117
</repository>
118118
</repositories>
119119
<properties>
120+
{{#java11}}
121+
<maven.compiler.source>11</maven.compiler.source>
122+
<maven.compiler.target>11</maven.compiler.target>
123+
{{/java11}}
120124
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
121125
<maven-plugin-version>1.0.0</maven-plugin-version>
122126
<jetty-version>9.4.9.v20180320</jetty-version>

0 commit comments

Comments
 (0)