From 714c51401ddfef8cc389efc7e0ea48bd7e2d810d Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 14 Aug 2025 15:31:52 +0200 Subject: [PATCH 1/8] Switched using classloader to using classgraph library. --- pom.xml | 6 +- .../plugins/scripting/java/JavaEngine.java | 133 +++++------------- 2 files changed, 40 insertions(+), 99 deletions(-) diff --git a/pom.xml b/pom.xml index 44cf8af..1035e79 100644 --- a/pom.xml +++ b/pom.xml @@ -111,7 +111,11 @@ Institute of Molecular Cell Biology and Genetics. org.scijava scijava-common - + + io.github.classgraph + classgraph + 4.8.172 + junit diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java index 2225447..6d61f5d 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -31,6 +31,33 @@ package org.scijava.plugins.scripting.java; +import io.github.classgraph.ClassGraph; +import org.scijava.command.CommandService; +import org.scijava.minimaven.BuildEnvironment; +import org.scijava.minimaven.Coordinate; +import org.scijava.minimaven.MavenProject; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.PluginService; +import org.scijava.run.RunService; +import org.scijava.script.AbstractScriptEngine; +import org.scijava.util.FileUtils; +import org.scijava.util.LineOutputStream; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import javax.script.ScriptEngine; +import javax.script.ScriptException; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -43,44 +70,13 @@ import java.io.Reader; import java.io.StringReader; import java.io.Writer; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; -import java.util.jar.Attributes.Name; -import java.util.jar.JarFile; -import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.script.ScriptEngine; -import javax.script.ScriptException; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.scijava.command.CommandService; -import org.scijava.minimaven.BuildEnvironment; -import org.scijava.minimaven.Coordinate; -import org.scijava.minimaven.MavenProject; -import org.scijava.plugin.Parameter; -import org.scijava.plugin.PluginService; -import org.scijava.run.RunService; -import org.scijava.script.AbstractScriptEngine; -import org.scijava.util.FileUtils; -import org.scijava.util.LineOutputStream; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - /** * A pseudo-{@link ScriptEngine} compiling and executing Java classes. *

@@ -787,23 +783,14 @@ private static Element append(final Document document, final Element parent, getAllDependencies(final BuildEnvironment env) { final List result = new ArrayList(); - for (ClassLoader loader = Thread.currentThread().getContextClassLoader(); loader != null; loader = - loader.getParent()) - { - if (loader instanceof URLClassLoader) { - for (final URL url : ((URLClassLoader) loader).getURLs()) { - if (url.getProtocol().equals("file")) { - final File file = new File(url.getPath()); - if (url.toString().matches( - ".*/target/surefire/surefirebooter[0-9]*\\.jar")) - { - getSurefireBooterURLs(file, url, env, result); - continue; - } - result.add(fakeDependency(env, file)); - } - } - } + ClassGraph cg = new ClassGraph(); + String cp = cg.getClasspath(); + String[] candidates = cp.split(File.pathSeparator); + + for( String candidate : candidates ){ + File file = new File(candidate); + Coordinate c = fakeDependency(env, file); + result.add(c); } return result; } @@ -830,56 +817,6 @@ private static Coordinate fakeDependency(final BuildEnvironment env, return dependency; } - /** - * Figures out the class path given a {@code .jar} file generated by the - * {@code maven-surefire-plugin}. - *

- * A little-known feature of JAR files is that their manifest can specify - * additional class path elements in a {@code Class-Path} entry. The - * {@code maven-surefire-plugin} makes extensive use of that: the URLs of the - * of the active {@link URLClassLoader} will consist of only a single - * {@code .jar} file that is empty except for a manifest whose sole purpose is - * to specify the dependencies. - *

- *

- * This method can be used to discover those additional class path elements. - *

- * - * @param file the {@code .jar} file generated by the - * {@code maven-surefire-plugin} - * @param baseURL the {@link URL} of the {@code .jar} file, needed for class - * path elements specified as relative paths - * @param env the {@link BuildEnvironment}, to store the Maven POMs faked for - * the class path elements - * @param result the list of dependencies to which the discovered dependencies - * are added - */ - private static void getSurefireBooterURLs(final File file, final URL baseURL, - final BuildEnvironment env, final List result) - { - try { - final JarFile jar = new JarFile(file); - Manifest manifest = jar.getManifest(); - if (manifest != null) { - final String classPath = - manifest.getMainAttributes().getValue(Name.CLASS_PATH); - if (classPath != null) { - for (final String element : classPath.split(" +")) - try { - final File dependency = - new File(new URL(baseURL, element).getPath()); - result.add(fakeDependency(env, dependency)); - } - catch (MalformedURLException e) { - e.printStackTrace(); - } - } - } - } - catch (final IOException e) { - e.printStackTrace(); - } - } /** * Read complete contents of a Reader and return as String. From b72274b82acbfb1dd156f88856ce1c29c5993edf Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:21:29 -0500 Subject: [PATCH 2/8] POM: update parent to pom-scijava 42.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1035e79..fd8fc39 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 26.0.0 + 42.0.0 From c3fecc77595cc7e359b115da1690709e952d009d Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:22:07 -0500 Subject: [PATCH 3/8] Update copyright blurbs for 2025 --- LICENSE.txt | 2 +- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 2 +- .../org/scijava/plugins/scripting/java/JavaEngineBindings.java | 2 +- .../org/scijava/plugins/scripting/java/JavaScriptLanguage.java | 2 +- .../java/org/scijava/plugins/scripting/java/JavaEngineTest.java | 2 +- .../java/org/scijava/plugins/scripting/java/MakeJarTest.java | 2 +- src/test/resources/Dummy.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 28fb714..3ee5b32 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2008 - 2017, Board of Regents of the University of +Copyright (c) 2008 - 2025, Board of Regents of the University of Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck Institute of Molecular Cell Biology and Genetics. All rights reserved. diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java index 6d61f5d..88d7e51 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2017 Board of Regents of the University of + * Copyright (C) 2008 - 2025 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaEngineBindings.java b/src/main/java/org/scijava/plugins/scripting/java/JavaEngineBindings.java index 0cf76eb..ea82a3d 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngineBindings.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngineBindings.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2017 Board of Regents of the University of + * Copyright (C) 2008 - 2025 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/java/JavaScriptLanguage.java index 00be7fe..6ecad22 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaScriptLanguage.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaScriptLanguage.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2017 Board of Regents of the University of + * Copyright (C) 2008 - 2025 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java index d2128ab..7c413d8 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2017 Board of Regents of the University of + * Copyright (C) 2008 - 2025 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/org/scijava/plugins/scripting/java/MakeJarTest.java b/src/test/java/org/scijava/plugins/scripting/java/MakeJarTest.java index 60794b7..ae0b60f 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/MakeJarTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/MakeJarTest.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2017 Board of Regents of the University of + * Copyright (C) 2008 - 2025 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/resources/Dummy.java b/src/test/resources/Dummy.java index 5e788c4..3b86531 100644 --- a/src/test/resources/Dummy.java +++ b/src/test/resources/Dummy.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2017 Board of Regents of the University of + * Copyright (C) 2008 - 2025 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% From 40cb95da3abcc76611e0625c8acc277d34629d85 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:22:54 -0500 Subject: [PATCH 4/8] POM: declare classgraph version as a property --- pom.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fd8fc39..5f354c6 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,8 @@ Institute of Molecular Cell Biology and Genetics. sign,deploy-to-scijava + + 4.8.172 @@ -111,11 +113,14 @@ Institute of Molecular Cell Biology and Genetics. org.scijava scijava-common
+ + io.github.classgraph classgraph - 4.8.172 + ${classgraph.version} + junit From d6918c0570c430832946b593f7cf456c5fca95f8 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:25:36 -0500 Subject: [PATCH 5/8] Update CI to current standards; rename main branch --- .github/build.sh | 2 +- .github/setup.sh | 2 +- .github/workflows/build-pr.yml | 23 ------------------- .../workflows/{build-main.yml => build.yml} | 8 +++++-- README.md | 2 +- 5 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/build-pr.yml rename .github/workflows/{build-main.yml => build.yml} (81%) diff --git a/.github/build.sh b/.github/build.sh index 7da4262..523abeb 100755 --- a/.github/build.sh +++ b/.github/build.sh @@ -1,3 +1,3 @@ #!/bin/sh -curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/ci-build.sh +curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/main/ci-build.sh sh ci-build.sh diff --git a/.github/setup.sh b/.github/setup.sh index f359bbe..a03464b 100755 --- a/.github/setup.sh +++ b/.github/setup.sh @@ -1,3 +1,3 @@ #!/bin/sh -curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/ci-setup-github-actions.sh +curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/main/ci-setup-github-actions.sh sh ci-setup-github-actions.sh diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml deleted file mode 100644 index 925b576..0000000 --- a/.github/workflows/build-pr.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: build PR - -on: - pull_request: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Java - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'zulu' - cache: 'maven' - - name: Set up CI environment - run: .github/setup.sh - - name: Execute the build - run: .github/build.sh diff --git a/.github/workflows/build-main.yml b/.github/workflows/build.yml similarity index 81% rename from .github/workflows/build-main.yml rename to .github/workflows/build.yml index 5ef5692..b0a181e 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build.yml @@ -3,9 +3,12 @@ name: build on: push: branches: - - master + - main tags: - "*-[0-9]+.*" + pull_request: + branches: + - main jobs: build: @@ -28,5 +31,6 @@ jobs: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} MAVEN_USER: ${{ secrets.MAVEN_USER }} MAVEN_PASS: ${{ secrets.MAVEN_PASS }} - OSSRH_PASS: ${{ secrets.OSSRH_PASS }} + CENTRAL_USER: ${{ secrets.CENTRAL_USER }} + CENTRAL_PASS: ${{ secrets.CENTRAL_PASS }} SIGNING_ASC: ${{ secrets.SIGNING_ASC }} diff --git a/README.md b/README.md index 09650b7..a16ffca 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![](https://github.com/scijava/scripting-java/actions/workflows/build-main.yml/badge.svg)](https://github.com/scijava/scripting-java/actions/workflows/build-main.yml) +[![](https://github.com/scijava/scripting-java/actions/workflows/build.yml/badge.svg)](https://github.com/scijava/scripting-java/actions/workflows/build.yml) # Java Scripting From 31fd9c6ca0983caba169d5e259e6b7987e8304dd Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:29:18 -0500 Subject: [PATCH 6/8] POM: bump version to 1.0.0-SNAPSHOT It's past time to start deploying SciJava components like this one to Maven Central! --- pom.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 5f354c6..73afaf8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.4.2-SNAPSHOT + 1.0.0-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. @@ -97,9 +97,6 @@ Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck Institute of Molecular Cell Biology and Genetics. - - sign,deploy-to-scijava - 4.8.172 From e8af7611ac12e369706f0414e263ac8854234da2 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:30:49 -0500 Subject: [PATCH 7/8] POM: use HTTPS for schema location URL Maven no longer supports plain HTTP for the schema location. And using HTTP now generates errors in Eclipse (and probably other IDEs). --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 73afaf8..808b03d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 From 4b1c9dd6f7311796a490923125415f46fc9a970e Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 14 Aug 2025 13:31:01 -0500 Subject: [PATCH 8/8] Bump to next development cycle Signed-off-by: Curtis Rueden --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 808b03d..cd79974 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 1.0.0-SNAPSHOT + 1.0.1-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin.