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/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/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 diff --git a/pom.xml b/pom.xml index 44cf8af..cd79974 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,16 @@ - + 4.0.0 org.scijava pom-scijava - 26.0.0 + 42.0.0 scripting-java - 0.4.2-SNAPSHOT + 1.0.1-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. @@ -97,8 +97,7 @@ 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 @@ -112,6 +111,13 @@ Institute of Molecular Cell Biology and Genetics. scijava-common + + + io.github.classgraph + classgraph + ${classgraph.version} + + 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..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. * %% @@ -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. 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. * %%