Skip to content

Commit

Permalink
Add customizations hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Sep 11, 2024
1 parent 848cf87 commit 95da58e
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 17 deletions.
1 change: 1 addition & 0 deletions codegen/projections/rails_json/lib/rails_json.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codegen/projections/rpcv2_cbor/lib/rpcv2_cbor.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codegen/projections/white_label/lib/white_label.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions codegen/projections/white_label/spec/customizations_spec.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions codegen/smithy-ruby-codegen-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,29 @@ tasks.register("generate-smithy-build") {
}
}


tasks.register<Copy>("copyWhiteLabelGem") {
val src = "$buildDir/smithyprojections/smithy-ruby-codegen-test/white-label/ruby-codegen"
val dest = "$buildDir/../../projections/"
val customizations = "white_label/lib/white_label/customizations.rb"
mustRunAfter("copyIntegrationSpecs")
from("$buildDir/smithyprojections/smithy-ruby-codegen-test/white-label/ruby-codegen")
into("$buildDir/../../projections/")
from(src) {
if (file(dest + customizations).exists()) {
exclude(customizations)
}
}
into(dest)
}

tasks.register<Copy>("copyRpcv2CborGem") {
mustRunAfter("copyIntegrationSpecs")
from("$buildDir/smithyprojections/smithy-ruby-codegen-test/rpcv2cbor/ruby-codegen")
into("$buildDir/../../projections/")
}

tasks.register<Delete>("cleanProjections") {
delete("$buildDir/../../projections/white_label/")
delete("$buildDir/../../projections/rpcv2_cbor/")
val src = "$buildDir/smithyprojections/smithy-ruby-codegen-test/rpcv2cbor/ruby-codegen"
val dest = "$buildDir/../../projections/"
val customizations = "rpcv2_cbor/lib/rpcv2_cbor/customizations.rb"
from(src) {
if (file(dest + customizations).exists()) {
exclude(customizations)
}
}
into(dest)
}

tasks.register<Copy>("copyIntegrationSpecs") {
Expand All @@ -176,14 +183,13 @@ tasks.create<SmithyBuild>("buildSdk") {
}.dependsOn(tasks["generate-smithy-build"])

tasks["build"]
.dependsOn(
// tasks["cleanProjections"],
tasks["buildSdk"])
.dependsOn(tasks["buildSdk"])
.finalizedBy(
tasks["copyIntegrationSpecs"],
tasks["copyWhiteLabelGem"],
tasks["copyRpcv2CborGem"]
)

java.sourceSets["main"].java {
srcDirs("model", "src/main/smithy")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative 'spec_helper'

module WhiteLabel
describe Customization do
describe '#customization?' do
it 'exists and returns true' do
expect(Customization.customization?).to eq(true)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import software.amazon.smithy.ruby.codegen.generators.AuthGenerator;
import software.amazon.smithy.ruby.codegen.generators.ClientGenerator;
import software.amazon.smithy.ruby.codegen.generators.ConfigGenerator;
import software.amazon.smithy.ruby.codegen.generators.CustomizationsGenerator;
import software.amazon.smithy.ruby.codegen.generators.EndpointGenerator;
import software.amazon.smithy.ruby.codegen.generators.EventStreamGenerator;
import software.amazon.smithy.ruby.codegen.generators.GemspecGenerator;
Expand Down Expand Up @@ -182,6 +183,9 @@ public void generateService(GenerateServiceDirective<GenerationContext, RubySett
GlobalConfigPluginGenerator globalConfigPluginGenerator = new GlobalConfigPluginGenerator(directive);
globalConfigPluginGenerator.render();

CustomizationsGenerator customizationsGenerator = new CustomizationsGenerator(directive);
customizationsGenerator.render();

MiddlewareGenerator middlewareGenerator = new MiddlewareGenerator(directive, middlewareBuilder);
middlewareGenerator.render();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.ruby.codegen.generators;

import java.util.logging.Logger;
import software.amazon.smithy.codegen.core.directed.ContextualDirective;
import software.amazon.smithy.ruby.codegen.GenerationContext;
import software.amazon.smithy.ruby.codegen.RubySettings;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public class CustomizationsGenerator extends RubyGeneratorBase {
private static final Logger LOGGER =
Logger.getLogger(CustomizationsGenerator.class.getName());

public CustomizationsGenerator(ContextualDirective<GenerationContext, RubySettings> directive) {
super(directive);
}

@Override
protected String getModule() {
return "Customizations";
}

public void render() {
write(writer -> {
writer
.write("# frozen_string_literal: true")
.write("");
});
LOGGER.fine("Wrote customizations to " + rbFile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ModuleGenerator {
Logger.getLogger(ModuleGenerator.class.getName());

private static final String[] DEFAULT_REQUIRES = {
"auth", "builders", "client", "config", "errors", "endpoint", "middleware",
"auth", "builders", "client", "config", "customizations", "errors", "endpoint", "middleware",
"paginators", "params", "parsers", "stubs", "telemetry", "types", "validators", "waiters"
};

Expand Down
2 changes: 1 addition & 1 deletion hearth/spec/hearth/middleware/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TestEndpointInput
end
let(:params) { double }

before(:each) do
before do
expect(param_builder).to receive(:build)
.with({ config1: config1,
config2: config2 }, input, context).and_return(params)
Expand Down

0 comments on commit 95da58e

Please sign in to comment.