Skip to content

Commit

Permalink
Merge branch 'main' into fix/ModuleInModule
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Sep 24, 2024
2 parents 4126bc3 + d2c825c commit eb8b048
Show file tree
Hide file tree
Showing 217 changed files with 5,611 additions and 3,095 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ jobs:
displayName: Recipe nullability best practices
description: Use OpenRewrite internal nullability annotations; drop JetBrains annotations; use `package-info.java` instead.
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jetbrains.annotations.Nullable
newFullyQualifiedTypeName: org.openrewrite.internal.lang.Nullable
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: jakarta.annotation.Nullable
newFullyQualifiedTypeName: org.openrewrite.internal.lang.Nullable
- org.openrewrite.staticanalysis.NullableOnMethodReturnType
- org.openrewrite.java.RemoveAnnotation:
annotationPattern: '@org.jetbrains.annotations.NotNull'
- org.openrewrite.java.RemoveAnnotation:
annotationPattern: '@jakarta.annotation.Nonnull'
- org.openrewrite.java.jspecify.MigrateToJspecify
8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down Expand Up @@ -178,15 +178,15 @@ Apache License
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file formatPrefix. We also recommend that a
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.internal.lang.NonNull;

import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down
4 changes: 2 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public String toString() {
.map(t -> t instanceof Tree ?
t.getClass().getSimpleName() :
t.toString())
.collect(Collectors.joining("->"))
+ "}";
.collect(Collectors.joining("->")) +
"}";
}

public Cursor dropParentUntil(Predicate<Object> valuePredicate) {
Expand Down
74 changes: 63 additions & 11 deletions rewrite-core/src/main/java/org/openrewrite/GitRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openrewrite;

import lombok.Value;
import org.apache.commons.lang3.StringUtils;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.jgit.transport.URIish;
Expand All @@ -38,13 +39,57 @@ public class GitRemote {

String repositoryName;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GitRemote gitRemote = (GitRemote) o;
return service == gitRemote.service &&
StringUtils.equalsIgnoreCase(url, gitRemote.url) &&
StringUtils.equalsIgnoreCase(origin, gitRemote.origin) &&
StringUtils.equalsIgnoreCase(path, gitRemote.path) &&
StringUtils.equalsIgnoreCase(organization, gitRemote.organization) &&
StringUtils.equalsIgnoreCase(repositoryName, gitRemote.repositoryName);
}

@Override
public int hashCode() {
return Objects.hash(service,
url == null ? null : url.toLowerCase(Locale.ENGLISH),
origin == null ? null : origin.toLowerCase(Locale.ENGLISH),
path == null ? null : path.toLowerCase(Locale.ENGLISH),
organization == null ? null : organization.toLowerCase(Locale.ENGLISH),
repositoryName == null ? null : repositoryName.toLowerCase(Locale.ENGLISH));
}

public enum Service {
GitHub,
GitLab,
Bitbucket,
BitbucketCloud,
AzureDevOps,
Unknown
Unknown;

public static Service forName(String serviceName) {
switch (serviceName.toLowerCase(Locale.ENGLISH).replaceAll("[-_ ]", "")) {
case "github":
return GitHub;
case "gitlab":
return GitLab;
case "bitbucket":
return Bitbucket;
case "bitbucketcloud":
return BitbucketCloud;
case "azuredevops":
return AzureDevOps;
default:
return Unknown;
}
}
}

public static class Parser {
Expand Down Expand Up @@ -80,7 +125,10 @@ public URI toUri(GitRemote remote, String protocol) {
selectedBaseUrl = URI.create(protocol + "://" + stripProtocol(remote.origin));
} else {
selectedBaseUrl = servers.stream()
.filter(server -> server.allOrigins().contains(stripProtocol(remote.origin)))
.filter(server -> server.allOrigins()
.stream()
.anyMatch(origin -> origin.equalsIgnoreCase(stripProtocol(remote.origin)))
)
.flatMap(server -> server.getUris().stream())
.filter(uri -> uri.getScheme().equals(protocol))
.findFirst()
Expand Down Expand Up @@ -156,7 +204,7 @@ public Parser registerRemote(Service service, String origin) {
}

public RemoteServer findRemoteServer(String origin) {
return servers.stream().filter(server -> server.origin.equals(origin))
return servers.stream().filter(server -> server.origin.equalsIgnoreCase(origin))
.findFirst()
.orElseGet(() -> {
URI normalizedUri = normalize(origin);
Expand All @@ -166,7 +214,7 @@ public RemoteServer findRemoteServer(String origin) {
}

private void add(RemoteServer server) {
if (server.service != Service.Unknown || servers.stream().noneMatch(s -> s.origin.equals(server.origin))) {
if (server.service != Service.Unknown || servers.stream().noneMatch(s -> s.origin.equalsIgnoreCase(server.origin))) {
servers.add(server);
}
}
Expand All @@ -179,15 +227,15 @@ public GitRemote parse(String url) {

switch (match.service) {
case AzureDevOps:
if (match.matchedUri.getHost().equals("ssh.dev.azure.com")) {
repositoryPath = repositoryPath.replaceFirst("v3/", "");
if (match.matchedUri.getHost().equalsIgnoreCase("ssh.dev.azure.com")) {
repositoryPath = repositoryPath.replaceFirst("(?i)v3/", "");
} else {
repositoryPath = repositoryPath.replaceFirst("/_git/", "/");
repositoryPath = repositoryPath.replaceFirst("(?i)/_git/", "/");
}
break;
case Bitbucket:
if (url.startsWith("http")) {
repositoryPath = repositoryPath.replaceFirst("scm/", "");
repositoryPath = repositoryPath.replaceFirst("(?i)scm/", "");
}
break;
}
Expand Down Expand Up @@ -222,7 +270,9 @@ private String repositoryPath(RemoteServerMatch match, URI normalizedUri) {
String uri = normalizedUri.toString();
String contextPath = origin.getPath();
String path = normalizedUri.getPath();
if (!normalizedUri.getHost().equals(origin.getHost()) || normalizedUri.getPort() != origin.getPort() || !path.startsWith(contextPath)) {
if (!normalizedUri.getHost().equalsIgnoreCase(origin.getHost()) ||
normalizedUri.getPort() != origin.getPort() ||
!path.toLowerCase(Locale.ENGLISH).startsWith(contextPath.toLowerCase(Locale.ENGLISH))) {
throw new IllegalArgumentException("Origin: " + origin + " does not match the clone url: " + uri);
}
return path.substring(contextPath.length())
Expand Down Expand Up @@ -264,7 +314,7 @@ static URI normalize(String url) {
String maybePort = maybePort(uri.getPort(), scheme);

String path = uri.getPath().replaceFirst("/$", "")
.replaceFirst("\\.git$", "")
.replaceFirst("(?i)\\.git$", "")
.replaceFirst("^/", "");
return URI.create((scheme + "://" + host + maybePort + "/" + path).replaceFirst("/$", ""));
} catch (URISyntaxException e) {
Expand Down Expand Up @@ -310,8 +360,10 @@ public RemoteServer(Service service, String origin, Collection<URI> uris) {
}

private GitRemote.Parser.@Nullable RemoteServerMatch match(URI normalizedUri) {
String lowerCaseNormalizedUri = normalizedUri.toString().toLowerCase(Locale.ENGLISH);
for (URI uri : uris) {
if (normalizedUri.toString().startsWith(Parser.normalize(uri.toString()).toString())) {
String normalizedServerUri = Parser.normalize(uri.toString()).toString().toLowerCase(Locale.ENGLISH);
if (lowerCaseNormalizedUri.startsWith(normalizedServerUri)) {
return new Parser.RemoteServerMatch(service, origin, uri);
}
}
Expand Down
10 changes: 5 additions & 5 deletions rewrite-core/src/main/java/org/openrewrite/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private static boolean matchesGlob(String pattern, String path) {
if (!StringUtils.matchesGlob(pathTokens[pathIdxEnd], pattTokens[pattIdxEnd])) {
return false;
}
if (pattIdxEnd == (pattTokens.length - 1)
&& (isFileSeparator(pattern.charAt(pattern.length() - 1)) ^ isFileSeparator(path.charAt(path.length() - 1)))) {
if (pattIdxEnd == (pattTokens.length - 1) &&
(isFileSeparator(pattern.charAt(pattern.length() - 1)) ^ isFileSeparator(path.charAt(path.length() - 1)))) {
return false;
}
pattIdxEnd--;
Expand Down Expand Up @@ -293,8 +293,8 @@ private static boolean isFileSeparator(char ch) {

@SuppressWarnings("SameParameterValue")
private static boolean isFileSeparator(boolean strict, char ch) {
return strict
? ch == File.separatorChar
: ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR;
return strict ?
ch == File.separatorChar :
ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public final List<Recipe> getRecipeList() {
getName() + " declares the ScanningRecipe " + precondition.getName() + " as a precondition." +
"ScanningRecipe cannot be used as Preconditions.");
}
andPreconditions.add(precondition::getVisitor);
andPreconditions.add(() -> orVisitors(precondition));
}
PreconditionBellwether bellwether = new PreconditionBellwether(Preconditions.and(andPreconditions.toArray(new Supplier[]{})));
List<Recipe> recipeListWithBellwether = new ArrayList<>(recipeList.size() + 1);
Expand All @@ -279,6 +279,19 @@ public final List<Recipe> getRecipeList() {
return recipeListWithBellwether;
}

private static TreeVisitor<?, ExecutionContext> orVisitors(Recipe recipe) {
if (recipe.getRecipeList().isEmpty()) {
return recipe.getVisitor();
}
List<TreeVisitor<?, ExecutionContext>> conditions = new ArrayList<>();
conditions.add(recipe.getVisitor());
for (Recipe r : recipe.getRecipeList()) {
conditions.add(orVisitors(r));
}
//noinspection unchecked
return Preconditions.or(conditions.toArray(new TreeVisitor[0]));
}

private static boolean isScanningRecipe(Recipe recipe) {
if (recipe instanceof ScanningRecipe) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.openrewrite.internal;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.internal.lang.NonNull;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -466,8 +466,8 @@ private static boolean matchesGlob(String pattern, String str, boolean caseSensi
if (ch == '*') {
break;
}
if (ch != '?'
&& different(caseSensitive, ch, str.charAt(strIdxStart))) {
if (ch != '?' &&
different(caseSensitive, ch, str.charAt(strIdxStart))) {
return false; // Character mismatch
}
patIdxStart++;
Expand Down Expand Up @@ -554,9 +554,9 @@ private static boolean allStars(String chars, int start, int end) {
}

private static boolean different(boolean caseSensitive, char ch, char other) {
return caseSensitive
? ch != other
: Character.toUpperCase(ch) != Character.toUpperCase(other);
return caseSensitive ?
ch != other :
Character.toUpperCase(ch) != Character.toUpperCase(other);
}

public static String indent(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public Response send(Request request) {
String methodValue = method.toString();
if (entity.length > 0) {
String contentType = request.getRequestHeaders().get("Content-Type");
MediaType mediaType = contentType != null
? MediaType.get(contentType + "; charset=utf-8")
: MEDIA_TYPE_APPLICATION_JSON;
MediaType mediaType = contentType != null ?
MediaType.get(contentType + "; charset=utf-8") :
MEDIA_TYPE_APPLICATION_JSON;
RequestBody body = RequestBody.create(entity, mediaType);
requestBuilder.method(methodValue, body);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public GitProvenance(UUID id,
if (environment instanceof JenkinsBuildEnvironment) {
JenkinsBuildEnvironment jenkinsBuildEnvironment = (JenkinsBuildEnvironment) environment;
try (Repository repository = new RepositoryBuilder().findGitDir(projectDir.toFile()).build()) {
String branch = jenkinsBuildEnvironment.getLocalBranch() != null
? jenkinsBuildEnvironment.getLocalBranch()
: localBranchName(repository, jenkinsBuildEnvironment.getBranch());
String branch = jenkinsBuildEnvironment.getLocalBranch() != null ?
jenkinsBuildEnvironment.getLocalBranch() :
localBranchName(repository, jenkinsBuildEnvironment.getBranch());
return fromGitConfig(repository, branch, getChangeset(repository), gitRemoteParser);
} catch (IllegalArgumentException | GitAPIException e) {
// Silently ignore if the project directory is not a git repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.With;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.lang.NonNull;

import java.io.File;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static BitbucketBuildEnvironment build(UnaryOperator<String> environment)

@Override
public GitProvenance buildGitProvenance() throws IncompleteGitConfigException {
if (StringUtils.isBlank(httpOrigin)
|| StringUtils.isBlank(branch)
|| StringUtils.isBlank(sha)) {
if (StringUtils.isBlank(httpOrigin) ||
StringUtils.isBlank(branch) ||
StringUtils.isBlank(sha)) {
throw new IncompleteGitConfigException();
} else {
return new GitProvenance(UUID.randomUUID(), httpOrigin, branch, sha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public interface BuildEnvironment extends Marker {
if (environment.apply("GITLAB_CI") != null) {
return GitlabBuildEnvironment.build(environment);
}
if (environment.apply("CI") != null && environment.apply("GITHUB_ACTION") != null
&& environment.apply("GITHUB_RUN_ID") != null) {
if (environment.apply("CI") != null && environment.apply("GITHUB_ACTION") != null &&
environment.apply("GITHUB_RUN_ID") != null) {
return GithubActionsBuildEnvironment.build(environment);
}
if (environment.apply("DRONE") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static CustomBuildEnvironment build(UnaryOperator<String> environment) {

@Override
public GitProvenance buildGitProvenance() throws IncompleteGitConfigException {
if (StringUtils.isBlank(cloneURL)
|| StringUtils.isBlank(ref)
|| StringUtils.isBlank(sha)) {
if (StringUtils.isBlank(cloneURL) ||
StringUtils.isBlank(ref) ||
StringUtils.isBlank(sha)) {
throw new IncompleteGitConfigException();
} else {
return new GitProvenance(UUID.randomUUID(), cloneURL, ref, sha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public static DroneBuildEnvironment build(UnaryOperator<String> environment) {

@Override
public GitProvenance buildGitProvenance() throws IncompleteGitConfigException {
if (StringUtils.isBlank(remoteURL)
|| (StringUtils.isBlank(branch) && StringUtils.isBlank(tag))
|| StringUtils.isBlank(commitSha)) {
if (StringUtils.isBlank(remoteURL) ||
(StringUtils.isBlank(branch) && StringUtils.isBlank(tag)) ||
StringUtils.isBlank(commitSha)) {
throw new IncompleteGitConfigException();
}
return new GitProvenance(UUID.randomUUID(), remoteURL,
Expand Down
Loading

0 comments on commit eb8b048

Please sign in to comment.