groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: GROOVY-8805 reloading a script under GroovyScriptEngine should succeed when dependent class is deleted(closes #799)
Date Sat, 06 Oct 2018 07:35:27 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 31b206d1c -> 886b1223c


GROOVY-8805 reloading a script under GroovyScriptEngine should succeed when dependent class
is deleted(closes #799)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/886b1223
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/886b1223
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/886b1223

Branch: refs/heads/master
Commit: 886b1223cb5d7745270f700ef0fafbfa3d380dd6
Parents: 31b206d
Author: Gary Clayburg <gclaybur@comcast.net>
Authored: Fri Sep 21 13:50:23 2018 -0600
Committer: Daniel Sun <sunlan@apache.org>
Committed: Sat Oct 6 15:34:40 2018 +0800

----------------------------------------------------------------------
 .../groovy/groovy/util/GroovyScriptEngine.java  | 23 +++++++++++++-------
 .../util/GroovyScriptEngineReloadingTest.groovy | 19 +++++++++++++++-
 2 files changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/886b1223/src/main/groovy/groovy/util/GroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/GroovyScriptEngine.java b/src/main/groovy/groovy/util/GroovyScriptEngine.java
index c9e0c5b..8634e3a 100644
--- a/src/main/groovy/groovy/util/GroovyScriptEngine.java
+++ b/src/main/groovy/groovy/util/GroovyScriptEngine.java
@@ -264,12 +264,8 @@ public class GroovyScriptEngine implements ResourceConnector {
                 Set<String> newDep = new HashSet<String>(origDep.size());
                 for (String depName : origDep) {
                     ScriptCacheEntry dep = scriptCache.get(depName);
-                    try {
-                        if (origEntry == dep || GroovyScriptEngine.this.isSourceNewer(dep))
{
-                            newDep.add(depName);
-                        }
-                    } catch (ResourceException re) {
-
+                    if (origEntry == dep || GroovyScriptEngine.this.isSourceNewer(dep)) {
+                        newDep.add(depName);
                     }
                 }
                 StringSetMap cache = localData.dependencyCache;
@@ -613,7 +609,7 @@ public class GroovyScriptEngine implements ResourceConnector {
         return lastMod;
     }
 
-    protected boolean isSourceNewer(ScriptCacheEntry entry) throws ResourceException {
+    protected boolean isSourceNewer(ScriptCacheEntry entry) {
         if (entry == null) return true;
 
         long mainEntryLastCheck = entry.lastCheck;
@@ -634,7 +630,18 @@ public class GroovyScriptEngine implements ResourceConnector {
             long nextSourceCheck = depEntry.lastCheck + config.getMinimumRecompilationInterval();
             if (nextSourceCheck > now) continue;
 
-            long lastMod = getLastModified(scriptName);
+            long lastMod;
+            try {
+                lastMod = getLastModified(scriptName);
+            } catch (ResourceException e) {
+                /*
+                Class A depends on class B and they both are compiled once.  If class A is
then
+                loaded again from loadScriptByName(scriptName) after class B and all references
to
+                it have been deleted from the root, this exception will occur.  It is still
valid
+                and necessary to attempt a recompile of class A.
+                */
+                return true;
+            }
             if (depEntry.lastModified < lastMod) {
                 depEntry = new ScriptCacheEntry(depEntry, lastMod, true);
                 scriptCache.put(scriptName, depEntry);

http://git-wip-us.apache.org/repos/asf/groovy/blob/886b1223/src/test/groovy/util/GroovyScriptEngineReloadingTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GroovyScriptEngineReloadingTest.groovy b/src/test/groovy/util/GroovyScriptEngineReloadingTest.groovy
index 1ca7f01..443a692 100644
--- a/src/test/groovy/util/GroovyScriptEngineReloadingTest.groovy
+++ b/src/test/groovy/util/GroovyScriptEngineReloadingTest.groovy
@@ -92,6 +92,19 @@ class GroovyScriptEngineReloadingTest extends GroovyTestCase {
         execute (100000, 200000, 2)
     }
 
+    void testDeleteDependent() {
+        sleep 10000
+        MapFileSystem.instance.modFile('ClassA.groovy','DependentClass ic = new DependentClass()',gse.@time
as long)
+        MapFileSystem.instance.modFile('DependentClass.groovy','class DependentClass {}',gse.@time
as long)
+        def clazz = gse.loadScriptByName('ClassA.groovy')
+        assert clazz != null //classA is valid with dep
+        sleep 11000
+        MapFileSystem.instance.modFile('ClassA.groovy',"println 'this is a valid script'",gse.@time
as long)
+        MapFileSystem.instance.deleteFile('DependentClass.groovy')
+        clazz = gse.loadScriptByName('ClassA.groovy')
+        assert clazz != null //classA is valid with dep removed
+    }
+
     public void testReloadWith2ScriptsDependentOnSameBeanAndReloadForSecond() {
         gse.config.minimumRecompilationInterval = 1000
         writeBean(1)
@@ -456,7 +469,11 @@ class GroovyScriptEngineReloadingTest extends GroovyTestCase {
                 fileCache.put(name, new MapFileEntry(content, lutime))
             }
         }
-    
+
+        def deleteFile(String name) {
+            return fileCache.remove(name)
+        }
+
         String getFilesrc(String name) {
             return fileCache.get(name).content
         }


Mime
View raw message