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

Allow pom download failures #1

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
adc40ba
Do not use tabs in `MergeYaml.yaml`'s `@Option.example`
timtebeek Dec 3, 2024
b373d9f
refactor: update OWASP suppression date bounds (#4739)
zieka Dec 3, 2024
9936a7a
Enrich GradleDependency.Matcher to match on cases where a ResolvedDep…
shanman190 Dec 4, 2024
cd4a37f
Fix `JavaNamingService` license header year
Laurens-W Dec 4, 2024
f9d71bc
Fix multiline example in CreateYamlFile
timtebeek Dec 4, 2024
c30f37d
Fix gradle/groovy parser issue with gradle 6 (#4742)
Laurens-W Dec 4, 2024
efc38e3
Take J.Case statements into account in JavaTemplate (#4744)
Laurens-W Dec 4, 2024
8878990
add configuration option
stefdev49 Nov 20, 2024
0b8525e
add configuration option to allow pom download failure
stefdev49 Dec 3, 2024
a1a0f6a
code formatting and typo
stefdev49 Dec 3, 2024
390ae5a
Apply formatter to minimize diff
timtebeek Dec 3, 2024
62dcb5f
Update rewrite-maven/src/test/java/org/openrewrite/maven/internal/Mav…
adastraperangusta Dec 5, 2024
6530337
Added a few missing `@Nullable` annotations to `JavaType`
knutwannheden Dec 5, 2024
a551727
A `J.Case`, like `J.Block` is a scope that ends statements with a sem…
Laurens-W Dec 5, 2024
72793ae
Fix AddImport match variable's name (#4747)
SiBorea Dec 5, 2024
20de532
feat: Added option to comment out property in yaml (#4741)
ashakirin Dec 5, 2024
45f228a
Fix #4705 Groovy parser does not correctly handle redundant "def" pre…
sambsnyd Dec 5, 2024
55dded4
add test for the expected behaviour
stefdev49 Dec 5, 2024
7013518
Support variable expressions in parenthesis (#4751)
jevanlingen Dec 6, 2024
e571da7
Update get classpath by artifact name to support bazel (#4750)
amishra-u Dec 6, 2024
4c0f0ca
IncrementProjectVersion should only update matching old version
timtebeek Dec 6, 2024
4e723d8
Add RegExp support to ChangeTagValue recipe (#4733)
anthochristen Dec 6, 2024
104f705
Add initial support for java references for yaml (#4698)
nielsdebruin Dec 6, 2024
16df13a
Adding master password decrypting (#4753)
svaningelgem Dec 8, 2024
1095923
Make sure provided download target exist before writing files to it (…
lkerford Dec 9, 2024
3403f7e
`AddOrUpdateAnnotationAttribute` should also visit nested annotations
timtebeek Dec 10, 2024
cce4629
Merge branch 'main' into allow_pom_download_failures
timtebeek Dec 10, 2024
54a2057
`RemoveMethodInvocationsVisitor` can remove static method (#4754)
dralagen Dec 10, 2024
bee3e2f
Remove redundant versions for Gradle (#4492)
shanman190 Dec 11, 2024
ecfb0e5
Allow building uri from origin, path and service type (#4767)
pstreef Dec 11, 2024
7489e3a
Apply OpenRewrite best practices, and make those easier to apply
timtebeek Dec 11, 2024
2bcf394
Document the use of `rewrite.yml`
timtebeek Dec 11, 2024
d789bcb
Performance improvements of `Find` recipe (#4758)
nielsdebruin Dec 11, 2024
ecc2d62
Strip origin in findRemoteServer (#4771)
pstreef Dec 11, 2024
a473f26
Groovy parser does not support multiple closure arguments without par…
jevanlingen Dec 11, 2024
0ff22c7
file scheme handling
stefdev49 Dec 11, 2024
2020321
we don't nedd a property anymore
stefdev49 Dec 11, 2024
b5eccb3
prepare test for remote repository case
stefdev49 Dec 11, 2024
f794dc1
tests updates
stefdev49 Dec 11, 2024
4ca26ce
try for jar if remote pom doesn't exist
stefdev49 Dec 12, 2024
15f2502
Correct `J.FieldAccess#isFullyQualifiedClassReference()` (#4774)
knutwannheden Dec 12, 2024
f4f1996
Normalize server URLs to avoid missing scheme (#4780)
pstreef Dec 12, 2024
fdc042b
Remove a few `String#substring()` calls from Groovy parser
knutwannheden Dec 12, 2024
ceb3dab
Fix duplicate data table entries.
sambsnyd Dec 12, 2024
5cb3945
Drop unused GraphvizResolutionEventListener & dependency (#4778)
timtebeek Dec 12, 2024
dd5614a
Don't download the jar bytes; only check if response is successful
timtebeek Dec 12, 2024
a717e71
Minimize diff as compared to main for now
timtebeek Dec 12, 2024
fd56ecf
Record the absence of the pom file when jar is found
timtebeek Dec 12, 2024
203ade0
Minor polish
timtebeek Dec 12, 2024
c2e10f0
Merge branch 'main' into allow_pom_download_failures
timtebeek Dec 12, 2024
299292f
Update rewrite-xml/src/test/java/org/openrewrite/xml/ChangeTagValueTe…
adastraperangusta Dec 13, 2024
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
61 changes: 0 additions & 61 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,3 @@ jobs:
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main
with:
recipe: 'org.openrewrite.recipes.OpenRewriteBestPracticesSubset'
rewrite_yml: |
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.OpenRewriteBestPracticesSubset
displayName: OpenRewrite best practices
description: Best practices for OpenRewrite recipe development.
recipeList:
- org.openrewrite.recipes.JavaRecipeBestPracticesSubset
- org.openrewrite.recipes.RecipeTestingBestPracticesSubset
- org.openrewrite.recipes.RecipeNullabilityBestPracticesSubset
#- org.openrewrite.java.OrderImports
- org.openrewrite.java.format.EmptyNewlineAtEndOfFile
- org.openrewrite.staticanalysis.InlineVariable
- org.openrewrite.staticanalysis.MissingOverrideAnnotation
- org.openrewrite.staticanalysis.UseDiamondOperator
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.JavaRecipeBestPracticesSubset
displayName: Java Recipe best practices
description: Best practices for Java recipe development.
preconditions:
- org.openrewrite.java.search.FindTypes:
fullyQualifiedTypeName: org.openrewrite.Recipe
checkAssignability: true
recipeList:
- org.openrewrite.java.recipes.BlankLinesAroundFieldsWithAnnotations
- org.openrewrite.java.recipes.ExecutionContextParameterName
- org.openrewrite.java.recipes.MissingOptionExample
- org.openrewrite.java.recipes.RecipeEqualsAndHashCodeCallSuper
- org.openrewrite.java.recipes.UseTreeRandomId
- org.openrewrite.staticanalysis.NeedBraces
#- org.openrewrite.staticanalysis.RemoveSystemOutPrintln
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.RecipeTestingBestPracticesSubset
displayName: Recipe testing best practices
description: Best practices for testing recipes.
preconditions:
- org.openrewrite.java.search.FindTypes:
fullyQualifiedTypeName: org.openrewrite.test.RewriteTest
checkAssignability: true
recipeList:
- org.openrewrite.java.recipes.RewriteTestClassesShouldNotBePublic
#- org.openrewrite.java.recipes.SelectRecipeExamples
- org.openrewrite.java.recipes.SourceSpecTextBlockIndentation
- org.openrewrite.java.testing.cleanup.RemoveTestPrefix
- org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
- org.openrewrite.staticanalysis.NeedBraces
- org.openrewrite.staticanalysis.RemoveSystemOutPrintln
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.RecipeNullabilityBestPracticesSubset
displayName: Recipe nullability best practices
description: Use OpenRewrite internal nullability annotations; drop JetBrains annotations; use `package-info.java` instead.
recipeList:
- 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
61 changes: 43 additions & 18 deletions rewrite-core/src/main/java/org/openrewrite/GitRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,51 +113,64 @@ public Parser() {
* @return the clone url
*/
public URI toUri(GitRemote remote, String protocol) {
return buildUri(remote.service, remote.origin, remote.path, protocol);
}

/**
* Build a {@link URI} clone url from components, if that protocol is supported (configured) by the matched server
*
* @param service the type of SCM service
* @param origin the origin of the SCM service, any protocol will be stripped (and not used for matching)
* @param path the path to the repository
* @param protocol the protocol to use. Supported protocols: ssh, http, https
* @return the clone URL if it could be created.
* @throws IllegalArgumentException if the protocol is not supported by the server.
*/
public URI buildUri(Service service, String origin, String path, String protocol) {
if (!ALLOWED_PROTOCOLS.contains(protocol)) {
throw new IllegalArgumentException("Invalid protocol: " + protocol + ". Must be one of: " + ALLOWED_PROTOCOLS);
}
URI selectedBaseUrl;

if (remote.service == Service.Unknown) {
if (PORT_PATTERN.matcher(remote.origin).find()) {
throw new IllegalArgumentException("Unable to determine protocol/port combination for an unregistered origin with a port: " + remote.origin);
if (service == Service.Unknown) {
if (PORT_PATTERN.matcher(origin).find()) {
throw new IllegalArgumentException("Unable to determine protocol/port combination for an unregistered origin with a port: " + origin);
}
selectedBaseUrl = URI.create(protocol + "://" + stripProtocol(remote.origin));
selectedBaseUrl = URI.create(protocol + "://" + stripProtocol(origin));
} else {
selectedBaseUrl = servers.stream()
.filter(server -> server.allOrigins()
.stream()
.anyMatch(origin -> origin.equalsIgnoreCase(stripProtocol(remote.origin)))
.anyMatch(o -> o.equalsIgnoreCase(stripProtocol(origin)))
)
.flatMap(server -> server.getUris().stream())
.filter(uri -> uri.getScheme().equals(protocol))
.filter(uri -> Parser.normalize(uri).getScheme().equals(protocol))
.findFirst()
.orElseGet(() -> {
URI normalizedUri = Parser.normalize(remote.origin);
URI normalizedUri = Parser.normalize(origin);
if (!normalizedUri.getScheme().equals(protocol)) {
throw new IllegalStateException("No matching server found that supports ssh for origin: " + remote.origin);
throw new IllegalArgumentException("Unable to build clone URL. No matching server found that supports " + protocol + " for origin: " + origin);
}
return normalizedUri;
});
}

String path = remote.path.replaceFirst("^/", "");
path = path.replaceFirst("^/", "");
boolean ssh = protocol.equals("ssh");
switch (remote.service) {
switch (service) {
case Bitbucket:
if (!ssh) {
path = "scm/" + remote.path;
path = "scm/" + path;
}
break;
case AzureDevOps:
if (ssh) {
path = "v3/" + remote.path;
path = "v3/" + path;
} else {
path = remote.path.replaceFirst("([^/]+)/([^/]+)/(.*)", "$1/$2/_git/$3");
path = path.replaceFirst("([^/]+)/([^/]+)/(.*)", "$1/$2/_git/$3");
}
break;
}
if (remote.service != Service.AzureDevOps) {
if (service != Service.AzureDevOps) {
path += ".git";
}
String maybeSlash = selectedBaseUrl.toString().endsWith("/") ? "" : "/";
Expand Down Expand Up @@ -203,11 +216,18 @@ public Parser registerRemote(Service service, String origin) {
return this;
}

/**
* Find a registered remote server by an origin.
*
* @param origin the origin of the server. Any protocol will be stripped (and not used to match)
* @return The server if found, or an unknown type server with a normalized url/origin if not found.
*/
public RemoteServer findRemoteServer(String origin) {
return servers.stream().filter(server -> server.origin.equalsIgnoreCase(origin))
String strippedOrigin = stripProtocol(origin);
return servers.stream().filter(server -> server.origin.equalsIgnoreCase(strippedOrigin))
.findFirst()
.orElseGet(() -> {
URI normalizedUri = normalize(origin);
URI normalizedUri = normalize(strippedOrigin);
String normalizedOrigin = normalizedUri.getHost() + maybePort(normalizedUri.getPort(), normalizedUri.getScheme());
return new RemoteServer(Service.Unknown, normalizedOrigin, normalizedUri);
});
Expand Down Expand Up @@ -281,6 +301,10 @@ private String repositoryPath(RemoteServerMatch match, URI normalizedUri) {

private static final Pattern PORT_PATTERN = Pattern.compile(":\\d+(/.+)(/.+)+");

static URI normalize(URI url) {
return normalize(url.toString());
}

static URI normalize(String url) {
try {
URIish uri = new URIish(url);
Expand Down Expand Up @@ -374,10 +398,11 @@ public Set<String> allOrigins() {
Set<String> origins = new LinkedHashSet<>();
origins.add(origin);
for (URI uri : uris) {
URI normalized = Parser.normalize(uri.toString());
URI normalized = Parser.normalize(uri);
origins.add(Parser.stripProtocol(normalized.toString()));
}
return origins;
}

}
}
48 changes: 40 additions & 8 deletions rewrite-core/src/main/java/org/openrewrite/text/Find.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import org.openrewrite.remote.Remote;
import org.openrewrite.table.TextMatches;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -91,6 +89,22 @@ public String getDescription() {
@Nullable
String filePattern;

private static Deque<Integer> findAllNewLineIndexes(String input, int offset) {
ArrayDeque<Integer> indexes = new ArrayDeque<>();
int index = input.lastIndexOf('\n', offset); // Find the first occurrence
if (index != -1) {
indexes.add(index);
}

index = input.indexOf('\n', offset); // Find occurrence after the offset
while (index != -1) {
indexes.add(index); // Add the index to the list
index = input.indexOf('\n', index + 1); // Find the next occurrence
}

return indexes;
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {

Expand Down Expand Up @@ -123,24 +137,42 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
return sourceFile;
}
matcher.reset();

String sourceFilePath = sourceFile.getSourcePath().toString();

List<PlainText.Snippet> snippets = new ArrayList<>();
int previousEnd = 0;

Deque<Integer> newlineIndexes = null;
int lastNewLineIndex = -1;

while (matcher.find()) {
if (newlineIndexes == null) {
newlineIndexes = findAllNewLineIndexes(rawText, matcher.start());
}

int matchStart = matcher.start();
snippets.add(snippet(rawText.substring(previousEnd, matchStart)));
snippets.add(SearchResult.found(snippet(rawText.substring(matchStart, matcher.end()))));
previousEnd = matcher.end();

int startLine = Math.max(0, rawText.substring(0, matchStart).lastIndexOf('\n') + 1);
while (!newlineIndexes.isEmpty() && newlineIndexes.peek() < matchStart) {
lastNewLineIndex = newlineIndexes.pop();
}
int startLine = Math.max(0, lastNewLineIndex + 1);

int endLine = rawText.indexOf('\n', matcher.end());
if (endLine == -1) {
endLine = rawText.length();
}

textMatches.insertRow(ctx, new TextMatches.Row(
sourceFile.getSourcePath().toString(),
rawText.substring(startLine, matcher.start()) + "~~>" +
rawText.substring(matcher.start(), endLine)
sourceFilePath,
new StringBuilder(endLine - startLine + 3)
.append(rawText, startLine, matcher.start())
.append("~~>")
.append(rawText, matcher.start(), endLine)
.toString()
));
}
snippets.add(snippet(rawText.substring(previousEnd)));
Expand All @@ -160,8 +192,8 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
return visitor;
}


private static PlainText.Snippet snippet(String text) {
return new PlainText.Snippet(Tree.randomId(), Markers.EMPTY, text);
}

}
34 changes: 22 additions & 12 deletions rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,21 @@ void shouldNotStripJgit() {
assertThat(remote.getPath()).isEqualTo("openrewrite/jgit");
}

@Test
void shouldNotReplaceExistingWellKnownServer(){
GitRemote.Parser parser = new GitRemote.Parser()
.registerRemote(GitRemote.Service.GitHub, URI.create("https://github.com"), List.of(URI.create("ssh://notgithub.com")));

assertThat(parser.findRemoteServer("github.com").getUris())
.containsExactlyInAnyOrder(URI.create("https://github.com"), URI.create("ssh://[email protected]"));
}

@Test
void findRemote() {
GitRemote.Parser parser = new GitRemote.Parser()
.registerRemote(GitRemote.Service.Bitbucket, URI.create("scm.company.com/stash"), Collections.emptyList());
assertThat(parser.findRemoteServer("github.com").getService()).isEqualTo(GitRemote.Service.GitHub);
assertThat(parser.findRemoteServer("https://github.com").getService()).isEqualTo(GitRemote.Service.GitHub);
assertThat(parser.findRemoteServer("gitlab.com").getService()).isEqualTo(GitRemote.Service.GitLab);
assertThat(parser.findRemoteServer("bitbucket.org").getService()).isEqualTo(GitRemote.Service.BitbucketCloud);
assertThat(parser.findRemoteServer("dev.azure.com").getService()).isEqualTo(GitRemote.Service.AzureDevOps);
Expand Down Expand Up @@ -265,18 +275,18 @@ void parseOriginCaseInsensitive(String cloneUrl, String expectedOrigin, String e

@ParameterizedTest
@CsvSource(textBlock = """
GitHub, GitHub
GITLAB, GitLab
bitbucket, Bitbucket
BitbucketCloud, BitbucketCloud
Bitbucket Cloud, BitbucketCloud
BITBUCKET_CLOUD, BitbucketCloud
AzureDevOps, AzureDevOps
AZURE_DEVOPS, AzureDevOps
Azure DevOps, AzureDevOps
idontknow, Unknown
""")
void findServiceForName(String name, GitRemote.Service service){
GitHub, GitHub
GITLAB, GitLab
bitbucket, Bitbucket
BitbucketCloud, BitbucketCloud
Bitbucket Cloud, BitbucketCloud
BITBUCKET_CLOUD, BitbucketCloud
AzureDevOps, AzureDevOps
AZURE_DEVOPS, AzureDevOps
Azure DevOps, AzureDevOps
idontknow, Unknown
""")
void findServiceForName(String name, GitRemote.Service service) {
assertThat(GitRemote.Service.forName(name)).isEqualTo(service);
}

Expand Down
Loading
Loading