File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed
main/java/software/amazon/awssdk/codegen
test/java/software/amazon/awssdk/codegen Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 3030import software .amazon .awssdk .codegen .model .intermediate .OperationModel ;
3131import software .amazon .awssdk .codegen .model .intermediate .ShapeModel ;
3232import software .amazon .awssdk .codegen .model .service .PaginatorDefinition ;
33+ import software .amazon .awssdk .utils .Lazy ;
3334import software .amazon .awssdk .utils .Pair ;
3435import software .amazon .awssdk .utils .StringUtils ;
3536
3839 */
3940abstract class OperationDocProvider {
4041
42+ private static final Lazy <ExampleMetadataProvider > EXAMPLE_PROVIDER =
43+ new Lazy <>(() -> ExampleMetadataProvider .getInstance (EXAMPLE_META_PATH ));
44+
4145 /**
4246 * Doc string for {@link java.nio.file.Path} parameter in simple method overload for streaming input operations.
4347 */
@@ -90,9 +94,8 @@ String getDocs() {
9094 docBuilder .see (crosslink );
9195 }
9296
93- ExampleMetadataProvider exampleProvider = ExampleMetadataProvider .getInstance (EXAMPLE_META_PATH );
94- Optional <String > codeExampleLink = exampleProvider .createLinkToCodeExample (model .getMetadata (),
95- opModel .getOperationName ());
97+ Optional <String > codeExampleLink = EXAMPLE_PROVIDER .getValue ()
98+ .createLinkToCodeExample (model .getMetadata (), opModel .getOperationName ());
9699 codeExampleLink .ifPresent (docBuilder ::see );
97100 return docBuilder .build ().replace ("$" , "$" );
98101 }
Original file line number Diff line number Diff line change @@ -64,6 +64,13 @@ public static ExampleMetadataProvider getInstance(String exampleMetaPath) {
6464 }
6565 return INSTANCE_CACHE .computeIfAbsent (exampleMetaPath , ExampleMetadataProvider ::new );
6666 }
67+
68+ /**
69+ * Clears the instance cache.
70+ */
71+ public static void clearCache () {
72+ INSTANCE_CACHE .clear ();
73+ }
6774
6875 /**
6976 * Creates a link to a code example for the given operation.
Original file line number Diff line number Diff line change 1919import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2020
2121import java .util .Optional ;
22+ import org .junit .jupiter .api .AfterEach ;
2223import org .junit .jupiter .api .Test ;
2324import software .amazon .awssdk .codegen .internal .ExampleMetadataProvider ;
2425import software .amazon .awssdk .codegen .model .intermediate .Metadata ;
@@ -27,6 +28,11 @@ public class OperationDocProviderTest {
2728
2829 private static final String TEST_EXAMPLE_META_PATH = "software/amazon/awssdk/codegen/test-example-meta.json" ;
2930
31+ @ AfterEach
32+ void cleanupCache () {
33+ ExampleMetadataProvider .clearCache ();
34+ }
35+
3036 @ Test
3137 public void exampleMetadataService_createLinkToCodeExample_withValidExample_returnsCorrectLink () {
3238 ExampleMetadataProvider provider = ExampleMetadataProvider .getInstance (TEST_EXAMPLE_META_PATH );
Original file line number Diff line number Diff line change 2121import java .io .InputStream ;
2222import java .util .List ;
2323import java .util .Scanner ;
24+ import org .junit .jupiter .api .AfterEach ;
2425import org .junit .jupiter .api .Test ;
2526import software .amazon .awssdk .codegen .emitters .GeneratorTaskParams ;
2627import software .amazon .awssdk .codegen .internal .ExampleMetadataProvider ;
@@ -31,6 +32,11 @@ public class PackageInfoGeneratorTasksTest {
3132
3233 private static final String TEST_EXAMPLE_META_PATH = "software/amazon/awssdk/codegen/test-example-meta.json" ;
3334
35+ @ AfterEach
36+ void cleanupCache () {
37+ ExampleMetadataProvider .clearCache ();
38+ }
39+
3440 @ Test
3541 public void exampleMetadataService_withExamples_returnsCorrectExamples () {
3642 ExampleMetadataProvider provider = ExampleMetadataProvider .getInstance (TEST_EXAMPLE_META_PATH );
You can’t perform that action at this time.
0 commit comments