You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In short: the file.getName() and pattern Pattern.compile("[/\\\\]" + artifactName + "-?.*\\.jar$") is mismatch so that the pattern.matcher will always be false. The file.getName() returns a simple filename without any / but the pattern needs a /.
In this dependenciesFromResources method it list all files in local system (default path is ~/.rewrite/classpath and it doesn't matter for this bug), then try to compute whether these files match the artifactNames given in args.
As we can see the source code is:
PatternjarPattern = Pattern.compile("[/\\\\]" + artifactName + "-?.*\\.jar$");
File[] extracted = resourceTarget.listFiles();
if (extracted != null) {
for (Filefile : extracted) {
if (jarPattern.matcher(file.getName()).find()) {
artifacts.add(file.toPath());
continuenextArtifact;
}
}
}
For example:
if artifactName = spring-beans-5.* and their are a spring-beans-5.3.27.jar in target path, then we want match for it;
if artifactName = spring-beans-4.* and their are a spring-beans-5.3.27.jar in target path, then we want NOT match for it;
But the issue is: for now this pattern will always be NOT match no matter what the artifactName and local file is. The reason is the file.getName() and pattern Pattern.compile("[/\\\\]" + artifactName + "-?.*\\.jar$") is mismatch.
file.getName() returns a short name without any /.
but the pattern needs a /.
What version of OpenRewrite are you using?
I am using
OpenRewrite 8.1.6
Maven/Gradle plugin Maven 3.3.9 (irrelevant)
rewrite-java 8.1.6
How are you running OpenRewrite?
I am using the sbm-support-rewrite in spring-boot-migrator which will call open-rewrite.
What is the smallest, simplest way to reproduce the problem?
// want to use /xxx/yyy as target jar foldersFilefolderFile = Path.of("/xxx/yyy").normalize().toFile();
InMemoryExecutionContextcontext = newInMemoryExecutionContext();
context.putMessage("org.openrewrite.java.parserClasspathDownloadLocation", folderFile);
// Init javaParser with above contextJavaParser.Builder<? extendsJavaParser, ?> javaParserBuilder = JavaParser.fromJavaVersion()
.logCompilationWarningsAndErrors(false).classpathFromResources(context,
"spring-beans", "spring-context", "...");
ResourceParserrp = newResourceParser(baseDir, newSlf4jToMavenLoggerAdapter(LOGGER), Set.of(), getPlainTextMasks(), -1, Set.of(), javaParserBuilder.clone());
// Use ResourceParser to parse source codes// Run some recipes that will use jars in /xxx/yyy
When use debug breakpoint I can see all artifactNames mismatch with local jars even they exists in my local. And the missingArtifactNames in this line is NOT empty.
Description of issue
In short: the
file.getName()
and patternPattern.compile("[/\\\\]" + artifactName + "-?.*\\.jar$")
is mismatch so that the pattern.matcher will always befalse
. Thefile.getName()
returns a simple filename without any/
but the pattern needs a/
.In this dependenciesFromResources method it list all files in local system (default path is ~/.rewrite/classpath and it doesn't matter for this bug), then try to compute whether these files match the artifactNames given in args.
As we can see the source code is:
For example:
spring-beans-5.*
and their are aspring-beans-5.3.27.jar
in target path, then we want match for it;spring-beans-4.*
and their are aspring-beans-5.3.27.jar
in target path, then we want NOT match for it;But the issue is: for now this pattern will always be NOT match no matter what the artifactName and local file is. The reason is the
file.getName()
and patternPattern.compile("[/\\\\]" + artifactName + "-?.*\\.jar$")
is mismatch.file.getName()
returns a short name without any/
./
.What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the sbm-support-rewrite in spring-boot-migrator which will call open-rewrite.
What is the smallest, simplest way to reproduce the problem?
Any codes that using dependenciesFromResources can reproduce this issue. For my case it is:
What did you expect to see?
All artifactNames should be find in local folder and the missingArtifactNames in this line should be empty.
What did you see instead?
When use debug breakpoint I can see all artifactNames mismatch with local jars even they exists in my local. And the missingArtifactNames in this line is NOT empty.
Are you interested in contributing a fix to OpenRewrite?
Would like to if we agree that it's a bug.
The text was updated successfully, but these errors were encountered: