Skip to content

Commit cf5a43b

Browse files
authored
Port OpenRewrite to Main (Azure#43884)
* Port Azure OpenRewrite into java repo * updates to port PR * updates to port PR: package name fixes * fix azure-tools-service pom * Updates based on Srikanta's comments * Updates based on Srikanta's comments * Additional updates to PR * Updating PR README.md * Removing author names. Making azure-core a test dependency. * Adjusting CI * Adjusting README.MD to fix CI failures * Adjusting MIGRATION.md * Adjusting PR based on comments * Fixing CI failure * Adjusting for alphabetical order. * Changing rewrite dependency to reflect java baseline. * Changing dependency scope to test
1 parent 0f86c1a commit cf5a43b

35 files changed

+3384
-0
lines changed

eng/versioning/external_dependencies.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ com.fasterxml.jackson.core:jackson-core;2.17.2
1616
com.fasterxml.jackson.core:jackson-databind;2.17.2
1717
com.fasterxml.jackson.dataformat:jackson-dataformat-avro;2.17.2
1818
com.fasterxml.jackson.dataformat:jackson-dataformat-xml;2.17.2
19+
com.fasterxml.jackson.dataformat:jackson-dataformat-smile;2.17.2
1920
com.fasterxml.jackson.datatype:jackson-datatype-jsr310;2.17.2
2021
com.fasterxml.jackson.module:jackson-module-afterburner;2.17.2
2122
com.fasterxml.jackson.module:jackson-module-blackbird;2.17.2
@@ -95,6 +96,7 @@ io.lettuce:lettuce-core;6.4.0.RELEASE
9596
org.redisson:redisson;3.36.0
9697
testdep_net.bytebuddy:byte-buddy;1.15.5
9798
testdep_net.bytebuddy:byte-buddy-agent;1.15.5
99+
org.openrewrite.recipe:rewrite-recipe-bom;3.0.2
98100

99101
## Spring boot dependency versions
100102
org.springframework.boot:spring-boot-maven-plugin;2.7.18

eng/versioning/version_client.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ com.azure:azure-monitor-ingestion;1.2.7;1.3.0-beta.1
165165
com.azure:azure-monitor-ingestion-perf;1.0.0-beta.1;1.0.0-beta.1
166166
com.azure:azure-monitor-query;1.5.4;1.6.0-beta.1
167167
com.azure:azure-monitor-query-perf;1.0.0-beta.1;1.0.0-beta.1
168+
com.azure:azure-openrewrite;1.0.0-beta.1;1.0.0-beta.1
168169
com.azure:azure-perf-test-parent;1.0.0-beta.1;1.0.0-beta.1
169170
com.azure:azure-quantum-jobs;1.0.0-beta.1;1.0.0-beta.2
170171
com.azure:azure-search-documents;11.7.4;11.8.0-beta.5
@@ -477,6 +478,7 @@ io.clientcore:http-okhttp3;1.0.0-beta.1;1.0.0-beta.1
477478
io.clientcore:http-stress;1.0.0-beta.1;1.0.0-beta.1
478479
io.clientcore:optional-dependency-tests;1.0.0-beta.1;1.0.0-beta.1
479480

481+
480482
# Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current
481483
# version. Unreleased dependencies are only valid for dependency versions.
482484
# Format;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Release History
2+
3+
## 1.0.0-beta.1 (Unreleased)
4+
5+
### Features Added
6+
7+
### Breaking Changes
8+
9+
### Bugs Fixed
10+
11+
### Other Changes
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Azure Code Migration with OpenRewrite
2+
3+
This library contains integrations for OpenRewrite with Maven for code migrating Azure SDK libraries
4+
such as `azure-core` to `azure-core-v2`.
5+
6+
## Setup
7+
8+
### Prerequisites
9+
The following tools are required to build and execute this project:
10+
- Java (version 8 or higher)
11+
- Maven
12+
13+
### Recipe Configuration
14+
15+
The migration recipe is defined in the `azure-openrewrite` module as detailed below:
16+
17+
```yaml
18+
### Recipe Configuration for OpenRewrite
19+
type: specs.openrewrite.org/v1beta/recipe
20+
name: com.azure.openrewrite.migrateToVNext
21+
displayName: Migrate from azure-core to azure-core-v2
22+
description: This recipe migrates the azure sdk libraries from azure-core to azure-core-v2 and clientcore libraries.
23+
recipeList:
24+
...
25+
```
26+
You can find the full recipe configuration in the `rewrite.yml` file [here](https://github.com/Azure/azsdk-java-rewrite-recipes/blob/main/rewrite-java-core/src/main/resources/META-INF/rewrite/rewrite.yml).
27+
28+
29+
## Usage
30+
### Maven Plugin Configuration
31+
The OpenRewrite Maven plugin is configured in the `rewrite-java-core` module to run the migration recipe on the sample project
32+
as follows:
33+
```xml
34+
<plugin>
35+
<groupId>org.openrewrite.maven</groupId>
36+
<artifactId>rewrite-maven-plugin</artifactId>
37+
<version>5.7.1</version>
38+
<configuration>
39+
<activeRecipes>
40+
<recipe>com.azure.openrewrite.migrateToVNext</recipe>
41+
</activeRecipes>
42+
</configuration>
43+
<dependencies>
44+
<dependency>
45+
<groupId>com.azure</groupId>
46+
<artifactId>azure-openrewrite</artifactId>
47+
<version>1.0.0</version>
48+
</dependency>
49+
</dependencies>
50+
</plugin>
51+
```
52+
The plugin configuration is defined in the `pom.xml` file [here](https://github.com/Azure/azsdk-java-rewrite-recipes/blob/main/rewrite-sample/pom.xml).
53+
54+
## Execution
55+
The `rewrite-sample` module is configured to use the `openrewrite-maven-plugin` to run the OpenRewrite recipe on the sample project.
56+
The `rewrite-sample` module contains the modules `azure-ai-translation-text-v1` and `azure-ai-translation-text-v2`
57+
to demonstrate the migration of code from `azure-core` to `azure-core-v2`.
58+
59+
**Note:** To execute the below commands, ensure that you are within the `rewrite-sample` directory.
60+
61+
### Dry Run
62+
To run the OpenRewrite recipe in dry-run mode, execute the following command:
63+
```shell
64+
mvn rewrite:dryRun
65+
```
66+
If the above command is not recognised, execute the full version of the command:
67+
68+
```shell
69+
mvn org.openrewrite.maven:rewrite-maven-plugin:dryRun
70+
```
71+
72+
This will generate a file `rewrite.patch` in `rewrite-sample/target/rewrite` directory.
73+
74+
### Run (apply changes)
75+
To actually apply the changes to the sample project, execute the following command:
76+
```shell
77+
mvn rewrite:run
78+
```
79+
If the above command is not recognised, execute the full version of the command:
80+
81+
```shell
82+
mvn org.openrewrite.maven:rewrite-maven-plugin:run
83+
```
84+
85+
## Testing
86+
To run the unit tests for the OpenRewrite recipe, execute the following command:
87+
```shell
88+
mvn:test
89+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Azure OpenRewrite Plugin library for Java
2+
## Getting started
3+
## Key concepts
4+
## Examples
5+
## Troubleshooting
6+
## Next steps
7+
## Contributing
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
2+
Licensed under the MIT License. -->
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.azure</groupId>
8+
<artifactId>azure-openrewrite</artifactId>
9+
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-openrewrite;dependency} -->
10+
11+
<name>Microsoft Azure OpenRewrite Plugin library for Java</name>
12+
<description>This module contains OpenRewrite recipe for migrating to next generation Microsoft Azure client libraries.</description>
13+
14+
<dependencyManagement>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.openrewrite.recipe</groupId>
18+
<artifactId>rewrite-recipe-bom</artifactId>
19+
<version>3.0.2</version> <!-- {x-version-update;org.openrewrite.recipe:rewrite-recipe-bom;external_dependency} -->
20+
<type>pom</type>
21+
<scope>import</scope>
22+
</dependency>
23+
</dependencies>
24+
</dependencyManagement>
25+
26+
<dependencies>
27+
<!-- rewrite-java dependencies only necessary for Java Recipe development -->
28+
<dependency>
29+
<groupId>org.openrewrite</groupId>
30+
<artifactId>rewrite-java</artifactId>
31+
<scope>compile</scope>
32+
</dependency>
33+
34+
<!-- You only need the version that corresponds to your current
35+
Java version. It is fine to add all of them, though, as
36+
they can coexist on a classpath. -->
37+
<dependency>
38+
<groupId>org.openrewrite</groupId>
39+
<artifactId>rewrite-java-8</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
43+
<!-- rewrite-maven dependency only necessary for Maven Recipe development -->
44+
<dependency>
45+
<groupId>org.openrewrite</groupId>
46+
<artifactId>rewrite-maven</artifactId>
47+
<scope>compile</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.azure</groupId>
51+
<artifactId>azure-core</artifactId>
52+
<version>1.54.1</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.openrewrite</groupId>
57+
<artifactId>rewrite-test</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.junit.jupiter</groupId>
62+
<artifactId>junit-jupiter-api</artifactId>
63+
<version>5.11.4</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-engine</artifactId>
69+
<version>5.11.4</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
70+
<scope>test</scope>
71+
</dependency>
72+
<!-- Optional dependency on assertJ to provide fluent assertions. -->
73+
<dependency>
74+
<groupId>org.assertj</groupId>
75+
<artifactId>assertj-core</artifactId>
76+
<version>3.26.0</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
77+
<scope>test</scope>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>com.fasterxml.jackson.core</groupId>
82+
<artifactId>jackson-core</artifactId>
83+
<version>2.17.2</version> <!-- {x-version-update;com.fasterxml.jackson.core:jackson-core;external_dependency} -->
84+
</dependency>
85+
<!-- Jackson Dataformat Smile -->
86+
<dependency>
87+
<groupId>com.fasterxml.jackson.dataformat</groupId>
88+
<artifactId>jackson-dataformat-smile</artifactId>
89+
<version>2.17.2</version> <!-- {x-version-update;com.fasterxml.jackson.dataformat:jackson-dataformat-smile;external_dependency} -->
90+
</dependency>
91+
<dependency>
92+
<groupId>com.fasterxml.jackson.core</groupId>
93+
<artifactId>jackson-databind</artifactId>
94+
<version>2.17.2</version> <!-- {x-version-update;com.fasterxml.jackson.core:jackson-databind;external_dependency} -->
95+
</dependency>
96+
<dependency>
97+
<groupId>org.projectlombok</groupId>
98+
<artifactId>lombok</artifactId>
99+
<version>1.18.34</version> <!-- {x-version-update;org.projectlombok:lombok;external_dependency} -->
100+
<scope>provided</scope>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>com.azure</groupId>
105+
<artifactId>azure-ai-translation-text</artifactId>
106+
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-ai-translation-text;dependency} -->
107+
<scope>test</scope>
108+
</dependency>
109+
110+
<dependency>
111+
<groupId>com.azure</groupId>
112+
<artifactId>azure-storage-blob</artifactId>
113+
<version>12.29.0</version> <!-- {x-version-update;com.azure:azure-storage-blob;dependency} -->
114+
<scope>test</scope>
115+
</dependency>
116+
</dependencies>
117+
118+
<build>
119+
<plugins>
120+
<!--
121+
Used to extract PMD report metrics for the recipes
122+
* Run with mvn pmd:pmd
123+
-->
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-pmd-plugin</artifactId>
127+
<version>3.15.0</version>
128+
</plugin>
129+
</plugins>
130+
</build>
131+
</project>

0 commit comments

Comments
 (0)