From 44b6a8a5b55c8d9beca5e1cca36a286a3b94de11 Mon Sep 17 00:00:00 2001 From: Sean McGrail Date: Tue, 4 May 2021 17:56:39 -0700 Subject: [PATCH] Remove moduleVersion configuration, correct package name declaration to support vN module version paths. --- .../amazon/smithy/go/codegen/GoSettings.java | 24 +------------------ .../amazon/smithy/go/codegen/GoWriter.java | 16 ++++++++++++- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoSettings.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoSettings.java index 4456ca600..819569047 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoSettings.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoSettings.java @@ -34,11 +34,9 @@ public final class GoSettings { private static final String SERVICE = "service"; private static final String MODULE_NAME = "module"; private static final String MODULE_DESCRIPTION = "moduleDescription"; - private static final String MODULE_VERSION = "moduleVersion"; private ShapeId service; private String moduleName; - private String moduleVersion; private String moduleDescription = ""; private ShapeId protocol; @@ -50,11 +48,10 @@ public final class GoSettings { */ public static GoSettings from(ObjectNode config) { GoSettings settings = new GoSettings(); - config.warnIfAdditionalProperties(Arrays.asList(SERVICE, MODULE_NAME, MODULE_DESCRIPTION, MODULE_VERSION)); + config.warnIfAdditionalProperties(Arrays.asList(SERVICE, MODULE_NAME, MODULE_DESCRIPTION)); settings.setService(config.expectStringMember(SERVICE).expectShapeId()); settings.setModuleName(config.expectStringMember(MODULE_NAME).getValue()); - settings.setModuleVersion(config.expectStringMember(MODULE_VERSION).getValue()); settings.setModuleDescription(config.getStringMemberOrDefault( MODULE_DESCRIPTION, settings.getModuleName() + " client")); @@ -115,25 +112,6 @@ public void setModuleName(String moduleName) { this.moduleName = Objects.requireNonNull(moduleName); } - /** - * Gets the required module version for the module that will be generated. - * - * @return The version of the module that will be generated. - * @throws NullPointerException if the module version has not been set. - */ - public String getModuleVersion() { - return Objects.requireNonNull(moduleVersion, MODULE_VERSION + " not set"); - } - - /** - * Sets the required module version for the module that will be generated. - * - * @param moduleVersion The version of the module that will be generated. - */ - public void setModuleVersion(String moduleVersion) { - this.moduleVersion = Objects.requireNonNull(moduleVersion); - } - /** * Gets the optional module description for the module that will be generated. * diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoWriter.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoWriter.java index 1ebd064a3..2e72df371 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoWriter.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoWriter.java @@ -356,8 +356,22 @@ public String toString() { String[] packageParts = fullPackageName.split("/"); String header = String.format("// Code generated by smithy-go-codegen DO NOT EDIT.%n%n"); + String packageName = packageParts[packageParts.length - 1]; + if (packageName.startsWith("v") && packageParts.length >= 2) { + String remaining = packageName.substring(1); + try { + int value = Integer.parseInt(remaining); + packageName = packageParts[packageParts.length - 2]; + if (value == 0 || value == 1) { + throw new CodegenException("module paths vN version component must only be N >= 2"); + } + } catch (NumberFormatException ne) { + // Do nothing + } + } + String packageDocs = this.packageDocs.toString(); - String packageStatement = String.format("package %s%n%n", packageParts[packageParts.length - 1]); + String packageStatement = String.format("package %s%n%n", packageName); String importString = imports.toString(); String strippedContents = StringUtils.stripStart(contents, null);