Skip to content

Commit

Permalink
Use @Export.typeString in SDK
Browse files Browse the repository at this point in the history
part of #629
  • Loading branch information
pawelprazak committed Jul 22, 2022
1 parent 77fe1db commit 72021db
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@

/**
* @return the generic type parameter of the annotated @see {@link com.pulumi.core.Output}
* @deprecated use {@link #typeString()}
*/
Class<?> type();
@Deprecated
Class<?> type() default Object.class;

/**
* @return the generic type parameters of the @see {@link #type()}
* If not set, the assumption is that the @see {@link #type()} is not a generic type.
* @deprecated use {@link #typeString()}
*/
@Deprecated
Class<?>[] parameters() default {};

/**
* @return the generic type parameter of the annotated @see {@link com.pulumi.core.Output}
*/
String typeString() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,31 @@ public static ImmutableMap<String, ExportMetadata<?>> of(Class<?> extractionType
)));

var fieldType = field.getType();
var exportType = export.type();
var parameters = export.parameters();

return of(field, export, fieldType, exportType, parameters);
if (export.typeString().isBlank()) {
var exportType = export.type();
var parameters = export.parameters();
return of(field, export, fieldType, exportType, parameters);
} else {
var exportTypeNew = TypeShape.fromString(export.typeString());
return of(field, export, fieldType, exportTypeNew);
}
})
.collect(toImmutableMap(
ImportExportMetadata::getName,
Function.identity()
));
}

private static <T> ExportMetadata<T> of(
Field field,
Export exportAnnotation,
Class<?> fieldType,
TypeShape<T> dataType
) {
//noinspection unchecked
return new ExportMetadata<>(field, exportAnnotation, (Class<Output<T>>) fieldType, dataType);
}

private static <T> ExportMetadata<T> of(
Field field,
Export exportAnnotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CustomResource extends Resource {

private CompletableFuture<Output<String>> idFuture; // effectively final, lazy init

@Export(name = Constants.IdPropertyName, type = String.class)
@Export(name = Constants.IdPropertyName, typeString = "java.lang.String")
private Output<String> id; // effectively final, lazy init

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class Resource {

private final CompletableFuture<Output<String>> urnFuture = new CompletableFuture<>();

@Export(name = Constants.UrnPropertyName, type = String.class)
@Export(name = Constants.UrnPropertyName, typeString="java.lang.String")
private final Output<String> urn = Output.of(urnFuture).apply(urn -> urn);

private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public class StackReference extends CustomResource {
/**
* The name of the referenced stack.
*/
@Export(name = "name", type = String.class)
@Export(name = "name", typeString="java.lang.String")
private Output<String> name;

/**
* The outputs of the referenced stack.
*/
@Export(name = "outputs", type = Map.class, parameters = {String.class, Object.class})
@Export(name = "outputs", typeString = "java.util.Map<java.lang.String,java.lang.Object>")
public Output<Map<String, Object>> outputs;

/**
* The names of any stack outputs which contain secrets.
*/
@Export(name = "secretOutputNames", type = List.class, parameters = String.class)
@Export(name = "secretOutputNames", typeString = "java.util.List<java.lang.String>")
public Output<List<String>> secretOutputNames;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ class ImportExportMetadataTest {
@SuppressWarnings("unused")
public static class Tester {

@Export(name = "complex1", type = Either.class, parameters = {Integer.class, String.class})
@Export(name = "complex1", typeString = "com.pulumi.core.Either<java.lang.Integer,java.lang.String>")
public final Output<Either<Integer, String>> complex1 = Output.of(Either.ofLeft(1));

@Export(name = "complex2", type = Either.class, parameters = {Integer.class, String.class})
@Export(name = "complex2", typeString = "com.pulumi.core.Either<java.lang.Integer,java.lang.String>")
public final Output<Either<Integer, String>> complex2 = Output.of(Either.ofRight("1"));

@Export(name = "foo", type = String.class)
@Export(name = "foo", typeString="java.lang.String")
final Output<String> explicitFoo = Output.of("");

@Export(type = String.class)
@Export(typeString="java.lang.String")
private final Output<String> implicitFoo = Output.of("");

@Export(type = Map.class, parameters = {String.class, Integer.class})
@Export(typeString = "java.util.Map<java.lang.String,java.lang.Integer>")
public final Output<Map<String, Integer>> implicitBaz = Output.of(Map.of());

@Export(type = Double.class)
@Export(typeString = "java.lang.Double")
private Output<Double> incomplete;

@Import(name = "bar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class OutputCompletionSourceTest {

@SuppressWarnings("unused")
private static class Tester {
@Export(type = String.class)
@Export(typeString="java.lang.String")
Output<String> foo;

@Export(type = Either.class, parameters = {Integer.class, String.class})
@Export(typeString = "com.pulumi.core.Either<java.lang.Integer,java.lang.String>")
private Output<Either<Integer, String>> complex1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void testStackWithInvalidSchema() {

@ResourceType(type = "aws:ec2/instance:Instance")
public static class Instance extends CustomResource {
@Export(type = String.class)
@Export(typeString="java.lang.String")
public Output<String> publicIp;

public Instance(String name, InstanceArgs args, @Nullable CustomResourceOptions options) {
Expand All @@ -222,7 +222,7 @@ public static final class InstanceArgs extends ResourceArgs {
}

public static class MyCustom extends CustomResource {
@Export(type = Instance.class)
@Export(typeString = "com.pulumi.deployment.MocksTest.Instance")
public Output<Instance> instance;

public MyCustom(String name, MyCustomArgs args, @Nullable CustomResourceOptions options) {
Expand Down

0 comments on commit 72021db

Please sign in to comment.