Skip to content

Commit 7dbebc1

Browse files
committed
address PR feedback
1 parent bcad510 commit 7dbebc1

File tree

5 files changed

+56
-76
lines changed

5 files changed

+56
-76
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package software.amazon.smithy.python.aws.codegen;
6+
7+
import java.io.BufferedReader;
8+
import java.io.InputStream;
9+
import java.io.InputStreamReader;
10+
import java.nio.charset.StandardCharsets;
11+
import java.util.List;
12+
import java.util.stream.Collectors;
13+
import software.amazon.smithy.python.codegen.GenerationContext;
14+
import software.amazon.smithy.python.codegen.integrations.PythonIntegration;
15+
import software.amazon.smithy.python.codegen.integrations.RuntimeClientPlugin;
16+
17+
/**
18+
* Integration that generates LICENSE and NOTICE files for AWS Python clients.
19+
*/
20+
public class AwsLicenseAndNoticeIntegration implements PythonIntegration {
21+
22+
@Override
23+
public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
24+
return List.of(
25+
RuntimeClientPlugin.builder()
26+
.writeAdditionalFiles((c) -> {
27+
writeLicense(c);
28+
writeNotice(c);
29+
return List.of();
30+
})
31+
.build());
32+
}
33+
34+
private static void writeLicense(GenerationContext context) {
35+
context.writerDelegator().useFileWriter("LICENSE", writer -> {
36+
writer.write(loadResourceAsString("/software/amazon/smithy/python/codegen/apache-2.0-license.txt"));
37+
});
38+
}
39+
40+
private static void writeNotice(GenerationContext context) {
41+
context.writerDelegator().useFileWriter("NOTICE", writer -> {
42+
writer.write("Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.");
43+
});
44+
}
45+
46+
private static String loadResourceAsString(String resourcePath) {
47+
try (InputStream inputStream = AwsLicenseAndNoticeIntegration.class.getResourceAsStream(resourcePath);
48+
BufferedReader reader =
49+
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
50+
return reader.lines().collect(Collectors.joining("\n"));
51+
} catch (Exception e) {
52+
throw new RuntimeException("Failed to load resource: " + resourcePath, e);
53+
}
54+
}
55+
}

codegen/aws/core/src/main/resources/META-INF/services/software.amazon.smithy.python.codegen.integrations.PythonIntegration

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ software.amazon.smithy.python.aws.codegen.AwsServiceIdIntegration
99
software.amazon.smithy.python.aws.codegen.AwsUserAgentIntegration
1010
software.amazon.smithy.python.aws.codegen.AwsStandardRegionalEndpointsIntegration
1111
software.amazon.smithy.python.aws.codegen.AwsRstDocFileGenerator
12+
software.amazon.smithy.python.aws.codegen.AwsLicenseAndNoticeIntegration

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/SetupGenerator.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
*/
55
package software.amazon.smithy.python.codegen.generators;
66

7-
import java.io.BufferedReader;
8-
import java.io.IOException;
9-
import java.io.InputStream;
10-
import java.io.InputStreamReader;
11-
import java.nio.charset.StandardCharsets;
12-
import java.time.LocalDate;
137
import java.util.Collection;
148
import java.util.Collections;
159
import java.util.List;
@@ -28,8 +22,6 @@
2822
import software.amazon.smithy.model.traits.StringTrait;
2923
import software.amazon.smithy.model.traits.TitleTrait;
3024
import software.amazon.smithy.python.codegen.*;
31-
import software.amazon.smithy.python.codegen.sections.LicenseSection;
32-
import software.amazon.smithy.python.codegen.sections.NoticeSection;
3325
import software.amazon.smithy.python.codegen.sections.PyprojectSection;
3426
import software.amazon.smithy.python.codegen.sections.ReadmeSection;
3527
import software.amazon.smithy.python.codegen.writer.PythonWriter;
@@ -52,8 +44,6 @@ public static void generateSetup(
5244
var dependencies = gatherDependencies(context.writerDelegator().getDependencies().stream());
5345
writePyproject(settings, context.writerDelegator(), dependencies);
5446
writeReadme(settings, context);
55-
writeLicense(context);
56-
writeNotice(context);
5747
}
5848

5949
/**
@@ -285,38 +275,6 @@ private static void writeReadme(
285275
});
286276
}
287277

288-
private static void writeLicense(
289-
GenerationContext context
290-
) {
291-
context.writerDelegator().useFileWriter("LICENSE", writer -> {
292-
writer.pushState(new LicenseSection());
293-
writer.write(loadResourceAsString("/software/amazon/smithy/python/codegen/apache-2.0-license.txt"));
294-
writer.popState();
295-
});
296-
}
297-
298-
private static void writeNotice(
299-
GenerationContext context
300-
) {
301-
context.writerDelegator().useFileWriter("NOTICE", writer -> {
302-
writer.pushState(new NoticeSection());
303-
var currentYear = LocalDate.now().getYear();
304-
writer.write("Copyright " + currentYear + " Amazon.com, Inc. or its affiliates. All Rights Reserved.");
305-
writer.popState();
306-
});
307-
308-
}
309-
310-
private static String loadResourceAsString(String resourcePath) {
311-
try (InputStream inputStream = SetupGenerator.class.getResourceAsStream(resourcePath);
312-
BufferedReader reader =
313-
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
314-
return reader.lines().collect(Collectors.joining("\n"));
315-
} catch (IOException e) {
316-
throw new CodegenException("Failed to load resource: " + resourcePath, e);
317-
}
318-
}
319-
320278
/**
321279
* Write the files required for sphinx doc generation
322280
*/

codegen/core/src/main/java/software/amazon/smithy/python/codegen/sections/LicenseSection.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

codegen/core/src/main/java/software/amazon/smithy/python/codegen/sections/NoticeSection.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)