Skip to content

Commit 520d21e

Browse files
authored
Add support for static headers and query params in compile time codegen (Azure#44750)
1 parent 9c91d94 commit 520d21e

17 files changed

Lines changed: 721 additions & 605 deletions

File tree

sdk/clientcore/annotation-processor-test/copy-generated-impl.ps1

Lines changed: 0 additions & 11 deletions
This file was deleted.

sdk/clientcore/annotation-processor-test/pom.xml

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@
104104
</dependencies>
105105

106106
<build>
107-
<resources>
108-
<resource>
109-
<directory>${project.build.directory}/generated-sources</directory>
110-
</resource>
111-
</resources>
112107
<plugins>
113108
<plugin>
114109
<groupId>org.apache.maven.plugins</groupId>
@@ -157,25 +152,62 @@
157152
</dependencies>
158153
</plugin>
159154

155+
<!-- This plugin removes previously generated *ServiceImpl files before annotation processing runs, preventing FileExists errors during code generation. -->
160156
<plugin>
161-
<groupId>org.codehaus.mojo</groupId>
162-
<artifactId>build-helper-maven-plugin</artifactId>
163-
<version>3.6.0</version> <!-- {x-version-update;org.codehaus.mojo:build-helper-maven-plugin;external_dependency} -->
157+
<groupId>org.apache.maven.plugins</groupId>
158+
<artifactId>maven-clean-plugin</artifactId>
159+
<version>3.4.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-clean-plugin;external_dependency} -->
164160
<executions>
165161
<execution>
166-
<id>add-generated-sources</id>
167-
<phase>generate-sources</phase>
162+
<id>custom-clean</id>
163+
<phase>initialize</phase>
168164
<goals>
169-
<goal>add-source</goal>
165+
<goal>clean</goal>
170166
</goals>
171167
<configuration>
172-
<sources>
173-
<source>${basedir}/target/generated-sources</source>
174-
</sources>
168+
<filesets>
169+
<fileset>
170+
<directory>src/main/java/io/clientcore/annotation/processor/test/</directory>
171+
<includes>
172+
<include>**/*ServiceImpl.java</include>
173+
</includes>
174+
</fileset>
175+
</filesets>
175176
</configuration>
176177
</execution>
177178
</executions>
178179
</plugin>
180+
181+
<!-- Copy the generated impl file to src/main -->
182+
<plugin>
183+
<groupId>org.apache.maven.plugins</groupId>
184+
<artifactId>maven-antrun-plugin</artifactId>
185+
<version>3.1.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-antrun-plugin;external_dependency} -->
186+
<executions>
187+
<execution>
188+
<id>copy-and-clean-generated-impl</id>
189+
<phase>generate-sources</phase>
190+
<configuration>
191+
<target>
192+
<available file="target/generated-sources/io/clientcore/annotation/processor/test/" type="dir" property="generated.dir.exists"/>
193+
<copy todir="src/main/java/io/clientcore/annotation/processor/test/"
194+
overwrite="true"
195+
failonerror="false"
196+
verbose="true">
197+
<fileset dir="target/generated-sources/io/clientcore/annotation/processor/test/" erroronmissingdir="false">
198+
<include name="**/*.java"/>
199+
</fileset>
200+
</copy>
201+
<!-- Delete the generated-sources directory after copying -->
202+
<delete dir="target/generated-sources/io/clientcore/annotation/processor/test/" failonerror="false"/>
203+
</target>
204+
</configuration>
205+
<goals>
206+
<goal>run</goal>
207+
</goals>
208+
</execution>
209+
</executions>
210+
</plugin>
179211
</plugins>
180212
</build>
181213
</project>

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/SimpleXmlSerializableServiceImpl.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
import io.clientcore.core.instrumentation.logging.ClientLogger;
1414
import io.clientcore.core.serialization.json.JsonSerializer;
1515
import io.clientcore.core.serialization.xml.XmlSerializer;
16-
import io.clientcore.core.implementation.utils.UriEscapers;
1716
import java.io.IOException;
18-
import java.io.UncheckedIOException;
17+
import io.clientcore.core.models.CoreException;
1918
import io.clientcore.core.utils.CoreUtils;
2019
import io.clientcore.core.serialization.SerializationFormat;
2120
import io.clientcore.core.serialization.ObjectSerializer;
@@ -73,11 +72,7 @@ public void sendApplicationXml(SimpleXmlSerializable simpleXmlSerializable) {
7372
if (!expectedResponse) {
7473
throw new RuntimeException("Unexpected response code: " + responseCode);
7574
}
76-
try {
77-
networkResponse.close();
78-
} catch (IOException e) {
79-
throw LOGGER.logThrowableAsError(new UncheckedIOException(e));
80-
}
75+
networkResponse.close();
8176
}
8277

8378
@SuppressWarnings({ "unchecked", "cast" })
@@ -102,11 +97,7 @@ public void sendTextXml(SimpleXmlSerializable simpleXmlSerializable) {
10297
if (!expectedResponse) {
10398
throw new RuntimeException("Unexpected response code: " + responseCode);
10499
}
105-
try {
106-
networkResponse.close();
107-
} catch (IOException e) {
108-
throw LOGGER.logThrowableAsError(new UncheckedIOException(e));
109-
}
100+
networkResponse.close();
110101
}
111102

112103
@SuppressWarnings({ "unchecked", "cast" })
@@ -133,11 +124,7 @@ public SimpleXmlSerializable getXml(String contentType) {
133124
} else {
134125
throw new RuntimeException(new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + "."));
135126
}
136-
try {
137-
networkResponse.close();
138-
} catch (IOException e) {
139-
throw LOGGER.logThrowableAsError(new UncheckedIOException(e));
140-
}
127+
networkResponse.close();
141128
return (io.clientcore.annotation.processor.test.implementation.models.SimpleXmlSerializable) result;
142129
}
143130

@@ -164,11 +151,7 @@ public SimpleXmlSerializable getInvalidXml() {
164151
} else {
165152
throw new RuntimeException(new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + "."));
166153
}
167-
try {
168-
networkResponse.close();
169-
} catch (IOException e) {
170-
throw LOGGER.logThrowableAsError(new UncheckedIOException(e));
171-
}
154+
networkResponse.close();
172155
return (io.clientcore.annotation.processor.test.implementation.models.SimpleXmlSerializable) result;
173156
}
174157

@@ -178,7 +161,7 @@ public SimpleXmlSerializable getInvalidXml() {
178161
* @param serializer The serializer to use.
179162
* @param returnType The type of the ParameterizedType return value.
180163
* @return The decoded value.
181-
* @throws IOException If the deserialization fails.
164+
* @throws CoreException If the deserialization fails.
182165
*/
183166
private static Object decodeNetworkResponse(BinaryData data, ObjectSerializer serializer, ParameterizedType returnType) {
184167
if (data == null) {
@@ -194,7 +177,7 @@ private static Object decodeNetworkResponse(BinaryData data, ObjectSerializer se
194177
}
195178
return serializer.deserializeFromBytes(data.toBytes(), token);
196179
} catch (IOException e) {
197-
throw LOGGER.logThrowableAsError(new UncheckedIOException(e));
180+
throw LOGGER.logThrowableAsError(CoreException.from(e));
198181
}
199182
}
200183
}

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/implementation/TestInterfaceClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ HttpBinJSON put(@HostParam("uri") String uri, @BodyParam(ContentType.APPLICATION
231231
method = HttpMethod.GET,
232232
path = "anything",
233233
expectedStatusCodes = { 200 },
234-
queryParams = { "constantParam1=", "constantParam1" })
234+
queryParams = { "queryparamwithequalsandnovalue=", "queryparamwithnoequals" })
235235
HttpBinJSON get4(@HostParam("uri") String uri);
236236

237237
@HttpRequestInformation(

0 commit comments

Comments
 (0)