Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kotlin] Fixed additional property omitGradleWrapper for kotlin generator #15584

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
protected boolean doNotUseRxAndCoroutines = true;
protected boolean generateRoomModels = false;
protected String roomModelPackage = "";

protected boolean omitGradleWrapper = false;

protected String authFolder;


public enum DateLibrary {
STRING("string"),
THREETENBP("threetenbp"),
Expand Down Expand Up @@ -265,6 +266,10 @@ public boolean getGenerateRoomModels() {
return generateRoomModels;
}

public boolean getOmitGradleWrapper() {
return omitGradleWrapper;
}

public void setGenerateRoomModels(Boolean generateRoomModels) {
this.generateRoomModels = generateRoomModels;
}
Expand Down Expand Up @@ -336,6 +341,10 @@ public void setRoomModelPackage(String roomModelPackage) {
this.roomModelPackage = roomModelPackage;
}

public void setOmitGradleWrapper(boolean omitGradleWrapper) {
this.omitGradleWrapper = omitGradleWrapper;
}

@Override
public String modelFilename(String templateName, String modelName) {
String suffix = modelTemplateFiles().get(templateName);
Expand Down Expand Up @@ -426,6 +435,10 @@ public void processOpts() {
setRequestDateConverter(additionalProperties.get(REQUEST_DATE_CONVERTER).toString());
}

if (additionalProperties.containsKey(OMIT_GRADLE_WRAPPER)) {
setOmitGradleWrapper(Boolean.parseBoolean(additionalProperties.get(OMIT_GRADLE_WRAPPER).toString()));
}

commonSupportingFiles();

switch (getLibrary()) {
Expand Down Expand Up @@ -787,10 +800,12 @@ private void commonSupportingFiles() {
}

// gradle wrapper supporting files
supportingFiles.add(new SupportingFile("gradlew.mustache", "", "gradlew"));
supportingFiles.add(new SupportingFile("gradlew.bat.mustache", "", "gradlew.bat"));
supportingFiles.add(new SupportingFile("gradle-wrapper.properties.mustache", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.properties"));
supportingFiles.add(new SupportingFile("gradle-wrapper.jar", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.jar"));
if (!getOmitGradleWrapper()) {
supportingFiles.add(new SupportingFile("gradlew.mustache", "", "gradlew"));
supportingFiles.add(new SupportingFile("gradlew.bat.mustache", "", "gradlew.bat"));
supportingFiles.add(new SupportingFile("gradle-wrapper.properties.mustache", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.properties"));
supportingFiles.add(new SupportingFile("gradle-wrapper.jar", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.jar"));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,27 @@ public void testNativeClientExplodedQueryParamObject() throws IOException {
);
}

@Test
public void testOmitGradleWrapperDoesNotGenerateWrapper() throws IOException {
File output = Files.createTempDirectory("test").toFile();
String path = output.getAbsolutePath();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("kotlin")
.setInputSpec("src/test/resources/3_0/ping.yaml")
.addAdditionalProperty("omitGradleWrapper", true)
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
DefaultGenerator generator = new DefaultGenerator();

generator.opts(configurator.toClientOptInput()).generate();

TestUtils.assertFileNotExists(Paths.get(path, "gradlew"));
TestUtils.assertFileNotExists(Paths.get(path, "gradlew.bat"));
TestUtils.assertFileNotExists(Paths.get(path, "gradle", "wrapper", "gradle-wrapper.properties"));
TestUtils.assertFileNotExists(Paths.get(path, "gradle", "wrapper", "gradle-wrapper.jar"));
}

private static class ModelNameTest {
private final String expectedName;
private final String expectedClassName;
Expand Down