From 2b877c61ccca7f287fb79de97725e4276d10631e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Schn=C3=A9ider?= Date: Mon, 2 Sep 2024 18:14:42 -0400 Subject: [PATCH 1/3] Revert "Force lowercase urls and origins in `GitRemote` (#4456)" (#4462) This reverts commit 758bbd8201c37fda503632fcac2f6547e7169e41. --- .../src/main/java/org/openrewrite/GitRemote.java | 13 ++++--------- .../test/java/org/openrewrite/GitRemoteTest.java | 15 ++++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/rewrite-core/src/main/java/org/openrewrite/GitRemote.java b/rewrite-core/src/main/java/org/openrewrite/GitRemote.java index fa9f6b06d41..dd85812bd7a 100644 --- a/rewrite-core/src/main/java/org/openrewrite/GitRemote.java +++ b/rewrite-core/src/main/java/org/openrewrite/GitRemote.java @@ -231,8 +231,7 @@ private String repositoryPath(RemoteServerMatch match, URI normalizedUri) { private static final Pattern PORT_PATTERN = Pattern.compile(":\\d+"); - static URI normalize(String original) { - String url = original.toLowerCase(Locale.ENGLISH); + static URI normalize(String url) { try { URIish uri = new URIish(url); String scheme = uri.getScheme(); @@ -267,7 +266,7 @@ static URI normalize(String original) { String path = uri.getPath().replaceFirst("/$", "") .replaceFirst("\\.git$", "") .replaceFirst("^/", ""); - return URI.create((scheme + "://" + host + maybePort + "/" + path).replaceFirst("/$", "").toLowerCase(Locale.ENGLISH)); + return URI.create((scheme + "://" + host + maybePort + "/" + path).replaceFirst("/$", "")); } catch (URISyntaxException e) { throw new IllegalStateException("Unable to parse origin from: " + url, e); } @@ -306,12 +305,8 @@ public RemoteServer(Service service, String origin, URI... uris) { public RemoteServer(Service service, String origin, Collection uris) { this.service = service; - this.origin = origin.toLowerCase(Locale.ENGLISH); - this.uris.addAll(uris.stream() - .map(URI::toString) - .map(urlString -> urlString.toLowerCase(Locale.ENGLISH)) - .map(URI::create) - .collect(Collectors.toList())); + this.origin = origin; + this.uris.addAll(uris); } private GitRemote.Parser.@Nullable RemoteServerMatch match(URI normalizedUri) { diff --git a/rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java b/rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java index 013cd8d965a..2fb0991b2b1 100644 --- a/rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java @@ -39,16 +39,13 @@ public class GitRemoteTest { git@gitlab.com:group/subgroup/subergroup/subestgroup/repo.git, gitlab.com, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo ssh://git@gitlab.com:22/group/subgroup/subergroup/subestgroup/repo.git, gitlab.com, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo - https://bitbucket.org/PRJ/repo, bitbucket.org, prj/repo, prj, repo - git@bitbucket.org:PRJ/repo.git, bitbucket.org, prj/repo, prj, repo - ssh://bitbucket.org/PRJ/repo.git, bitbucket.org, prj/repo, prj, repo + https://bitbucket.org/PRJ/repo, bitbucket.org, PRJ/repo, PRJ, repo + git@bitbucket.org:PRJ/repo.git, bitbucket.org, PRJ/repo, PRJ, repo + ssh://bitbucket.org/PRJ/repo.git, bitbucket.org, PRJ/repo, PRJ, repo https://org@dev.azure.com/org/project/_git/repo, dev.azure.com, org/project/repo, org/project, repo https://dev.azure.com/org/project/_git/repo, dev.azure.com, org/project/repo, org/project, repo git@ssh.dev.azure.com:v3/org/project/repo, dev.azure.com, org/project/repo, org/project, repo - - HTTPS://GITHUB.COM/ORG/REPO.GIT, github.com, org/repo, org, repo - HtTpS://GitHub.CoM/OrG/R3P0.GIT, github.com, org/r3p0, org, r3p0 """) void parseKnownRemotes(String cloneUrl, String expectedOrigin, String expectedPath, String expectedOrganization, String expectedRepositoryName) { GitRemote.Parser parser = new GitRemote.Parser(); @@ -86,9 +83,9 @@ void parseUnknownRemote(String cloneUrl, String expectedOrigin, String expectedP https://scm.company.com:443/stash/scm/org/repo.git, scm.company.com/stash, Bitbucket, scm.company.com/stash, org/repo, org, repo https://scm.company.com:1234/stash/scm/org/repo.git, https://scm.company.com:1234/stash, Bitbucket, scm.company.com:1234/stash, org/repo, org, repo git@scm.company.com:stash/org/repo.git, scm.company.com/stash, Bitbucket, scm.company.com/stash, org/repo, org, repo - ssh://scm.CompanY.com/stash/org/repo, scm.cOMpAnY.com/stash, Bitbucket, scm.company.com/stash, org/repo, org, repo + ssh://scm.company.com/stash/org/repo, scm.company.com/stash, Bitbucket, scm.company.com/stash, org/repo, org, repo ssh://scm.company.com:22/stash/org/repo, scm.company.com/stash, Bitbucket, scm.company.com/stash, org/repo, org, repo - ssh://scm.company.com:7999/stash/org/repo, ssh://sCm.company.com:7999/stash, Bitbucket, scm.company.com:7999/stash, org/repo, org, repo + ssh://scm.company.com:7999/stash/org/repo, ssh://scm.company.com:7999/stash, Bitbucket, scm.company.com:7999/stash, org/repo, org, repo https://scm.company.com/very/long/context/path/org/repo.git, scm.company.com/very/long/context/path, Bitbucket, scm.company.com/very/long/context/path, org/repo, org, repo https://scm.company.com:1234/very/long/context/path/org/repo.git, https://scm.company.com:1234/very/long/context/path, Bitbucket, scm.company.com:1234/very/long/context/path, org/repo, org, repo @@ -100,7 +97,7 @@ void parseUnknownRemote(String cloneUrl, String expectedOrigin, String expectedP git@scm.company.com:group/subgroup/subergroup/subestgroup/repo.git, ssh://scm.company.com, GitLab, scm.company.com, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo https://scm.company.com:443/group/subgroup/subergroup/subestgroup/repo.git, scm.company.com, GitLab, scm.company.com, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo ssh://scm.company.com:22/group/subgroup/subergroup/subestgroup/repo.git, ssh://scm.company.com, GitLab, scm.company.com, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo - ssh://SCM.COMPANY.COM:222/group/subgroup/subergroup/subestgroup/repo.git, ssh://SCM.CoMpAnY.cOm:222, GitLab, scm.company.com:222, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo + ssh://scm.company.com:222/group/subgroup/subergroup/subestgroup/repo.git, ssh://scm.company.com:222, GitLab, scm.company.com:222, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo https://scm.company.com/very/long/context/path/group/subgroup/subergroup/subestgroup/repo, scm.company.com/very/long/context/path, GitLab, scm.company.com/very/long/context/path, group/subgroup/subergroup/subestgroup/repo, group/subgroup/subergroup/subestgroup, repo """) From 458a35a8e95d9be0466b8d35ce83c06e018adaad Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 3 Sep 2024 07:32:56 +0000 Subject: [PATCH 2/3] refactor: OpenRewrite best practices Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.OpenRewriteBestPractices?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../test/java/org/openrewrite/java/AddMethodParameterTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rewrite-java/src/test/java/org/openrewrite/java/AddMethodParameterTest.java b/rewrite-java/src/test/java/org/openrewrite/java/AddMethodParameterTest.java index 620e39c6b61..4c39321bfe3 100644 --- a/rewrite-java/src/test/java/org/openrewrite/java/AddMethodParameterTest.java +++ b/rewrite-java/src/test/java/org/openrewrite/java/AddMethodParameterTest.java @@ -16,12 +16,14 @@ package org.openrewrite.java; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; class AddMethodParameterTest implements RewriteTest { + @DocumentExample @Test void primitive() { rewriteRun( From 1f4564cbdb0e7ac20fc364b1daa7689a78b709ef Mon Sep 17 00:00:00 2001 From: Laurens Westerlaken Date: Tue, 3 Sep 2024 11:28:36 +0200 Subject: [PATCH 3/3] Retain default behaviour when we cannot determine conflict (#4464) Co-authored-by: Laurens Westerlaken --- .../src/main/java/org/openrewrite/java/ChangeType.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java b/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java index 1d9504f3f10..2ae65f707ff 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java @@ -307,7 +307,7 @@ public J visitIdentifier(J.Identifier ident, ExecutionContext ctx) { .withType(null) .withPrefix(ident.getPrefix())); } else { - if (sf != null && hasNoConflictingImport(sf)) { + if (hasNoConflictingImport(sf)) { ident = ident.withSimpleName(((JavaType.FullyQualified) targetType).getClassName()); } else { ident = ident.withSimpleName(((JavaType.FullyQualified) targetType).getFullyQualifiedName()); @@ -508,11 +508,11 @@ private boolean isTargetFullyQualifiedType(JavaType.@Nullable FullyQualified fq) return fq != null && TypeUtils.isOfClassType(fq, originalType.getFullyQualifiedName()) && targetType instanceof JavaType.FullyQualified; } - private boolean hasNoConflictingImport(JavaSourceFile sf) { + private boolean hasNoConflictingImport(@Nullable JavaSourceFile sf) { JavaType.FullyQualified oldType = TypeUtils.asFullyQualified(originalType); JavaType.FullyQualified newType = TypeUtils.asFullyQualified(targetType); - if (oldType == null || newType == null) { - return false; // No way to be sure + if (sf == null || oldType == null || newType == null) { + return true; // No way to be sure so we retain previous behaviour } for (J.Import anImport : sf.getImports()) { JavaType.FullyQualified currType = TypeUtils.asFullyQualified(anImport.getQualid().getType());