From 5f4fce77dff4375ff5de73016ba2a1f16e66d7b8 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Wed, 11 Feb 2015 07:03:12 -0600
Subject: [PATCH 01/94] Happy belated New Year 2015
---
LICENSE.txt | 2 +-
.../org/scijava/plugins/scripting/jython/JythonBindings.java | 2 +-
.../scijava/plugins/scripting/jython/JythonScriptEngine.java | 2 +-
.../scijava/plugins/scripting/jython/JythonScriptLanguage.java | 2 +-
.../java/org/scijava/plugins/scripting/jython/JythonTest.java | 2 +-
5 files changed, 5 insertions(+), 5 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/jython/JythonBindings.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
index 595f85a..3d6a493 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
@@ -2,7 +2,7 @@
* #%L
* JSR-223-compliant Jython 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/jython/JythonScriptEngine.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptEngine.java
index 8fdee6c..bd710b8 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptEngine.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptEngine.java
@@ -2,7 +2,7 @@
* #%L
* JSR-223-compliant Jython 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/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 0cf9e24..84e4664 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -2,7 +2,7 @@
* #%L
* JSR-223-compliant Jython 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/jython/JythonTest.java b/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
index b86143a..74ff47a 100644
--- a/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
+++ b/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
@@ -2,7 +2,7 @@
* #%L
* JSR-223-compliant Jython 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 a86cdc903aba336fefc5110b90ae706835e16ef6 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Wed, 25 Feb 2015 10:22:31 -0600
Subject: [PATCH 02/94] Move script-templates to script_templates
This fixes a conflict with javadoc generation not handling "-"
characters in directories.
---
.../{script-templates => script_templates}/Python/Greeting.py | 0
.../{script-templates => script_templates}/Python/Hello_World.py | 0
2 files changed, 0 insertions(+), 0 deletions(-)
rename src/main/resources/{script-templates => script_templates}/Python/Greeting.py (100%)
rename src/main/resources/{script-templates => script_templates}/Python/Hello_World.py (100%)
diff --git a/src/main/resources/script-templates/Python/Greeting.py b/src/main/resources/script_templates/Python/Greeting.py
similarity index 100%
rename from src/main/resources/script-templates/Python/Greeting.py
rename to src/main/resources/script_templates/Python/Greeting.py
diff --git a/src/main/resources/script-templates/Python/Hello_World.py b/src/main/resources/script_templates/Python/Hello_World.py
similarity index 100%
rename from src/main/resources/script-templates/Python/Hello_World.py
rename to src/main/resources/script_templates/Python/Hello_World.py
From 5d85363d748fca967605499909a1ace2660f5ab5 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Wed, 25 Feb 2015 13:55:14 -0600
Subject: [PATCH 03/94] Bump to pom-scijava 5.9.0
Updated to latest parent pom.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5727a41..0e7a96f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.scijava
pom-scijava
- 3.4
+ 5.9.0
From 8244a6579edfb711bfe49945f31f05939bc988e5 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Wed, 25 Feb 2015 14:19:44 -0600
Subject: [PATCH 04/94] 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 0e7a96f..b0b7983 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scripting-jython
- 0.1.5-SNAPSHOT
+ 0.2.1-SNAPSHOT
SciJava Scripting: Jython
JSR-223-compliant Jython scripting language plugin.
From c235cd5852fc97727f81fe4af74a45dbc57b6a22 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Thu, 26 Feb 2015 14:17:01 -0600
Subject: [PATCH 05/94] Bump to pom-scijava 5.10.0
Includes a fixed scijava-common dependency.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b0b7983..d5138b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.scijava
pom-scijava
- 5.9.0
+ 5.10.0
From cf48d85e19992e8b67298de8a7537d8a12fb22d1 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Tue, 28 Apr 2015 23:03:35 -0500
Subject: [PATCH 06/94] README.md: add Jenkins build status badge
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index 9951263..1510948 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+
+
# Jython Scripting
This library provides a
From c75e61810acf7a7e413fb6d30ea7b62df8c27a1f Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Tue, 28 Apr 2015 23:23:34 -0500
Subject: [PATCH 07/94] 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 d5138b7..26f5e11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,7 +77,7 @@
Jenkins
- https://jenkins.imagej.net/job/scripting-Jython/
+ http://jenkins.imagej.net/job/scripting-Jython/
From 2c78768034a60bea8e58246b7fc566633395fe25 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Wed, 29 Apr 2015 14:45:31 -0500
Subject: [PATCH 08/94] 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 1510948..d9a2943 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
+[](http://jenkins.imagej.net/job/scripting-Jython/)
# Jython Scripting
From ba3e66044cfe3b5caadd60fbd3c48fc486a829cf Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Thu, 30 Apr 2015 08:46:30 -0500
Subject: [PATCH 09/94] Greeting.py: add property examples
Add a label and description to the name parameter.
---
src/main/resources/script_templates/Python/Greeting.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/script_templates/Python/Greeting.py b/src/main/resources/script_templates/Python/Greeting.py
index a08cce7..eaeb754 100644
--- a/src/main/resources/script_templates/Python/Greeting.py
+++ b/src/main/resources/script_templates/Python/Greeting.py
@@ -1,4 +1,4 @@
-# @String name
+# @String name (label=Please enter your name,description=Name field)
# @OUTPUT String greeting
# A Jython script with parameters.
From 93cfd07eb8560ee899a49c66c9d07dfa5a470f77 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Thu, 30 Apr 2015 13:24:20 -0500
Subject: [PATCH 10/94] Make String properties more future-proof
This is the recommended way to list properties, which should be
compatible with any future CSV-parser.
---
src/main/resources/script_templates/Python/Greeting.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/script_templates/Python/Greeting.py b/src/main/resources/script_templates/Python/Greeting.py
index eaeb754..210aaa6 100644
--- a/src/main/resources/script_templates/Python/Greeting.py
+++ b/src/main/resources/script_templates/Python/Greeting.py
@@ -1,4 +1,4 @@
-# @String name (label=Please enter your name,description=Name field)
+# @String(label="Please enter your name",description="Name field") name
# @OUTPUT String greeting
# A Jython script with parameters.
From 877c717224421e3732f02e350968d60c963a6d43 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Fri, 1 May 2015 11:51:54 -0500
Subject: [PATCH 11/94] Bump to pom-scijava 7.1.0
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 26f5e11..bf4539c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.scijava
pom-scijava
- 5.10.0
+ 7.1.0
From 1603a0ebfef6dfc9151147b420cc5a90016e001d Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Fri, 1 May 2015 11:53:50 -0500
Subject: [PATCH 12/94] 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 bf4539c..c25223d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scripting-jython
- 0.2.1-SNAPSHOT
+ 0.2.2-SNAPSHOT
SciJava Scripting: Jython
JSR-223-compliant Jython scripting language plugin.
From 2a4d4dcc9f58c04ac31150eb8bb941f13deb9dd6 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Tue, 2 Jun 2015 11:04:59 +0200
Subject: [PATCH 13/94] Unwrap Python objects when they wrap Java ones
This avoids, e.g., PyObjectDerived objects coming
out of the script engine after script execution.
---
.../plugins/scripting/jython/JythonScriptLanguage.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 84e4664..627fe6c 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -34,6 +34,7 @@
import javax.script.ScriptEngine;
import org.python.core.PyNone;
+import org.python.core.PyObject;
import org.scijava.plugin.Plugin;
import org.scijava.script.AdaptedScriptLanguage;
import org.scijava.script.ScriptLanguage;
@@ -59,7 +60,14 @@ public ScriptEngine getScriptEngine() {
@Override
public Object decode(final Object object) {
- return object instanceof PyNone ? null : object;
+ if (object instanceof PyNone) return null;
+ if (object instanceof PyObject) {
+ // Unwrap Python objects when they wrap Java ones.
+ final PyObject pyObj = (PyObject) object;
+ final Class> javaType = pyObj.getType().getProxyType();
+ if (javaType != null) return pyObj.__tojava__(javaType);
+ }
+ return object;
}
}
From cf8d43b6528a75b7ce77edc96c3db470e291f24b Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Wed, 3 Jun 2015 08:59:11 +0200
Subject: [PATCH 14/94] Unwrap Python strings to Java strings
---
.../plugins/scripting/jython/JythonScriptLanguage.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 627fe6c..7cf4fda 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -35,6 +35,7 @@
import org.python.core.PyNone;
import org.python.core.PyObject;
+import org.python.core.PyString;
import org.scijava.plugin.Plugin;
import org.scijava.script.AdaptedScriptLanguage;
import org.scijava.script.ScriptLanguage;
@@ -67,6 +68,9 @@ public Object decode(final Object object) {
final Class> javaType = pyObj.getType().getProxyType();
if (javaType != null) return pyObj.__tojava__(javaType);
}
+ if (object instanceof PyString) {
+ return ((PyString) object).getString();
+ }
return object;
}
From eb7d73ea6f5ee35e6e6c3aa1b7c823caf2e4e71b Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Mon, 15 Jun 2015 11:27:29 -0500
Subject: [PATCH 15/94] Bump parent to pom-scijava 7.3.1
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c25223d..9f784dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.scijava
pom-scijava
- 7.1.0
+ 7.3.1
From 07f46a5c1273bdc539ff2ec22c8a8b6cb9f2fb5c Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Mon, 15 Jun 2015 12:33:21 -0500
Subject: [PATCH 16/94] 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 9f784dc..f8c8d42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scripting-jython
- 0.2.2-SNAPSHOT
+ 0.2.3-SNAPSHOT
SciJava Scripting: Jython
JSR-223-compliant Jython scripting language plugin.
From bdabd1a0078cedccd6a9875cec31d2d7ee2a800b Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 19 Nov 2015 08:51:16 -0600
Subject: [PATCH 17/94] 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 f8c8d42..557e5ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,6 @@
JSR-223-compliant Jython scripting language plugin.
http://scijava.org/
2008
-
Simplified BSD License
@@ -69,12 +68,10 @@
HEAD
https://github.com/scijava/scripting-jython
-
GitHub Issues
https://github.com/scijava/scripting-jython/issues
-
Jenkins
http://jenkins.imagej.net/job/scripting-Jython/
@@ -126,5 +123,4 @@ Institute of Molecular Cell Biology and Genetics.
-
From c2183e0ed8c9f7954fa6e53b3a76219057d0c762 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 19 Nov 2015 10:38:37 -0600
Subject: [PATCH 18/94] 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 557e5ca..c374ece 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-jython
scm:git:git@github.com:scijava/scripting-jython
From 8654262fb29ec94739eeadf60ea4ed0e98f86463 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 19 Nov 2015 11:00:00 -0600
Subject: [PATCH 19/94] POM: update developers and contributors
See: http://imagej.net/Team
---
pom.xml | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/pom.xml b/pom.xml
index c374ece..1481363 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,32 +25,48 @@
- 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
+
+
scm:git:git://github.com/scijava/scripting-jython
From 5f55c08cedf38d0ee3818056223de6c41e037cb3 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 19 Nov 2015 11:00:01 -0600
Subject: [PATCH 20/94] 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 1481363..acdcb64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.scijava
pom-scijava
- 7.3.1
+ 9.0.0
From 9e81c537444e971a70172a0ed6834f7045739caa Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 19 Nov 2015 12:55:18 -0600
Subject: [PATCH 21/94] 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 acdcb64..f43bee2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scripting-jython
- 0.2.3-SNAPSHOT
+ 0.2.4-SNAPSHOT
SciJava Scripting: Jython
JSR-223-compliant Jython scripting language plugin.
From 0444100e78129562791629501bbf9185877d4616 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Mon, 14 Dec 2015 14:42:53 -0600
Subject: [PATCH 22/94] JythonScriptLanguage: clean interpreter
Uses PhantomReferences to clean up after the interpreter
---
.../jython/JythonScriptLanguage.java | 94 ++++++++++++++++++-
1 file changed, 93 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 7cf4fda..236c4cc 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -31,14 +31,23 @@
package org.scijava.plugins.scripting.jython;
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
import javax.script.ScriptEngine;
import org.python.core.PyNone;
import org.python.core.PyObject;
import org.python.core.PyString;
+import org.python.util.PythonInterpreter;
+import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.script.AdaptedScriptLanguage;
import org.scijava.script.ScriptLanguage;
+import org.scijava.thread.ThreadService;
/**
* An adapter of the Jython interpreter to the SciJava scripting interface.
@@ -49,6 +58,14 @@
@Plugin(type = ScriptLanguage.class, name = "Python")
public class JythonScriptLanguage extends AdaptedScriptLanguage {
+ private final LinkedList phantomReferences =
+ new LinkedList();
+ private final ReferenceQueue queue =
+ new ReferenceQueue();
+
+ @Parameter
+ private ThreadService threadService;
+
public JythonScriptLanguage() {
super("jython");
}
@@ -56,7 +73,51 @@ public JythonScriptLanguage() {
@Override
public ScriptEngine getScriptEngine() {
// TODO: Consider adapting the wrapped ScriptEngineFactory's ScriptEngine.
- return new JythonScriptEngine();
+ final JythonScriptEngine engine = new JythonScriptEngine();
+
+ synchronized (phantomReferences) {
+ phantomReferences.add(new JythonEnginePhantomReference(engine, queue));
+
+ // If we added references to an empty queue, we need to start
+ // a new polling thread
+ if (phantomReferences.size() == 1) {
+ threadService.run(new Runnable() {
+
+ @Override
+ public void run() {
+ boolean done = false;
+
+ // poll the queue
+ while (!done) {
+ try {
+ Thread.sleep(100);
+
+ synchronized (phantomReferences) {
+ JythonEnginePhantomReference ref =
+ (JythonEnginePhantomReference) queue.poll();
+
+ // if we have a ref, clean it up
+ if (ref != null) {
+ ref.cleanup();
+ phantomReferences.remove(ref);
+ }
+
+ // Once we're done with our known phantom refs
+ // we can shut down this thread.
+ done = phantomReferences.size() == 0;
+ }
+
+ }
+ catch (final Exception ex) {
+ // log exception, continue
+ }
+ }
+ }
+ });
+
+ }
+ }
+ return engine;
}
@Override
@@ -74,4 +135,35 @@ public Object decode(final Object object) {
return object;
}
+ private static class JythonEnginePhantomReference extends
+ PhantomReference
+ {
+
+ public PythonInterpreter interpreter;
+
+ public JythonEnginePhantomReference(JythonScriptEngine engine,
+ ReferenceQueue queue)
+ {
+ super(engine, queue);
+ interpreter = engine.interpreter;
+ }
+
+ public void cleanup() {
+ final List scriptLocals = new ArrayList();
+ PythonInterpreter interp = interpreter;
+ if (interp == null) return;
+
+ final PyObject locals = interp.getLocals();
+ for (final PyObject item : locals.__iter__().asIterable()) {
+ final String localVar = item.toString();
+ if (!localVar.contains("__name__") && !localVar.contains("__doc__")) {
+
+ scriptLocals.add(item.toString());
+ }
+ }
+ for (final String string : scriptLocals) {
+ interp.set(string, null);
+ }
+ }
+ }
}
From 1f8826d6472abb84cdf2177c438353455a5b96cc Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Mon, 14 Dec 2015 14:43:21 -0600
Subject: [PATCH 23/94] JythonBindings: don't store engine or module
If the JythonScriptEngine or containing ScriptModule is set within the
PythonInterpreter, we will get a circular reference chain preventing
memory from the PythonInterpreter being reclaimed.
To avoid completely discarding these objects, we can keep them in a
shallow map to WeakReferences.
---
.../scripting/jython/JythonBindings.java | 30 +++++++++++++++----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
index 3d6a493..1ed800e 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
@@ -31,8 +31,10 @@
package org.scijava.plugins.scripting.jython;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -42,6 +44,7 @@
import org.python.core.PyStringMap;
import org.python.util.PythonInterpreter;
+import org.scijava.script.ScriptModule;
/**
* A {@link Bindings} wrapper around Jython's local variables.
@@ -52,6 +55,9 @@ public class JythonBindings implements Bindings {
protected final PythonInterpreter interpreter;
+ private Map> shallowMap =
+ new HashMap>();
+
public JythonBindings(final PythonInterpreter interpreter) {
this.interpreter = interpreter;
}
@@ -81,6 +87,10 @@ public boolean containsValue(Object value) {
@Override
public Object get(Object key) {
+ if (shallowMap.containsKey(key)) {
+ return shallowMap.get(key).get();
+ }
+
try {
return interpreter.get((String)key);
} catch (Error e) {
@@ -91,18 +101,28 @@ public Object get(Object key) {
@Override
public Object put(String key, Object value) {
final Object result = get(key);
- try {
- interpreter.set(key, value);
- } catch (Error e) {
- // ignore
+
+ if (value instanceof ScriptModule || value instanceof JythonScriptEngine){
+ shallowMap.put(key, new WeakReference
+
+ org.scijava.plugins.scripting.jython
+
+ 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.
+
+
ctrueden
@@ -88,29 +97,4 @@
test
-
-
-
-
- maven-jar-plugin
-
-
-
- org.scijava.plugins.scripting.jython
-
-
-
-
-
- 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 629214775ce973c67c3308a994829002aac1ee3b Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Fri, 2 Sep 2016 11:20:40 -0500
Subject: [PATCH 42/94] JythonTest: decode variables before checking them
I could have sworn that I tested this, but apparently not.
It turns out that return values are not decoded by default.
So for the time being, let's just do it in the test here.
(Ultimately, we probably want to decode them automatically.)
Values extracted directly from the bindings are also not decoded,
so let's decode those manually as well.
(That should probably also be automatic, though I'm not sure.)
---
.../org/scijava/plugins/scripting/jython/JythonTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java b/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
index ccad6c5..e141aa2 100644
--- a/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
+++ b/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
@@ -64,7 +64,7 @@ public void testBasic() throws InterruptedException, ExecutionException,
final ScriptService scriptService = context.getService(ScriptService.class);
final String script = "1 + 2";
final ScriptModule m = scriptService.run("add.py", script, true).get();
- final Object result = m.getReturnValue();
+ final Object result = m.getLanguage().decode(m.getReturnValue());
assertSame(Integer.class, result.getClass());
assertEquals(3, result);
}
@@ -78,8 +78,8 @@ public void testLocals() throws ScriptException {
final ScriptEngine engine = language.getScriptEngine();
assertEquals(JythonScriptEngine.class, engine.getClass());
engine.put("hello", 17);
- assertEquals("17", engine.eval("hello").toString());
- assertEquals("17", engine.get("hello").toString());
+ assertEquals(17, language.decode(engine.eval("hello")));
+ assertEquals(17, language.decode(engine.get("hello")));
final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.clear();
From 78a3c6c4c2f3637cb08b5e67857b993d8e7dfd97 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Fri, 2 Sep 2016 11:24:21 -0500
Subject: [PATCH 43/94] 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 a3f1987..65bc93e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scripting-jython
- 0.3.1-SNAPSHOT
+ 0.3.2-SNAPSHOT
SciJava Scripting: Jython
JSR-223-compliant Jython scripting language plugin.
From b3a983f2e78ab66cbada6059db7a675899aaa700 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Fri, 2 Sep 2016 13:02:12 -0500
Subject: [PATCH 44/94] Clean up style
---
.../jython/DefaultJythonService.java | 9 ++-
.../scripting/jython/JythonBindings.java | 59 ++++++++++---------
.../jython/JythonReferenceCleaner.java | 12 ++--
.../scripting/jython/JythonScriptEngine.java | 14 ++---
.../jython/JythonScriptLanguage.java | 12 ++--
.../scripting/jython/JythonService.java | 5 +-
.../plugins/scripting/jython/JythonTest.java | 8 +--
7 files changed, 64 insertions(+), 55 deletions(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/DefaultJythonService.java b/src/main/java/org/scijava/plugins/scripting/jython/DefaultJythonService.java
index b76fd04..514ff46 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/DefaultJythonService.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/DefaultJythonService.java
@@ -8,13 +8,13 @@
* %%
* 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
@@ -28,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
+
package org.scijava.plugins.scripting.jython;
import javax.script.ScriptEngine;
@@ -46,7 +47,9 @@
* @author Mark Hiner hinerm at gmail.com
*/
@Plugin(type = Service.class)
-public class DefaultJythonService extends AbstractService implements JythonService {
+public class DefaultJythonService extends AbstractService implements
+ JythonService
+{
// -- Fields --
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
index 00d1b76..e01312f 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonBindings.java
@@ -8,13 +8,13 @@
* %%
* 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
@@ -48,7 +48,7 @@
/**
* A {@link Bindings} wrapper around Jython's local variables.
- *
+ *
* @author Johannes Schindelin
*/
public class JythonBindings implements Bindings {
@@ -71,8 +71,7 @@ public class JythonBindings implements Bindings {
* PythonInterpreter, as the ScriptModule has a hard
* reference to its ScriptEngine.
*/
- private Map> shallowMap =
- new HashMap>();
+ private final Map> shallowMap = new HashMap<>();
public JythonBindings(final PythonInterpreter interpreter) {
this.interpreter = interpreter;
@@ -89,12 +88,12 @@ public boolean isEmpty() {
}
@Override
- public boolean containsKey(Object key) {
+ public boolean containsKey(final Object key) {
return get(key) != null;
}
@Override
- public boolean containsValue(Object value) {
+ public boolean containsValue(final Object value) {
for (final Object value2 : values()) {
if (value.equals(value2)) return true;
}
@@ -102,30 +101,31 @@ public boolean containsValue(Object value) {
}
@Override
- public Object get(Object key) {
+ public Object get(final Object key) {
if (shallowMap.containsKey(key)) {
return shallowMap.get(key).get();
}
try {
- return interpreter.get((String)key);
- } catch (Error e) {
+ return interpreter.get((String) key);
+ }
+ catch (final Error e) {
return null;
}
}
@Override
- public Object put(String key, Object value) {
+ public Object put(final String key, final Object value) {
final Object result = get(key);
- if (value instanceof ScriptModule || value instanceof JythonScriptEngine){
- shallowMap.put(key, new WeakReference
*/
@Test
- public void testLongType() throws InterruptedException, ExecutionException,
- IOException, ScriptException
- {
+ public void testLongType() throws InterruptedException, ExecutionException {
final String script = "" + //
"#@output String varType\n" + //
"a = 10L\n" + //
@@ -170,9 +163,7 @@ public void testEval() throws ScriptException {
}
@Test
- public void testGetPID() throws InterruptedException, ExecutionException,
- IOException, ScriptException
- {
+ public void testGetPID() throws InterruptedException, ExecutionException {
final String script = "" + //
"#@output Object pid\n" + //
"import os\n" + //
From b7d7a1b920347c60680cbaa3b7e8c4180e5d4a9f Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Wed, 29 Jun 2022 12:59:23 -0500
Subject: [PATCH 87/94] Rename this language from Python to Jython
This makes it more clear how it works, and paves the
way for another Python-based language soon to come.
---
.../plugins/scripting/jython/JythonScriptLanguage.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 1678ebe..babad4e 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -52,7 +52,7 @@
* @author Mark Hiner
* @see ScriptEngine
*/
-@Plugin(type = ScriptLanguage.class, name = "Python")
+@Plugin(type = ScriptLanguage.class, name = "Jython")
public class JythonScriptLanguage extends AdaptedScriptLanguage {
@Parameter
@@ -78,7 +78,7 @@ public Object decode(final Object object) {
return ((PyString) object).getString();
}
if (object instanceof PyObject) {
- // Unwrap Python objects when they wrap Java ones.
+ // Unwrap Jython objects when they wrap Java ones.
final PyObject pyObj = (PyObject) object;
final Class> javaType = pyObj.getType().getProxyType();
if (javaType != null) return pyObj.__tojava__(javaType);
From 07dc8b0a5fe840c0f70669be564cfc1f926c1f12 Mon Sep 17 00:00:00 2001
From: Karl Duderstadt
Date: Fri, 29 Jul 2022 13:24:43 +0200
Subject: [PATCH 88/94] Rename this language from Jython to Python (Jython)
---
.../scijava/plugins/scripting/jython/JythonScriptLanguage.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index babad4e..35ebfae 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -52,7 +52,7 @@
* @author Mark Hiner
* @see ScriptEngine
*/
-@Plugin(type = ScriptLanguage.class, name = "Jython")
+@Plugin(type = ScriptLanguage.class, name = "Python (Jython)")
public class JythonScriptLanguage extends AdaptedScriptLanguage {
@Parameter
From bb91ea50f91403ddfe2a0f1d30d9c953c0cdd0ae Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 9 Mar 2023 19:58:44 -0600
Subject: [PATCH 89/94] POM: update imagej.net URLs
---
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9c1ba9b..558a715 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
ctrueden
Curtis Rueden
- https://imagej.net/User:Rueden
+ https://imagej.net/people/ctrueden
lead
developer
@@ -45,13 +45,13 @@
Johannes Schindelin
- https://imagej.net/User:Schindelin
+ https://imagej.net/people/dscho
founder
dscho
Mark Hiner
- https://imagej.net/User:Hinerm
+ https://imagej.net/people/hinerm
hinerm
From c220853ecb56e694bfeacf71c4498e8f7ce6a2c5 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 9 Mar 2023 19:59:28 -0600
Subject: [PATCH 90/94] POM: update parent to pom-scijava 34.0.0
---
pom.xml | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 558a715..cf62fac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.scijava
pom-scijava
- 27.0.1
+ 34.0.0
@@ -92,8 +92,6 @@ Institute of Molecular Cell Biology and Genetics.
sign,deploy-to-scijava
-
- 2.7.2
@@ -107,7 +105,6 @@ Institute of Molecular Cell Biology and Genetics.
org.python
jython-slim
- ${jython-slim.version}
From 7454ec86d0291d87a5e9c1fefb5c26b4aa078998 Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 9 Mar 2023 19:59:42 -0600
Subject: [PATCH 91/94] Happy New Year 2023
---
LICENSE.txt | 4 +---
pom.xml | 4 +---
.../plugins/scripting/jython/JythonScriptLanguage.java | 4 +---
.../java/org/scijava/plugins/scripting/jython/JythonTest.java | 4 +---
4 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/LICENSE.txt b/LICENSE.txt
index 28fb714..9356d7c 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,6 +1,4 @@
-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.
+Copyright (c) 2008 - 2023, SciJava developers.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
diff --git a/pom.xml b/pom.xml
index cf62fac..71a4bc5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,9 +85,7 @@
org.scijava.plugins.scripting.jython
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.
+ SciJava developers.
**/script_templates/**
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 35ebfae..6ec4340 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -2,9 +2,7 @@
* #%L
* JSR-223-compliant Jython scripting language plugin.
* %%
- * 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.
+ * Copyright (C) 2008 - 2023 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java b/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
index fa9d1cd..60b5877 100644
--- a/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
+++ b/src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java
@@ -2,9 +2,7 @@
* #%L
* JSR-223-compliant Jython scripting language plugin.
* %%
- * 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.
+ * Copyright (C) 2008 - 2023 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
From 8cf8171e766ca3164f0c37062b29f7f139e8babe Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 9 Mar 2023 20:00:32 -0600
Subject: [PATCH 92/94] 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 71a4bc5..0237e11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,5 @@
-
+
4.0.0
From a12807d6be8137be90ad3d882ce49cf245f3677d Mon Sep 17 00:00:00 2001
From: Curtis Rueden
Date: Thu, 9 Mar 2023 20:02:35 -0600
Subject: [PATCH 93/94] 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 0237e11..8ef0f03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scripting-jython
- 1.0.1-SNAPSHOT
+ 1.0.2-SNAPSHOT
SciJava Scripting: Jython
JSR-223-compliant Jython scripting language plugin.
From 43d5afec4005c17f39f88a6ac437828bad2cc4e5 Mon Sep 17 00:00:00 2001
From: Mark Hiner
Date: Tue, 26 Aug 2025 09:37:59 -0500
Subject: [PATCH 94/94] Rename script language to simply "Jython"
To differentiate from true Python:
https://github.com/scijava/scripting-python/
---
.../scijava/plugins/scripting/jython/JythonScriptLanguage.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
index 6ec4340..8fe493a 100644
--- a/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
+++ b/src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java
@@ -50,7 +50,7 @@
* @author Mark Hiner
* @see ScriptEngine
*/
-@Plugin(type = ScriptLanguage.class, name = "Python (Jython)")
+@Plugin(type = ScriptLanguage.class, name = "Jython")
public class JythonScriptLanguage extends AdaptedScriptLanguage {
@Parameter