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
2 changes: 1 addition & 1 deletion experimental/s3-client-annotation-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependencies {
implementation project(":kora-app-annotation-processor")

testImplementation testFixtures(project(":annotation-processor-common"))
testImplementation project(":experimental:s3-client")
testImplementation project(":experimental:s3-client-kora")
}

apply from: "${project.rootDir}/gradle/in-test-generated.gradle"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.koraframework.s3.client.annotation.processor;
package io.koraframework.s3.client.kora.annotation.processor;

import com.palantir.javapoet.ArrayTypeName;
import com.palantir.javapoet.ClassName;
Expand All @@ -10,42 +10,42 @@

public class S3ClassNames {
public static class Annotation {
public static final ClassName CLIENT = ClassName.get("io.koraframework.s3.client.annotation", "S3", "Client");
public static final ClassName BUCKET = ClassName.get("io.koraframework.s3.client.annotation", "S3", "Bucket");
public static final ClassName GET = ClassName.get("io.koraframework.s3.client.annotation", "S3", "Get");
public static final ClassName LIST = ClassName.get("io.koraframework.s3.client.annotation", "S3", "List");
public static final ClassName PUT = ClassName.get("io.koraframework.s3.client.annotation", "S3", "Put");
public static final ClassName DELETE = ClassName.get("io.koraframework.s3.client.annotation", "S3", "Delete");
public static final ClassName HEAD = ClassName.get("io.koraframework.s3.client.annotation", "S3", "Head");
public static final ClassName CLIENT = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "Client");
public static final ClassName BUCKET = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "Bucket");
public static final ClassName GET = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "Get");
public static final ClassName LIST = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "List");
public static final ClassName PUT = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "Put");
public static final ClassName DELETE = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "Delete");
public static final ClassName HEAD = ClassName.get("io.koraframework.s3.client.kora.annotation", "S3", "Head");

public static final Set<ClassName> OPERATIONS = Set.of(GET, LIST, PUT, DELETE, HEAD);
}


public static final ClassName CLIENT = ClassName.get("io.koraframework.s3.client", "S3Client");
public static final ClassName AWS_CREDENTIALS = ClassName.get("io.koraframework.s3.client", "AwsCredentials");
public static final ClassName CLIENT_FACTORY = ClassName.get("io.koraframework.s3.client", "S3ClientFactory");
public static final ClassName CONFIG = ClassName.get("io.koraframework.s3.client", "S3ClientConfig");
public static final ClassName CONFIG_WITH_CREDS = ClassName.get("io.koraframework.s3.client", "S3ClientConfigWithCredentials");
public static final ClassName CLIENT = ClassName.get("io.koraframework.s3.client.kora", "S3Client");
public static final ClassName S3_CREDENTIALS = ClassName.get("io.koraframework.s3.client.kora", "S3Credentials");
public static final ClassName CLIENT_FACTORY = ClassName.get("io.koraframework.s3.client.kora", "S3ClientFactory");
public static final ClassName CONFIG = ClassName.get("io.koraframework.s3.client.kora", "S3ClientConfig");
public static final ClassName CONFIG_WITH_CREDS = ClassName.get("io.koraframework.s3.client.kora", "S3ClientConfigWithCredentials");

public static final ClassName CONTENT_WRITER = CLIENT.nestedClass("ContentWriter");

public static final ClassName PUT_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "PutObjectArgs");
public static final ClassName GET_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "GetObjectArgs");
public static final ClassName DELETE_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "DeleteObjectArgs");
public static final ClassName HEAD_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "HeadObjectArgs");
public static final ClassName LIST_OBJECTS_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "ListObjectsArgs");
public static final ClassName CREATE_MULTIPART_UPLOAD_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "CreateMultipartUploadArgs");
public static final ClassName COMPLETE_MULTIPART_UPLOAD_ARGS = ClassName.get("io.koraframework.s3.client.model.request", "CompleteMultipartUploadArgs");
public static final ClassName PUT_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "PutObjectArgs");
public static final ClassName GET_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "GetObjectArgs");
public static final ClassName DELETE_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "DeleteObjectArgs");
public static final ClassName HEAD_OBJECT_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "HeadObjectArgs");
public static final ClassName LIST_OBJECTS_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "ListObjectsArgs");
public static final ClassName CREATE_MULTIPART_UPLOAD_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "CreateMultipartUploadArgs");
public static final ClassName COMPLETE_MULTIPART_UPLOAD_ARGS = ClassName.get("io.koraframework.s3.client.kora.model.request", "CompleteMultipartUploadArgs");
public static final Set<TypeName> ARGS = Set.of(PUT_OBJECT_ARGS, GET_OBJECT_ARGS, DELETE_OBJECT_ARGS, HEAD_OBJECT_ARGS, LIST_OBJECTS_ARGS);

public static final ClassName GET_OBJECT_RESULT = ClassName.get("io.koraframework.s3.client.model.response", "GetObjectResult");
public static final ClassName HEAD_OBJECT_RESULT = ClassName.get("io.koraframework.s3.client.model.response", "HeadObjectResult");
public static final ClassName LIST_BUCKET_RESULT = ClassName.get("io.koraframework.s3.client.model.response", "ListBucketResult");
public static final ClassName UPLOADED_PART = ClassName.get("io.koraframework.s3.client.model.response", "UploadedPart");
public static final ClassName GET_OBJECT_RESULT = ClassName.get("io.koraframework.s3.client.kora.model.response", "GetObjectResult");
public static final ClassName HEAD_OBJECT_RESULT = ClassName.get("io.koraframework.s3.client.kora.model.response", "HeadObjectResult");
public static final ClassName LIST_BUCKET_RESULT = ClassName.get("io.koraframework.s3.client.kora.model.response", "ListBucketResult");
public static final ClassName UPLOADED_PART = ClassName.get("io.koraframework.s3.client.kora.model.response", "UploadedPart");
public static final ClassName LIST_BUCKET_RESULT_ITEM = LIST_BUCKET_RESULT.nestedClass("ListBucketItem");

public static final ClassName UNKNOWN_EXCEPTION = ClassName.get("io.koraframework.s3.client.exception", "S3ClientUnknownException");
public static final ClassName UNKNOWN_EXCEPTION = ClassName.get("io.koraframework.s3.client.kora.exception", "S3ClientUnknownException");

public static final Set<TypeName> BODY_TYPES = Set.of(
ArrayTypeName.of(TypeName.BYTE),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.koraframework.s3.client.annotation.processor;
package io.koraframework.s3.client.kora.annotation.processor;

import com.palantir.javapoet.ClassName;
import com.palantir.javapoet.JavaFile;
import io.koraframework.annotation.processor.common.AbstractKoraProcessor;
import io.koraframework.annotation.processor.common.ProcessingErrorException;
import io.koraframework.s3.client.annotation.processor.gen.BucketsConfigGenerator;
import io.koraframework.s3.client.annotation.processor.gen.ClientGenerator;
import io.koraframework.s3.client.annotation.processor.gen.ModuleGenerator;
import io.koraframework.s3.client.kora.annotation.processor.gen.BucketsConfigGenerator;
import io.koraframework.s3.client.kora.annotation.processor.gen.ClientGenerator;
import io.koraframework.s3.client.kora.annotation.processor.gen.ModuleGenerator;

import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.koraframework.s3.client.annotation.processor;
package io.koraframework.s3.client.kora.annotation.processor;

import com.palantir.javapoet.TypeName;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -61,7 +61,7 @@ public static VariableElement credentialsParameter(ExecutableElement method) {
VariableElement foundParam = null;
for (var param : method.getParameters()) {
var typeName = TypeName.get(param.asType());
if (S3ClassNames.AWS_CREDENTIALS.equals(typeName)) {
if (S3ClassNames.S3_CREDENTIALS.equals(typeName)) {
if (foundParam != null) {
throw new ProcessingErrorException("Multiple AwsCredentials parameters found", method, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.koraframework.s3.client.annotation.processor.gen;
package io.koraframework.s3.client.kora.annotation.processor.gen;

import com.palantir.javapoet.*;
import io.koraframework.annotation.processor.common.AnnotationUtils;
import io.koraframework.annotation.processor.common.CommonClassNames;
import io.koraframework.annotation.processor.common.NameUtils;
import io.koraframework.s3.client.annotation.processor.S3ClassNames;
import io.koraframework.s3.client.annotation.processor.S3ClientAnnotationProcessor;
import io.koraframework.s3.client.annotation.processor.S3ClientUtils;
import io.koraframework.s3.client.kora.annotation.processor.S3ClassNames;
import io.koraframework.s3.client.kora.annotation.processor.S3ClientAnnotationProcessor;
import io.koraframework.s3.client.kora.annotation.processor.S3ClientUtils;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Modifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.koraframework.s3.client.annotation.processor.gen;
package io.koraframework.s3.client.kora.annotation.processor.gen;

import com.palantir.javapoet.*;
import io.koraframework.annotation.processor.common.AnnotationUtils;
import io.koraframework.annotation.processor.common.CommonUtils;
import io.koraframework.annotation.processor.common.NameUtils;
import io.koraframework.annotation.processor.common.ProcessingErrorException;
import io.koraframework.s3.client.annotation.processor.S3ClassNames;
import io.koraframework.s3.client.annotation.processor.S3ClientAnnotationProcessor;
import io.koraframework.s3.client.annotation.processor.S3ClientUtils;
import io.koraframework.s3.client.kora.annotation.processor.S3ClassNames;
import io.koraframework.s3.client.kora.annotation.processor.S3ClientAnnotationProcessor;
import io.koraframework.s3.client.kora.annotation.processor.S3ClientUtils;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.*;
Expand All @@ -31,7 +31,7 @@ public static TypeSpec generate(ProcessingEnvironment processingEnv, TypeElement
var configType = credsRequired
? S3ClassNames.CONFIG_WITH_CREDS
: S3ClassNames.CONFIG;
var b = CommonUtils.extendsKeepAop(s3client, NameUtils.generatedType(s3client, "ClientImpl"))
var b = CommonUtils.extendsKeepAop(s3client, NameUtils.generatedType(s3client, "S3ClientImpl"))
.addAnnotation(AnnotationUtils.generated(S3ClientAnnotationProcessor.class))
.addField(S3ClassNames.CLIENT, "client", Modifier.PRIVATE, Modifier.FINAL)
.addField(configType, "config", Modifier.PRIVATE, Modifier.FINAL);
Expand Down Expand Up @@ -358,7 +358,7 @@ private static CodeBlock generateKey(ExecutableElement method, AnnotationMirror
.filter(p -> {
var parameterTypeName = TypeName.get(p.asType());
return !AnnotationUtils.isAnnotationPresent(p, S3ClassNames.Annotation.BUCKET)
&& !S3ClassNames.AWS_CREDENTIALS.equals(parameterTypeName)
&& !S3ClassNames.S3_CREDENTIALS.equals(parameterTypeName)
&& !S3ClassNames.ARGS.contains(parameterTypeName)
&& !S3ClassNames.BODY_TYPES.contains(parameterTypeName)
;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.koraframework.s3.client.annotation.processor.gen;
package io.koraframework.s3.client.kora.annotation.processor.gen;

import com.palantir.javapoet.ClassName;
import com.palantir.javapoet.MethodSpec;
Expand All @@ -7,9 +7,9 @@
import io.koraframework.annotation.processor.common.AnnotationUtils;
import io.koraframework.annotation.processor.common.CommonClassNames;
import io.koraframework.annotation.processor.common.NameUtils;
import io.koraframework.s3.client.annotation.processor.S3ClassNames;
import io.koraframework.s3.client.annotation.processor.S3ClientAnnotationProcessor;
import io.koraframework.s3.client.annotation.processor.S3ClientUtils;
import io.koraframework.s3.client.kora.annotation.processor.S3ClassNames;
import io.koraframework.s3.client.kora.annotation.processor.S3ClientAnnotationProcessor;
import io.koraframework.s3.client.kora.annotation.processor.S3ClientUtils;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ElementKind;
Expand All @@ -21,8 +21,8 @@ public class ModuleGenerator {
public static TypeSpec generate(ProcessingEnvironment processingEnv, TypeElement s3client) {
var packageName = processingEnv.getElementUtils().getPackageOf(s3client).getQualifiedName().toString();
var bucketsType = ClassName.get(packageName, NameUtils.generatedType(s3client, "BucketsConfig"));
var clientType = ClassName.get(packageName, NameUtils.generatedType(s3client, "ClientImpl"));
var b = TypeSpec.interfaceBuilder(NameUtils.generatedType(s3client, "Module"))
var clientType = ClassName.get(packageName, NameUtils.generatedType(s3client, "S3ClientImpl"));
var b = TypeSpec.interfaceBuilder(NameUtils.generatedType(s3client, "S3Module"))
.addModifiers(Modifier.PUBLIC)
.addAnnotation(CommonClassNames.module)
.addAnnotation(AnnotationUtils.generated(S3ClientAnnotationProcessor.class))
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.koraframework.s3.client.annotation.processor.S3ClientAnnotationProcessor
io.koraframework.s3.client.kora.annotation.processor.S3ClientAnnotationProcessor

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.koraframework.s3.client.annotation.processor;
package io.koraframework.s3.client.kora.annotation.processor;

import io.koraframework.annotation.processor.common.AbstractAnnotationProcessorTest;
import io.koraframework.aop.annotation.processor.AopAnnotationProcessor;
import io.koraframework.s3.client.S3Client;
import io.koraframework.s3.client.S3ClientConfigWithCredentials;
import io.koraframework.s3.client.S3ClientFactory;
import io.koraframework.s3.client.kora.S3Client;
import io.koraframework.s3.client.kora.S3ClientConfigWithCredentials;
import io.koraframework.s3.client.kora.S3ClientFactory;
import org.intellij.lang.annotations.Language;
import org.mockito.Mockito;

Expand All @@ -21,12 +21,12 @@ protected String commonImports() {
import java.util.Iterator;
import java.util.Collection;
import java.util.Optional;
import io.koraframework.s3.client.annotation.*;
import io.koraframework.s3.client.annotation.S3.*;
import io.koraframework.s3.client.model.request.*;
import io.koraframework.s3.client.model.response.*;
import io.koraframework.s3.client.*;
import io.koraframework.s3.client.S3Client.*;
import io.koraframework.s3.client.kora.annotation.*;
import io.koraframework.s3.client.kora.annotation.S3.*;
import io.koraframework.s3.client.kora.model.request.*;
import io.koraframework.s3.client.kora.model.response.*;
import io.koraframework.s3.client.kora.*;
import io.koraframework.s3.client.kora.S3Client.*;
""";
}

Expand All @@ -41,6 +41,6 @@ protected AbstractAnnotationProcessorTest.TestObject compile(@Language("java") S
args.add(clientFactory);
args.add(config);
args.addAll(List.of(addArgs));
return new AbstractAnnotationProcessorTest.TestObject(loadClass("$Client_ClientImpl"), args);
return new AbstractAnnotationProcessorTest.TestObject(loadClass("$Client_S3ClientImpl"), args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.koraframework.s3.client.kora.annotation.processor;

class S3ClientAnnotationProcessorTest {

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.koraframework.s3.client.annotation.processor;
package io.koraframework.s3.client.kora.annotation.processor;

import io.koraframework.s3.client.kora.S3Credentials;
import org.junit.jupiter.api.Test;
import io.koraframework.config.common.factory.MapConfigFactory;
import io.koraframework.s3.client.AwsCredentials;
import io.koraframework.s3.client.model.request.DeleteObjectArgs;
import io.koraframework.s3.client.kora.model.request.DeleteObjectArgs;

import java.util.Map;

Expand Down Expand Up @@ -61,11 +61,11 @@ public void testDeleteWithAwsCredentials() throws Exception {
@S3.Bucket(".bucket")
public interface Client {
@S3.Delete
void deleteWithCreds(AwsCredentials creds, String key);
void deleteWithCreds(S3Credentials creds, String key);
}
""", newGeneratedObject("$Client_BucketsConfig", bucketConfig));

var creds = AwsCredentials.of("test", "test");
var creds = S3Credentials.of("test", "test");
client.invoke("deleteWithCreds", creds, "key");

verify(s3Client).deleteObject(same(creds), eq("bucket_value"), eq("key"), isNull());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.koraframework.s3.client.annotation.processor;
package io.koraframework.s3.client.kora.annotation.processor;


import io.koraframework.s3.client.kora.S3Credentials;
import org.junit.jupiter.api.Test;
import io.koraframework.config.common.factory.MapConfigFactory;
import io.koraframework.http.common.body.HttpBodyInput;
import io.koraframework.s3.client.AwsCredentials;
import io.koraframework.s3.client.model.request.GetObjectArgs;
import io.koraframework.s3.client.model.response.GetObjectResult;
import io.koraframework.s3.client.kora.model.request.GetObjectArgs;
import io.koraframework.s3.client.kora.model.response.GetObjectResult;

import java.io.ByteArrayInputStream;
import java.util.Map;
Expand Down Expand Up @@ -83,12 +83,12 @@ public void testGetWithAwsCredentials() throws Exception {
public interface Client {
@S3.Get
@Nullable
GetObjectResult getWithCreds(AwsCredentials creds, String key);
GetObjectResult getWithCreds(S3Credentials creds, String key);
}
""", newGeneratedObject("$Client_BucketsConfig", bucketConfig));

var getObjectResult = mock(GetObjectResult.class);
var creds = AwsCredentials.of("test", "test");
var creds = S3Credentials.of("test", "test");
when(s3Client.getObject(same(creds), eq("bucket_value"), eq("key"), isNull(), eq(false))).thenReturn(getObjectResult);

var result = client.<GetObjectResult>invoke("getWithCreds", creds, "key");
Expand All @@ -101,7 +101,7 @@ public interface Client {
@Test
public void testGetWithGetObjectArgsParam() throws Exception {
var client = this.compile("""
import io.koraframework.s3.client.model.request.GetObjectArgs;@S3.Client
import io.koraframework.s3.client.kora.model.request.GetObjectArgs;@S3.Client
public interface Client {
@S3.Get
GetObjectResult getWithArgs(@S3.Bucket String bucket, String key, GetObjectArgs args);
Expand Down
Loading
Loading