4747import java .lang .reflect .Field ;
4848import java .net .URL ;
4949import java .net .URLClassLoader ;
50- import java .nio .file .*;
51- import java .nio .file .attribute .BasicFileAttributes ;
50+ import java .nio .file .Files ;
51+ import java .nio .file .Path ;
52+ import java .nio .file .Paths ;
53+ import java .nio .file .StandardOpenOption ;
5254import java .util .*;
5355
5456import javax .inject .Inject ;
@@ -131,11 +133,6 @@ public void initEngine() {
131133 classGenerator .generateDynamicListener (eventListeners );
132134
133135 reloadSkills ();
134-
135- JSObject postInit = (JSObject ) scriptContext .getBindings (ScriptContext .ENGINE_SCOPE ).get ("runPostInitialization" );
136- if (postInit != null && postInit .isFunction ()) {
137- postInit .call (null );
138- }
139136 } catch (Exception e ) {
140137 error ("Could not load script engine" , e );
141138 }
@@ -162,33 +159,24 @@ private Path mergeScriptFiles() {
162159 final StringBuilder bigChunkOfCode = new StringBuilder ();
163160 bigChunkOfCode .append (assetService .getAssetAsString ("Main.js" )).append (System .lineSeparator ());
164161
165- Path additionalMainPath = Paths .get (scripts_root + File .separator + "MainAdd.js" );
166- if (!additionalMainPath .toFile ().exists ()) assetService .copyToFile ("MainAdd.js" , additionalMainPath );
167-
168- try {
169- for (String line : Files .readAllLines (additionalMainPath ))
170- bigChunkOfCode .append (line ).append (System .lineSeparator ());
171- } catch (IOException e ) {
172- e .printStackTrace ();
173- }
174-
175162 try {
176- Files .walkFileTree (scripts_root , new SimpleFileVisitor <Path >() {
177- @ Override
178- public FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) throws IOException {
179- if (file .toString ().endsWith (".js" ) && !file .toString ().endsWith ("MainAdd.js" )) {
163+ Queue <Path > directories = new PriorityQueue <>();
164+ directories .add (scripts_root );
165+ while (directories .size () != 0 ) {
166+ Files .list (directories .poll ()).forEach ((file -> {
167+ if (file .toFile ().isDirectory ()) directories .add (file );
168+ else if (file .toFile ().getName ().endsWith (".js" )) {
180169 bigChunkOfCode .append (System .lineSeparator ()).append ("// " ).append (file .toFile ().getName ()).append (System .lineSeparator ());
181- for (String line : Files .readAllLines (file ))
182- bigChunkOfCode .append (line ).append (System .lineSeparator ());
170+ try {
171+ for (String line : Files .readAllLines (file ))
172+ bigChunkOfCode .append (line ).append (System .lineSeparator ());
173+ } catch (IOException e ) {
174+ e .printStackTrace ();
175+ }
183176 }
184- return super .visitFile (file , attrs );
185- }
186- });
187- } catch (IOException e ) {
188- e .printStackTrace ();
189- }
177+ }));
178+ }
190179
191- try {
192180 return Files .write (path , bigChunkOfCode .toString ().getBytes (), StandardOpenOption .CREATE_NEW );
193181 } catch (IOException e ) {
194182 throw new RuntimeException ("Could not write .deployed.js " , e );
0 commit comments