Skip to content

Azure OpenRewrite Sample Compiler CI #45569

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

Merged
merged 45 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2ace644
adding openrewrite compiler pipeline
jairmyree Jun 2, 2025
bc51f77
add azure-openrewrite install job
jairmyree Jun 2, 2025
789b332
Remove uneccessary dependsOn parameter
jairmyree Jun 2, 2025
f0d0180
Add build tasks for clientcore and core-v2
jairmyree Jun 3, 2025
94b8923
Updating maven build options
jairmyree Jun 3, 2025
0d0bf04
Update maven build options
jairmyree Jun 3, 2025
4dd2302
Update build options
jairmyree Jun 3, 2025
81b4186
Build Perf test core
jairmyree Jun 3, 2025
74b58d4
Consolidate build tasks
jairmyree Jun 3, 2025
c535320
more consolidation
jairmyree Jun 3, 2025
2b256a6
Adding quotes to args
jairmyree Jun 3, 2025
3894eb1
Fixing build error due to .skip
jairmyree Jun 3, 2025
44a2a56
adjusting pipeline
jairmyree Jun 3, 2025
39fbede
Update sdk/tools/openrewrite-sample-compiler-ci.yml
jairmyree Jun 3, 2025
32ea245
Update sdk/tools/openrewrite-sample-compiler-ci.yml
jairmyree Jun 3, 2025
701989d
Fixing copilot commit error
jairmyree Jun 3, 2025
67341cc
Fixing copilot commit
jairmyree Jun 3, 2025
30215b6
Updating sample to reflect what's in main
jairmyree Jun 3, 2025
ee2d677
Remove unknown matching in recipes
jairmyree Jun 3, 2025
1ee2d38
Updates from comments on PR
jairmyree Jun 10, 2025
bbc3bd0
Update compiler PR
jairmyree Jun 10, 2025
c947332
Merge branch 'main' into jairmyree/openrewrite/sample-compiler
jairmyree Jun 10, 2025
66eee8b
pipeline adjustment
jairmyree Jun 10, 2025
09dae43
pipeline adjustment
jairmyree Jun 10, 2025
7c105ee
pipeline adjustment
jairmyree Jun 10, 2025
3581c01
update pipeline
jairmyree Jun 10, 2025
8e7bfbb
pipeline adjustment
jairmyree Jun 10, 2025
71c85ed
Update compiler to not use loop
jairmyree Jun 16, 2025
abff98e
pipeline adjustment
jairmyree Jun 16, 2025
d19c9f9
pipeline adjustment
jairmyree Jun 16, 2025
4be9f1f
pipeline adjustment
jairmyree Jun 16, 2025
525843a
pipeline adjustment
jairmyree Jun 16, 2025
9d50c6d
Update compiler PR
jairmyree Jun 16, 2025
4669c80
Update pipeline
jairmyree Jun 16, 2025
9fcb4c3
Merge branch 'main' into jairmyree/openrewrite/sample-compiler
jairmyree Jun 17, 2025
f578506
pipeline adjustment
jairmyree Jun 17, 2025
f990e3b
Merge branch 'jairmyree/openrewrite/sample-compiler' of https://githu…
jairmyree Jun 17, 2025
e0b8a4f
pipeline adjustment
jairmyree Jun 17, 2025
d36fade
pipeline adjustment
jairmyree Jun 17, 2025
104e293
fixing the maven command
jairmyree Jun 17, 2025
52e0f67
adding azure-openrewrite-compiler-maven-plugin to tools pom
jairmyree Jun 17, 2025
f979c39
Updating checkout paths
jairmyree Jun 17, 2025
90e1823
Updating checkout paths
jairmyree Jun 17, 2025
5c6ac0c
Addding no transfer progress to second Maven task
jairmyree Jun 17, 2025
2b77818
Merge branch 'main' into jairmyree/openrewrite/sample-compiler
jairmyree Jun 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
JavaTemplate replacementTemplate;

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders add(java.lang.String, java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("add(#{any(io.clientcore.core.http.models.HttpHeaderName)}, #{any(java.lang.String)})")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -68,7 +68,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders put(java.lang.String, java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("set(HttpHeaderName.fromString(#{any(java.lang.String)}), #{any(java.lang.String)})")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -77,7 +77,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders set(java.lang.String, java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("set(HttpHeaderName.fromString(#{any(java.lang.String)}), #{any(java.lang.String)})")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -86,7 +86,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders setAll(java.util.Map)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("setAll(#{any(io.clientcore.core.http.models.HttpHeaders)})")
.imports("io.clientcore.core.http.models.HttpHeaders")
.build();
Expand All @@ -95,7 +95,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders get(java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("get(HttpHeaderName.fromString(#{any(java.lang.String)}))")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -104,7 +104,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders remove(java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("remove(HttpHeaderName.fromString(#{any(java.lang.String)}))")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -113,7 +113,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders getValue(java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("getValue(HttpHeaderName.fromString(#{any(java.lang.String)}))")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -122,7 +122,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders getValues(java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("getValues(HttpHeaderName.fromString(#{any(java.lang.String)}))")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -131,7 +131,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders getValues(com.azure.core.http.HttpHeaderName)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("getValues(#{any(io.clientcore.core.http.models.HttpHeaderName)})")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public J visitMethodInvocation(J.MethodInvocation methodInvocation, ExecutionCon
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpRequest setUrl(java.net.URL)");
if (methodMatcher.matches((J.MethodInvocation) visited, true)) {
if (methodMatcher.matches((J.MethodInvocation) visited)) {
replacementTemplate = configuredParserJavaTemplateBuilder.getJavaTemplateBuilder("setUri(#{any(java.net.URL)}.toURI())")
.imports("java.net.URI")
.build();
Expand All @@ -136,7 +136,7 @@ public J visitMethodInvocation(J.MethodInvocation methodInvocation, ExecutionCon
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpRequest getUrl()");
if (methodMatcher.matches((J.MethodInvocation) visited, true)) {
if (methodMatcher.matches((J.MethodInvocation) visited)) {
replacementTemplate = configuredParserJavaTemplateBuilder.getJavaTemplateBuilder(String.format("%s.getUri().toURL()", ((J.MethodInvocation) visited).getSelect().toString()))
.imports("java.net.URL")
.build();
Expand All @@ -146,7 +146,7 @@ public J visitMethodInvocation(J.MethodInvocation methodInvocation, ExecutionCon
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpRequest setHeader(..)");
if (methodMatcher.matches((J.MethodInvocation) visited, true)) {
if (methodMatcher.matches((J.MethodInvocation) visited)) {
J variableIdentifier = ((J.MethodInvocation) visited).getSelect();
while ((variableIdentifier instanceof J.MethodInvocation)) {

Expand All @@ -165,15 +165,15 @@ public J visitMethodInvocation(J.MethodInvocation methodInvocation, ExecutionCon
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpRequest getBodyAsBinaryData()");
if (methodMatcher.matches((J.MethodInvocation) visited, true)) {
if (methodMatcher.matches((J.MethodInvocation) visited)) {
replacementTemplate = configuredParserJavaTemplateBuilder.getJavaTemplateBuilder("getBody()")
.build();
visited = replacementTemplate.apply(updateCursor(visited), ((J.MethodInvocation) visited).getCoordinates().replaceMethod());
return visited;
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpRequest setBody(byte[])");
if (methodMatcher.matches((J.MethodInvocation) visited, true)) {
if (methodMatcher.matches((J.MethodInvocation) visited)) {
replacementTemplate = configuredParserJavaTemplateBuilder.getJavaTemplateBuilder("setBody(BinaryData.fromBytes(#{anyArray(byte)})")
.imports("io.clientcore.core.models.binarydata.BinaryData")
.build();
Expand All @@ -183,7 +183,7 @@ public J visitMethodInvocation(J.MethodInvocation methodInvocation, ExecutionCon
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpRequest copy()");
if (methodMatcher.matches((J.MethodInvocation) visited, true)) {
if (methodMatcher.matches((J.MethodInvocation) visited)) {
J variableIdentifier = ((J.MethodInvocation) visited).getSelect();
while ((variableIdentifier instanceof J.MethodInvocation)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
JavaTemplate replacementTemplate;

methodMatcher = new MethodMatcher("com.azure.core.http.HttpResponse getHeaderValue(java.lang.String)");
if (methodMatcher.matches(visitedMethod, true)) {
if (methodMatcher.matches(visitedMethod)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder(String.format("%s.getHeaders().getValue(HttpHeaderName.fromString(#{any(java.lang.String)}))", visitedMethod.getSelect().toString()))
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand All @@ -72,31 +72,31 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpResponse getHeaderValue(io.clientcore.core.http.models.HttpHeaderName)");
if (methodMatcher.matches(visitedMethod, true)) {
if (methodMatcher.matches(visitedMethod)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder(String.format("%s.getHeaders().getValue(#{any(io.clientcore.core.http.models.HttpHeaderName)})", visitedMethod.getSelect().toString()))
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
return replacementTemplate.apply(updateCursor(visitedMethod), visitedMethod.getCoordinates().replace(), visitedMethod.getArguments().toArray());
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpResponse getHeaderValue(java.lang.String)");
if (methodMatcher.matches(visitedMethod, true)) {
if (methodMatcher.matches(visitedMethod)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("getHeaders().getValue(io.clientcore.core.http.models.HttpHeaderName.fromString(#{any(java.lang.String)}))")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
return replacementTemplate.apply(updateCursor(visitedMethod), visitedMethod.getCoordinates().replaceMethod(), visitedMethod.getArguments().toArray());
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpResponse getHeaderValue(com.azure.core.http.HttpHeaderName)");
if (methodMatcher.matches(visitedMethod, true)) {
if (methodMatcher.matches(visitedMethod)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("getHeaders().getValue(#{any(com.azure.core.http.HttpHeaderName)})")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
return replacementTemplate.apply(updateCursor(visitedMethod), visitedMethod.getCoordinates().replaceMethod(), visitedMethod.getArguments().toArray());
}

methodMatcher = new MethodMatcher("com.azure.core.http.HttpResponse getBodyAsBinaryData()");
if (methodMatcher.matches(visitedMethod, true)) {
if (methodMatcher.matches(visitedMethod)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder(String.format("BinaryData.fromObject(%s.getValue())", visitedMethod.getSelect().toString()))
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.azure.openrewrite.core.http.rest;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
Expand All @@ -11,11 +10,11 @@
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.tree.Flag;
import org.openrewrite.java.tree.J;

import com.azure.openrewrite.util.ConfiguredParserJavaTemplateBuilder;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.Space;

import com.azure.openrewrite.util.ConfiguredParserJavaTemplateBuilder;

/**
* A custom OpenRewrite recipe to migrate the use of RequestOptions.
*
Expand Down Expand Up @@ -60,9 +59,9 @@ public JavaIsoVisitor<ExecutionContext> getVisitor() {
return new JavaIsoVisitor<ExecutionContext>() {

@Override
public @Nullable J visit(@Nullable Tree tree, ExecutionContext executionContext) {
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) {
doAfterVisit(new ConvertToImmutableVisitor());
return super.visit(tree, executionContext);
return super.visitCompilationUnit(cu, executionContext);
}

@Override
Expand All @@ -72,9 +71,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
MethodMatcher methodMatcher;
JavaTemplate replacementTemplate;

methodMatcher = new MethodMatcher("com.azure.core.http.rest.RequestOptions addHeader(java.lang.String, java.lang.String)");
methodMatcher = new MethodMatcher("com.azure.core.http.rest.RequestOptions setHeader(java.lang.String, java.lang.String)");
if (methodMatcher.matches(visitedMethodInvocation)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("addHeader(HttpHeaderName.fromString(#{any(java.lang.String)}), #{any(java.lang.String)})")
replacementTemplate = templateBuilder.getJavaTemplateBuilder("setHeader(HttpHeaderName.fromString(#{any(java.lang.String)}), #{any(java.lang.String)})")
.imports("io.clientcore.core.http.models.HttpHeaderName")
.build();
visitedMethodInvocation = replacementTemplate.apply(getCursor(), visitedMethodInvocation.getCoordinates().replaceMethod(), visitedMethodInvocation.getArguments().toArray());
Expand All @@ -94,7 +93,7 @@ private static class ConvertToImmutableVisitor extends JavaVisitor<ExecutionCont
final String FLUENT_KEY = "fluentConstructor";

@Override
public @Nullable J visit(@Nullable Tree tree, ExecutionContext executionContext) {
public J visit(Tree tree, ExecutionContext executionContext) {
return super.visit(tree, executionContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ public static void main(String... args) {

// Sample 1: Basic usage
RequestOptions options1 = new RequestOptions();
options1.addHeader("Custom-Header", "CustomValue");
options1.addHeader("Another-Header", "AnotherValue");
options1.setHeader("Custom-Header", "CustomValue");
options1.setHeader("Another-Header", "AnotherValue");

options1.addHeader(HttpHeaderName.CONTENT_TYPE, "application/json");
options1.addHeader(HttpHeaderName.ACCEPT, "application/json");
options1.setHeader(HttpHeaderName.CONTENT_TYPE, "application/json");
options1.setHeader(HttpHeaderName.ACCEPT, "application/json");

options1.addQueryParam("queryParam1", "value1")
.addQueryParam("queryParam2", "value2")
.addQueryParam("queryParam3", "value3");

RequestOptions options2 = new RequestOptions()
.addHeader(HttpHeaderName.CONTENT_TYPE, "application/json")
.addHeader(HttpHeaderName.ACCEPT, "application/json")
.setHeader(HttpHeaderName.CONTENT_TYPE, "application/json")
.setHeader(HttpHeaderName.ACCEPT, "application/json")
.addQueryParam("queryParam1", "value1");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ public static void main(String... args) {

// Sample 1: Basic usage
RequestContext options1 = RequestContext.none();
options1 = options1.toBuilder().addHeader(HttpHeaderName.fromString("Custom-Header"), "CustomValue").build();
options1 = options1.toBuilder().addHeader(HttpHeaderName.fromString("Another-Header"), "AnotherValue").build();
options1 = options1.toBuilder().setHeader(HttpHeaderName.fromString("Custom-Header"), "CustomValue").build();
options1 = options1.toBuilder().setHeader(HttpHeaderName.fromString("Another-Header"), "AnotherValue").build();

options1 = options1.toBuilder().addHeader(HttpHeaderName.CONTENT_TYPE, "application/json").build();
options1 = options1.toBuilder().addHeader(HttpHeaderName.ACCEPT, "application/json").build();
options1 = options1.toBuilder().setHeader(HttpHeaderName.CONTENT_TYPE, "application/json").build();
options1 = options1.toBuilder().setHeader(HttpHeaderName.ACCEPT, "application/json").build();

options1 = options1.toBuilder().addQueryParam("queryParam1", "value1")
.addQueryParam("queryParam2", "value2")
.addQueryParam("queryParam3", "value3").build();

RequestContext options2 = RequestContext.builder()
.addHeader(HttpHeaderName.CONTENT_TYPE, "application/json")
.addHeader(HttpHeaderName.ACCEPT, "application/json")
.setHeader(HttpHeaderName.CONTENT_TYPE, "application/json")
.setHeader(HttpHeaderName.ACCEPT, "application/json")
.addQueryParam("queryParam1", "value1").build();

}
Expand Down
Loading