Skip to content

Commit

Permalink
Added support useJakartaEe flag
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 committed Sep 22, 2024
1 parent c0e4562 commit 2598829
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ public void processOpts() {
}
writePropertyBack(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG, generateOperationOnlyForFirstTag);

if (additionalProperties.containsKey(USE_JAKARTA_EE)) {
setUseJakartaEe(convertPropertyToBoolean(USE_JAKARTA_EE));
}
writePropertyBack(USE_JAKARTA_EE, useJakartaEe);
writePropertyBack(JAVAX_PACKAGE, useJakartaEe ? "jakarta" : "javax");

maybeSetTestTool();
writePropertyBack(OPT_TEST, testTool);
if (testTool.equals(OPT_TEST_JUNIT)) {
Expand Down Expand Up @@ -524,9 +530,6 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("common/configuration/application.yml.mustache", resourceFolder, "application.yml").doNotOverwrite());
supportingFiles.add(new SupportingFile("common/configuration/logback.xml.mustache", resourceFolder, "logback.xml").doNotOverwrite());

// Use jakarta instead of javax
additionalProperties.put("javaxPackage", "jakarta");

// Use the default java time
switch (dateLibrary) {
case OPT_DATE_LIBRARY_OFFSET_DATETIME -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ protected AbstractMicronautKotlinCodegen() {

// CHECKSTYLE:OFF
// Set all the fields
useJakartaEe = true;
useBeanValidation = true;
visitable = false;
hideGenerationTimestamp = false;
Expand Down Expand Up @@ -557,6 +558,12 @@ public void processOpts() {
}
writePropertyBack(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG, generateOperationOnlyForFirstTag);

if (additionalProperties.containsKey(USE_JAKARTA_EE)) {
setUseJakartaEe(convertPropertyToBoolean(USE_JAKARTA_EE));
}
writePropertyBack(USE_JAKARTA_EE, useJakartaEe);
writePropertyBack(JAVAX_PACKAGE, useJakartaEe ? "jakarta" : "javax");

maybeSetTestTool();
writePropertyBack(OPT_TEST, testTool);
if (testTool.equals(OPT_TEST_JUNIT)) {
Expand All @@ -583,9 +590,6 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("common/configuration/application.yml.mustache", resourcesFolder, "application.yml").doNotOverwrite());
supportingFiles.add(new SupportingFile("common/configuration/logback.xml.mustache", resourcesFolder, "logback.xml").doNotOverwrite());

// Use jakarta instead of javax
additionalProperties.put("javaxPackage", "jakarta");

// Use the default java time
switch (dateLibrary) {
case OPT_DATE_LIBRARY_OFFSET_DATETIME -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private void configureOptions() {
javaCodeGen.setImplicitHeadersRegex(options.implicitHeadersRegex);
}

javaCodeGen.setUseJakartaEe(options.useJakartaEe);
javaCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces);
javaCodeGen.setReactive(options.reactive);
javaCodeGen.setGenerateHttpResponseAlways(options.generateHttpResponseAlways);
Expand Down Expand Up @@ -257,6 +258,7 @@ private void configureOptions() {
if (options.implicitHeadersRegex != null && !options.implicitHeadersRegex.isBlank()) {
kotlinCodeGen.setImplicitHeadersRegex(options.implicitHeadersRegex);
}
kotlinCodeGen.setUseJakartaEe(options.useJakartaEe);
kotlinCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces);
kotlinCodeGen.setReactive(options.reactive);
kotlinCodeGen.setGenerateHttpResponseAlways(options.generateHttpResponseAlways);
Expand Down Expand Up @@ -505,6 +507,7 @@ private static class DefaultOptionsBuilder implements MicronautCodeGeneratorOpti

private String apiPackage;
private String artifactId;
private boolean useJakartaEe = true;
private boolean beanValidation = true;
private boolean useEnumCaseInsensitive;
private String invokerPackage;
Expand Down Expand Up @@ -738,13 +741,20 @@ public MicronautCodeGeneratorOptionsBuilder withUseOneOfInterfaces(boolean useOn
return this;
}

@Override
public MicronautCodeGeneratorOptionsBuilder withUseJakartaEe(boolean useJakartaEe) {
this.useJakartaEe = useJakartaEe;
return this;
}

private Options build() {
return new Options(
lang,
apiPackage,
modelPackage,
invokerPackage,
artifactId,
useJakartaEe,
parameterMappings,
responseBodyMappings,
schemaMapping,
Expand Down Expand Up @@ -802,6 +812,7 @@ private record Options(
String modelPackage,
String invokerPackage,
String artifactId,
boolean useJakartaEe,
List<ParameterMapping> parameterMappings,
List<ResponseBodyMapping> responseBodyMappings,
Map<String, String> schemaMapping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ public interface MicronautCodeGeneratorOptionsBuilder {
*/
MicronautCodeGeneratorOptionsBuilder withUseOneOfInterfaces(boolean useOneOfInterfaces);

/**
* Flag to indicate whether to use the "jakarta" or "javax" package.
*
* @param useJakartaEe if true, then use the "jakarta" package, otherwise - "javax".
*
* @return this builder
*/
MicronautCodeGeneratorOptionsBuilder withUseJakartaEe(boolean useJakartaEe);

/**
* The possible date-time formatting configurations.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.micronaut.core.util.StringUtils;
import io.micronaut.http.MutableHttpRequest;
import io.micronaut.http.client.bind.AnnotatedClientRequestBinder;
import io.micronaut.http.client.bind.ClientRequestUriContext;
import jakarta.inject.Singleton;
import {{javaxPackage}}.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
{{#generatedAnnotation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package {{package}}
{{/imports}}
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import spock.lang.Specification
import jakarta.inject.Inject
import {{javaxPackage}}.inject.Inject
import spock.lang.Ignore
{{#wrapInHttpResponse}}
import io.micronaut.http.HttpResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import jakarta.inject.Inject;
import {{javaxPackage}}.inject.Inject;
{{#wrapInHttpResponse}}
import io.micronaut.http.HttpResponse;
{{/wrapInHttpResponse}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package {{package}}
{{/imports}}
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import spock.lang.Specification
import jakarta.inject.Inject
import {{javaxPackage}}.inject.Inject

/**
* Model tests for {{classname}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.micronaut.http.uri.UriTemplate
import io.micronaut.http.cookie.Cookie
import io.micronaut.http.client.multipart.MultipartBody
import io.micronaut.core.type.Argument
import jakarta.inject.Inject
import {{javaxPackage}}.inject.Inject
import spock.lang.Specification
import spock.lang.Ignore
{{#reactive}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.micronaut.core.type.GenericArgument;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Assertions;
import jakarta.inject.Inject;
import {{javaxPackage}}.inject.Inject;
{{#reactive}}
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.micronaut.core.naming.NameUtils
import io.micronaut.http.MutableHttpRequest
import io.micronaut.http.client.bind.AnnotatedClientRequestBinder
import io.micronaut.http.client.bind.ClientRequestUriContext
import jakarta.inject.Singleton
import {{javaxPackage}}.inject.Singleton
{{#generatedAnnotation}}
import {{javaxPackage}}.annotation.Generated
{{/generatedAnnotation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.micronaut.core.type.Argument
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Assertions
import jakarta.inject.Inject
import {{javaxPackage}}.inject.Inject
{{#reactive}}
import reactor.core.publisher.Flux
{{/reactive}}
Expand Down

0 comments on commit 2598829

Please sign in to comment.