2626import java .net .MalformedURLException ;
2727import java .net .URLClassLoader ;
2828
29- import scala .collection .JavaConversions ;
30- import scala .tools .nsc .MainClass ;
31- import scala .tools .nsc .Settings ;
32- import scala .tools .nsc .CompilerCommand ;
29+ import scala .jdk .CollectionConverters ;
3330
3431import javax .tools .*;
3532import javax .tools .JavaCompiler .CompilationTask ;
@@ -54,7 +51,7 @@ public String getExtension() {
5451
5552 static ResourceFile getClassFileByResourceFile (ResourceFile sourceFile , String rawName ) {
5653 String javaAbsolutePath = sourceFile .getAbsolutePath ();
57- String classAbsolutePath = javaAbsolutePath .replace (".java " , ".class" );
54+ String classAbsolutePath = javaAbsolutePath .replace (".scala " , ".class" );
5855
5956 return new ResourceFile (classAbsolutePath );
6057 }
@@ -90,8 +87,8 @@ public GhidraScript getScriptInstance(ResourceFile sourceFile, PrintWriter write
9087 sourceFile .getName () + " does not." );
9188 }
9289 catch (ClassNotFoundException e ) {
93- throw new GhidraScriptLoadException ("The class could not be found. " +
94- "It must be the public class of the .java file: " + e .getMessage (), e );
90+ throw new GhidraScriptLoadException ("The class " + e . getMessage () + " could not be found. " +
91+ "Make sure the primary class in " + sourceFile + " is named " + e .getMessage () + "." , e );
9592 }
9693 catch (NoClassDefFoundError e ) {
9794 throw new GhidraScriptLoadException ("The class could not be found or loaded, " +
@@ -102,6 +99,7 @@ public GhidraScript getScriptInstance(ResourceFile sourceFile, PrintWriter write
10299 "Error during class initialization: " + e .getException (), e .getException ());
103100 }
104101 catch (Exception e ) {
102+ e .printStackTrace ();
105103 throw new GhidraScriptLoadException ("Unexpected error: " + e );
106104 }
107105
@@ -156,29 +154,7 @@ private boolean doCompile(ResourceFile sourceFile, final PrintWriter writer) {
156154 return helper .compile (msg -> writer .println (msg ), outputDirectory , getSourcePath (), getClassPath (), sourceFile .getAbsolutePath ());
157155 }
158156
159- private List <Class <?>> getParentClasses (ResourceFile scriptSourceFile ) {
160-
161- Class <?> scriptClass = getScriptClass (scriptSourceFile );
162- if (scriptClass == null ) {
163- return null ; // special signal that there was a problem
164- }
165-
166- List <Class <?>> parentClasses = new ArrayList <>();
167- Class <?> superClass = scriptClass .getSuperclass ();
168- while (superClass != null ) {
169- if (superClass .equals (GhidraScript .class )) {
170- break ; // not interested in the built-in classes
171- }
172- else if (superClass .equals (HeadlessScript .class )) {
173- break ; // not interested in the built-in classes
174- }
175- parentClasses .add (superClass );
176- superClass = superClass .getSuperclass ();
177- }
178- return parentClasses ;
179- }
180-
181- private Class <?> getScriptClass (ResourceFile scriptSourceFile ) {
157+ private Class <?> getScriptClass (ResourceFile scriptSourceFile ) throws ClassNotFoundException {
182158 String clazzName = GhidraScriptUtil .getBaseName (scriptSourceFile );
183159 try {
184160 URL classURL = outputDir (scriptSourceFile ).getFile (false ).toURI ().toURL ();
@@ -188,6 +164,7 @@ private Class<?> getScriptClass(ResourceFile scriptSourceFile) {
188164 }
189165 catch (NoClassDefFoundError | ClassNotFoundException e ) {
190166 Msg .error (this , "Unable to find class file for script file: " + scriptSourceFile , e );
167+ throw e ;
191168 }
192169 catch (MalformedURLException e ) {
193170 Msg .error (this , "Malformed URL exception:" , e );
0 commit comments