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

Migrate to ApacheHttpClient 5.x recipe updates org.apache.httpcomponents.core5: httpcore5 to version 5.3.x #28

Open
smoring2 opened this issue Aug 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@smoring2
Copy link

What version of OpenRewrite are you using?

I am using

  • Maven plugin v5.35.0

How are you running OpenRewrite?

mvn -U org.openrewrite.maven:rewrite-maven-plugin:5.35.0:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-apache:1.4.2 -Drewrite.activeRecipes=org.openrewrite.apache.httpclient5.UpgradeApacheHttpClient_5 -Drewrite.exportDatatables=true

I am using the Maven plugin, and my project is a single module project.

What is the smallest, simplest way to reproduce the problem?

   <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.16</version>
        </dependency>

What did you expect to see?

<dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5</artifactId>
            <version>5.3-beta1</version>
        </dependency>

What did you see instead?

5.3.x could not be resolved from maven central https://mvnrepository.com/artifact/org.apache.httpcomponents.core5/httpcore5

<dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5</artifactId>
            <version>5.3.x</version>
        </dependency>

What is the full stack trace of any errors you encountered?

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

@smoring2 smoring2 added the bug Something isn't working label Aug 22, 2024
@timtebeek
Copy link
Contributor

Hi @smoring2 ; That's quite odd! Let me first link the relevant parts of the recipe and recipe tests.

- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.apache.httpcomponents
oldArtifactId: httpcore
newGroupId: org.apache.httpcomponents.core5
newArtifactId: httpcore5
newVersion: 5.3.x

@Test
void migrateDependencies() {
rewriteRun(
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
</dependencies>
</project>
""", spec -> spec.after(pom -> {
Matcher version = Pattern.compile("5\\.3\\.\\d+").matcher(pom);
assertThat(version.find()).describedAs("Expected 5.3.x in %s", pom).isTrue();
return """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>%s</version>
</dependency>
</dependencies>
</project>
""".formatted(version.group(0));
})));
}

As you can see the recipe uses our XRange version selector. The unit test then verifies that the last .x is replaced with a digit, which on my machine resolves to 5.3.1. Which is odd, since that version does not yet exist. 😕 The latest, as you've pointed out is 5.3-beta1.
https://repo1.maven.org/maven2/org/apache/httpcomponents/core5/httpcore5/maven-metadata.xml

This might be something to do with how those version ranges are resolved against the unexpected versioning pattern for httpcore5 in openrewrite/rewrite.

@timtebeek timtebeek moved this to Backlog in OpenRewrite Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants