3
3
import com .cleanroommc .groovyscript .GroovyScript ;
4
4
import com .cleanroommc .groovyscript .api .GroovyLog ;
5
5
import com .cleanroommc .groovyscript .sandbox .FileUtil ;
6
+ import com .cleanroommc .groovyscript .sandbox .RunConfig ;
6
7
import org .codehaus .groovy .ast .ModuleNode ;
7
8
import org .codehaus .groovy .ast .PackageNode ;
8
9
import org .codehaus .groovy .control .SourceUnit ;
@@ -25,6 +26,11 @@ public abstract class ModuleNodeMixin {
25
26
public void init (SourceUnit context , CallbackInfo ci ) {
26
27
// auto set package name
27
28
String script = context .getName ();
29
+ if (!RunConfig .isGroovyFile (script )) {
30
+ // probably not a script file
31
+ // can happen with traits
32
+ return ;
33
+ }
28
34
String rel = FileUtil .relativize (GroovyScript .getScriptPath (), script );
29
35
int i = rel .lastIndexOf (File .separatorChar );
30
36
if (i >= 0 ) {
@@ -37,6 +43,11 @@ public void init(SourceUnit context, CallbackInfo ci) {
37
43
@ Inject (method = "setPackage" , at = @ At ("HEAD" ), cancellable = true )
38
44
public void setPackage (PackageNode packageNode , CallbackInfo ci ) {
39
45
if (this .packageNode == null || this .context == null ) return ;
46
+ if (!RunConfig .isGroovyFile (this .context .getName ())) {
47
+ // probably not a script file
48
+ // can happen with traits
49
+ return ;
50
+ }
40
51
// package name was already set -> only copy data of new node
41
52
String cur = this .packageNode .getName ();
42
53
String newName = packageNode .getName ();
0 commit comments