mbien commented on code in PR #5482:
URL: https://github.com/apache/netbeans/pull/5482#discussion_r1104041098
##########
java/maven/src/org/netbeans/modules/maven/options/MavenSettings.java:
##########
@@ -480,6 +481,18 @@ public void setBinaryDownloadStrategy(DownloadStrategy ds)
{
}
}
+ try {
+ try (Stream<Path> jars = Files.list(lib).filter(file ->
file.getFileName().toString().startsWith("maven-core"))) { // NOI18N
+ for (Path mavenCoreJar : jars.collect(Collectors.toList())) {
+ String mavenCoreJarName =
mavenCoreJar.getFileName().toString();
+ if
(mavenCoreJarName.matches("maven-core-\\d+\\.\\d+\\.\\d+\\.jar")) {
+ return mavenCoreJarName.replace("maven-core-",
"").replace(".jar", "");
+ }
+ }
+ }
+ } catch (IOException ignored) {
+ }
Review Comment:
just a nitpick: it would be even faster by terminating the stream early (and
not collecting the jars which forces the stream to visit all jars):
```java
Pattern jarPattern =
Pattern.compile("maven-core-\\d+\\.\\d+\\.\\d+\\.jar"); // NOI18N
try (Stream<Path> jars = Files.list(lib)
.map(file -> file.getFileName())
.filter(file ->
file.toString().startsWith("maven-core")) // NOI18N
.filter(file ->
jarPattern.matcher(file.toString()).matches())) {
Optional<Path> mavencore = jars.findFirst();
if (mavencore.isPresent()) {
return mavencore.get().toString().replace("maven-core-",
"").replace(".jar", ""); // NOI18N
}
} catch (IOException ignored) {}
```
this uses one stream start to finish and it should terminate as soon the jar
is found. The pattern is now also compiled outside of the loop.
I did also attach the catch to the inner try so that we only need one try
block for this.
(isn't tested, hope it compiles)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists