From 535760da7aad6dfe2ccdcbeb00bb5f00251a2cc6 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 28 Aug 2014 11:47:28 +0200 Subject: [PATCH 01/83] Add compile(Reader) method JavaEngine provides the possibility to evaluate Java code from a Reader, sometimes one might not want to have that code immediately executed. For a Java File, the compile(File,Writer) method was provided already, this commit adds such a method for compiling from Reader. --- .../plugins/scripting/java/JavaEngine.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) 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 1686d50..6903df0 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -90,6 +90,7 @@ *

* * @author Johannes Schindelin + * @author Jonathan Hale */ public class JavaEngine extends AbstractScriptEngine { @@ -141,6 +142,31 @@ public Object eval(String script) throws ScriptException { */ @Override public Object eval(Reader reader) throws ScriptException { + final Writer writer = getContext().getErrorWriter(); + try { + final Class clazz = compile(reader); + javaService.run(clazz); + } catch (Exception e) { + if (writer != null) { + final PrintWriter err = new PrintWriter(writer); + e.printStackTrace(err); + err.flush(); + } else { + if (e instanceof ScriptException) + throw (ScriptException) e; + throw new ScriptException(e); + } + } + return null; + } + + /** + * Compiles and runs the specified {@code .java} class. + * + * @param reader the reader producing the source code for a Java class + * @returns the compiled Java class as {@link Class}. + */ + public Class compile(Reader reader) throws ScriptException { final String path = (String)get(FILENAME); File file = path == null ? null : new File(path); @@ -170,12 +196,11 @@ public Object eval(Reader reader) throws ScriptException { URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); - // needed for sezpoz + // needed for annotation processing Thread.currentThread().setContextClassLoader(classLoader); - // launch main class - final Class clazz = classLoader.loadClass(mainClass); - javaService.run(clazz); + // load main class + return classLoader.loadClass(mainClass); } finally { builder.cleanup(); } From 865edaf85b93c8f560fac42b429473c5ac75a53d Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 28 Aug 2014 11:49:10 +0200 Subject: [PATCH 02/83] Add compile(String) method A convenience method to compile from String, analog to eval(String). --- .../org/scijava/plugins/scripting/java/JavaEngine.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 6903df0..9bc7276 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -160,6 +160,16 @@ public Object eval(Reader reader) throws ScriptException { return null; } + /** + * Compiles and runs the specified {@code .java} class. + * + * @param script the source code for a Java class + * @return the compiled Java class as {@link Class}. + */ + public Class compile(String script) throws ScriptException { + return compile(new StringReader(script)); + } + /** * Compiles and runs the specified {@code .java} class. * From 447cf937fc92065d5601c7823d00b3ae43e12115 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 26 Sep 2014 14:55:35 -0500 Subject: [PATCH 03/83] Use a better value for the default groupId This project migrated from ImageJ2, where net.imagej was an intuitive choice for default groupId. But the project is part of the Scijava scripting framework now, so a groupId matching that fact makes more sense. We use org.scijava.scripting.java, rather than only org.scijava, to avoid potential name clashes with actual SciJava projects such as scijava-common, scripting-java, etc. --- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 2 +- .../org/scijava/plugins/scripting/java/JavaEngineTest.java | 2 +- .../java/org/scijava/plugins/scripting/java/MakeJarTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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 1686d50..0afe033 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -93,7 +93,7 @@ */ public class JavaEngine extends AbstractScriptEngine { - private final static String DEFAULT_GROUP_ID = "net.imagej"; + private final static String DEFAULT_GROUP_ID = "org.scijava.scripting.java"; private final static String DEFAULT_VERSION = "1.0.0-SNAPSHOT"; /** 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 ad8f8c9..8715acf 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java @@ -198,7 +198,7 @@ private File makeProject(final String mainClass, final String... args) " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0\n" + // " http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + // " 4.0.0\n" + // - " net.imagej\n" + // + " org.scijava.scripting.java\n" + // " MinimalTest\n" + // " 1.0.0\n" + // " \n" + // 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 81bc517..76c994a 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/MakeJarTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/MakeJarTest.java @@ -58,10 +58,10 @@ public void testSingle() throws Exception { final File output = new File(tmpDir, "test.jar"); engine.makeJar(file, false, output, writer); assertJarEntries(output, "META-INF/MANIFEST.MF", - "META-INF/maven/net.imagej/Dummy/pom.xml", "Dummy.class"); + "META-INF/maven/org.scijava.scripting.java/Dummy/pom.xml", "Dummy.class"); engine.makeJar(file, true, output, writer); assertJarEntries(output, "META-INF/MANIFEST.MF", - "META-INF/maven/net.imagej/Dummy/pom.xml", "Dummy.class", + "META-INF/maven/org.scijava.scripting.java/Dummy/pom.xml", "Dummy.class", "pom.xml", "src/main/java/Dummy.java"); } From 39b5a04cbe5f1b9ba0d8b3f6776461fac9f279ae Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 7 Oct 2014 10:39:28 -0500 Subject: [PATCH 04/83] JavaRunner: tweak javadoc --- .../java/org/scijava/plugins/scripting/java/JavaRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java index bcd8607..f37c926 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java @@ -37,7 +37,7 @@ import org.scijava.plugin.Plugin; /** - * A plugin which extends an Java script language's execution handling. A + * A plugin which extends the Java script language's execution handling. A * {@code JavaRunner} knows how to execute certain classes, beyond just Java's * usual {@code main} method. *

From 55ee39bc454dae55d61bb5f9051c81aa2bb82a7c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 15 Oct 2014 18:36:32 -0500 Subject: [PATCH 05/83] Bump parent to 3.6 Signed-off-by: Johannes Schindelin --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7512a32..e1f2734 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 3.0 + 3.6 From ae42086b0498d6d19dbfaab9d680f0f95e0316f6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 15 Oct 2014 18:38:28 -0500 Subject: [PATCH 06/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e1f2734..7d5860c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.2.5-SNAPSHOT + 0.2.6-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From bef176947f68b997b25dd34884a7e54eac8c7652 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 11 Feb 2015 07:01:07 -0600 Subject: [PATCH 07/83] Happy belated New Year 2015 --- LICENSE.txt | 2 +- .../scijava/plugins/scripting/java/AbstractJavaRunner.java | 2 +- .../org/scijava/plugins/scripting/java/CommandJavaRunner.java | 2 +- .../scijava/plugins/scripting/java/DefaultJavaService.java | 4 ++-- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 2 +- .../scijava/plugins/scripting/java/JavaEngineBindings.java | 2 +- .../java/org/scijava/plugins/scripting/java/JavaRunner.java | 2 +- .../scijava/plugins/scripting/java/JavaScriptLanguage.java | 2 +- .../java/org/scijava/plugins/scripting/java/JavaService.java | 4 ++-- .../org/scijava/plugins/scripting/java/MainJavaRunner.java | 2 +- .../org/scijava/plugins/scripting/java/JavaEngineTest.java | 2 +- .../java/org/scijava/plugins/scripting/java/MakeJarTest.java | 2 +- src/test/resources/Dummy.java | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index e896c7f..cce13af 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2008 - 2014, Board of Regents of the University of +Copyright (c) 2008 - 2015, 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/AbstractJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java index d6b362e..9c4165b 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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/CommandJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java index aa61123..37daa90 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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/DefaultJavaService.java b/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java index 2542c46..81b27f7 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java +++ b/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java @@ -1,8 +1,8 @@ /* * #%L - * SciJava Common shared library for SciJava software. + * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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/JavaEngine.java b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java index 0afe033..a17bbdf 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 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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 d38cf0f..173165c 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 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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/JavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java index f37c926..005696c 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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 ac13d21..0aa43dd 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 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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/JavaService.java b/src/main/java/org/scijava/plugins/scripting/java/JavaService.java index a44ba46..232d1b8 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaService.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaService.java @@ -1,8 +1,8 @@ /* * #%L - * SciJava Common shared library for SciJava software. + * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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/MainJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java index 5486b7c..b4dea91 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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 8715acf..15bb104 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 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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 76c994a..5729664 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 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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 74474e6..6d168ce 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 - 2014 Board of Regents of the University of + * Copyright (C) 2008 - 2015 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 510a488ab90e21d8d006b027e8ecbfeb49934f5e Mon Sep 17 00:00:00 2001 From: Squareys Date: Fri, 6 Mar 2015 13:13:01 +0100 Subject: [PATCH 08/83] Add utility method for getting Reader contents as String Needed in future recompilation avoidance for hash calculation. TODO: Move to a utility class? Signed-off-by: Squareys --- .../plugins/scripting/java/JavaEngine.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 9bc7276..44a33d4 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -46,6 +46,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.CharBuffer; import java.util.ArrayList; import java.util.List; import java.util.jar.JarFile; @@ -730,4 +731,26 @@ private static void getSurefireBooterURLs(final File file, final URL baseURL, } } + /** + * Read complete contents of a Reader and return as String. + * + * @param reader {@link Reader} whose output should be returned as String. + * @return contents of reader as String. + */ + private static String getReaderContentsAsString(Reader reader) throws IOException { + if (reader == null) { + return null; + } + + CharBuffer buffer = CharBuffer.allocate(1024); + StringBuilder builder = new StringBuilder(); + + int read; + while ((read = reader.read(buffer)) != -1) { + builder.append(buffer, 0, read); + } + + return builder.toString(); + } + } From 4913afd3e43279381cb75b7b2f11f8ea816e9061 Mon Sep 17 00:00:00 2001 From: Squareys Date: Fri, 6 Mar 2015 13:28:18 +0100 Subject: [PATCH 09/83] Swap execution order of compile(String) and compile(Reader) This allows us to compute a hash on the script as a String even if it was input via the gererating Reader. We need to compute the hash for future recompilation avoidance. Signed-off-by: Squareys --- .../plugins/scripting/java/JavaEngine.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) 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 44a33d4..fb651cf 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -168,21 +168,14 @@ public Object eval(Reader reader) throws ScriptException { * @return the compiled Java class as {@link Class}. */ public Class compile(String script) throws ScriptException { - return compile(new StringReader(script)); - } - - /** - * Compiles and runs the specified {@code .java} class. - * - * @param reader the reader producing the source code for a Java class - * @returns the compiled Java class as {@link Class}. - */ - public Class compile(Reader reader) throws ScriptException { final String path = (String)get(FILENAME); File file = path == null ? null : new File(path); final Writer writer = getContext().getErrorWriter(); try { + // script may be null, but then we cannot create a StringReader for it, + // therefore null is passed if script is null. + final Reader reader = (script == null) ? null : new StringReader(script); final Builder builder = new Builder(file, reader, writer); final MavenProject project = builder.project; String mainClass = builder.mainClass; @@ -229,6 +222,23 @@ public Class compile(Reader reader) throws ScriptException { return null; } + /** + * Compiles and runs the specified {@code .java} class. + * + * @param reader the reader producing the source code for a Java class + * @return the compiled Java class as {@link Class}. + */ + public Class compile(Reader reader) throws ScriptException { + String script; + try { + script = getReaderContentsAsString(reader); + } + catch (IOException e) { + throw new ScriptException(e); + } + return compile(script); + } + /** * Compiles the specified {@code .java} file. * From fededa42fe77b11b5b2bb7600fa221f70f1cf51c Mon Sep 17 00:00:00 2001 From: Squareys Date: Fri, 6 Mar 2015 13:33:38 +0100 Subject: [PATCH 10/83] Swap execution order of eval(String) and eval(Reader) This order is much more efficient with the recently swapped execution order of compile(String) and compile(Reader). See e663151. Signed-off-by: Squareys --- .../plugins/scripting/java/JavaEngine.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) 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 fb651cf..00a82e7 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -128,7 +128,23 @@ public class JavaEngine extends AbstractScriptEngine { */ @Override public Object eval(String script) throws ScriptException { - return eval(new StringReader(script)); + final Writer writer = getContext().getErrorWriter(); + try { + final Class clazz = compile(script); + javaService.run(clazz); + } + catch (Exception e) { + if (writer != null) { + final PrintWriter err = new PrintWriter(writer); + e.printStackTrace(err); + err.flush(); + } + else { + if (e instanceof ScriptException) throw (ScriptException) e; + throw new ScriptException(e); + } + } + return null; } /** @@ -143,22 +159,14 @@ public Object eval(String script) throws ScriptException { */ @Override public Object eval(Reader reader) throws ScriptException { - final Writer writer = getContext().getErrorWriter(); + String script; try { - final Class clazz = compile(reader); - javaService.run(clazz); - } catch (Exception e) { - if (writer != null) { - final PrintWriter err = new PrintWriter(writer); - e.printStackTrace(err); - err.flush(); - } else { - if (e instanceof ScriptException) - throw (ScriptException) e; - throw new ScriptException(e); - } + script = getReaderContentsAsString(reader); } - return null; + catch (IOException e) { + throw new ScriptException(e); + } + return eval(script); } /** From 1f8ec6990e9b25e864574178b3d92db956f19a11 Mon Sep 17 00:00:00 2001 From: Squareys Date: Mon, 9 Mar 2015 12:04:35 +0100 Subject: [PATCH 11/83] Format JavaEngine.java --- .../plugins/scripting/java/JavaEngine.java | 208 +++++++++++------- 1 file changed, 128 insertions(+), 80 deletions(-) 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 00a82e7..016f9b0 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -101,7 +101,8 @@ public class JavaEngine extends AbstractScriptEngine { /** * The key to specify how to indent the XML written out by Xalan. */ - private final static String XALAN_INDENT_AMOUNT = "{http://xml.apache.org/xslt}indent-amount"; + private final static String XALAN_INDENT_AMOUNT = + "{http://xml.apache.org/xslt}indent-amount"; { engineScopeBindings = new JavaEngineBindings(); @@ -176,7 +177,7 @@ public Object eval(Reader reader) throws ScriptException { * @return the compiled Java class as {@link Class}. */ public Class compile(String script) throws ScriptException { - final String path = (String)get(FILENAME); + final String path = (String) get(FILENAME); File file = path == null ? null : new File(path); final Writer writer = getContext().getErrorWriter(); @@ -193,8 +194,7 @@ public Class compile(String script) throws ScriptException { if (mainClass == null) { mainClass = project.getMainClass(); if (mainClass == null) { - throw new ScriptException( - "No main class found for file " + file); + throw new ScriptException("No main class found for file " + file); } } @@ -213,17 +213,19 @@ public Class compile(String script) throws ScriptException { // load main class return classLoader.loadClass(mainClass); - } finally { + } + finally { builder.cleanup(); } - } catch (Exception e) { + } + catch (Exception e) { if (writer != null) { final PrintWriter err = new PrintWriter(writer); e.printStackTrace(err); err.flush(); - } else { - if (e instanceof ScriptException) - throw (ScriptException) e; + } + else { + if (e instanceof ScriptException) throw (ScriptException) e; throw new ScriptException(e); } } @@ -274,7 +276,9 @@ public void compile(final File file, final Writer errorWriter) { * @param output the {@code .jar} file to write to * @param errorWriter the destination for error messages */ - public void makeJar(final File file, final boolean includeSources, final File output, final Writer errorWriter) { + public void makeJar(final File file, final boolean includeSources, + final File output, final Writer errorWriter) + { try { final Builder builder = new Builder(file, null, errorWriter); try { @@ -283,10 +287,12 @@ public void makeJar(final File file, final boolean includeSources, final File ou if (output != null && !target.equals(output)) { BuildEnvironment.copyFile(target, output); } - } finally { + } + finally { builder.cleanup(); } - } catch (Throwable t) { + } + catch (Throwable t) { printOrThrow(t, errorWriter); } } @@ -303,7 +309,8 @@ public void makeJar(final File file, final boolean includeSources, final File ou * @param errorWriter the error writer, or null */ private void printOrThrow(Throwable t, Writer errorWriter) { - RuntimeException e = t instanceof RuntimeException ? (RuntimeException) t + RuntimeException e = + t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t); if (errorWriter == null) { throw e; @@ -319,6 +326,7 @@ private void printOrThrow(Throwable t, Writer errorWriter) { * @author Johannes Schindelin */ private class Builder { + private final PrintStream err; private final File temporaryDirectory; private String mainClass; @@ -327,8 +335,9 @@ private class Builder { /** * Constructs a wrapper around a possibly temporary project. * - * @param file the {@code .java} file to build (or null, if {@code reader} is set). - * @param reader provides the Java source if {@code file} is {@code null} + * @param file the {@code .java} file to build (or null, if {@code reader} + * is set). + * @param reader provides the Java source if {@code file} is {@code null} * @param errorWriter where to write the error output. * @throws ScriptException * @throws IOException @@ -339,13 +348,15 @@ private class Builder { * @throws TransformerFactoryConfigurationError */ private Builder(final File file, final Reader reader, - final Writer errorWriter) throws ScriptException, IOException, - ParserConfigurationException, SAXException, - TransformerConfigurationException, TransformerException, - TransformerFactoryConfigurationError { + final Writer errorWriter) throws ScriptException, IOException, + ParserConfigurationException, SAXException, + TransformerConfigurationException, TransformerException, + TransformerFactoryConfigurationError + { if (errorWriter == null) { err = null; - } else { + } + else { err = new PrintStream(new LineOutputStream() { @Override @@ -358,22 +369,22 @@ public void println(final String line) throws IOException { boolean verbose = "true".equals(get("verbose")); boolean debug = "true".equals(get("debug")); - BuildEnvironment env = new BuildEnvironment(err, true, verbose, - debug); + BuildEnvironment env = new BuildEnvironment(err, true, verbose, debug); - if (file == null || !file.exists()) - try { - project = writeTemporaryProject(env, reader); - temporaryDirectory = project.getDirectory(); - mainClass = project.getMainClass(); - } catch (Exception e) { - throw new ScriptException(e); - } + if (file == null || !file.exists()) try { + project = writeTemporaryProject(env, reader); + temporaryDirectory = project.getDirectory(); + mainClass = project.getMainClass(); + } + catch (Exception e) { + throw new ScriptException(e); + } else { temporaryDirectory = null; if (file.getName().equals("pom.xml")) { project = env.parse(file, null); - } else { + } + else { mainClass = getFullClassName(file); project = getMavenProject(env, file, mainClass); } @@ -384,12 +395,11 @@ public void println(final String line) throws IOException { * Cleans up the project, if it was only temporary. */ private void cleanup() { - if (err != null) - err.close(); - if (err != null) - err.close(); - if (temporaryDirectory != null - && !FileUtils.deleteRecursively(temporaryDirectory)) { + if (err != null) err.close(); + if (err != null) err.close(); + if (temporaryDirectory != null && + !FileUtils.deleteRecursively(temporaryDirectory)) + { temporaryDirectory.deleteOnExit(); } } @@ -414,13 +424,17 @@ private void cleanup() { * @throws TransformerFactoryConfigurationError */ private MavenProject getMavenProject(final BuildEnvironment env, - final File file, final String mainClass) throws IOException, - ParserConfigurationException, SAXException, ScriptException, - TransformerConfigurationException, TransformerException, - TransformerFactoryConfigurationError { + final File file, final String mainClass) throws IOException, + ParserConfigurationException, SAXException, ScriptException, + TransformerConfigurationException, TransformerException, + TransformerFactoryConfigurationError + { String path = file.getAbsolutePath(); - if (!path.replace(File.separatorChar, '.').endsWith("." + mainClass + ".java")) { - throw new ScriptException("Class " + mainClass + " in invalid directory: " + path); + if (!path.replace(File.separatorChar, '.').endsWith( + "." + mainClass + ".java")) + { + throw new ScriptException("Class " + mainClass + + " in invalid directory: " + path); } path = path.substring(0, path.length() - mainClass.length() - 5); if (path.replace(File.separatorChar, '/').endsWith("/src/main/java/")) { @@ -446,19 +460,21 @@ private static String getFullClassName(final File file) throws IOException { name = name.substring(0, name.length() - 5); String packageName = ""; - final Pattern packagePattern = Pattern.compile("package ([a-zA-Z0-9_.]*).*"); - final Pattern classPattern = Pattern.compile(".*public class ([a-zA-Z0-9_]*).*"); + final Pattern packagePattern = + Pattern.compile("package ([a-zA-Z0-9_.]*).*"); + final Pattern classPattern = + Pattern.compile(".*public class ([a-zA-Z0-9_]*).*"); final BufferedReader reader = new BufferedReader(new FileReader(file)); for (;;) { String line = reader.readLine().trim(); if (line == null) break; - outerLoop: + outerLoop: while (line.startsWith("/*")) { int end = line.indexOf("*/", 2); while (end < 0) { - line = reader.readLine(); - if (line == null) break outerLoop; - end = line.indexOf("*/"); + line = reader.readLine(); + if (line == null) break outerLoop; + end = line.indexOf("*/"); } line = line.substring(end + 2).trim(); } @@ -474,7 +490,8 @@ private static String getFullClassName(final File file) throws IOException { } } reader.close(); - return packageName + name; // the 'package' statement must be the first in the file + return packageName + name; // the 'package' statement must be the first in + // the file } /** @@ -510,16 +527,20 @@ private static MavenProject writeTemporaryProject(final BuildEnvironment env, out.close(); final String mainClass = getFullClassName(file); - final File result = new File(directory, "src/main/java/" + mainClass.replace('.', '/') + ".java"); + final File result = + new File(directory, "src/main/java/" + mainClass.replace('.', '/') + + ".java"); if (!result.getParentFile().mkdirs()) { throw new IOException("Could not make directory for " + result); } if (!file.renameTo(result)) { - throw new IOException("Could not move " + file + " into the correct location"); + throw new IOException("Could not move " + file + + " into the correct location"); } // write POM - final String artifactId = mainClass.substring(mainClass.lastIndexOf('.') + 1); + final String artifactId = + mainClass.substring(mainClass.lastIndexOf('.') + 1); return fakePOM(env, directory, artifactId, mainClass, true); } @@ -535,13 +556,16 @@ private static MavenProject writeTemporaryProject(final BuildEnvironment env, * @param name the project name * @return the generated {@code artifactId} */ - private static String fakeArtifactId(final BuildEnvironment env, final String name) { + private static String fakeArtifactId(final BuildEnvironment env, + final String name) + { int dot = name.indexOf('.'); - final String prefix = dot < 0 ? name : dot == 0 ? "dependency" : name.substring(0, dot); + final String prefix = + dot < 0 ? name : dot == 0 ? "dependency" : name.substring(0, dot); if (!env.containsProject(DEFAULT_GROUP_ID, prefix)) { return prefix; } - for (int i = 1; ; i++) { + for (int i = 1;; i++) { final String artifactId = prefix + "-" + i; if (!env.containsProject(DEFAULT_GROUP_ID, artifactId)) { return artifactId; @@ -573,17 +597,21 @@ private static String fakeArtifactId(final BuildEnvironment env, final String na * @throws TransformerFactoryConfigurationError */ private static MavenProject fakePOM(final BuildEnvironment env, - final File directory, final String artifactId, final String mainClass, boolean writePOM) - throws IOException, ParserConfigurationException, SAXException, - TransformerConfigurationException, TransformerException, - TransformerFactoryConfigurationError { - final Document pom = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + final File directory, final String artifactId, final String mainClass, + boolean writePOM) throws IOException, ParserConfigurationException, + SAXException, TransformerConfigurationException, TransformerException, + TransformerFactoryConfigurationError + { + final Document pom = + DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); final Element project = pom.createElement("project"); pom.appendChild(project); project.setAttribute("xmlns", "http://maven.apache.org/POM/4.0.0"); - project.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - project.setAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 " + - "http://maven.apache.org/xsd/maven-4.0.0.xsd"); + project.setAttribute("xmlns:xsi", + "http://www.w3.org/2001/XMLSchema-instance"); + project.setAttribute("xsi:schemaLocation", + "http://maven.apache.org/POM/4.0.0 " + + "http://maven.apache.org/xsd/maven-4.0.0.xsd"); append(pom, project, "groupId", DEFAULT_GROUP_ID); append(pom, project, "artifactId", artifactId); @@ -608,12 +636,16 @@ private static MavenProject fakePOM(final BuildEnvironment env, append(pom, dep, "artifactId", dependency.getArtifactId()); append(pom, dep, "version", dependency.getVersion()); } - final Transformer transformer = TransformerFactory.newInstance().newTransformer(); + final Transformer transformer = + TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(XALAN_INDENT_AMOUNT, "4"); - if (directory.getPath().replace(File.separatorChar, '/').endsWith("/src/main/java")) { - final File projectRootDirectory = directory.getParentFile().getParentFile().getParentFile(); + if (directory.getPath().replace(File.separatorChar, '/').endsWith( + "/src/main/java")) + { + final File projectRootDirectory = + directory.getParentFile().getParentFile().getParentFile(); final File pomFile = new File(projectRootDirectory, "pom.xml"); if (!pomFile.exists()) { final FileWriter writer = new FileWriter(pomFile); @@ -622,11 +654,13 @@ private static MavenProject fakePOM(final BuildEnvironment env, } } if (writePOM) { - transformer.transform(new DOMSource(pom), new StreamResult(new File(directory, "pom.xml"))); + transformer.transform(new DOMSource(pom), new StreamResult(new File( + directory, "pom.xml"))); } final ByteArrayOutputStream out = new ByteArrayOutputStream(); transformer.transform(new DOMSource(pom), new StreamResult(out)); - return env.parse(new ByteArrayInputStream(out.toByteArray()), directory, null, null); + return env.parse(new ByteArrayInputStream(out.toByteArray()), directory, + null, null); } /** @@ -638,9 +672,12 @@ private static MavenProject fakePOM(final BuildEnvironment env, * @param content the content of the tag to append * @return the appended node */ - private static Element append(final Document document, final Element parent, final String tag, final String content) { + private static Element append(final Document document, final Element parent, + final String tag, final String content) + { Element child = document.createElement(tag); - if (content != null) child.appendChild(document.createCDATASection(content)); + if (content != null) child + .appendChild(document.createCDATASection(content)); parent.appendChild(child); return child; } @@ -660,15 +697,20 @@ private static Element append(final Document document, final Element parent, fin * @param env the {@link BuildEnvironment} in which the faked POMs are stored * @return the list of dependencies, as {@link Coordinate}s */ - private static List getAllDependencies(final BuildEnvironment env) { + private static List + getAllDependencies(final BuildEnvironment env) + { final List result = new ArrayList(); - for (ClassLoader loader = Thread.currentThread().getContextClassLoader(); - loader != null; loader = loader.getParent()) { + for (ClassLoader loader = Thread.currentThread().getContextClassLoader(); loader != null; loader = + loader.getParent()) + { if (loader instanceof URLClassLoader) { - for (final URL url : ((URLClassLoader)loader).getURLs()) { + 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")) { + if (url.toString().matches( + ".*/target/surefire/surefirebooter[0-9]*\\.jar")) + { getSurefireBooterURLs(file, url, env, result); continue; } @@ -692,9 +734,12 @@ private static List getAllDependencies(final BuildEnvironment env) { * @param file the dependency * @return the {@link Coordinate} specifying the dependency */ - private static Coordinate fakeDependency(final BuildEnvironment env, final File file) { + private static Coordinate fakeDependency(final BuildEnvironment env, + final File file) + { final String artifactId = fakeArtifactId(env, file.getName()); - Coordinate dependency = new Coordinate(DEFAULT_GROUP_ID, artifactId, "1.0.0"); + Coordinate dependency = + new Coordinate(DEFAULT_GROUP_ID, artifactId, "1.0.0"); env.fakePOM(file, dependency); return dependency; } @@ -735,7 +780,8 @@ private static void getSurefireBooterURLs(final File file, final URL baseURL, if (classPath != null) { for (final String element : classPath.split(" +")) try { - final File dependency = new File(new URL(baseURL, element).getPath()); + final File dependency = + new File(new URL(baseURL, element).getPath()); result.add(fakeDependency(env, dependency)); } catch (MalformedURLException e) { @@ -755,7 +801,9 @@ private static void getSurefireBooterURLs(final File file, final URL baseURL, * @param reader {@link Reader} whose output should be returned as String. * @return contents of reader as String. */ - private static String getReaderContentsAsString(Reader reader) throws IOException { + private static String getReaderContentsAsString(Reader reader) + throws IOException + { if (reader == null) { return null; } From 040383e0c395a0c6edc603b5c5a033894ddfdbea Mon Sep 17 00:00:00 2001 From: Squareys Date: Mon, 9 Mar 2015 12:17:34 +0100 Subject: [PATCH 12/83] Add compile(File) method compile(File, Writer) now uses the context error writer if the specified writer is null. compile(file) calls compile(File, null), therefore compiles a given file and writes errors to the context error writer. This maintains the consistency througout the compile(..) and eval(..) methods. --- .../plugins/scripting/java/JavaEngine.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) 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 016f9b0..0024787 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -199,14 +199,14 @@ public Class compile(String script) throws ScriptException { } // make class loader - String[] paths = project.getClassPath(false).split( - File.pathSeparator); + String[] paths = project.getClassPath(false).split(File.pathSeparator); URL[] urls = new URL[paths.length]; for (int i = 0; i < urls.length; i++) - urls[i] = new URL("file:" + paths[i] - + (paths[i].endsWith(".jar") ? "" : "/")); - URLClassLoader classLoader = new URLClassLoader(urls, - Thread.currentThread().getContextClassLoader()); + urls[i] = + new URL("file:" + paths[i] + (paths[i].endsWith(".jar") ? "" : "/")); + URLClassLoader classLoader = + new URLClassLoader(urls, Thread.currentThread() + .getContextClassLoader()); // needed for annotation processing Thread.currentThread().setContextClassLoader(classLoader); @@ -250,20 +250,42 @@ public Class compile(Reader reader) throws ScriptException { } /** - * Compiles the specified {@code .java} file. + * Compiles the specified {@code .java} file. Errors are written to the + * context error writer. * * @param file the source code - * @param errorWriter where to write the errors + * @see #compile(File, Writer) + * @see #compile(Reader) + * @see #compile(String) + */ + public void compile(final File file) { + compile(file, null); + } + + /** + * Compiles the specified {@code .java} file. Errors are written to the + * specified errorWriter or if it is null, to the context error writer. + * + * @param file the source code + * @param errorWriter where to write the errors or null to use context + * errorWriter + * @see #compile(File) + * @see #compile(Reader) + * @see #compile(String) */ public void compile(final File file, final Writer errorWriter) { try { - final Builder builder = new Builder(file, null, errorWriter); + final Writer writer = + (errorWriter == null) ? getContext().getErrorWriter() : errorWriter; + final Builder builder = new Builder(file, null, writer); try { builder.project.build(); - } finally { + } + finally { builder.cleanup(); } - } catch (Throwable t) { + } + catch (Throwable t) { printOrThrow(t, errorWriter); } } From c2a33d37cc3f453a222af5caa95111ea45411fba Mon Sep 17 00:00:00 2001 From: Squareys Date: Mon, 9 Mar 2015 12:59:02 +0100 Subject: [PATCH 13/83] Refactor Builder constructor for readability There are now two constructors which clearly differentiate between creating a project for a File and creating a project for a Reader. This makes the calling code easier to read. To avoid code duplication, two small private methods were added to Builder. --- .../plugins/scripting/java/JavaEngine.java | 125 +++++++++++++----- 1 file changed, 90 insertions(+), 35 deletions(-) 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 0024787..9dff7d7 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -182,10 +182,21 @@ public Class compile(String script) throws ScriptException { final Writer writer = getContext().getErrorWriter(); try { - // script may be null, but then we cannot create a StringReader for it, - // therefore null is passed if script is null. - final Reader reader = (script == null) ? null : new StringReader(script); - final Builder builder = new Builder(file, reader, writer); + + final Builder builder; + + if (file != null && file.exists()) { + // if the filename set in engine scope bindings is valid, + // ignore the given script and use that file instead. + builder = new Builder(file, writer); + } + else { + // script may be null, but then we cannot create a StringReader for it, + // therefore null is passed if script is null. + final Reader reader = + (script == null) ? null : new StringReader(script); + builder = new Builder(reader, writer); + } final MavenProject project = builder.project; String mainClass = builder.mainClass; @@ -277,7 +288,7 @@ public void compile(final File file, final Writer errorWriter) { try { final Writer writer = (errorWriter == null) ? getContext().getErrorWriter() : errorWriter; - final Builder builder = new Builder(file, null, writer); + final Builder builder = new Builder(file, writer); try { builder.project.build(); } @@ -302,7 +313,7 @@ public void makeJar(final File file, final boolean includeSources, final File output, final Writer errorWriter) { try { - final Builder builder = new Builder(file, null, errorWriter); + final Builder builder = new Builder(file, errorWriter); try { builder.project.build(true, true, includeSources); final File target = builder.project.getTarget(); @@ -346,6 +357,7 @@ private void printOrThrow(Throwable t, Writer errorWriter) { * A wrapper around a (possibly only temporary) project. * * @author Johannes Schindelin + * @author Jonathan Hale */ private class Builder { @@ -355,11 +367,11 @@ private class Builder { private MavenProject project; /** - * Constructs a wrapper around a possibly temporary project. + * Constructs a wrapper around a possibly project for a source or maven + * project file. * * @param file the {@code .java} file to build (or null, if {@code reader} * is set). - * @param reader provides the Java source if {@code file} is {@code null} * @param errorWriter where to write the error output. * @throws ScriptException * @throws IOException @@ -369,31 +381,50 @@ private class Builder { * @throws TransformerException * @throws TransformerFactoryConfigurationError */ - private Builder(final File file, final Reader reader, - final Writer errorWriter) throws ScriptException, IOException, - ParserConfigurationException, SAXException, - TransformerConfigurationException, TransformerException, + private Builder(final File file, final Writer errorWriter) + throws ScriptException, IOException, ParserConfigurationException, + SAXException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError { - if (errorWriter == null) { - err = null; - } - else { - err = new PrintStream(new LineOutputStream() { + err = createErrorPrintStream(errorWriter); - @Override - public void println(final String line) throws IOException { - errorWriter.append(line).append('\n'); - } + BuildEnvironment env = createBuildEnvironment(); - }); + // will throw IOException if file does not exist. + temporaryDirectory = null; + if (file.getName().equals("pom.xml")) { + project = env.parse(file, null); } + else { + mainClass = getFullClassName(file); + project = getMavenProject(env, file, mainClass); + } + } - boolean verbose = "true".equals(get("verbose")); - boolean debug = "true".equals(get("debug")); - BuildEnvironment env = new BuildEnvironment(err, true, verbose, debug); + /** + * Constructs a wrapper around a possibly temporary project for source code + * generated by a Reader. + * + * @param reader provides the Java source if {@code file} is {@code null} + * @param errorWriter where to write the error output. + * @throws ScriptException + * @throws IOException + * @throws ParserConfigurationException + * @throws SAXException + * @throws TransformerConfigurationException + * @throws TransformerException + * @throws TransformerFactoryConfigurationError + */ + private Builder(final Reader reader, final Writer errorWriter) + throws ScriptException, IOException, ParserConfigurationException, + SAXException, TransformerConfigurationException, TransformerException, + TransformerFactoryConfigurationError + { + err = createErrorPrintStream(errorWriter); + + BuildEnvironment env = createBuildEnvironment(); - if (file == null || !file.exists()) try { + try { project = writeTemporaryProject(env, reader); temporaryDirectory = project.getDirectory(); mainClass = project.getMainClass(); @@ -401,16 +432,40 @@ public void println(final String line) throws IOException { catch (Exception e) { throw new ScriptException(e); } - else { - temporaryDirectory = null; - if (file.getName().equals("pom.xml")) { - project = env.parse(file, null); - } - else { - mainClass = getFullClassName(file); - project = getMavenProject(env, file, mainClass); - } + } + + /** + * Create a {@link PrintStream} from an error {@link Writer}. + * + * @param errorWriter the {@link Writer} to write errors to. + * @return a {@link PrintStream} which writes to errorWriter. + */ + private PrintStream createErrorPrintStream(final Writer errorWriter) { + if (errorWriter == null) { + return null; } + + // create a PrintStream which redirects output to errorWriter + return new PrintStream(new LineOutputStream() { + + @Override + public void println(final String line) throws IOException { + errorWriter.append(line).append('\n'); + } + + }); + } + + /** + * Create a {@link BuildEnvironment} for current engine scope bindings + * context. + * + * @return the created {@link BuildEnvironment}. + */ + private BuildEnvironment createBuildEnvironment() { + boolean verbose = "true".equals(get("verbose")); + boolean debug = "true".equals(get("debug")); + return new BuildEnvironment(err, true, verbose, debug); } /** From 23394b3e00fc87e730233e69205a641961189ce2 Mon Sep 17 00:00:00 2001 From: Squareys Date: Mon, 9 Mar 2015 13:02:40 +0100 Subject: [PATCH 14/83] Document behaviour of compile and eval methods When a valid filename is specified by the ScriptEngine.FILENAME key in the engine scope bindings, the given script will be ignored and the file described by the filename will be compiled (and run) instead. Signed-off-by: Squareys --- .../plugins/scripting/java/JavaEngine.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 9dff7d7..c4fdc53 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -118,7 +118,9 @@ public class JavaEngine extends AbstractScriptEngine { private JavaService javaService; /** - * Compiles and runs the specified {@code .java} class. + * Compiles and runs the specified {@code .java} class. If a filename is set + * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key, + * this method compiles that file and runs the resulting main class instead. *

* The currently active {@link JavaService} is responsible for running the * class. @@ -149,7 +151,9 @@ public Object eval(String script) throws ScriptException { } /** - * Compiles and runs the specified {@code .java} class. + * Compiles and runs the specified {@code .java} class. If a filename is set + * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key, + * this method compiles that file and runs the resulting main class instead. *

* The currently active {@link JavaService} is responsible for running the * class. @@ -171,12 +175,16 @@ public Object eval(Reader reader) throws ScriptException { } /** - * Compiles and runs the specified {@code .java} class. + * Compiles and runs the specified {@code .java} class. If a filename is set + * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key, + * this method compiles that file and returns its resulting main class + * instead. * * @param script the source code for a Java class * @return the compiled Java class as {@link Class}. */ public Class compile(String script) throws ScriptException { + // get filename from engine scope bindings final String path = (String) get(FILENAME); File file = path == null ? null : new File(path); @@ -244,7 +252,10 @@ public Class compile(String script) throws ScriptException { } /** - * Compiles and runs the specified {@code .java} class. + * Compiles and runs the specified {@code .java} class. If a filename is set + * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key, + * this method compiles that file and returns its resulting main class + * instead. * * @param reader the reader producing the source code for a Java class * @return the compiled Java class as {@link Class}. From 048ff0114f84ebd14738cedbe331dba961805bb3 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 16 Mar 2015 12:24:34 -0500 Subject: [PATCH 15/83] Bump parent to pom-scijava 6.0.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7d5860c..9a94c78 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ org.scijava pom-scijava - 3.6 + 6.0.0 scripting-java - 0.2.6-SNAPSHOT + 0.3.0-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From b8bf9535eb3122dff29fc5b1bccbbf821c0fa7ff Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 16 Mar 2015 13:44:53 -0500 Subject: [PATCH 16/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9a94c78..38030e9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.0-SNAPSHOT + 0.3.1-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From 75731c99c66177b9f2f0443b91e4a644910ac214 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Mar 2015 12:05:49 -0500 Subject: [PATCH 17/83] JavaEngine: organize imports --- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 76842c2..102cc0c 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -49,9 +49,9 @@ import java.nio.CharBuffer; 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.jar.Attributes.Name; import java.util.regex.Matcher; import java.util.regex.Pattern; From 1e9c9fd2906c54def1adeb59c2197954db698d69 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Mar 2015 12:05:59 -0500 Subject: [PATCH 18/83] JavaEngine: fix critical buffering bug This fixes Fiji bug #1029: http://fiji.sc/bugzilla/show_bug.cgi?id=1029 The CharBuffer has a position which does not get reset, and so length() returns 0 even when there is data in subsequent read passes. We avoid the issue by using a simple char[] instead of a new-fangled "object". Without this change, Java scripts longer than 1024 characters will produce exceptions like: java.lang.IndexOutOfBoundsException: start 0, end 582, s.length() 442 at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:453) at java.lang.StringBuilder.append(StringBuilder.java:179) at org.scijava.plugins.scripting.java.JavaEngine.getReaderContentsAsString(JavaEngine.java:904) at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:169) --- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 102cc0c..93f0cde 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -46,7 +46,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.nio.CharBuffer; import java.util.ArrayList; import java.util.List; import java.util.jar.Attributes.Name; @@ -896,7 +895,7 @@ private static String getReaderContentsAsString(Reader reader) return null; } - CharBuffer buffer = CharBuffer.allocate(1024); + char[] buffer = new char[1024]; StringBuilder builder = new StringBuilder(); int read; From 696388047ef656facfee25121d4b6e1646efb9df Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 23 Mar 2015 13:19:26 -0500 Subject: [PATCH 19/83] Change XML comment style to avoid mixed whitespace The previous style required leading tabs followed by five spaces. Consequently, no autoformatting tools supported it, meaning it had to be done manually every time, and thus there were many incorrectly formatted comments around. Let's change to a comment style that uses only leading tabs, and is hence autoformattable by standard tools. --- pom.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 38030e9..b22dab2 100644 --- a/pom.xml +++ b/pom.xml @@ -124,8 +124,10 @@ Institute of Molecular Cell Biology and Genetics. - + tools-jar From 33a693d7db1be46f7dc5f1650f931f78f400fbf6 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 15 Apr 2015 13:35:01 -0500 Subject: [PATCH 20/83] Bump pom-scijava parent to 7.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b22dab2..04e8fa9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 6.0.0 + 7.0.0 From e375ec6c1c638367fd4667a8b9537fe11f1a9bd5 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 15 Apr 2015 13:41:18 -0500 Subject: [PATCH 21/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 04e8fa9..ccf07f2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From e432e2e70f858a6703567bac5628cadc0714b767 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 28 Apr 2015 23:03:35 -0500 Subject: [PATCH 22/83] README.md: add Jenkins build status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a683aa9..052a098 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![](http://jenkins.imagej.net/job/scripting-Java/lastBuild/badge/icon) + # Java Scripting This library provides a From e82bdcd245c05489870b2e0d4ca171b4d0391182 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 28 Apr 2015 23:23:31 -0500 Subject: [PATCH 23/83] POM: fix Jenkins URL (http, not https) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ccf07f2..c93165b 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ Jenkins - https://jenkins.imagej.net/job/scripting-Java/ + http://jenkins.imagej.net/job/scripting-Java/ From 32e98b282939b4d29022a1f936f52eef63b3a895 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 29 Apr 2015 14:45:28 -0500 Subject: [PATCH 24/83] README.md: link Jenkins badge to the job --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 052a098..1f95798 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](http://jenkins.imagej.net/job/scripting-Java/lastBuild/badge/icon) +[![](http://jenkins.imagej.net/job/scripting-Java/lastBuild/badge/icon)](http://jenkins.imagej.net/job/scripting-Java/) # Java Scripting From e653768490e8b83be44b5b826df07679bbafcd03 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Mon, 15 Jun 2015 11:10:54 -0500 Subject: [PATCH 25/83] Bump parent to pom-scijava 7.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c93165b..6f7e5dc 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 7.0.0 + 7.3.0 From 37522430636195ec794eabc032bae6ca6331d44d Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Mon, 15 Jun 2015 11:12:07 -0500 Subject: [PATCH 26/83] Register script engine with JSR-223 framework Closes #9 --- .../resources/META-INF/services/javax.script.ScriptEngineFactory | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/resources/META-INF/services/javax.script.ScriptEngineFactory diff --git a/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory b/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory new file mode 100644 index 0000000..bb5de81 --- /dev/null +++ b/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory @@ -0,0 +1 @@ +org.scijava.plugins.scripting.java.JavaScriptLanguage From 3eb2224a6b0c63bcff45ebf3ed71013d7b46e8f2 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Mon, 15 Jun 2015 11:14:08 -0500 Subject: [PATCH 27/83] Test Java discovery by JSR-223 framework --- pom.xml | 5 +++++ .../scijava/plugins/scripting/java/JavaEngineTest.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6f7e5dc..65eb42e 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,11 @@ junit test + + org.scijava + scijava-common + tests + 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 15bb104..8af1ca5 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java @@ -48,6 +48,7 @@ import org.junit.Test; import org.scijava.Context; import org.scijava.object.ObjectService; +import org.scijava.script.AbstractScriptLanguageTest; import org.scijava.script.ScriptLanguage; import org.scijava.script.ScriptService; import org.scijava.test.TestUtils; @@ -57,7 +58,12 @@ * * @author Johannes Schindelin */ -public class JavaEngineTest { +public class JavaEngineTest extends AbstractScriptLanguageTest { + + @Test + public void testDiscovery() { + assertDiscovered(JavaScriptLanguage.class); + } @Before public void assumeJavaC() { From 7ea78c103a062d69738044f58ecae9a54bbd3ab7 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Mon, 15 Jun 2015 11:15:38 -0500 Subject: [PATCH 28/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 65eb42e..f827850 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.2-SNAPSHOT + 0.3.3-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From cc6589a319f72bec5bcc452118a0c8d33fc03ec5 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 16 Jun 2015 14:02:23 -0500 Subject: [PATCH 29/83] Use test scope for scijava-common tests lib It was an oversight, which now causes pain because the scijava-common tests library includes some extra services and plugins which hose up downstream applications. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index f827850..ac2b685 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,7 @@ org.scijava scijava-common tests + test From 4933cc27afaa3f106a6d237a1a42308305049068 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 16 Jun 2015 15:45:17 -0500 Subject: [PATCH 30/83] POM: bump to pom-scijava 7.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ac2b685..fead837 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 7.3.0 + 7.4.0 From 04b041882596f2a48c98ce4997e282a43fa6b279 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 16 Jun 2015 16:40:51 -0500 Subject: [PATCH 31/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fead837..8199280 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.3-SNAPSHOT + 0.3.4-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From c72a5d4048ee089712e9dc60bfe23a74ea930134 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 6 Nov 2015 18:39:39 -0600 Subject: [PATCH 32/83] Bump pom-scijava parent to 8.5.0 This fixes an Eclipse lifecycle configuration issue with build-helper-maven-plugin. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8199280..7deff80 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 7.4.0 + 8.5.0 From a082749459327777d7e0411438504ee182fef576 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Nov 2015 08:51:11 -0600 Subject: [PATCH 33/83] POM: remove excess whitespace This makes tidy-maven-plugin happy. --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7deff80..deb35da 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,6 @@ JSR-223-compliant Java scripting language plugin. http://scijava.org/ 2008 - Simplified BSD License @@ -69,12 +68,10 @@ HEAD https://github.com/scijava/scripting-java - GitHub Issues https://github.com/scijava/scripting-java/issues - Jenkins http://jenkins.imagej.net/job/scripting-Java/ @@ -154,5 +151,4 @@ Institute of Molecular Cell Biology and Genetics. - From 04cb57c7fd0f1d6443b93eca5a424e6f7e3c7299 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Nov 2015 10:38:37 -0600 Subject: [PATCH 34/83] POM: remove redundant mailingLists section It is inherited from the pom-scijava parent. --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index deb35da..e82e06a 100644 --- a/pom.xml +++ b/pom.xml @@ -52,16 +52,6 @@ - - - SciJava - https://groups.google.com/group/scijava - https://groups.google.com/group/scijava - scijava@googlegroups.com - https://groups.google.com/group/scijava - - - scm:git:git://github.com/scijava/scripting-java scm:git:git@github.com:scijava/scripting-java From 5cfcc2ad513cefbc92fccd2cfd06a96c5a9d4a8f Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Nov 2015 10:57:05 -0600 Subject: [PATCH 35/83] POM: update developers and contributors See: http://imagej.net/Team --- pom.xml | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index e82e06a..0636582 100644 --- a/pom.xml +++ b/pom.xml @@ -25,32 +25,52 @@ - dscho - Johannes Schindelin - schindelin@wisc.edu - http://loci.wisc.edu/people/johannes-schindelin + ctrueden + Curtis Rueden + ctrueden@wisc.edu + http://loci.wisc.edu/people/curtis-rueden UW-Madison LOCI http://loci.wisc.edu/ - architect + lead developer + debugger + reviewer + support + maintainer -6 - ctrueden - Curtis Rueden - ctrueden@wisc.edu - http://loci.wisc.edu/people/curtis-rueden + hinerm + Mark Hiner + hiner@wisc.edu + http://loci.wisc.edu/people/mark-hiner UW-Madison LOCI http://loci.wisc.edu/ - architect + lead developer + debugger + reviewer + support + maintainer -6 + + + Johannes Schindelin + http://imagej.net/User:Schindelin + founder + dscho + + + Jonathan Hale + Squareys + + scm:git:git://github.com/scijava/scripting-java From e83a41b23d0ddbe5cbb0c39848e9ce42be973fff Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Nov 2015 10:57:09 -0600 Subject: [PATCH 36/83] POM: bump parent to pom-scijava 9.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0636582..4f6d94f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 8.5.0 + 9.0.0 From 91e2d867e67b0e62a2a62a890a684b19e9409bd7 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 19 Nov 2015 12:52:49 -0600 Subject: [PATCH 37/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4f6d94f..6b6a69b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.4-SNAPSHOT + 0.3.5-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From 06d8ee7d5c910a4aeac454125ed7f1d023e704a5 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Wed, 2 Dec 2015 13:48:36 -0600 Subject: [PATCH 38/83] JavaEngine: avoid setting classloader If a ClassLoader sticks around it will prevent future versions of classes from being loaded. There is no evidence that preserving the ClassLoader is actually necessary for annotation processing at this time. --- .../org/scijava/plugins/scripting/java/JavaEngine.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 93f0cde..10a85b8 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -222,12 +222,9 @@ public Class compile(String script) throws ScriptException { for (int i = 0; i < urls.length; i++) urls[i] = new URL("file:" + paths[i] + (paths[i].endsWith(".jar") ? "" : "/")); - URLClassLoader classLoader = - new URLClassLoader(urls, Thread.currentThread() - .getContextClassLoader()); - // needed for annotation processing - Thread.currentThread().setContextClassLoader(classLoader); + final URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread() + .getContextClassLoader()); // load main class return classLoader.loadClass(mainClass); From 44c044d4f98b95f33eb0dd5fcd29343d8cd20cd9 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Wed, 2 Dec 2015 14:36:49 -0600 Subject: [PATCH 39/83] JavaEngineTest: add annotation test Test that annotations are preserved --- .../scripting/java/JavaEngineTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 8af1ca5..ec9ce95 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java @@ -167,6 +167,32 @@ public void testEvalReader() throws Exception { assertTrue(result); } + @Test + public void testAnnotations() { + boolean result = true; + final String source = "" + // + "import org.scijava.command.Command;\n" + // + "import org.scijava.plugin.Plugin;\n" + // + "@Plugin(type = Command.class)\n" + // + "public class PluginTest implements Command {\n" + // + "\t@Override\n" + // + "\tpublic void run() {\n" + // + "\t\tSystem.out.println(\"I am a plugin!\");\n" + // + "\t}\n" + // + "}"; + + final ScriptEngine miniMaven = miniMaven(); + try { + miniMaven.eval(source); + } + catch (final ScriptException e) { + e.printStackTrace(); + result = false; + } + + assertTrue(result); + } + // -- helper functions private File makeMinimalProject() throws IOException { From 6c713b119e18a2a6dea2c64509a161ee9820d9a4 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 7 Dec 2015 13:28:59 -0600 Subject: [PATCH 40/83] POM: bump parent to pom-scijava 9.1.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6b6a69b..42c50c0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 9.0.0 + 9.1.0 From 37ae753477e058843c3f68c88fae6badc708168c Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 7 Dec 2015 13:36:54 -0600 Subject: [PATCH 41/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 42c50c0..6768e81 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.5-SNAPSHOT + 0.3.6-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From d19ff0d06bcebc4711cbc397a0eae57d69b2f878 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 21 Dec 2015 14:41:36 -0600 Subject: [PATCH 42/83] JavaEngine: respect SciJava log level If it's set to INFO, set verbose=true. If it's set to DEBUG, set debug=true. --- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 10a85b8..02874d5 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -470,8 +470,8 @@ public void println(final String line) throws IOException { * @return the created {@link BuildEnvironment}. */ private BuildEnvironment createBuildEnvironment() { - boolean verbose = "true".equals(get("verbose")); - boolean debug = "true".equals(get("debug")); + boolean verbose = "true".equals(get("verbose")) || log().isInfo(); + boolean debug = "true".equals(get("debug")) || log().isDebug(); return new BuildEnvironment(err, true, verbose, debug); } From f6625e8ce4b0ecb1dccfd56c33eaa2477c3e37e3 Mon Sep 17 00:00:00 2001 From: Gabriel Einsdorf Date: Wed, 2 Mar 2016 14:06:15 -0600 Subject: [PATCH 43/83] Fix NPE when reader reads null line. Old code called trim() on ``line``, and tested for ``line == null`` afterwards. If ``line`` is actually ``null`` this will cause an ``NullPointerException`` --- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 02874d5..7ef7b91 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -550,8 +550,9 @@ private static String getFullClassName(final File file) throws IOException { Pattern.compile(".*public class ([a-zA-Z0-9_]*).*"); final BufferedReader reader = new BufferedReader(new FileReader(file)); for (;;) { - String line = reader.readLine().trim(); + String line = reader.readLine(); if (line == null) break; + line = line.trim(); outerLoop: while (line.startsWith("/*")) { int end = line.indexOf("*/", 2); From e6aa298610a35486da16f5a25f400d8b1bc89818 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 1 Apr 2016 13:54:18 -0500 Subject: [PATCH 44/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6768e81..6742682 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.3.6-SNAPSHOT + 0.3.7-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From e93616aa0d978f923982d5f53dad90077cda7c20 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 6 Feb 2015 05:42:00 -0600 Subject: [PATCH 45/83] JavaEngine: split Builder initialization logic Rather than doing all the work in the constructor, and throwing a bunch of exceptions, let's keep construction as simple as possible, then do all that initialization in its own method. This will make error handling more robust in that we will be able to attempt calls to builder.cleanup() even if something went wrong during initialization. --- .../plugins/scripting/java/JavaEngine.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) 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 7ef7b91..7231e2c 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -188,21 +188,19 @@ public Class compile(String script) throws ScriptException { File file = path == null ? null : new File(path); final Writer writer = getContext().getErrorWriter(); + final Builder builder = new Builder(); try { - - final Builder builder; - if (file != null && file.exists()) { // if the filename set in engine scope bindings is valid, // ignore the given script and use that file instead. - builder = new Builder(file, writer); + builder.initialize(file, writer); } else { // script may be null, but then we cannot create a StringReader for it, // therefore null is passed if script is null. final Reader reader = (script == null) ? null : new StringReader(script); - builder = new Builder(reader, writer); + builder.initialize(reader, writer); } final MavenProject project = builder.project; String mainClass = builder.mainClass; @@ -292,10 +290,11 @@ public void compile(final File file) { * @see #compile(String) */ public void compile(final File file, final Writer errorWriter) { + final Writer writer = + (errorWriter == null) ? getContext().getErrorWriter() : errorWriter; + final Builder builder = new Builder(); try { - final Writer writer = - (errorWriter == null) ? getContext().getErrorWriter() : errorWriter; - final Builder builder = new Builder(file, writer); + builder.initialize(file, writer); try { builder.project.build(); } @@ -319,8 +318,9 @@ public void compile(final File file, final Writer errorWriter) { public void makeJar(final File file, final boolean includeSources, final File output, final Writer errorWriter) { + final Builder builder = new Builder(); try { - final Builder builder = new Builder(file, errorWriter); + builder.initialize(file, errorWriter); try { builder.project.build(true, true, includeSources); final File target = builder.project.getTarget(); @@ -368,14 +368,17 @@ private void printOrThrow(Throwable t, Writer errorWriter) { */ private class Builder { - private final PrintStream err; - private final File temporaryDirectory; + private PrintStream err; + private File temporaryDirectory; private String mainClass; private MavenProject project; /** * Constructs a wrapper around a possibly project for a source or maven * project file. + *

+ * This method is intended to be called only once. + *

* * @param file the {@code .java} file to build (or null, if {@code reader} * is set). @@ -388,7 +391,7 @@ private class Builder { * @throws TransformerException * @throws TransformerFactoryConfigurationError */ - private Builder(final File file, final Writer errorWriter) + private void initialize(final File file, final Writer errorWriter) throws ScriptException, IOException, ParserConfigurationException, SAXException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError @@ -411,6 +414,9 @@ private Builder(final File file, final Writer errorWriter) /** * Constructs a wrapper around a possibly temporary project for source code * generated by a Reader. + *

+ * This method is intended to be called only once. + *

* * @param reader provides the Java source if {@code file} is {@code null} * @param errorWriter where to write the error output. @@ -422,7 +428,7 @@ private Builder(final File file, final Writer errorWriter) * @throws TransformerException * @throws TransformerFactoryConfigurationError */ - private Builder(final Reader reader, final Writer errorWriter) + private void initialize(final Reader reader, final Writer errorWriter) throws ScriptException, IOException, ParserConfigurationException, SAXException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError From 52b6d50a37869af2b41f65d726e79d20918e2921 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 6 Feb 2015 05:46:05 -0600 Subject: [PATCH 46/83] JavaEngine: always to try clean up the mess Even if the error occurred during the builder initialization, rather than the build step, let's make sure to try calling cleanup() afterward. This change makes the code simpler, too, since we no longer need nested try/catch/finally blocks. This is an attempted bug-fix for Fiji BugZilla issue #906: http://fiji.sc/bugzilla/show_bug.cgi?id=906 This patch looks best with "git show -b" to ignore whitespace changes. --- .../plugins/scripting/java/JavaEngine.java | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) 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 7231e2c..8db0bef 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -205,31 +205,26 @@ public Class compile(String script) throws ScriptException { final MavenProject project = builder.project; String mainClass = builder.mainClass; - try { - project.build(true); + project.build(true); + if (mainClass == null) { + mainClass = project.getMainClass(); if (mainClass == null) { - mainClass = project.getMainClass(); - if (mainClass == null) { - throw new ScriptException("No main class found for file " + file); - } + throw new ScriptException("No main class found for file " + file); } + } - // make class loader - String[] paths = project.getClassPath(false).split(File.pathSeparator); - URL[] urls = new URL[paths.length]; - for (int i = 0; i < urls.length; i++) - urls[i] = - new URL("file:" + paths[i] + (paths[i].endsWith(".jar") ? "" : "/")); + // make class loader + String[] paths = project.getClassPath(false).split(File.pathSeparator); + URL[] urls = new URL[paths.length]; + for (int i = 0; i < urls.length; i++) + urls[i] = + new URL("file:" + paths[i] + (paths[i].endsWith(".jar") ? "" : "/")); - final URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread() - .getContextClassLoader()); + final URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread() + .getContextClassLoader()); - // load main class - return classLoader.loadClass(mainClass); - } - finally { - builder.cleanup(); - } + // load main class + return classLoader.loadClass(mainClass); } catch (Exception e) { if (writer != null) { @@ -242,6 +237,9 @@ public Class compile(String script) throws ScriptException { throw new ScriptException(e); } } + finally { + builder.cleanup(); + } return null; } @@ -295,16 +293,14 @@ public void compile(final File file, final Writer errorWriter) { final Builder builder = new Builder(); try { builder.initialize(file, writer); - try { - builder.project.build(); - } - finally { - builder.cleanup(); - } + builder.project.build(); } catch (Throwable t) { printOrThrow(t, errorWriter); } + finally { + builder.cleanup(); + } } /** @@ -321,20 +317,18 @@ public void makeJar(final File file, final boolean includeSources, final Builder builder = new Builder(); try { builder.initialize(file, errorWriter); - try { - builder.project.build(true, true, includeSources); - final File target = builder.project.getTarget(); - if (output != null && !target.equals(output)) { - BuildEnvironment.copyFile(target, output); - } - } - finally { - builder.cleanup(); + builder.project.build(true, true, includeSources); + final File target = builder.project.getTarget(); + if (output != null && !target.equals(output)) { + BuildEnvironment.copyFile(target, output); } } catch (Throwable t) { printOrThrow(t, errorWriter); } + finally { + builder.cleanup(); + } } /** From e37ab7f362b9b90f4ccd634c971871b314e1f100 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Wed, 2 Dec 2015 11:37:32 -0600 Subject: [PATCH 47/83] POM: bump to pom-scijava parent 10.0.1 In particular, this updates the minimaven dependency to 2.2.0. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6b6a69b..a7780c1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ org.scijava pom-scijava - 9.0.0 + 10.0.1 scripting-java - 0.3.5-SNAPSHOT + 0.4.0-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From efa69682896ef3debb9bdbc0f3f7d4d9653a4ab6 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 4 Apr 2016 10:52:11 -0500 Subject: [PATCH 48/83] POM: switch to Java 1.8 We are not going to support Java 6 anymore; see: http://imagej.net/2015-12-22_-_The_road_to_Java_8 --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index a7780c1..905d907 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,10 @@ http://jenkins.imagej.net/job/scripting-Java/ + + 1.8 + + From cf5607ba5392a56d7fe91671e2b6bdf72f087cfd Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Wed, 2 Dec 2015 11:37:52 -0600 Subject: [PATCH 49/83] Remove com.sun.tools profile --- pom.xml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/pom.xml b/pom.xml index 905d907..b4ba64b 100644 --- a/pom.xml +++ b/pom.xml @@ -141,28 +141,4 @@ Institute of Molecular Cell Biology and Genetics.
- - - - tools-jar - - - - ${java.home}/../lib/tools.jar - - - - - com.sun - tools - 1.4.2 - system - ${java.home}/../lib/tools.jar - - - - From 2f899f634e7e9a7eaab29e286b248f91f682d1f6 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Wed, 2 Dec 2015 12:01:17 -0600 Subject: [PATCH 50/83] JavaEngineTest: remove com.sun.tools use --- .../java/org/scijava/plugins/scripting/java/JavaEngineTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ec9ce95..5317c92 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java @@ -70,7 +70,7 @@ public void assumeJavaC() { boolean found = false; try { final ClassLoader classLoader = getClass().getClassLoader(); - found = classLoader.loadClass("com.sun.tools.javac.Main") != null; + found = classLoader.loadClass("javax.tools.ToolProvider") != null; } catch (final Throwable t) { // NB: No action needed. From 6855b6127885628393432e025614b4c755dac4fe Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 6 Apr 2016 16:06:46 -0500 Subject: [PATCH 51/83] Happy New Year 2016 --- LICENSE.txt | 2 +- .../org/scijava/plugins/scripting/java/AbstractJavaRunner.java | 2 +- .../org/scijava/plugins/scripting/java/CommandJavaRunner.java | 2 +- .../org/scijava/plugins/scripting/java/DefaultJavaService.java | 2 +- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 2 +- .../org/scijava/plugins/scripting/java/JavaEngineBindings.java | 2 +- .../java/org/scijava/plugins/scripting/java/JavaRunner.java | 2 +- .../org/scijava/plugins/scripting/java/JavaScriptLanguage.java | 2 +- .../java/org/scijava/plugins/scripting/java/JavaService.java | 2 +- .../java/org/scijava/plugins/scripting/java/MainJavaRunner.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 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index cce13af..886feee 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2008 - 2015, Board of Regents of the University of +Copyright (c) 2008 - 2016, 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/AbstractJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java index 9c4165b..8512648 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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/CommandJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java index 37daa90..ab6bf54 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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/DefaultJavaService.java b/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java index 81b27f7..e4b394f 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java +++ b/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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/JavaEngine.java b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java index 8db0bef..dda10c2 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 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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 173165c..bfdf665 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 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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/JavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java index 005696c..5bcb385 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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 0aa43dd..fe0fbc8 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 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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/JavaService.java b/src/main/java/org/scijava/plugins/scripting/java/JavaService.java index 232d1b8..2659ef2 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaService.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaService.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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/MainJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java index b4dea91..53d2187 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java +++ b/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java @@ -2,7 +2,7 @@ * #%L * JSR-223-compliant Java scripting language plugin. * %% - * Copyright (C) 2008 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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 5317c92..59b0521 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 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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 5729664..ab72c1a 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 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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 6d168ce..bda38a6 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 - 2015 Board of Regents of the University of + * Copyright (C) 2008 - 2016 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 14c035cc78a3a10ae253523ad43093e7c4ed7e19 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 5 Apr 2016 19:37:53 -0500 Subject: [PATCH 52/83] Remove the JavaService in favor of the RunService The core logic of JavaService was generalized and moved to SciJava Common in the form of the org.scijava.run package and friends. See: https://github.com/scijava/scijava-common/issues/226 --- pom.xml | 3 +- .../scripting/java/AbstractJavaRunner.java | 53 ----------- .../scripting/java/CommandJavaRunner.java | 74 --------------- .../scripting/java/DefaultJavaService.java | 83 ---------------- .../plugins/scripting/java/JavaEngine.java | 7 +- .../plugins/scripting/java/JavaRunner.java | 58 ----------- .../plugins/scripting/java/JavaService.java | 51 ---------- .../scripting/java/MainJavaRunner.java | 95 ------------------- .../scripting/java/JavaEngineTest.java | 3 +- 9 files changed, 7 insertions(+), 420 deletions(-) delete mode 100644 src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java delete mode 100644 src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java delete mode 100644 src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java delete mode 100644 src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java delete mode 100644 src/main/java/org/scijava/plugins/scripting/java/JavaService.java delete mode 100644 src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java diff --git a/pom.xml b/pom.xml index b4ba64b..b9f0d6d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 10.0.1 + 10.1.0 @@ -140,5 +140,4 @@ Institute of Molecular Cell Biology and Genetics. - diff --git a/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java deleted file mode 100644 index 8512648..0000000 --- a/src/main/java/org/scijava/plugins/scripting/java/AbstractJavaRunner.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * #%L - * JSR-223-compliant Java scripting language plugin. - * %% - * Copyright (C) 2008 - 2016 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. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package org.scijava.plugins.scripting.java; - -import org.scijava.plugin.AbstractHandlerPlugin; - -/** - * Abstract superclass of {@link JavaRunner} implementations. - * - * @author Curtis Rueden - */ -public abstract class AbstractJavaRunner extends - AbstractHandlerPlugin> implements JavaRunner -{ - - // -- Typed methods -- - - @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Class> getType() { - return (Class) Class.class; - } - -} diff --git a/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java deleted file mode 100644 index ab6bf54..0000000 --- a/src/main/java/org/scijava/plugins/scripting/java/CommandJavaRunner.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * #%L - * JSR-223-compliant Java scripting language plugin. - * %% - * Copyright (C) 2008 - 2016 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. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package org.scijava.plugins.scripting.java; - -import org.scijava.command.Command; -import org.scijava.command.CommandInfo; -import org.scijava.command.CommandService; -import org.scijava.plugin.Parameter; -import org.scijava.plugin.Plugin; -import org.scijava.plugin.PluginService; - -/** - * Runs the given {@link Command} class. - * - * @author Curtis Rueden - */ -@Plugin(type = JavaRunner.class) -public class CommandJavaRunner extends AbstractJavaRunner { - - @Parameter - private PluginService pluginService; - - @Parameter - private CommandService commandService; - - // -- JavaRunner methods -- - - @Override - public void run(final Class c) { - @SuppressWarnings("unchecked") - final Class commandClass = (Class) c; - final Plugin annotation = c.getAnnotation(Plugin.class); - final CommandInfo info = new CommandInfo(commandClass, annotation); - pluginService.addPlugin(info); - commandService.run(info, true); - } - - // -- Typed methods -- - - @Override - public boolean supports(final Class c) { - return Command.class.isAssignableFrom(c); - } - -} diff --git a/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java b/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java deleted file mode 100644 index e4b394f..0000000 --- a/src/main/java/org/scijava/plugins/scripting/java/DefaultJavaService.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * #%L - * JSR-223-compliant Java scripting language plugin. - * %% - * Copyright (C) 2008 - 2016 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. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package org.scijava.plugins.scripting.java; - -import javax.script.ScriptException; - -import org.scijava.log.LogService; -import org.scijava.plugin.AbstractHandlerService; -import org.scijava.plugin.Parameter; -import org.scijava.plugin.Plugin; -import org.scijava.service.Service; - -/** - * Default service for managing available {@link JavaRunner} plugins. - * - * @author Curtis Rueden - */ -@Plugin(type = Service.class) -public class DefaultJavaService extends - AbstractHandlerService, JavaRunner> implements JavaService -{ - - @Parameter - private LogService log; - - // -- JavaService methods -- - - @Override - public void run(final Class c) throws ScriptException { - for (final JavaRunner runner : getInstances()) { - if (runner.supports(c)) { - runner.run(c); - return; - } - } - log.error("Unknown class type: " + c.getName()); - } - - // -- PTService methods -- - - @Override - public Class getPluginType() { - return JavaRunner.class; - } - - // -- Typed methods -- - - @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Class> getType() { - return (Class) Class.class; - } - -} 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 dda10c2..76b5b7f 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -73,6 +73,7 @@ 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; @@ -114,14 +115,14 @@ public class JavaEngine extends AbstractScriptEngine { private CommandService commandService; @Parameter - private JavaService javaService; + private RunService runService; /** * Compiles and runs the specified {@code .java} class. If a filename is set * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key, * this method compiles that file and runs the resulting main class instead. *

- * The currently active {@link JavaService} is responsible for running the + * The currently active {@link RunService} is responsible for running the * class. *

* @@ -133,7 +134,7 @@ public Object eval(String script) throws ScriptException { final Writer writer = getContext().getErrorWriter(); try { final Class clazz = compile(script); - javaService.run(clazz); + runService.run(clazz); } catch (Exception e) { if (writer != null) { diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java deleted file mode 100644 index 5bcb385..0000000 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaRunner.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * #%L - * JSR-223-compliant Java scripting language plugin. - * %% - * Copyright (C) 2008 - 2016 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. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package org.scijava.plugins.scripting.java; - -import javax.script.ScriptException; - -import org.scijava.plugin.HandlerPlugin; -import org.scijava.plugin.Plugin; - -/** - * A plugin which extends the Java script language's execution handling. A - * {@code JavaRunner} knows how to execute certain classes, beyond just Java's - * usual {@code main} method. - *

- * Java runner plugins discoverable at runtime must implement this interface and - * be annotated with @{@link Plugin} with attribute {@link Plugin#type()} = - * {@link JavaRunner}.class. While it possible to create an console argument - * plugin merely by implementing this interface, it is encouraged to instead - * extend {@link AbstractJavaRunner}, for convenience. - *

- * - * @author Curtis Rueden - */ -public interface JavaRunner extends HandlerPlugin> { - - /** Executes the given class. */ - void run(Class c) throws ScriptException; - -} diff --git a/src/main/java/org/scijava/plugins/scripting/java/JavaService.java b/src/main/java/org/scijava/plugins/scripting/java/JavaService.java deleted file mode 100644 index 2659ef2..0000000 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaService.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * #%L - * JSR-223-compliant Java scripting language plugin. - * %% - * Copyright (C) 2008 - 2016 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. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package org.scijava.plugins.scripting.java; - -import javax.script.ScriptException; - -import org.scijava.plugin.HandlerService; -import org.scijava.service.SciJavaService; - -/** - * Interface for service that manages available {@link JavaRunner} plugins. - * - * @author Curtis Rueden - */ -public interface JavaService extends - HandlerService, JavaRunner>, SciJavaService -{ - - /** Executes the given class using the most appropriate handler. */ - void run(Class c) throws ScriptException; - -} diff --git a/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java b/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java deleted file mode 100644 index 53d2187..0000000 --- a/src/main/java/org/scijava/plugins/scripting/java/MainJavaRunner.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * #%L - * JSR-223-compliant Java scripting language plugin. - * %% - * Copyright (C) 2008 - 2016 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. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package org.scijava.plugins.scripting.java; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import javax.script.ScriptException; - -import org.scijava.Priority; -import org.scijava.log.LogService; -import org.scijava.plugin.Parameter; -import org.scijava.plugin.Plugin; - -/** - * Executes the given class's {@code main} method. - * - * @author Curtis Rueden - */ -@Plugin(type = JavaRunner.class, priority = Priority.LOW_PRIORITY) -public class MainJavaRunner extends AbstractJavaRunner { - - @Parameter(required = false) - private LogService log; - - // -- JavaRunner methods -- - - @Override - public void run(final Class c) throws ScriptException { - try { - getMain(c).invoke(null, new Object[] { new String[0] }); - } - catch (final IllegalArgumentException exc) { - throw new ScriptException(exc); - } - catch (final IllegalAccessException exc) { - throw new ScriptException(exc); - } - catch (final InvocationTargetException exc) { - throw new ScriptException(exc); - } - } - - // -- Typed methods -- - - @Override - public boolean supports(final Class c) { - return getMain(c) != null; - } - - // -- Helper methods -- - - private Method getMain(final Class c) { - try { - return c.getMethod("main", String[].class); - } - catch (final SecurityException exc) { - if (log != null) log.debug(exc); - return null; - } - catch (final NoSuchMethodException exc) { - if (log != null) log.debug(exc); - return null; - } - } - -} 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 59b0521..3187231 100644 --- a/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java +++ b/src/test/java/org/scijava/plugins/scripting/java/JavaEngineTest.java @@ -48,6 +48,7 @@ import org.junit.Test; import org.scijava.Context; import org.scijava.object.ObjectService; +import org.scijava.run.RunService; import org.scijava.script.AbstractScriptLanguageTest; import org.scijava.script.ScriptLanguage; import org.scijava.script.ScriptService; @@ -273,7 +274,7 @@ private void writeFiles(final File dir, final String... args) private ScriptEngine miniMaven() { final Context context = - new Context(ScriptService.class, ObjectService.class, JavaService.class); + new Context(ScriptService.class, ObjectService.class, RunService.class); final ObjectService objectService = context.getService(ObjectService.class); final ScriptLanguage java = objectService.getObjects(JavaScriptLanguage.class).get(0); From 0795edb1f033a5ebcfa41347354e46b384da66e5 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 6 Apr 2016 16:30:10 -0500 Subject: [PATCH 53/83] Bump to next development cycle Signed-off-by: Jenkins --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b9f0d6d..669955e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.4.0-SNAPSHOT + 0.4.1-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From afd3de8ae6a2061388360a0306e367f69ec2e7f8 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 4 May 2016 13:48:46 -0500 Subject: [PATCH 54/83] Use imagej.net URL for all developers And remove the superfluous (and prone to obsolescence) other info. --- pom.xml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 669955e..d8ec2d7 100644 --- a/pom.xml +++ b/pom.xml @@ -27,10 +27,7 @@ ctrueden Curtis Rueden - ctrueden@wisc.edu - http://loci.wisc.edu/people/curtis-rueden - UW-Madison LOCI - http://loci.wisc.edu/ + http://imagej.net/User:Rueden lead developer @@ -39,15 +36,11 @@ support maintainer - -6 hinerm Mark Hiner - hiner@wisc.edu - http://loci.wisc.edu/people/mark-hiner - UW-Madison LOCI - http://loci.wisc.edu/ + http://imagej.net/User:Hinerm lead developer @@ -56,7 +49,6 @@ support maintainer - -6 From 1eeec9553811fd6fa701e02e2620501ab93b5ec4 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Jun 2016 15:48:35 -0500 Subject: [PATCH 55/83] POM: add Gabriel Einsdorf to contributors list --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index d8ec2d7..533e764 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,11 @@ founder dscho + + Gabriel Einsdorf + http://imagej.net/User:Gab1one + gab1one + Jonathan Hale Squareys From b462aee72e4177ba20350df60addd072e7c9ba2c Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Jun 2016 15:48:44 -0500 Subject: [PATCH 56/83] POM: goodbye Mark! --- pom.xml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 533e764..d0f1fad 100644 --- a/pom.xml +++ b/pom.xml @@ -37,19 +37,6 @@ maintainer - - hinerm - Mark Hiner - http://imagej.net/User:Hinerm - - lead - developer - debugger - reviewer - support - maintainer - - @@ -67,6 +54,11 @@ Jonathan Hale Squareys + + Mark Hiner + http://imagej.net/User:Hinerm + hinerm + From 1a10d069f3ede5ffe8efc4d1ab221f61eb6b3215 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Sun, 1 Jan 2017 21:04:59 -0600 Subject: [PATCH 57/83] Update parent to org.scijava:pom-scijava:12.0.0 See: http://forum.imagej.net/t/split-boms-from-parent-configuration/2563 --- pom.xml | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index d0f1fad..29fe637 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 10.1.0 + 12.0.0 @@ -16,6 +16,10 @@ JSR-223-compliant Java scripting language plugin. http://scijava.org/ 2008 + + SciJava + http://scijava.org/ + Simplified BSD License @@ -61,6 +65,16 @@ + + + SciJava + https://groups.google.com/group/scijava + https://groups.google.com/group/scijava + scijava.com + https://groups.google.com/group/scijava + + + scm:git:git://github.com/scijava/scripting-java scm:git:git@github.com:scijava/scripting-java @@ -77,7 +91,11 @@ - 1.8 + org.scijava.plugins.scripting.java + bsd_2 + 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. @@ -104,29 +122,4 @@ test - - - - - maven-jar-plugin - - - - org.scijava.plugins.scripting.java - - - - - - org.codehaus.mojo - license-maven-plugin - - bsd_2 - 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 b32e2f9b765b866b3d79bbe08a34a08576d65ec3 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Sun, 1 Jan 2017 21:05:01 -0600 Subject: [PATCH 58/83] Happy New Year 2017 --- 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 886feee..28fb714 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2008 - 2016, Board of Regents of the University of +Copyright (c) 2008 - 2017, 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 76b5b7f..eeaa8df 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 - 2016 Board of Regents of the University of + * Copyright (C) 2008 - 2017 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 bfdf665..0cf76eb 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 - 2016 Board of Regents of the University of + * Copyright (C) 2008 - 2017 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 fe0fbc8..00be7fe 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 - 2016 Board of Regents of the University of + * Copyright (C) 2008 - 2017 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 3187231..d2128ab 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 - 2016 Board of Regents of the University of + * Copyright (C) 2008 - 2017 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 ab72c1a..60794b7 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 - 2016 Board of Regents of the University of + * Copyright (C) 2008 - 2017 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 bda38a6..5e788c4 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 - 2016 Board of Regents of the University of + * Copyright (C) 2008 - 2017 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 ced55268db2a60ad1d9f06b47a68553756ea50ee Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 28 Feb 2017 08:17:56 -0600 Subject: [PATCH 59/83] Switch from Jenkins to Travis CI --- .travis.yml | 12 ++++++++++++ .travis/build.sh | 7 +++++++ .travis/notify.sh | 2 ++ .travis/settings.xml | 14 ++++++++++++++ README.md | 2 +- pom.xml | 4 ++-- 6 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .travis.yml create mode 100755 .travis/build.sh create mode 100755 .travis/notify.sh create mode 100644 .travis/settings.xml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..90caa27 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: java +jdk: oraclejdk8 +branches: + only: master +install: true +script: ".travis/build.sh" +after_success: ".travis/notify.sh Travis-Success" +after_failure: ".travis/notify.sh Travis-Failure" +env: + global: + - secure: mx1gt8i3B+jBlKcmOp4kDdWQID9ypKY2h7p0nwLcMbUh8BliMyyHqhT8i1O9UJ7KOWTDi56njVe/OpL/Yq4n8iI5Qc6U8JsUMko7IVEKl6s2DUBjZ0RlVuKcVBJCUZV/nd++brRt6KAOq+rIKo2JBGcih2t4xQ8pSk2Z567uuN8= + - secure: OvoesZlbqzxVHsPKkgjgbl9oaW7LLcdSkPjkjoCPi5NYn1Cm4dilAOOPV4qmwRInpsJY5YKecx8s++y36G09HW5M44MmIKFkGbyi7ug/lEYY2bfUWWow/Avgl8/EL4GN0nu4vLo0jwlFilYF/tFZxisTbRmMiVCIi2J7JY5v/Lw= diff --git a/.travis/build.sh b/.travis/build.sh new file mode 100755 index 0000000..4c2f8d2 --- /dev/null +++ b/.travis/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh +dir="$(dirname "$0")" +test "$TRAVIS_SECURE_ENV_VARS" = true \ + -a "$TRAVIS_PULL_REQUEST" = false \ + -a "$TRAVIS_BRANCH" = master && + mvn -Pdeploy-to-imagej deploy --settings "$dir/settings.xml" || + mvn install diff --git a/.travis/notify.sh b/.travis/notify.sh new file mode 100755 index 0000000..b3b239e --- /dev/null +++ b/.travis/notify.sh @@ -0,0 +1,2 @@ +#!/bin/sh +curl -fs "https://jenkins.imagej.net/job/$1/buildWithParameters?token=$TOKEN_NAME&repo=$TRAVIS_REPO_SLUG&commit=$TRAVIS_COMMIT&pr=$TRAVIS_PULL_REQUEST" diff --git a/.travis/settings.xml b/.travis/settings.xml new file mode 100644 index 0000000..71a5630 --- /dev/null +++ b/.travis/settings.xml @@ -0,0 +1,14 @@ + + + + imagej.releases + travis + ${env.MAVEN_PASS} + + + imagej.snapshots + travis + ${env.MAVEN_PASS} + + + diff --git a/README.md b/README.md index 1f95798..e66ba40 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![](http://jenkins.imagej.net/job/scripting-Java/lastBuild/badge/icon)](http://jenkins.imagej.net/job/scripting-Java/) +[![](https://travis-ci.org/scijava/scripting-java.svg?branch=master)](https://travis-ci.org/scijava/scripting-java) # Java Scripting diff --git a/pom.xml b/pom.xml index 29fe637..4dec96a 100644 --- a/pom.xml +++ b/pom.xml @@ -86,8 +86,8 @@ https://github.com/scijava/scripting-java/issues - Jenkins - http://jenkins.imagej.net/job/scripting-Java/ + Travis CI + https://travis-ci.org/scijava/scripting-java From bd3ae4511721858789b2e1681945ca2ee962e4b4 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Mar 2017 11:34:11 -0600 Subject: [PATCH 60/83] POM: fix typo in mailing list address --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4dec96a..0410ab0 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ SciJava https://groups.google.com/group/scijava https://groups.google.com/group/scijava - scijava.com + scijava@googlegroups.com https://groups.google.com/group/scijava From 49bd7757aadc491b088254bebafd37ee24d380b6 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Mar 2017 11:35:23 -0600 Subject: [PATCH 61/83] Update parent to org.scijava:pom-scijava:14.0.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0410ab0..a307b6e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 12.0.0 + 14.0.0 @@ -14,7 +14,7 @@ SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. - http://scijava.org/ + https://github.com/scijava/scripting-java 2008 SciJava From 6ccd0519f5baef76fa54f4fe62d627bcea7a15c2 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 26 Apr 2017 15:39:43 -0500 Subject: [PATCH 62/83] Fix the Travis configuration Without this, failed builds of master trigger another "mvn install". See: https://gist.github.com/ctrueden/ae0f024a0cdf2cb53c915d75b0759553 --- .travis/build.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis/build.sh b/.travis/build.sh index 4c2f8d2..8cddb5f 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -1,7 +1,10 @@ #!/bin/sh dir="$(dirname "$0")" -test "$TRAVIS_SECURE_ENV_VARS" = true \ +if [ "$TRAVIS_SECURE_ENV_VARS" = true \ -a "$TRAVIS_PULL_REQUEST" = false \ - -a "$TRAVIS_BRANCH" = master && - mvn -Pdeploy-to-imagej deploy --settings "$dir/settings.xml" || + -a "$TRAVIS_BRANCH" = master ] +then + mvn -Pdeploy-to-imagej deploy --settings "$dir/settings.xml" +else mvn install +fi From af9b612017df93d4d347c6b9f29a6c3b2bafc230 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 27 Apr 2017 14:06:20 -0500 Subject: [PATCH 63/83] Fix javadoc errors --- .../java/org/scijava/plugins/scripting/java/JavaEngine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 eeaa8df..2225447 100644 --- a/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java +++ b/src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java @@ -155,7 +155,7 @@ public Object eval(String script) throws ScriptException { * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key, * this method compiles that file and runs the resulting main class instead. *

- * The currently active {@link JavaService} is responsible for running the + * The currently active {@link RunService} is responsible for running the * class. *

* From 72d5cf0cbc1265c266eaf3ffd91b9d8b0310b95f Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Sun, 30 Apr 2017 14:12:30 -0500 Subject: [PATCH 64/83] 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 a307b6e..109b48b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ scripting-java - 0.4.1-SNAPSHOT + 0.4.2-SNAPSHOT SciJava Scripting: Java JSR-223-compliant Java scripting language plugin. From b7ac7a2b60a1212528020f57b28d1fa5b85389c7 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 5 Oct 2017 16:40:12 -0500 Subject: [PATCH 65/83] Update Travis configuration This will hopefully reduce the need for future en masse updates. --- .travis.yml | 6 +++--- .travis/build.sh | 11 ++--------- .travis/notify.sh | 2 -- 3 files changed, 5 insertions(+), 14 deletions(-) delete mode 100755 .travis/notify.sh diff --git a/.travis.yml b/.travis.yml index 90caa27..e75d18c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: java jdk: oraclejdk8 branches: - only: master + only: + - master + - "/.*-[0-9]+\\..*/" install: true script: ".travis/build.sh" -after_success: ".travis/notify.sh Travis-Success" -after_failure: ".travis/notify.sh Travis-Failure" env: global: - secure: mx1gt8i3B+jBlKcmOp4kDdWQID9ypKY2h7p0nwLcMbUh8BliMyyHqhT8i1O9UJ7KOWTDi56njVe/OpL/Yq4n8iI5Qc6U8JsUMko7IVEKl6s2DUBjZ0RlVuKcVBJCUZV/nd++brRt6KAOq+rIKo2JBGcih2t4xQ8pSk2Z567uuN8= diff --git a/.travis/build.sh b/.travis/build.sh index 8cddb5f..e939b6c 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -1,10 +1,3 @@ #!/bin/sh -dir="$(dirname "$0")" -if [ "$TRAVIS_SECURE_ENV_VARS" = true \ - -a "$TRAVIS_PULL_REQUEST" = false \ - -a "$TRAVIS_BRANCH" = master ] -then - mvn -Pdeploy-to-imagej deploy --settings "$dir/settings.xml" -else - mvn install -fi +curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh +sh travis-build.sh diff --git a/.travis/notify.sh b/.travis/notify.sh deleted file mode 100755 index b3b239e..0000000 --- a/.travis/notify.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -curl -fs "https://jenkins.imagej.net/job/$1/buildWithParameters?token=$TOKEN_NAME&repo=$TRAVIS_REPO_SLUG&commit=$TRAVIS_COMMIT&pr=$TRAVIS_PULL_REQUEST" From e52618e94eb2b41c3146d4232902448dda0ee806 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 5 Oct 2017 16:40:12 -0500 Subject: [PATCH 66/83] POM: update pom-scijava parent to 17.1.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 109b48b..75fbe41 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 14.0.0 + 17.1.1 From f634f1bee81c75f5594f94555c0a5bde1161abce Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 5 Oct 2017 16:40:12 -0500 Subject: [PATCH 67/83] POM: deploy releases to the ImageJ repository --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index 75fbe41..f08af3c 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,9 @@ 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. + + + deploy-to-imagej
From 3a428e249cb3613efe10c4fb06eb0f3559cd82c9 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 4 Apr 2019 13:35:18 -0500 Subject: [PATCH 68/83] POM: use HTTPS where feasible --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index f08af3c..d3fbcd3 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 2008 SciJava - http://scijava.org/ + https://scijava.org/ @@ -31,7 +31,7 @@ ctrueden Curtis Rueden - http://imagej.net/User:Rueden + https://imagej.net/User:Rueden lead developer @@ -45,13 +45,13 @@ Johannes Schindelin - http://imagej.net/User:Schindelin + https://imagej.net/User:Schindelin founder dscho Gabriel Einsdorf - http://imagej.net/User:Gab1one + https://imagej.net/User:Gab1one gab1one @@ -60,7 +60,7 @@ Mark Hiner - http://imagej.net/User:Hinerm + https://imagej.net/User:Hinerm hinerm From e65334a10dc781121a54aa14ba3afbb5ec6cb430 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 30 Apr 2019 17:04:49 -0500 Subject: [PATCH 69/83] POM: maven.imagej.net -> maven.scijava.org --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d3fbcd3..5df6352 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 17.1.1 + 26.0.0 @@ -97,8 +97,8 @@ Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck Institute of Molecular Cell Biology and Genetics. - - deploy-to-imagej + + deploy-to-scijava From 9891c3bb418b61be296eeb0ed87156558d92d654 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 30 Apr 2019 17:04:49 -0500 Subject: [PATCH 70/83] Travis: build using openjdk8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e75d18c..8c3e3dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: java -jdk: oraclejdk8 +jdk: openjdk8 branches: only: - master From c5e29f18b3a49bb06dadeabbacbba61da49677b4 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 30 Apr 2019 17:04:49 -0500 Subject: [PATCH 71/83] Travis: remove obsolete Maven settings --- .travis/settings.xml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .travis/settings.xml diff --git a/.travis/settings.xml b/.travis/settings.xml deleted file mode 100644 index 71a5630..0000000 --- a/.travis/settings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - imagej.releases - travis - ${env.MAVEN_PASS} - - - imagej.snapshots - travis - ${env.MAVEN_PASS} - - - From fde688f07019fec3f219889346509f3162858ad5 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 1 Jul 2021 15:45:53 -0500 Subject: [PATCH 72/83] Switch from Travis CI to GitHub Actions --- {.travis => .github}/build.sh | 4 +-- .github/setup.sh | 3 +++ .github/workflows/build-main.yml | 42 ++++++++++++++++++++++++++++++++ .github/workflows/build-pr.yml | 35 ++++++++++++++++++++++++++ .travis.yml | 12 --------- README.md | 2 +- pom.xml | 6 ++--- 7 files changed, 86 insertions(+), 18 deletions(-) rename {.travis => .github}/build.sh (61%) create mode 100755 .github/setup.sh create mode 100644 .github/workflows/build-main.yml create mode 100644 .github/workflows/build-pr.yml delete mode 100644 .travis.yml diff --git a/.travis/build.sh b/.github/build.sh similarity index 61% rename from .travis/build.sh rename to .github/build.sh index e939b6c..7da4262 100755 --- a/.travis/build.sh +++ b/.github/build.sh @@ -1,3 +1,3 @@ #!/bin/sh -curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh -sh travis-build.sh +curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/ci-build.sh +sh ci-build.sh diff --git a/.github/setup.sh b/.github/setup.sh new file mode 100755 index 0000000..f359bbe --- /dev/null +++ b/.github/setup.sh @@ -0,0 +1,3 @@ +#!/bin/sh +curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/ci-setup-github-actions.sh +sh ci-setup-github-actions.sh diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml new file mode 100644 index 0000000..45b6b5e --- /dev/null +++ b/.github/workflows/build-main.yml @@ -0,0 +1,42 @@ +name: build + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache m2 folder + uses: actions/cache@v2 + env: + cache-name: cache-m2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-build-${{ env.cache-name }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'zulu' + - name: Set up CI environment + run: .github/setup.sh + - name: Execute the build + run: .github/build.sh + env: + GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASS: ${{ secrets.MAVEN_PASS }} + OSSRH_PASS: ${{ secrets.OSSRH_PASS }} + SIGNING_ASC: ${{ secrets.SIGNING_ASC }} diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 0000000..92a0192 --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,35 @@ +name: build PR + +on: + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache m2 folder + uses: actions/cache@v2 + env: + cache-name: cache-m2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-build-${{ env.cache-name }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'zulu' + - name: Set up CI environment + run: .github/setup.sh + - name: Execute the build + run: .github/build.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8c3e3dd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: java -jdk: openjdk8 -branches: - only: - - master - - "/.*-[0-9]+\\..*/" -install: true -script: ".travis/build.sh" -env: - global: - - secure: mx1gt8i3B+jBlKcmOp4kDdWQID9ypKY2h7p0nwLcMbUh8BliMyyHqhT8i1O9UJ7KOWTDi56njVe/OpL/Yq4n8iI5Qc6U8JsUMko7IVEKl6s2DUBjZ0RlVuKcVBJCUZV/nd++brRt6KAOq+rIKo2JBGcih2t4xQ8pSk2Z567uuN8= - - secure: OvoesZlbqzxVHsPKkgjgbl9oaW7LLcdSkPjkjoCPi5NYn1Cm4dilAOOPV4qmwRInpsJY5YKecx8s++y36G09HW5M44MmIKFkGbyi7ug/lEYY2bfUWWow/Avgl8/EL4GN0nu4vLo0jwlFilYF/tFZxisTbRmMiVCIi2J7JY5v/Lw= diff --git a/README.md b/README.md index e66ba40..09650b7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![](https://travis-ci.org/scijava/scripting-java.svg?branch=master)](https://travis-ci.org/scijava/scripting-java) +[![](https://github.com/scijava/scripting-java/actions/workflows/build-main.yml/badge.svg)](https://github.com/scijava/scripting-java/actions/workflows/build-main.yml) # Java Scripting diff --git a/pom.xml b/pom.xml index 5df6352..fa66a58 100644 --- a/pom.xml +++ b/pom.xml @@ -86,8 +86,8 @@ https://github.com/scijava/scripting-java/issues - Travis CI - https://travis-ci.org/scijava/scripting-java + GitHub Actions + https://github.com/scijava/scripting-java/actions @@ -98,7 +98,7 @@ Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck Institute of Molecular Cell Biology and Genetics. - deploy-to-scijava + sign,deploy-to-scijava From 9aa1f2b0419337475f62ae785f560876f6fc797f Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 2 Jul 2021 09:49:47 -0500 Subject: [PATCH 73/83] CI: build release tags --- .github/workflows/build-main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml index 45b6b5e..3fb5622 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build-main.yml @@ -4,6 +4,8 @@ on: push: branches: - master + tags: + - "*-[0-9]+.*" jobs: build: From 67489be2ffc7d7803bc0559ab573ccaac14fa739 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 8 Nov 2021 15:42:36 -0600 Subject: [PATCH 74/83] POM: Stop using git:// protocol with github.com The GitHub platform is discontinuing support for it. See: https://github.blog/2021-09-01-improving-git-protocol-security-github/#whats-changing --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fa66a58..44cf8af 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ - scm:git:git://github.com/scijava/scripting-java + scm:git:https://github.com/scijava/scripting-java scm:git:git@github.com:scijava/scripting-java HEAD https://github.com/scijava/scripting-java From e9b4179bcb8ca3b585dc6d5de99fe1e7b6e33462 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 14 Jun 2022 15:54:27 -0500 Subject: [PATCH 75/83] CI: cache ~/.m2/repository correctly --- .github/workflows/build-main.yml | 18 +++--------------- .github/workflows/build-pr.yml | 18 +++--------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml index 3fb5622..5ef5692 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build-main.yml @@ -13,24 +13,12 @@ jobs: steps: - uses: actions/checkout@v2 - - - name: Cache m2 folder - uses: actions/cache@v2 - env: - cache-name: cache-m2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-build-${{ env.cache-name }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Set up JDK 8 - uses: actions/setup-java@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 diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 92a0192..925b576 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -11,24 +11,12 @@ jobs: steps: - uses: actions/checkout@v2 - - - name: Cache m2 folder - uses: actions/cache@v2 - env: - cache-name: cache-m2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-build-${{ env.cache-name }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Set up JDK 8 - uses: actions/setup-java@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 From 714c51401ddfef8cc389efc7e0ea48bd7e2d810d Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 14 Aug 2025 15:31:52 +0200 Subject: [PATCH 76/83] 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 77/83] 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 78/83] 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 79/83] 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 80/83] 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 81/83] 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 82/83] 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 83/83] 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.