From 3bc3a40073ab7a801766261d5f795da584d8d53a Mon Sep 17 00:00:00 2001 From: Cliffano Subagio Date: Tue, 13 Dec 2016 16:55:31 +1100 Subject: [PATCH] [java] Add licenseName and licenseUrl options. --- .../io/swagger/codegen/CodegenConstants.java | 21 +++++++----- .../languages/AbstractJavaCodegen.java | 28 +++++++++++++-- .../Java/libraries/feign/pom.mustache | 8 +++++ .../Java/libraries/jersey2/pom.mustache | 8 +++++ .../Java/libraries/okhttp-gson/pom.mustache | 17 +++++++--- .../Java/libraries/retrofit/pom.mustache | 8 +++++ .../Java/libraries/retrofit2/pom.mustache | 8 +++++ .../src/main/resources/Java/pom.mustache | 12 +++++-- .../main/resources/JavaInflector/pom.mustache | 10 +++++- .../src/main/resources/JavaJaxRS/pom.mustache | 9 +++++ .../codegen/java/JavaClientOptionsTest.java | 34 ++++++++++--------- .../codegen/options/JavaOptionsProvider.java | 4 +++ .../options/JaxRSServerOptionsProvider.java | 4 +++ 13 files changed, 137 insertions(+), 34 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java index 7a10c3f3ac67..84c5c9e8714e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java @@ -25,12 +25,18 @@ public class CodegenConstants { public static final String ARTIFACT_VERSION = "artifactVersion"; public static final String ARTIFACT_VERSION_DESC = "artifact version in generated pom.xml"; + public static final String LICENSE_NAME = "licenseName"; + public static final String LICENSE_NAME_DESC = "The name of the license"; + + public static final String LICENSE_URL = "licenseUrl"; + public static final String LICENSE_URL_DESC = "The URL of the license"; + public static final String SOURCE_FOLDER = "sourceFolder"; public static final String SOURCE_FOLDER_DESC = "source folder for generated code"; public static final String IMPL_FOLDER = "implFolder"; public static final String IMPL_FOLDER_DESC = "folder for generated implementation code"; - + public static final String LOCAL_VARIABLE_PREFIX = "localVariablePrefix"; public static final String LOCAL_VARIABLE_PREFIX_DESC = "prefix for generated code members and local variables"; @@ -48,13 +54,13 @@ public class CodegenConstants { public static final String USE_DATETIME_OFFSET = "useDateTimeOffset"; public static final String USE_DATETIME_OFFSET_DESC = "Use DateTimeOffset to model date-time properties"; - + public static final String ENSURE_UNIQUE_PARAMS = "ensureUniqueParams"; public static final String ENSURE_UNIQUE_PARAMS_DESC = "Whether to ensure parameter names are unique in an operation (rename parameters that are not)."; public static final String PACKAGE_NAME = "packageName"; public static final String PACKAGE_VERSION = "packageVersion"; - + public static final String PACKAGE_TITLE = "packageTitle"; public static final String PACKAGE_TITLE_DESC = "Specifies an AssemblyTitle for the .NET Framework global assembly attributes stored in the AssemblyInfo file."; public static final String PACKAGE_PRODUCTNAME = "packageProductName"; @@ -65,7 +71,7 @@ public class CodegenConstants { public static final String PACKAGE_COMPANY_DESC = "Specifies an AssemblyCompany for the .NET Framework global assembly attributes stored in the AssemblyInfo file."; public static final String PACKAGE_COPYRIGHT = "packageCopyright"; public static final String PACKAGE_COPYRIGHT_DESC = "Specifies an AssemblyCopyright for the .NET Framework global assembly attributes stored in the AssemblyInfo file."; - + public static final String POD_VERSION = "podVersion"; public static final String OPTIONAL_METHOD_ARGUMENT = "optionalMethodArgument"; @@ -79,13 +85,13 @@ public class CodegenConstants { public static final String RETURN_ICOLLECTION = "returnICollection"; public static final String RETURN_ICOLLECTION_DESC = "Return ICollection instead of the concrete type."; - + public static final String OPTIONAL_PROJECT_FILE = "optionalProjectFile"; public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate {PackageName}.csproj."; - + public static final String OPTIONAL_PROJECT_GUID = "packageGuid"; public static final String OPTIONAL_PROJECT_GUID_DESC = "The GUID that will be associated with the C# project"; - + public static final String MODEL_PROPERTY_NAMING = "modelPropertyNaming"; public static final String MODEL_PROPERTY_NAMING_DESC = "Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name"; @@ -132,5 +138,4 @@ public class CodegenConstants { public static final String GENERATE_PROPERTY_CHANGED = "generatePropertyChanged"; public static final String GENERATE_PROPERTY_CHANGED_DESC = "Specifies that models support raising property changed events."; - } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java index 2fb928e4c492..32c4a51f3ad5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java @@ -52,6 +52,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code protected String groupId = "io.swagger"; protected String artifactId = "swagger-java"; protected String artifactVersion = "1.0.0"; + protected String licenseName = "Apache License, Version 2.0"; + protected String licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"; protected String projectFolder = "src" + File.separator + "main"; protected String projectTestFolder = "src" + File.separator + "test"; protected String sourceFolder = projectFolder + File.separator + "java"; @@ -117,6 +119,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC)); cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC)); cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC)); + cliOptions.add(new CliOption(CodegenConstants.LICENSE_NAME, CodegenConstants.LICENSE_NAME_DESC)); + cliOptions.add(new CliOption(CodegenConstants.LICENSE_URL, CodegenConstants.LICENSE_URL_DESC)); cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC)); cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC)); cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC)); @@ -187,6 +191,18 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion); } + if (additionalProperties.containsKey(CodegenConstants.LICENSE_NAME)) { + this.setLicenseName((String) additionalProperties.get(CodegenConstants.LICENSE_NAME)); + } else { + additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName); + } + + if (additionalProperties.containsKey(CodegenConstants.LICENSE_URL)) { + this.setLicenseUrl((String) additionalProperties.get(CodegenConstants.LICENSE_URL)); + } else { + additionalProperties.put(CodegenConstants.LICENSE_URL, licenseUrl); + } + if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) { this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER)); } @@ -821,7 +837,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code op.path = sanitizePath(op.path); return op; } - + private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) { // This generator uses inline classes to define enums, which breaks when // dealing with models that have subTypes. To clean this up, we will analyze @@ -895,6 +911,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code this.artifactVersion = artifactVersion; } + public void setLicenseName(String licenseName) { + this.licenseName = licenseName; + } + + public void setLicenseUrl(String licenseUrl) { + this.licenseUrl = licenseUrl; + } + public void setSourceFolder(String sourceFolder) { this.sourceFolder = sourceFolder; } @@ -957,7 +981,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code } return sb.toString(); } - + public void setSupportJava6(boolean value) { this.supportJava6 = value; } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/feign/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/feign/pom.mustache index 11fc2dea1487..0b464a31b024 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/feign/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/feign/pom.mustache @@ -15,6 +15,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache index 3674b6072c5a..5c51b9cd677e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache @@ -15,6 +15,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache index 4e2e7e877c89..b34c3856f4dc 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache @@ -15,6 +15,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + @@ -131,7 +139,7 @@ ${jodatime-version} {{/java8}} - {{#useBeanValidation}} + {{#useBeanValidation}} javax.validation @@ -139,8 +147,8 @@ 1.1.0.Final provided - {{/useBeanValidation}} - {{#performBeanValidation}} + {{/useBeanValidation}} + {{#performBeanValidation}} org.hibernate @@ -153,7 +161,6 @@ 2.2 {{/performBeanValidation}} - junit @@ -174,4 +181,4 @@ 4.12 UTF-8 - \ No newline at end of file + diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache index c816526cd59b..e38068e27b2f 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache @@ -15,6 +15,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache index 474f980a020b..5f2d74d3c53e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache @@ -15,6 +15,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index 9bd93ccd5e9c..30d9b7bb839d 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -11,6 +11,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + @@ -194,7 +202,7 @@ ${commons_io_version} {{/supportJava6}} -{{#useBeanValidation}} +{{#useBeanValidation}} javax.validation @@ -202,7 +210,7 @@ 1.1.0.Final provided -{{/useBeanValidation}} +{{/useBeanValidation}} junit diff --git a/modules/swagger-codegen/src/main/resources/JavaInflector/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaInflector/pom.mustache index 5b6b7c0161d2..4d7bc8c26473 100644 --- a/modules/swagger-codegen/src/main/resources/JavaInflector/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaInflector/pom.mustache @@ -14,6 +14,14 @@ 2.2.0 + + + {{licenseName}} + {{licenseUrl}} + repo + + + install target @@ -117,4 +125,4 @@ 4.8.2 1.6.3 - \ No newline at end of file + diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache index 03582826a58f..19cbd0a95ad7 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache @@ -5,6 +5,15 @@ jar {{artifactId}} {{artifactVersion}} + + + + {{licenseName}} + {{licenseUrl}} + repo + + + src/main/java diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/JavaClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/JavaClientOptionsTest.java index 3fdd9756e826..413b61c3e000 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/JavaClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/JavaClientOptionsTest.java @@ -32,36 +32,38 @@ public class JavaClientOptionsTest extends AbstractOptionsTest { @Override protected void setExpectations() { new Expectations(clientCodegen) {{ - clientCodegen.setModelPackage(JavaClientOptionsProvider.MODEL_PACKAGE_VALUE); + clientCodegen.setModelPackage(JavaClientOptionsProvider.MODEL_PACKAGE_VALUE); times = 1; - clientCodegen.setApiPackage(JavaClientOptionsProvider.API_PACKAGE_VALUE); + clientCodegen.setApiPackage(JavaClientOptionsProvider.API_PACKAGE_VALUE); times = 1; - clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(JavaClientOptionsProvider.SORT_PARAMS_VALUE)); + clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(JavaClientOptionsProvider.SORT_PARAMS_VALUE)); times = 1; - clientCodegen.setInvokerPackage(JavaClientOptionsProvider.INVOKER_PACKAGE_VALUE); + clientCodegen.setInvokerPackage(JavaClientOptionsProvider.INVOKER_PACKAGE_VALUE); times = 1; - clientCodegen.setGroupId(JavaClientOptionsProvider.GROUP_ID_VALUE); + clientCodegen.setGroupId(JavaClientOptionsProvider.GROUP_ID_VALUE); times = 1; - clientCodegen.setArtifactId(JavaClientOptionsProvider.ARTIFACT_ID_VALUE); + clientCodegen.setArtifactId(JavaClientOptionsProvider.ARTIFACT_ID_VALUE); times = 1; - clientCodegen.setArtifactVersion(JavaClientOptionsProvider.ARTIFACT_VERSION_VALUE); + clientCodegen.setArtifactVersion(JavaClientOptionsProvider.ARTIFACT_VERSION_VALUE); times = 1; - clientCodegen.setSourceFolder(JavaClientOptionsProvider.SOURCE_FOLDER_VALUE); + clientCodegen.setLicenseName(JavaOptionsProvider.LICENSE_NAME_VALUE); times = 1; - clientCodegen.setLocalVariablePrefix(JavaClientOptionsProvider.LOCAL_PREFIX_VALUE); + clientCodegen.setLicenseUrl(JavaOptionsProvider.LICENSE_URL_VALUE); times = 1; - clientCodegen.setSerializableModel(Boolean.valueOf(JavaClientOptionsProvider.SERIALIZABLE_MODEL_VALUE)); + clientCodegen.setSourceFolder(JavaOptionsProvider.SOURCE_FOLDER_VALUE); + times = 1; + clientCodegen.setLocalVariablePrefix(JavaClientOptionsProvider.LOCAL_PREFIX_VALUE); + times = 1; + clientCodegen.setSerializableModel(Boolean.valueOf(JavaClientOptionsProvider.SERIALIZABLE_MODEL_VALUE)); times = 1; clientCodegen.setLibrary(JavaClientOptionsProvider.DEFAULT_LIBRARY_VALUE); times = 1; - clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaClientOptionsProvider.FULL_JAVA_UTIL_VALUE)); + clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaClientOptionsProvider.FULL_JAVA_UTIL_VALUE)); times = 1; - // clientCodegen.setSupportJava6(Boolean.valueOf(JavaClientOptionsProvider.SUPPORT_JAVA6)); - //times = 1; - clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaClientOptionsProvider.USE_BEANVALIDATION)); + clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaClientOptionsProvider.USE_BEANVALIDATION)); + times = 1; + clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaClientOptionsProvider.PERFORM_BEANVALIDATION)); times = 1; - clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaClientOptionsProvider.PERFORM_BEANVALIDATION)); - times = 1; }}; } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java index 15a553d53b30..9fe39cc95d3e 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java @@ -11,6 +11,8 @@ public class JavaOptionsProvider implements OptionsProvider { public static final String MODEL_PACKAGE_VALUE = "package"; public static final String API_PACKAGE_VALUE = "apiPackage"; public static final String INVOKER_PACKAGE_VALUE = "io.swagger.client.test"; + public static final String LICENSE_NAME_VALUE = "Apache License, Version 2.0"; + public static final String LICENSE_URL_VALUE = "http://www.apache.org/licenses/LICENSE-2.0"; public static final String SORT_PARAMS_VALUE = "false"; public static final String GROUP_ID_VALUE = "io.swagger.test"; public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT"; @@ -37,6 +39,8 @@ public class JavaOptionsProvider implements OptionsProvider { .put(CodegenConstants.GROUP_ID, GROUP_ID_VALUE) .put(CodegenConstants.ARTIFACT_ID, ARTIFACT_ID_VALUE) .put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE) + .put(CodegenConstants.LICENSE_NAME, LICENSE_NAME_VALUE) + .put(CodegenConstants.LICENSE_URL, LICENSE_URL_VALUE) .put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE) .put(CodegenConstants.LOCAL_VARIABLE_PREFIX, LOCAL_PREFIX_VALUE) .put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java index 3db594f94b8d..57896db9ca68 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java @@ -14,6 +14,8 @@ public class JaxRSServerOptionsProvider implements OptionsProvider { public static final String SORT_PARAMS_VALUE = "false"; public static final String GROUP_ID_VALUE = "io.swagger.test"; public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT"; + public static final String LICENSE_NAME_VALUE = "Apache License, Version 2.0"; + public static final String LICENSE_URL_VALUE = "http://www.apache.org/licenses/LICENSE-2.0"; public static final String SOURCE_FOLDER_VALUE = "src/main/java/test"; public static final String LOCAL_PREFIX_VALUE = "tst"; public static final String DEFAULT_LIBRARY_VALUE = "jersey2"; @@ -49,6 +51,8 @@ public class JaxRSServerOptionsProvider implements OptionsProvider { .put(CodegenConstants.GROUP_ID, GROUP_ID_VALUE) .put(CodegenConstants.ARTIFACT_ID, ARTIFACT_ID_VALUE) .put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE) + .put(CodegenConstants.LICENSE_NAME, LICENSE_NAME_VALUE) + .put(CodegenConstants.LICENSE_URL, LICENSE_URL_VALUE) .put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE) .put(CodegenConstants.LOCAL_VARIABLE_PREFIX, LOCAL_PREFIX_VALUE) .put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE)