Skip to content

Commit e695902

Browse files
authored
Add annotation-processor to clientcore ci.yml (Azure#43886)
1 parent 16251c7 commit e695902

File tree

48 files changed

+1309
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1309
-495
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@
200200
"sdk/loadtesting/azure-developer-loadtesting/**",
201201
"sdk/clientcore/core/**",
202202
"sdk/clientcore/http-okhttp3/**",
203+
"sdk/clientcore/annotation-processor/**",
204+
"sdk/clientcore/annotation-processor-test/**",
203205
"sdk/clientcore/tools/**",
204206
"sdk/serialization/azure-json-gson/**",
205207
"sdk/serialization/azure-json/**",

eng/.docsettings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ known_content_issues:
101101
- ['sdk/clientcore/http-okhttp3/README.md', '#3113']
102102
- ['sdk/clientcore/tools/annotation-processor/README.md', '#3113']
103103
- ['sdk/clientcore/optional-dependency-tests/README.md', '#3113']
104+
- ['sdk/clientcore/annotation-processor/README.md', '#3113']
105+
- ['sdk/clientcore/annotation-processor-test/README.md', '#3113']
104106
- ['sdk/core/azure-core-experimental/README.md', '#3113']
105107
- ['sdk/cosmos/faq/README.md', '#3113']
106108
- ['sdk/cosmos/azure-cosmos-benchmark/README.md', '#3113']

eng/versioning/external_dependencies.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ com.squareup.okhttp3:okhttp;4.12.0
4242
com.squareup:javapoet;1.13.0
4343
commons-codec:commons-codec;1.15
4444
commons-net:commons-net;3.9.0
45-
io.clientcore.tools:annotation-processor;1.0.0-beta.1
4645
io.cloudevents:cloudevents-api;2.2.0
4746
io.cloudevents:cloudevents-core;2.2.0
4847
io.fabric8:kubernetes-client;6.12.1

eng/versioning/version_client.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ io.clientcore:core;1.0.0-beta.3;1.0.0-beta.4
477477
io.clientcore:http-okhttp3;1.0.0-beta.1;1.0.0-beta.1
478478
io.clientcore:http-stress;1.0.0-beta.1;1.0.0-beta.1
479479
io.clientcore:optional-dependency-tests;1.0.0-beta.1;1.0.0-beta.1
480+
io.clientcore:annotation-processor;1.0.0-beta.1;1.0.0-beta.1
481+
io.clientcore:annotation-processor-test;1.0.0-beta.1;1.0.0-beta.1
480482

481483

482484
# Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Release History
2+
3+
## 1.0.0-beta.1 (Unreleased)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Core Tests shared library for Java
2+
3+
Tests that validate annotation-processor features of generating Service Interface Implementation for the Core library.
4+
5+
## Getting started
6+
7+
## Key concepts
8+
9+
## Examples
10+
11+
## Troubleshooting
12+
13+
## Next steps
14+
15+
## Contributing
16+
17+
<!-- links -->
18+
19+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%clientcore%2Fannotation-processor-test%2FREADME.png)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!--
2+
~ Copyright (c) Microsoft Corporation. All rights reserved.
3+
~ Licensed under the MIT License.
4+
-->
5+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
7+
<modelVersion>4.0.0</modelVersion>
8+
<parent>
9+
<groupId>io.clientcore</groupId>
10+
<artifactId>clientcore-parent</artifactId>
11+
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:clientcore-parent;current} -->
12+
<relativePath>../../parents/clientcore-parent</relativePath>
13+
</parent>
14+
15+
<groupId>io.clientcore</groupId>
16+
<artifactId>annotation-processor-test</artifactId>
17+
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor-test;current} -->
18+
19+
<name>Java Core library tests for annotation-processor features.</name>
20+
<description>Tests that validate features of the annotation-processor tooling.</description>
21+
<url>https://github.com/Azure/azure-sdk-for-java</url>
22+
23+
<licenses>
24+
<license>
25+
<name>The MIT License (MIT)</name>
26+
<url>http://opensource.org/licenses/MIT</url>
27+
<distribution>repo</distribution>
28+
</license>
29+
</licenses>
30+
31+
<scm>
32+
<url>https://github.com/Azure/azure-sdk-for-java</url>
33+
<connection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</connection>
34+
<developerConnection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</developerConnection>
35+
</scm>
36+
37+
<properties>
38+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39+
<jacoco.skip>true</jacoco.skip>
40+
<checkstyle.skip>true</checkstyle.skip>
41+
<spotbugs.skip>true</spotbugs.skip>
42+
<spotless.skip>true</spotless.skip>
43+
<revapi.skip>true</revapi.skip>
44+
<doclint>all,-missing</doclint>
45+
</properties>
46+
47+
<dependencies>
48+
<dependency>
49+
<groupId>io.clientcore</groupId>
50+
<artifactId>core</artifactId>
51+
<version>1.0.0-beta.3</version> <!-- {x-version-update;io.clientcore:core;current} -->
52+
</dependency>
53+
54+
<!-- Test dependencies -->
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-api</artifactId>
58+
<version>5.11.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.junit.jupiter</groupId>
63+
<artifactId>junit-jupiter-engine</artifactId>
64+
<version>5.11.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter-params</artifactId>
70+
<version>5.11.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} -->
71+
<scope>test</scope>
72+
</dependency>
73+
</dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.13.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-compiler-plugin;external_dependency} -->
81+
<configuration>
82+
<proc>only</proc>
83+
<!-- Supported source version 'RELEASE_8' from annotation processor 'io.clientcore.annotation.processor.AnnotationProcessor' less than -source '17' -->
84+
<failOnWarning>false</failOnWarning>
85+
<generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
86+
<annotationProcessorPaths>
87+
<annotationProcessorPath>
88+
<groupId>io.clientcore</groupId>
89+
<artifactId>annotation-processor</artifactId>
90+
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
91+
</annotationProcessorPath>
92+
</annotationProcessorPaths>
93+
<annotationProcessors>
94+
<annotationProcessor>io.clientcore.annotation.processor.AnnotationProcessor</annotationProcessor>
95+
</annotationProcessors>
96+
<compileSourceRoots>
97+
<compileSourceRoot>${project.build.directory}/generated-sources/</compileSourceRoot>
98+
</compileSourceRoots>
99+
</configuration>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
</project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package io.clientcore.annotation.processor.test;
5+
6+
import io.clientcore.core.http.models.HttpHeaders;
7+
import io.clientcore.core.http.models.HttpRequest;
8+
import io.clientcore.core.http.models.HttpResponse;
9+
import io.clientcore.core.implementation.util.JsonSerializer;
10+
import io.clientcore.core.util.binarydata.BinaryData;
11+
import io.clientcore.core.util.serializer.ObjectSerializer;
12+
13+
/**
14+
* A mock implementation of {@link HttpResponse} that can be used for testing.
15+
*/
16+
public class MockHttpResponse extends HttpResponse<BinaryData> {
17+
private static final ObjectSerializer SERIALIZER = new JsonSerializer();
18+
19+
/**
20+
* Creates an HTTP response associated with a {@code request}, returns the {@code statusCode}, and has an empty
21+
* response body.
22+
*
23+
* @param request HttpRequest associated with the response.
24+
* @param statusCode Status code of the response.
25+
*/
26+
public MockHttpResponse(HttpRequest request, int statusCode) {
27+
this(request, statusCode, BinaryData.empty());
28+
}
29+
30+
/**
31+
* Creates an HTTP response associated with a {@code request}, returns the {@code statusCode}, and response body of
32+
* {@code bodyBytes}.
33+
*
34+
* @param request HttpRequest associated with the response.
35+
* @param statusCode Status code of the response.
36+
* @param body Contents of the response.
37+
*/
38+
public MockHttpResponse(HttpRequest request, int statusCode, BinaryData body) {
39+
this(request, statusCode, new HttpHeaders(), body);
40+
}
41+
42+
/**
43+
* Creates an HTTP response associated with a {@code request}, returns the {@code statusCode}, and http headers.
44+
*
45+
* @param request HttpRequest associated with the response.
46+
* @param statusCode Status code of the response.
47+
* @param headers Headers of the response.
48+
*/
49+
public MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers) {
50+
this(request, statusCode, headers, BinaryData.empty());
51+
}
52+
53+
/**
54+
* Creates an HTTP response associated with a {@code request}, returns the {@code statusCode}, contains the
55+
* {@code headers}, and response body of {@code bodyBytes}.
56+
*
57+
* @param request HttpRequest associated with the response.
58+
* @param statusCode Status code of the response.
59+
* @param headers HttpHeaders of the response.
60+
* @param body Contents of the response.
61+
*/
62+
public MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers, BinaryData body) {
63+
super(request, statusCode, headers, body);
64+
}
65+
66+
/**
67+
* Creates an HTTP response associated with a {@code request}, returns the {@code statusCode}, and response body
68+
* that is JSON serialized from {@code serializable}.
69+
*
70+
* @param request HttpRequest associated with the response.
71+
* @param statusCode Status code of the response.
72+
* @param serializable Contents to be serialized into JSON for the response.
73+
*/
74+
public MockHttpResponse(HttpRequest request, int statusCode, Object serializable) {
75+
this(request, statusCode, new HttpHeaders(), serialize(serializable));
76+
}
77+
78+
private static BinaryData serialize(Object serializable) {
79+
if (serializable == null) {
80+
return null;
81+
}
82+
83+
return BinaryData.fromObject(serializable, SERIALIZER);
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package io.clientcore.annotation.processor.test;
5+
6+
import io.clientcore.core.http.models.ServiceVersion;
7+
8+
/**
9+
* Service version of OpenAIClient.
10+
*/
11+
public enum TestInterfaceServiceVersion implements ServiceVersion {
12+
/**
13+
* Enum value 2022-12-01.
14+
*/
15+
V_TEST_VALUE("test-value");
16+
17+
private final String version;
18+
19+
TestInterfaceServiceVersion(String version) {
20+
this.version = version;
21+
}
22+
23+
/**
24+
* {@inheritDoc}
25+
*/
26+
@Override
27+
public String getVersion() {
28+
return this.version;
29+
}
30+
31+
/**
32+
* Gets the latest service version supported by this client library.
33+
*
34+
* @return The latest {@link TestInterfaceServiceVersion}.
35+
*/
36+
public static TestInterfaceServiceVersion getLatest() {
37+
return V_TEST_VALUE;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package io.clientcore.annotation.processor.test.implementation;
5+
6+
import io.clientcore.core.annotation.ServiceInterface;
7+
import io.clientcore.core.http.annotation.HttpRequestInformation;
8+
import io.clientcore.core.http.models.HttpMethod;
9+
import io.clientcore.core.http.pipeline.HttpPipeline;
10+
import io.clientcore.core.util.serializer.ObjectSerializer;
11+
import io.clientcore.annotation.processor.test.TestInterfaceServiceVersion;
12+
13+
import java.lang.reflect.InvocationTargetException;
14+
15+
@ServiceInterface(name = "myService", host = "https://somecloud.com")
16+
public interface TestInterfaceClientService {
17+
static TestInterfaceClientService getInstance(HttpPipeline pipeline, ObjectSerializer serializer,
18+
TestInterfaceServiceVersion serviceVersion) {
19+
if (pipeline == null) {
20+
throw new IllegalArgumentException("pipeline cannot be null");
21+
}
22+
try {
23+
Class<?> clazz = Class.forName("io.clientcore.tools.codegen.implementation.TestInterfaceClientServiceImpl");
24+
return (TestInterfaceClientService) clazz
25+
.getMethod("getInstance", HttpPipeline.class, ObjectSerializer.class, TestInterfaceServiceVersion.class)
26+
.invoke(null, pipeline, serializer, serviceVersion);
27+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
28+
| InvocationTargetException e) {
29+
throw new RuntimeException(e);
30+
}
31+
}
32+
33+
static void reset() {
34+
try {
35+
Class<?> clazz = Class.forName("io.clientcore.tools.codegen.implementation.TestInterfaceClientServiceImpl");
36+
clazz.getMethod("reset").invoke(null);
37+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
38+
| InvocationTargetException e) {
39+
throw new RuntimeException(e);
40+
}
41+
}
42+
43+
@HttpRequestInformation(method = HttpMethod.HEAD, path = "my/uri/path", expectedStatusCodes = { 200 })
44+
void testHeadMethod();
45+
}

0 commit comments

Comments
 (0)