gnodet commented on code in PR #12993:
URL: https://github.com/apache/maven/pull/12993#discussion_r3913644472


##########
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/NashornCompatibilityStrategy.java:
##########
@@ -0,0 +1,268 @@
+/*
+ * 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.cling.invoker.mvnup.goals;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import eu.maveniverse.domtrip.Document;
+import eu.maveniverse.domtrip.Element;
+import org.apache.maven.api.cli.mvnup.UpgradeOptions;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.cling.invoker.mvnup.UpgradeContext;
+
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.ARTIFACT_ID;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.BUILD;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.DEPENDENCIES;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.GROUP_ID;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGIN;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGINS;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGIN_MANAGEMENT;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PROFILE;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PROFILES;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Plugins.DEFAULT_MAVEN_PLUGIN_GROUP_ID;
+
+/**
+ * Strategy for injecting the standalone OpenJDK Nashorn engine as a plugin 
dependency
+ * when {@code maven-antrun-plugin} uses inline JavaScript via {@code <script 
language="javascript">}.
+ *
+ * <p>Maven 4 requires JDK 17+, but the built-in Nashorn JavaScript engine was 
removed in JDK 15.
+ * Plugins executing JavaScript in-process (particularly {@code 
maven-antrun-plugin} with
+ * {@code <script language="javascript">}) fail with:
+ * <pre>
+ * [ERROR] Unable to create javax script engine for javascript
+ * </pre>
+ *
+ * <p>Toolchains cannot help because the script runs in Maven's own JVM, not 
in a forked process.
+ * The standalone OpenJDK Nashorn ({@code org.openjdk.nashorn:nashorn-core}) 
provides a drop-in
+ * replacement that registers via {@code ServiceLoader} and restores 
JavaScript support.
+ *
+ * @see <a href="https://github.com/apache/maven/issues/12988";>#12988</a>
+ */
+@Named
+@Singleton
+@Priority(19)
+public class NashornCompatibilityStrategy extends AbstractUpgradeStrategy {
+
+    static final String ANTRUN_ARTIFACT_ID = "maven-antrun-plugin";
+    static final String NASHORN_GROUP_ID = "org.openjdk.nashorn";
+    static final String NASHORN_ARTIFACT_ID = "nashorn-core";
+    static final String NASHORN_VERSION = "15.4";
+
+    private static final String SCRIPT = "script";
+    private static final String LANGUAGE = "language";
+    private static final String JAVASCRIPT = "javascript";
+
+    @Override

Review Comment:
   Updated to 15.7 in af4a22a. Good catch — no reason to pin to an old release.



-- 
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]

Reply via email to