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

Add upgrade-assistant support #1

Merged
merged 23 commits into from
Sep 26, 2024
Merged

Conversation

bryceatmoderne
Copy link
Collaborator

@bryceatmoderne bryceatmoderne commented Sep 19, 2024

What's changed?

Added UpgradeAssistant to execute recipes based on .NET's upgrade-assistant. Only upgrade subcommand is supported with this recipe.

Added UpgradeAssistantAnalyze to execute recipes based on .NET's upgrade-assistant. Only analyze subcommand is supported with this recipe. This recipe does not produce any change results but will generate an org.openrewrite.dotnet.UpgradeAssistantAnalysis data table that somewhat resembles what you'd see in Visual Studio's Upgrade Assistant tool: https://devblogs.microsoft.com/visualstudio/code-assessment-with-net-upgrade-assistant/#interpret-results

For both recipes, there is a single required option targetFramework. This maps directly to the values supplied to upgrade-assistant's --targetFramework flag such as net9.0.

What's your motivation?

upgrade-assistant is a tool used to migrate projects to current versions of .NET.

Anything in particular you'd like reviewers to focus on?

No.

Anyone you would like to review specifically?

@timtebeek @knutwannheden @sambsnyd

Have you considered any alternatives or workarounds?

No.

Any additional context

Requires https://github.com/moderneinc/moderne-cli/pull/2117 and openrewrite/rewrite#4518

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@bryceatmoderne bryceatmoderne self-assigned this Sep 19, 2024
@bryceatmoderne bryceatmoderne marked this pull request as draft September 19, 2024 18:57
@bryceatmoderne bryceatmoderne added the enhancement New feature or request label Sep 19, 2024
gradle/licenseHeader.txt Outdated Show resolved Hide resolved
@bryceatmoderne bryceatmoderne marked this pull request as ready for review September 23, 2024 19:07
@bryceatmoderne bryceatmoderne marked this pull request as draft September 23, 2024 19:07
README.md Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
README.md Outdated Show resolved Hide resolved
…java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
bryceatmoderne and others added 3 commits September 24, 2024 18:25
…st.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
timtebeek and others added 2 commits September 25, 2024 00:30
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@bryceatmoderne bryceatmoderne marked this pull request as ready for review September 24, 2024 23:27
Copy link

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@Option(
displayName = "Target framework version",
description = "Target framework to which source project should be upgraded.",
example = "net9.0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know this tool well enough, but would it make sense to limit the values here?
Would also be safer in terms of validation & passing arguments into execution.

Suggested change
example = "net9.0")
valid = {"net5.0", "net6.0", "net7.0", "net8.0", "net9.0"})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In parallel I'm wondering if it makes sense to add a declarative recipe that helps discoverability. Assuming there's no need to chain recipes that would look something like this:

src/main/resources/META-INF/rewrite/dotnet.yml:

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.dotnet.MigrateToNet5
recipeList:
  - org.openrewrite.dotnet.UpgradeAssistant:
      targetFramework: net5.0
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.dotnet.MigrateToNet6
recipeList:
  - org.openrewrite.dotnet.UpgradeAssistant:
      targetFramework: net6.0
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.dotnet.MigrateToNet7
recipeList:
  - org.openrewrite.dotnet.UpgradeAssistant:
      targetFramework: net7.0
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.dotnet.MigrateToNet8
recipeList:
  - org.openrewrite.dotnet.UpgradeAssistant:
      targetFramework: net8.0
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.dotnet.MigrateToNet9
recipeList:
  - org.openrewrite.dotnet.UpgradeAssistant:
      targetFramework: net9.0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding pre-defined target framework values, I'm hesitant to do this ATM because they are not well defined. I haven't been able to find such a list and aliases such as LTS and PREVIEW didn't work for me despite being referenced in upgrade-assistant upgrade.

When supplying an invalid version to upgrade-assistant upgrade you'll get an "Unknown target version" error logged to the terminal. The UpgradeAssistant recipe will look for this and will create a row for each project (.csproj file) in the org.openrewrite.table.SourcesFileErrors data table.

When a supplying an invalid version to upgrade-assistant analyze the command will generate a report with recommendations such as "No supported version found".

The pre-defined declarative recipes make sense. I'll add those. Thanks again for the feedback!

@bryceatmoderne bryceatmoderne merged commit 44db4c6 into main Sep 26, 2024
2 checks passed
@bryceatmoderne bryceatmoderne deleted the upgrade-assistant-support branch September 26, 2024 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants