diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java index f8390c628275..ec439870cfe8 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java @@ -149,6 +149,7 @@ protected int doInvoke(C context) throws Exception { validate(context); pushCoreProperties(context); pushUserProperties(context); + setupGuiceClassLoading(context); configureLogging(context); createTerminal(context); activateLogging(context); @@ -247,6 +248,16 @@ protected void pushUserProperties(C context) throws Exception { } } + /** + * Sets up Guice class loading mode to CHILD, if not already set. + * Default Guice class loading mode uses a terminally deprecated JDK memory-access classes. + */ + protected void setupGuiceClassLoading(C context) { + if (System.getProperty("guice_custom_class_loading", "").isBlank()) { + System.setProperty("guice_custom_class_loading", "CHILD"); + } + } + protected void configureLogging(C context) throws Exception { // LOG COLOR Map effectiveProperties = context.protoSession.getEffectiveProperties(); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java new file mode 100644 index 000000000000..2c5c6ed8a3c6 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.it; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * This is a test set for GH-10312. + */ +class MavenITgh10312TerminallyDeprecatedMethodInGuiceTest extends AbstractMavenIntegrationTestCase { + + MavenITgh10312TerminallyDeprecatedMethodInGuiceTest() { + super(ALL_MAVEN_VERSIONS); + } + + @Test + void worryingShouldNotBePrinted() throws Exception { + requiresJavaVersion("[24,)"); + File testDir = extractResources("/gh-10312-terminally-deprecated-method-in-guice"); + + Verifier verifier = new Verifier(testDir.getAbsolutePath()); + verifier.setForkJvm(true); + verifier.addCliArgument("validate"); + verifier.execute(); + + assertTrue(verifier.getStdout().isEmpty(), "Expected no output on stdout, but got: " + verifier.getStdout()); + + assertFalse( + verifier.getStderr() + .contains( + "WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner"), + "Expected no warning about sun.misc.Unsafe::staticFieldBase, but got: " + verifier.getStderr()); + } + + @Test + void allowOverwriteByUser() throws Exception { + requiresJavaVersion("[24,26)"); + File testDir = extractResources("/gh-10312-terminally-deprecated-method-in-guice"); + + Verifier verifier = new Verifier(testDir.getAbsolutePath()); + verifier.setForkJvm(true); + verifier.addCliArgument("validate"); + verifier.addCliArgument("-Dguice_custom_class_loading=BRIDGE"); + verifier.execute(); + + assertTrue(verifier.getStdout().isEmpty(), "Expected no output on stdout, but got: " + verifier.getStdout()); + + assertTrue( + verifier.getStderr() + .contains( + "WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner"), + "Expected warning about sun.misc.Unsafe::staticFieldBase, but got: " + verifier.getStderr()); + } +} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index d931454b0636..3bd40ee2d6ea 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -103,6 +103,7 @@ public TestSuiteOrdering() { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.class); suite.addTestSuite(MavenITgh10937QuotedPipesInMavenOptsTest.class); suite.addTestSuite(MavenITgh2532DuplicateDependencyEffectiveModelTest.class); suite.addTestSuite(MavenITmng8736ConcurrentFileActivationTest.class); diff --git a/its/core-it-suite/src/test/resources/gh-10312-terminally-deprecated-method-in-guice/pom.xml b/its/core-it-suite/src/test/resources/gh-10312-terminally-deprecated-method-in-guice/pom.xml new file mode 100644 index 000000000000..688f859a22fc --- /dev/null +++ b/its/core-it-suite/src/test/resources/gh-10312-terminally-deprecated-method-in-guice/pom.xml @@ -0,0 +1,11 @@ + + + + 4.0.0 + + org.apache.maven.its.gh2532 + parent + 1.0-SNAPSHOT + pom + + diff --git a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java index 75367b8c83e6..7f6d1794edd6 100644 --- a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java +++ b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java @@ -124,6 +124,10 @@ public class Verifier { private boolean skipMavenRc = true; + private ByteArrayOutputStream stdout; + + private ByteArrayOutputStream stderr; + public Verifier(String basedir) throws VerificationException { this(basedir, null); } @@ -240,8 +244,8 @@ public void execute() throws VerificationException { if (forkJvm) { mode = ExecutorHelper.Mode.FORKED; } - ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - ByteArrayOutputStream stderr = new ByteArrayOutputStream(); + stdout = new ByteArrayOutputStream(); + stderr = new ByteArrayOutputStream(); ExecutorRequest request = builder.stdOut(stdout).stdErr(stderr).build(); int ret = executorHelper.execute(mode, request); if (ret > 0) { @@ -472,6 +476,14 @@ public void verifyTextInLog(String text) throws VerificationException { } } + public String getStdout() { + return stdout != null ? stdout.toString(StandardCharsets.UTF_8) : ""; + } + + public String getStderr() { + return stderr != null ? stderr.toString(StandardCharsets.UTF_8) : ""; + } + public static String stripAnsi(String msg) { return msg.replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", ""); }