Skip to content

Commit 4913afd

Browse files
committed
Swap execution order of compile(String) and compile(Reader)
This allows us to compute a hash on the script as a String even if it was input via the gererating Reader. We need to compute the hash for future recompilation avoidance. Signed-off-by: Squareys <[email protected]>
1 parent 510a488 commit 4913afd

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

‎src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,14 @@ public Object eval(Reader reader) throws ScriptException{
168168
* @return the compiled Java class as{@link Class}.
169169
*/
170170
publicClass<?> compile(Stringscript) throwsScriptException{
171-
returncompile(newStringReader(script));
172-
}
173-
174-
/**
175-
* Compiles and runs the specified{@code .java} class.
176-
*
177-
* @param reader the reader producing the source code for a Java class
178-
* @returns the compiled Java class as{@link Class}.
179-
*/
180-
publicClass<?> compile(Readerreader) throwsScriptException{
181171
finalStringpath = (String)get(FILENAME);
182172
Filefile = path == null ? null : newFile(path);
183173

184174
finalWriterwriter = getContext().getErrorWriter();
185175
try{
176+
// script may be null, but then we cannot create a StringReader for it,
177+
// therefore null is passed if script is null.
178+
finalReaderreader = (script == null) ? null : newStringReader(script);
186179
finalBuilderbuilder = newBuilder(file, reader, writer);
187180
finalMavenProjectproject = builder.project;
188181
StringmainClass = builder.mainClass;
@@ -229,6 +222,23 @@ public Class<?> compile(Reader reader) throws ScriptException{
229222
returnnull;
230223
}
231224

225+
/**
226+
* Compiles and runs the specified{@code .java} class.
227+
*
228+
* @param reader the reader producing the source code for a Java class
229+
* @return the compiled Java class as{@link Class}.
230+
*/
231+
publicClass<?> compile(Readerreader) throwsScriptException{
232+
Stringscript;
233+
try{
234+
script = getReaderContentsAsString(reader);
235+
}
236+
catch (IOExceptione){
237+
thrownewScriptException(e);
238+
}
239+
returncompile(script);
240+
}
241+
232242
/**
233243
* Compiles the specified{@code .java} file.
234244
*

0 commit comments

Comments
(0)