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

Port OpenRewrite to Main #43884

Merged
merged 17 commits into from
Jan 27, 2025
Merged
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
2 changes: 2 additions & 0 deletions eng/versioning/external_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ com.fasterxml.jackson.core:jackson-core;2.17.2
com.fasterxml.jackson.core:jackson-databind;2.17.2
com.fasterxml.jackson.dataformat:jackson-dataformat-avro;2.17.2
com.fasterxml.jackson.dataformat:jackson-dataformat-xml;2.17.2
com.fasterxml.jackson.dataformat:jackson-dataformat-smile;2.17.2
com.fasterxml.jackson.datatype:jackson-datatype-jsr310;2.17.2
com.fasterxml.jackson.module:jackson-module-afterburner;2.17.2
com.fasterxml.jackson.module:jackson-module-blackbird;2.17.2
Expand Down Expand Up @@ -98,6 +99,7 @@ io.lettuce:lettuce-core;6.4.0.RELEASE
org.redisson:redisson;3.36.0
testdep_net.bytebuddy:byte-buddy;1.15.5
testdep_net.bytebuddy:byte-buddy-agent;1.15.5
org.openrewrite.recipe:rewrite-recipe-bom;3.0.2
jairmyree marked this conversation as resolved.
Show resolved Hide resolved

## Spring boot dependency versions
org.springframework.boot:spring-boot-maven-plugin;2.7.18
Expand Down
2 changes: 2 additions & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ com.azure:azure-monitor-ingestion;1.2.7;1.3.0-beta.1
com.azure:azure-monitor-ingestion-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-monitor-query;1.5.4;1.6.0-beta.1
com.azure:azure-monitor-query-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-openrewrite;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-perf-test-parent;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-quantum-jobs;1.0.0-beta.1;1.0.0-beta.2
com.azure:azure-search-documents;11.7.4;11.8.0-beta.5
Expand Down Expand Up @@ -485,6 +486,7 @@ 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


# Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current
# version. Unreleased dependencies are only valid for dependency versions.
# Format;
Expand Down
11 changes: 11 additions & 0 deletions sdk/tools/azure-openrewrite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release History

## 1.0.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
89 changes: 89 additions & 0 deletions sdk/tools/azure-openrewrite/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Azure Code Migration with OpenRewrite

This library contains integrations for OpenRewrite with Maven for code migrating Azure SDK libraries
such as `azure-core` to `azure-core-v2`.

## Setup

### Prerequisites
The following tools are required to build and execute this project:
- Java (version 8 or higher)
- Maven

### Recipe Configuration

The migration recipe is defined in the `azure-openrewrite` module as detailed below:

```yaml
### Recipe Configuration for OpenRewrite
type: specs.openrewrite.org/v1beta/recipe
name: com.azure.openrewrite.migrateToVNext
displayName: Migrate from azure-core to azure-core-v2
description: This recipe migrates the azure sdk libraries from azure-core to azure-core-v2 and clientcore libraries.
recipeList:
...
```
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).


## Usage
### Maven Plugin Configuration
The OpenRewrite Maven plugin is configured in the `rewrite-java-core` module to run the migration recipe on the sample project
as follows:
```xml
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.7.1</version>
<configuration>
<activeRecipes>
<recipe>com.azure.openrewrite.migrateToVNext</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-openrewrite</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
```
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).

## Execution
The `rewrite-sample` module is configured to use the `openrewrite-maven-plugin` to run the OpenRewrite recipe on the sample project.
The `rewrite-sample` module contains the modules `azure-ai-translation-text-v1` and `azure-ai-translation-text-v2`
to demonstrate the migration of code from `azure-core` to `azure-core-v2`.

**Note:** To execute the below commands, ensure that you are within the `rewrite-sample` directory.

### Dry Run
To run the OpenRewrite recipe in dry-run mode, execute the following command:
```shell
mvn rewrite:dryRun
```
If the above command is not recognised, execute the full version of the command:

```shell
mvn org.openrewrite.maven:rewrite-maven-plugin:dryRun
```

This will generate a file `rewrite.patch` in `rewrite-sample/target/rewrite` directory.

### Run (apply changes)
To actually apply the changes to the sample project, execute the following command:
```shell
mvn rewrite:run
```
If the above command is not recognised, execute the full version of the command:

```shell
mvn org.openrewrite.maven:rewrite-maven-plugin:run
```

## Testing
To run the unit tests for the OpenRewrite recipe, execute the following command:
```shell
mvn:test
```
7 changes: 7 additions & 0 deletions sdk/tools/azure-openrewrite/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Azure OpenRewrite Plugin library for Java
jairmyree marked this conversation as resolved.
Show resolved Hide resolved
## Getting started
## Key concepts
## Examples
## Troubleshooting
## Next steps
## Contributing
131 changes: 131 additions & 0 deletions sdk/tools/azure-openrewrite/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.azure</groupId>
<artifactId>azure-openrewrite</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-openrewrite;dependency} -->

<name>Microsoft Azure OpenRewrite Plugin library for Java</name>
<description>This module contains OpenRewrite recipe for migrating to next generation Microsoft Azure client libraries.</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
<version>3.0.2</version> <!-- {x-version-update;org.openrewrite.recipe:rewrite-recipe-bom;external_dependency} -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- rewrite-java dependencies only necessary for Java Recipe development -->
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>compile</scope>
</dependency>

<!-- You only need the version that corresponds to your current
Java version. It is fine to add all of them, though, as
they can coexist on a classpath. -->
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-8</artifactId>
<scope>test</scope>
</dependency>

<!-- rewrite-maven dependency only necessary for Maven Recipe development -->
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.54.1</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.4</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.4</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<scope>test</scope>
</dependency>
<!-- Optional dependency on assertJ to provide fluent assertions. -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.0</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.17.2</version> <!-- {x-version-update;com.fasterxml.jackson.core:jackson-core;external_dependency} -->
</dependency>
<!-- Jackson Dataformat Smile -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-smile</artifactId>
<version>2.17.2</version> <!-- {x-version-update;com.fasterxml.jackson.dataformat:jackson-dataformat-smile;external_dependency} -->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.2</version> <!-- {x-version-update;com.fasterxml.jackson.core:jackson-databind;external_dependency} -->
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version> <!-- {x-version-update;org.projectlombok:lombok;external_dependency} -->
<scope>provided</scope>
</dependency>

<dependency>
jairmyree marked this conversation as resolved.
Show resolved Hide resolved
<groupId>com.azure</groupId>
<artifactId>azure-ai-translation-text</artifactId>
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-ai-translation-text;dependency} -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.29.0</version> <!-- {x-version-update;com.azure:azure-storage-blob;dependency} -->
<scope>test</scope>
</dependency>
</dependencies>

<build>
jairmyree marked this conversation as resolved.
Show resolved Hide resolved
<plugins>
<!--
Used to extract PMD report metrics for the recipes
* Run with mvn pmd:pmd
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.15.0</version>
</plugin>
jairmyree marked this conversation as resolved.
Show resolved Hide resolved
</plugins>
</build>
</project>
Loading
Loading