Skip to content
Open
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
8 changes: 3 additions & 5 deletions aws/aws-mcp-types/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ dependencies {
}

afterEvaluate {
val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen")
val typesPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen").get()
sourceSets {
main {
java {
srcDir(typePath)
include("software/**")
srcDir("$typesPath/java")
}
resources {
srcDir(typePath)
include("META-INF/**")
srcDir("$typesPath/resources")
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/CodegenExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ fun Project.addGenerateSrcsTask(
val taskOutput = layout.buildDirectory.dir(generatedDir).get()
val sourceSets = project.the<SourceSetContainer>()
sourceSets.named("it") {
java.srcDir(taskOutput)
java.srcDirs("${taskOutput}/java", "${taskOutput}/resources")

}
val task = tasks.register<JavaExec>(taskName) {
dependsOn("test")
Expand All @@ -37,6 +38,7 @@ fun Project.addGenerateSrcsTask(
}
tasks.getByName("integ").dependsOn(task)
tasks.getByName("compileItJava").dependsOn(task)
tasks.getByName("processItResources").dependsOn(task)
return task
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ val generatedSrcDir = layout.buildDirectory.dir("generated-src").get()
sourceSets {
named("it") {
java {
srcDir(generatedSrcDir)
srcDir("$generatedSrcDir/java")
}
resources {
srcDir("$generatedSrcDir/resources")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static Symbol fromClass(Class<?> clazz) {
/**
* Gets a Symbol for a class with both a boxed and unboxed variant.
*
* @param boxed Boxed variant of class
* @param boxed Boxed variant of class
* @param unboxed Unboxed variant of class
* @return Symbol representing java class
*/
Expand Down Expand Up @@ -162,9 +162,8 @@ public static boolean isJavaArray(Symbol symbol) {
/**
* Determines if a given member represents a nullable type.
*
* @param model Model to use for resolving Nullable index.
* @param model Model to use for resolving Nullable index.
* @param member member to check for nullability.
*
* @return if the shape is a nullable type
*/
public static boolean isNullableMember(Model model, MemberShape member) {
Expand Down Expand Up @@ -242,8 +241,8 @@ public static boolean requiresSetterNullCheck(SymbolProvider provider, MemberSha
*
* <p>Documents are also not set because they use a null default for error correction.
*
* @see <a href="https://smithy.io/2.0/spec/aggregate-types.html#client-error-correction">client error correction</a>
* @return true if the member shape has a builtin default
* @see <a href="https://smithy.io/2.0/spec/aggregate-types.html#client-error-correction">client error correction</a>
*/
public static boolean hasBuiltinDefault(SymbolProvider provider, Model model, MemberShape memberShape) {
var target = model.expectShape(memberShape.getTarget());
Expand All @@ -267,7 +266,7 @@ public static String toDefaultValueName(String memberName) {
* Gets the name to use when defining a member as instance variable in a class.
*
* @param memberShape MemberShape
* @param model Model
* @param model Model
* @return Instance variable name of a member.
*/
public static String toMemberName(MemberShape memberShape, Model model) {
Expand All @@ -277,7 +276,7 @@ public static String toMemberName(MemberShape memberShape, Model model) {
/**
* Gets the name to use when defining the getter method of a member.
*
* @param memberShape memberShape.
* @param memberShape memberShape.
* @return Getter method name of a member.
*/
public static String toGetterName(MemberShape memberShape, Model model) {
Expand All @@ -296,7 +295,7 @@ public static String toGetterName(MemberShape memberShape, Model model) {
* @return serde file name
*/
public static String getSerdeFileName(JavaCodegenSettings settings) {
return String.format("./%s/model/SharedSerde.java", settings.packageNamespace().replace(".", "/"));
return getJavaFilePath(settings, "model", "SharedSerde");
}

/**
Expand All @@ -306,7 +305,7 @@ public static String getSerdeFileName(JavaCodegenSettings settings) {
* @return shared registry file name
*/
public static String getSharedRegistryFileName(JavaCodegenSettings settings) {
return String.format("./%s/model/SharedTypeRegistry.java", settings.packageNamespace().replace(".", "/"));
return getJavaFilePath(settings, "model", "SharedTypeRegistry");
}

/**
Expand Down Expand Up @@ -359,11 +358,11 @@ public static boolean recursiveShape(Model model, Shape shape) {
* <p><strong>NOTE</strong>: The provided class must have a public, no-arg constructor.
*
* @param clazz interface to get implementation of
* @param name fully-qualified class name
* @param name fully-qualified class name
* @param <T> Type to get implementation for.
* @return Class instance.
* @param <T> Type to get implementation for.
* @throws CodegenException if no valid implementation with a public no-arg constructor could be found on the
* classpath for the given class name.
* classpath for the given class name.
*/
@SuppressWarnings("unchecked")
public static <T> Class<? extends T> getImplementationByName(Class<T> clazz, String name) {
Expand Down Expand Up @@ -419,9 +418,9 @@ public static boolean isISO8601Date(String string) {
* created, and property is found).
*
* @param directive Directive to get the service from.
* @param prop Property to get from the symbol of the service.
* @param prop Property to get from the symbol of the service.
* @param <T> the property type.
* @return the property if found, or null.
* @param <T> the property type.
*/
public static <T> T tryGetServiceProperty(ShapeDirective<?, ?, ?> directive, Property<T> prop) {
var service = directive.service();
Expand All @@ -441,12 +440,12 @@ public static <T> T tryGetServiceProperty(ShapeDirective<?, ?, ?> directive, Pro
* code generated to extend from this exception.
*
* @param packageNamespace The package namespace to use for the service exception.
* @param serviceName The name of the service to use for the service exception.
* @param serviceName The name of the service to use for the service exception.
* @return the service exception symbol.
*/
public static Symbol getServiceExceptionSymbol(String packageNamespace, String serviceName) {
var name = serviceName + "Exception";
var filename = String.format("./%s/model/%s.java", packageNamespace.replace(".", "/"), name);
var filename = getJavaFilePath(packageNamespace, "model", name);
return Symbol.builder()
.name(name)
.namespace(packageNamespace + ".model", ".")
Expand All @@ -459,12 +458,12 @@ public static Symbol getServiceExceptionSymbol(String packageNamespace, String s
* Returns the class used as the {@link ApiService} for the service.
*
* @param packageNamespace The package namespace to use for the service.
* @param serviceName The name of the service to use for the service.
* @param serviceName The name of the service to use for the service.
* @return the service ApiService symbol.
*/
public static Symbol getServiceApiSymbol(String packageNamespace, String serviceName) {
var name = serviceName + "ApiService";
var filename = String.format("./%s/model/%s.java", packageNamespace.replace(".", "/"), name);
var filename = getJavaFilePath(packageNamespace, "model", name);
return Symbol.builder()
.name(name)
.namespace(packageNamespace + ".model", ".")
Expand All @@ -473,6 +472,31 @@ public static Symbol getServiceApiSymbol(String packageNamespace, String service
.build();
}

/**
* Returns the file path for the java file with simple name using the configure package in settings.
*
* @param settings The settings to get the package namespace
* @param packageSuffix The suffix for the namespace for the file
* @param simpleName The simple name of the java file
* @return the file path for the java file
*/
public static String getJavaFilePath(JavaCodegenSettings settings, String packageSuffix, String simpleName) {
return getJavaFilePath(settings.packageNamespace(), packageSuffix, simpleName);
}

/**
* Returns the file path for the java file with simple name using the configure package in settings.
*
* @param packageNamespace The package namespace for the file
* @param packageSuffix The suffix for the namespace for the file
* @param simpleName The simple name of the java file
* @return the file path for the java file
*/
public static String getJavaFilePath(String packageNamespace, String packageSuffix, String simpleName) {
var packagePath = packageNamespace.replace(".", "/");
return String.format("java/%s/%s/%s.java", packagePath, packageSuffix, simpleName);
}

private static String getMemberName(MemberShape shape, Model model, boolean escape) {
Shape containerShape = model.expectShape(shape.getContainer());
if (containerShape.isEnumShape() || containerShape.isIntEnumShape()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,14 @@ public Symbol operationShape(OperationShape operationShape) {
.putProperty(SymbolProperties.IS_PRIMITIVE, false)
.namespace(format("%s.service", packageNamespace), ".")
.declarationFile(
format("./%s/service/%s.java", packageNamespace.replace(".", "/"), stubName))
CodegenUtils.getJavaFilePath(packageNamespace, "service", stubName))
.build();
var asyncStubSymbol = Symbol.builder()
.name(asyncStubName)
.putProperty(SymbolProperties.IS_PRIMITIVE, false)
.namespace(format("%s.service", packageNamespace), ".")
.declarationFile(
format("./%s/service/%s.java", packageNamespace.replace(".", "/"), asyncStubName))
CodegenUtils.getJavaFilePath(packageNamespace, "service", asyncStubName))
.build();
return baseSymbol.toBuilder()
.putProperty(SymbolProperties.IS_PRIMITIVE, false)
Expand Down Expand Up @@ -380,7 +380,7 @@ private Symbol getJavaClassSymbol(Shape shape) {
.putProperty(SymbolProperties.IS_PRIMITIVE, false)
.putProperty(SymbolProperties.REQUIRES_STATIC_DEFAULT, true)
.namespace(format("%s.model", packageNamespace), ".")
.declarationFile(format("./%s/model/%s.java", packageNamespace.replace(".", "/"), name))
.declarationFile(CodegenUtils.getJavaFilePath(packageNamespace, "model", name))
.build();
}

Expand All @@ -394,7 +394,7 @@ private Symbol getClientServiceSymbol() {
.putProperty(SymbolProperties.SERVICE_API_SERVICE,
CodegenUtils.getServiceApiSymbol(packageNamespace, serviceName))
.namespace(format("%s.client", packageNamespace), ".")
.definitionFile(format("./%s/client/%s.java", packageNamespace.replace(".", "/"), name))
.definitionFile(CodegenUtils.getJavaFilePath(packageNamespace, "client", name))
.build();

return symbol.toBuilder()
Expand All @@ -403,7 +403,7 @@ private Symbol getClientServiceSymbol() {
symbol.toBuilder()
.name(name + "Impl")
.definitionFile(
format("./%s/client/%sImpl.java", packageNamespace.replace(".", "/"), name))
CodegenUtils.getJavaFilePath(packageNamespace, "client", name + "Impl"))
.build())
.build();
}
Expand All @@ -419,7 +419,7 @@ private Symbol getServerServiceSymbol() {
.putProperty(ServerSymbolProperties.TYPES_NAMESPACE, format("%s.model", packageNamespace))
.namespace(format("%s.service", packageNamespace), ".")
.declarationFile(
format("./%s/service/%s.java", packageNamespace.replace(".", "/"), serviceName))
CodegenUtils.getJavaFilePath(packageNamespace, "service", serviceName))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import static java.lang.String.format;

import java.io.IOException;
import java.nio.file.Files;
import java.io.ByteArrayInputStream;
import java.util.function.Consumer;
import software.amazon.smithy.codegen.core.directed.GenerateServiceDirective;
import software.amazon.smithy.java.client.rulesengine.Bytecode;
Expand All @@ -23,19 +22,11 @@ public class BddFileGenerator
implements Consumer<GenerateServiceDirective<CodeGenerationContext, JavaCodegenSettings>> {
@Override
public void accept(GenerateServiceDirective<CodeGenerationContext, JavaCodegenSettings> directive) {
try {
var baseDir = directive.fileManifest().getBaseDir();
var serviceName = directive.service().toShapeId().getName();
var fileDir = baseDir.resolve(format("resources/META-INF/endpoints/%s.bdd", serviceName));
var parentDir = fileDir.getParent();
if (parentDir != null) {
Files.createDirectories(parentDir);
}
var bytecode = compileBytecode(directive.service());
Files.write(fileDir, bytecode.getBytecode());
} catch (IOException e) {
throw new RuntimeException("Failed to write BDD bytecode binary file", e);
}
var fileManifest = directive.fileManifest();
var serviceName = directive.service().toShapeId().getName();
var bytecode = compileBytecode(directive.service());
fileManifest.writeFile(format("resources/META-INF/endpoints/%s.bdd", serviceName),
new ByteArrayInputStream(bytecode.getBytecode()));
}

private Bytecode compileBytecode(ServiceShape serviceShape) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static java.lang.String.format;

import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.java.codegen.CodegenUtils;
import software.amazon.smithy.java.codegen.JavaCodegenSettings;
import software.amazon.smithy.java.codegen.SymbolProperties;

Expand All @@ -25,9 +26,8 @@ public static Symbol getWaiterSymbol(Symbol clientSymbol, JavaCodegenSettings se
.name(waiterName)
.namespace(format("%s.client", settings.packageNamespace()), ".")
.putProperty(SymbolProperties.IS_PRIMITIVE, false)
.definitionFile(format("./%s/client/%s.java",
settings.packageNamespace().replace(".", "/"),
waiterName))
.definitionFile(
CodegenUtils.getJavaFilePath(settings.packageNamespace(), "client", waiterName))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public final class SchemaIndexGenerator
@Override
public void accept(CustomizeDirective<CodeGenerationContext, JavaCodegenSettings> directive) {
var className = "GeneratedSchemaIndex";
var fileName = String
.format("./%s/model/%s.java", directive.settings().packageNamespace().replace(".", "/"), className);
var fileName = CodegenUtils.getJavaFilePath(directive.settings(), "model", className);

directive.context()
.writerDelegator()
Expand All @@ -38,7 +37,7 @@ public void accept(CustomizeDirective<CodeGenerationContext, JavaCodegenSettings
writer -> generateSchemaIndexClass(writer, className, directive));

// Generate META-INF/services file
var serviceFileName = "./META-INF/services/" + SchemaIndex.class.getName();
var serviceFileName = "./resources/META-INF/services/" + SchemaIndex.class.getName();
var schemaIndexClassName = CodegenUtils.getModelNamespace(directive.settings()) + "." + className;

directive.context()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void accept(CustomizeDirective<CodeGenerationContext, JavaCodegenSettings
var order = directive.context().schemaFieldOrder();
for (var shapeOrder : order.partitions()) {
var className = shapeOrder.get(0).className();
var fileName = String
.format("./%s/model/%s.java", directive.settings().packageNamespace().replace(".", "/"), className);
var fileName = CodegenUtils.getJavaFilePath(directive.settings(), "model", className);
directive.context()
.writerDelegator()
.useFileWriter(fileName, CodegenUtils.getModelNamespace(directive.settings()), writer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String getFilename() {
@Override
public String toString() {
// Do not add headers or attempt symbol resolution for resource files
if (filename.startsWith("META-INF")) {
if (filename.contains("META-INF")) {
return super.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void verifySchemaReference(String structureName, String expectedSchema)

private String getFileString(String fileName) {
var fileStringOptional = manifest.getFileString(
Paths.get(String.format("/t/s/c/model/%s", fileName)));
Paths.get(String.format("/java/t/s/c/model/%s", fileName)));
assertThat(fileStringOptional).isPresent();
return fileStringOptional.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected ObjectNode settings() {

protected String getFileStringForClass(String className) {
var fileStringOptional = manifest.getFileString(
Paths.get(String.format("/test/smithy/codegen/%s.java", className)));
Paths.get(String.format("java/test/smithy/codegen/%s.java", className)));
assertTrue(fileStringOptional.isPresent());
return fileStringOptional.get();
}
Expand Down
Loading
Loading