-
Notifications
You must be signed in to change notification settings - Fork 906
Upgrade netbeans-gradle-tooling to use Gradle 8.11.1 #8810
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
========================================================================= | ||
== NOTICE file corresponding to the section 4 d of == | ||
== the Apache License, Version 2.0, == | ||
== in this case for the Gradle distribution. == | ||
========================================================================= | ||
|
||
This product includes software developed by | ||
The Apache Software Foundation (http://www.apache.org/). | ||
|
||
It includes the following other software: | ||
|
||
Groovy (http://groovy-lang.org) | ||
SLF4J (http://www.slf4j.org) | ||
JUnit (http://www.junit.org) | ||
JCIFS (http://jcifs.samba.org) | ||
HttpClient (https://hc.apache.org/httpcomponents-client-4.5.x/) | ||
|
||
For licenses, see the LICENSE file. | ||
|
||
If any software distributed with Gradle does not have an Apache 2 License, its license is explicitly listed in the | ||
LICENSE file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,7 +223,7 @@ public ValueAndType(Class type) { | |
|
||
NbProjectInfoBuilder(Project project) { | ||
this.project = project; | ||
this.adapter = sinceGradleOrDefault("7.6", () -> new GradleInternalAdapter.Gradle76(project), () -> new GradleInternalAdapter(project)); | ||
this.adapter = sinceGradleOrDefault("7.6", () -> new GradleInternalAdapter(project), () -> new GradleInternalAdapter.GradlePre76(project)); | ||
} | ||
|
||
private NbProjectInfoModel model = new NbProjectInfoModel(); | ||
|
@@ -367,11 +367,19 @@ private String dependenciesAsString(Task t, TaskDependency td) { | |
} | ||
|
||
private void detectConfigurationArtifacts(NbProjectInfoModel model) { | ||
// JDK-8301046: Don't use Configuration::getName as a method reference. The bug, when | ||
// compiling `Configuration::getName` against Gradle >= 8.4, causes javac to pick the | ||
// wrong receiver target (invokeinterface on Named::getName) in the lambda bootstrap | ||
// method params rather than the (correct per JLS) invokevirtual on the callsite's | ||
// erasure type (Configuration). This will break at runtime when calling Gradle <8.4, | ||
// as in earlier versions the Configuration class does not implement Named, and throws | ||
// a BootstrapMethodError wrapping a LambdaConversionException. The lambda form: | ||
// `c -> c.getName()` bootstraps correctly but costs an extra method def/indirection. | ||
List<Configuration> configs = project.getConfigurations() | ||
.stream() | ||
.filter(Configuration::isCanBeConsumed) | ||
.filter(c -> !c.isCanBeResolved()) | ||
.sorted(Comparator.comparing(Configuration::getName)) | ||
.sorted(Comparator.comparing(c -> c.getName())) // JDK-8301046 | ||
.collect(Collectors.toList()); | ||
Map<String, Object> data = new HashMap<>(); | ||
for (Configuration c : configs) { | ||
|
@@ -1362,18 +1370,24 @@ private void detectArtifacts(NbProjectInfoModel model) { | |
} | ||
} | ||
Map<String, Object> archives = new HashMap<>(); | ||
beforeGradle("5.2", () -> { | ||
// The jar.getCassifier() and jar.getArchievePath() are deprecated since 5.2 | ||
// These methods got removed in 8.0 | ||
project.getTasks().withType(Jar.class).forEach(jar -> { | ||
archives.put(jar.getClassifier(), jar.getArchivePath()); | ||
}); | ||
}); | ||
sinceGradle("5.2", () -> { | ||
project.getTasks().withType(Jar.class).forEach(jar -> { | ||
archives.put(jar.getArchiveClassifier().get(), jar.getDestinationDirectory().file(jar.getArchiveFileName().get()).get().getAsFile()); | ||
}); | ||
}); | ||
Consumer<Jar> jarToArchivesClassifierAndPath = | ||
sinceGradleOrDefault( | ||
"5.2", | ||
() -> jar -> archives.put(jar.getArchiveClassifier().get(), jar.getDestinationDirectory().file(jar.getArchiveFileName().get()).get().getAsFile()), | ||
() -> { | ||
// The jar.getCassifier() and jar.getArchievePath() are deprecated since 5.2 | ||
// These methods got removed in 8.0 | ||
Method getClassifier = Jar.class.getMethod("getClassifier"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could you cache the Method objects at the Builder level or at least in the method ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this made me curious so I wrote a quick JMH benchmark: private static final List<?> LIST = List.of("1");
private static final Method METHOD;
static {
Method m = null;
try {
m = List.class.getMethod("getFirst");
} catch (NoSuchMethodException ex) {
throw new IllegalStateException(ex);
}
METHOD = m;
}
/*
JDK 25.0.0
Benchmark Mode Cnt Score Error Units
ReflectionJMH.reference avgt 5 0.390 ± 0.009 ns/op
ReflectionJMH.constMethod avgt 5 1.098 ± 0.004 ns/op
ReflectionJMH.getMethod avgt 5 114.503 ± 1.479 ns/op
*/
@Benchmark
public void reference(Blackhole bh) throws ReflectiveOperationException {
bh.consume(LIST.getFirst());
}
@Benchmark
public void getMethod(Blackhole bh) throws ReflectiveOperationException {
bh.consume(List.class.getMethod("getFirst").invoke(LIST));
}
@Benchmark
public void constMethod(Blackhole bh) throws ReflectiveOperationException {
bh.consume(METHOD.invoke(LIST));
} having it as constant makes still a big difference. Also interesting that the JVM couldn't completely eliminate the reflective overhead of the static constant based invocation. (but take this with a grain of salt, micro benchmarks are always tricky, method call overhead can also go down in the noise if the method is actually doing something non-trivial) |
||
Method getArchivePath = Jar.class.getMethod("getArchivePath"); | ||
return jar -> { | ||
try { | ||
archives.put((String) getClassifier.invoke(jar), (File) getArchivePath.invoke(jar)); | ||
} catch (ReflectiveOperationException e) { | ||
sneakyThrow(e); | ||
} | ||
}; | ||
}); | ||
project.getTasks().withType(Jar.class).forEach(jarToArchivesClassifierAndPath); | ||
model.getInfo().put("archives", archives); | ||
} | ||
|
||
|
@@ -1567,17 +1581,7 @@ private void detectDependencies(NbProjectInfoModel model) { | |
Function<ProjectDependency, Project> projDependencyToProject = | ||
sinceGradleOrDefault( | ||
"9.0", | ||
() -> { | ||
Method getPath = ProjectDependency.class.getMethod("getPath"); | ||
return dep -> { | ||
try { | ||
String path = (String) getPath.invoke(dep); | ||
return project.findProject(path); | ||
} catch (ReflectiveOperationException e) { | ||
throw new UnsupportedOperationException(e); | ||
} | ||
}; | ||
}, | ||
() -> dep -> project.findProject(dep.getPath()), // getPath() added in Gradle 8.11 | ||
() -> ProjectDependency::getDependencyProject); // removed in Gradle 9 | ||
|
||
visibleConfigurations.forEach(it -> { | ||
|
@@ -1884,22 +1888,25 @@ interface ExceptionCallable<T, E extends Throwable> { | |
private static <T extends Throwable> void sneakyThrow(Throwable exception) throws T { | ||
throw (T) exception; | ||
} | ||
|
||
private <T, E extends Throwable> T sinceGradleOrDefault(String version, ExceptionCallable<T, E> c, Supplier<T> def) { | ||
|
||
private <T, E extends Throwable> T sinceGradleOrDefault( | ||
String version, ExceptionCallable<T, E> c, ExceptionCallable<T, E> def) { | ||
ExceptionCallable<T, E> impl; | ||
if (GRADLE_VERSION.compareTo(GradleVersion.version(version)) >= 0) { | ||
try { | ||
return c.call(); | ||
} catch (RuntimeException | Error e) { | ||
throw e; | ||
} catch (Throwable t) { | ||
sneakyThrow(t); | ||
return null; | ||
} | ||
impl = c; | ||
} else if (def != null) { | ||
return def.get(); | ||
impl = def; | ||
} else { | ||
return null; | ||
} | ||
try { | ||
return impl.call(); | ||
} catch (RuntimeException | Error e) { | ||
throw e; | ||
} catch (Throwable t) { | ||
sneakyThrow(t); | ||
return null; | ||
} | ||
} | ||
|
||
private <T, E extends Throwable> T sinceGradle(String version, ExceptionCallable<T, E> c) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reminded me on this old PR #4864