generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...main/java/com/cleanroommc/groovyscript/sandbox/transformer/GroovyScriptEarlyCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.cleanroommc.groovyscript.sandbox.transformer; | ||
|
||
import com.cleanroommc.groovyscript.GroovyScript; | ||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
import com.cleanroommc.groovyscript.sandbox.FileUtil; | ||
import org.codehaus.groovy.ast.ClassNode; | ||
import org.codehaus.groovy.ast.ModuleNode; | ||
import org.codehaus.groovy.classgen.GeneratorContext; | ||
import org.codehaus.groovy.control.CompilationFailedException; | ||
import org.codehaus.groovy.control.CompilePhase; | ||
import org.codehaus.groovy.control.SourceUnit; | ||
import org.codehaus.groovy.control.customizers.CompilationCustomizer; | ||
|
||
import java.io.File; | ||
|
||
public class GroovyScriptEarlyCompiler extends CompilationCustomizer { | ||
|
||
public GroovyScriptEarlyCompiler() { | ||
super(CompilePhase.CONVERSION); | ||
} | ||
|
||
@Override | ||
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { | ||
String root = GroovyScript.getScriptPath(); | ||
String script = source.getName(); | ||
ModuleNode module = classNode.getModule(); | ||
String rel = FileUtil.relativize(root, script); | ||
int i = rel.lastIndexOf(File.separatorChar); | ||
if (i >= 0) { | ||
String packageName = rel.substring(0, i).replace(File.separatorChar, '.') + '.'; | ||
if (module.getPackage() != null && !module.getPackage().getName().equals(packageName)) { | ||
GroovyLog.get().error("Expected package {} but got {} in script {}", packageName, module.getPackage().getName(), rel); | ||
} | ||
module.setPackageName(packageName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters