Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add annotation-processor to clientcore parent maven configuration #43886

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion eng/versioning/external_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ com.squareup.okhttp3:okhttp;4.12.0
com.squareup:javapoet;1.13.0
commons-codec:commons-codec;1.15
commons-net:commons-net;3.9.0
io.clientcore.tools:annotation-processor;1.0.0-beta.1
io.cloudevents:cloudevents-api;2.2.0
io.cloudevents:cloudevents-core;2.2.0
io.fabric8:kubernetes-client;6.12.1
Expand Down
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ io.clientcore:core;1.0.0-beta.2;1.0.0-beta.3
io.clientcore:http-okhttp3;1.0.0-beta.1;1.0.0-beta.1
io.clientcore:http-stress;1.0.0-beta.1;1.0.0-beta.1
io.clientcore:optional-dependency-tests;1.0.0-beta.1;1.0.0-beta.1
io.clientcore:annotation-processor;1.0.0-beta.1;1.0.0-beta.1

# Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current
# version. Unreleased dependencies are only valid for dependency versions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing only, delete.

// Licensed under the MIT License.

package io.clientcore.core;

import io.clientcore.core.annotation.ServiceInterface;
import io.clientcore.core.http.annotation.BodyParam;
import io.clientcore.core.http.annotation.HeaderParam;
import io.clientcore.core.http.annotation.HttpRequestInformation;
import io.clientcore.core.http.annotation.PathParam;
import io.clientcore.core.http.models.HttpMethod;
import io.clientcore.core.http.models.Response;
import io.clientcore.core.http.pipeline.HttpPipeline;
import io.clientcore.core.util.binarydata.BinaryData;
import io.clientcore.core.util.serializer.ObjectSerializer;

import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;

@ServiceInterface(name = "myService", host = "https://somecloud.com")
public interface TestInterfaceClientService {
static TestInterfaceClientService getInstance(HttpPipeline pipeline, ObjectSerializer serializer,
TestInterfaceServiceVersion serviceVersion) {
if (pipeline == null) {
throw new IllegalArgumentException("pipeline cannot be null");
}
try {
Class<?> clazz = Class.forName("com.service.clientlibrary.implementation.TestInterfaceClientServiceImpl");
return (TestInterfaceClientService) clazz
.getMethod("getInstance", HttpPipeline.class, ObjectSerializer.class, TestInterfaceServiceVersion.class)
.invoke(null, pipeline, serializer, serviceVersion);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
throw new RuntimeException(e);
}
}

static void reset() {
try {
Class<?> clazz = Class.forName("com.service.clientlibrary.implementation.TestInterfaceClientServiceImpl");
clazz.getMethod("reset").invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
throw new RuntimeException(e);
}
}

@HttpRequestInformation(method = HttpMethod.POST, path = "my/uri/path", expectedStatusCodes = { 200 })
Response<Void> testMethod(@BodyParam("application/octet-stream") ByteBuffer request,
@HeaderParam("Content-Type") String contentType, @HeaderParam("Content-Length") Long contentLength);

@HttpRequestInformation(method = HttpMethod.POST, path = "my/uri/path", expectedStatusCodes = { 200 })
Response<Void> testMethod(@BodyParam("application/octet-stream") BinaryData data,
@HeaderParam("Content-Type") String contentType, @HeaderParam("Content-Length") Long contentLength);

@HttpRequestInformation(method = HttpMethod.GET, path = "{nextLink}", expectedStatusCodes = { 200 })
Response<Void> testListNext(@PathParam(value = "nextLink", encoded = true) String nextLink);

@HttpRequestInformation(method = HttpMethod.GET, path = "my/uri/path", expectedStatusCodes = { 200 })
Void testMethodReturnsVoid();

@HttpRequestInformation(method = HttpMethod.HEAD, path = "my/uri/path", expectedStatusCodes = { 200 })
void testHeadMethod();

@HttpRequestInformation(method = HttpMethod.GET, path = "my/uri/path", expectedStatusCodes = { 200 })
Response<Void> testMethodReturnsResponseVoid();

@HttpRequestInformation(method = HttpMethod.GET, path = "my/uri/path", expectedStatusCodes = { 200 })
Response<InputStream> testDownload();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing only, delete.

// Licensed under the MIT License.

package io.clientcore.core;

import io.clientcore.core.http.models.ServiceVersion;

/**
* Service version of OpenAIClient.
*/
public enum TestInterfaceServiceVersion implements ServiceVersion {
/**
* Enum value 2022-12-01.
*/
V_TEST_VALUE("test-value");

private final String version;

TestInterfaceServiceVersion(String version) {
this.version = version;
}

/**
* {@inheritDoc}
*/
@Override
public String getVersion() {
return this.version;
}

/**
* Gets the latest service version supported by this client library.
*
* @return The latest {@link TestInterfaceServiceVersion}.
*/
public static TestInterfaceServiceVersion getLatest() {
return V_TEST_VALUE;
}
}
4 changes: 2 additions & 2 deletions sdk/clientcore/tools/annotation-processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ The client-core annotation processor for introducing compile-time code generatio
```xml
<dependencies>
<dependency>
<groupId>io.clientcore.tools</groupId>
<groupId>io.clientcore</groupId>
<artifactId>annotation-processor</artifactId>
<version>1.0.0.beta.1</version> <!-- {x-version-update;io.clientcore.tools:annotation-processor;external_dependency} -->
<version>1.0.0.beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
16 changes: 13 additions & 3 deletions sdk/clientcore/tools/annotation-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

<modelVersion>4.0.0</modelVersion>

<groupId>io.clientcore.tools</groupId>
<groupId>io.clientcore</groupId>
<artifactId>annotation-processor</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore.tools:annotation-processor;external_dependency} -->
<packaging>jar</packaging>
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->

<name>Client Core Compile-Time Annotation Processor</name>
<description>The client-core annotation processor for introducing compile-time code generation for libraries based on client core</description>
Expand Down Expand Up @@ -71,7 +72,6 @@
<groupId>io.clientcore</groupId>
<artifactId>core</artifactId>
<version>1.0.0-beta.2</version> <!-- {x-version-update;io.clientcore:core;dependency} -->
<scope>compile</scope>
</dependency>

<!-- Unit Test -->
Expand Down Expand Up @@ -108,5 +108,15 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
import java.util.stream.Collectors;

@SupportedAnnotationTypes("io.clientcore.core.annotation.*")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedSourceVersion(SourceVersion.RELEASE_17)
public class AnnotationProcessor extends AbstractProcessor {

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// We iterate through each interface annotated with @ServiceInterface separately.
Expand Down
31 changes: 27 additions & 4 deletions sdk/parents/clientcore-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@
<version>0.8.12</version> <!-- {x-version-update;org.jacoco:org.jacoco.agent;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.clientcore</groupId>
<artifactId>annotation-processor</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -656,7 +661,6 @@
</excludes>
<includes combine.children="append">
<include>io.clientcore:*</include>

</includes>
</bannedDependencies>

Expand Down Expand Up @@ -733,10 +737,19 @@
<arg>-Xlint:-requires-transitive-automatic</arg> <!-- FIXME: this is required for now as it introduces a build failure -->
</compilerArgs>

<!-- Default is annotation processing being off. -->
<proc>${compiler.proc}</proc>

<!-- Default is annotation processing being on. -->
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>io.clientcore</groupId>
<artifactId>annotation-processor</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
</annotationProcessorPath>
</annotationProcessorPaths>
<createMissingPackageInfoClass>false</createMissingPackageInfoClass>
<annotationProcessors>
<annotationProcessor>io.clientcore.tools.codegen.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
</configuration>
</plugin>

Expand Down Expand Up @@ -1151,6 +1164,12 @@
</configuration>
</execution>
</executions>
<configuration>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
<annotationProcessors>
<annotationProcessor>io.clientcore.tools.codegen.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -1181,6 +1200,10 @@
<arg>-Xlint:-options</arg> <!-- Needed to compile with Java 20+ -->
</compilerArgs>
<release>${java.vm.specification.version}</release>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
<annotationProcessors>
<annotationProcessor>io.clientcore.tools.codegen.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>

Expand Down
Loading