gameserver/scripting/L2ScriptEngineManager.java (+45 -57) diffs
+ import java.io.PrintWriter;
+ import java.io.StringWriter;
+ _log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion()
+ + " - Language: " + factory.getLanguageName() + " " + factory.getLanguageVersion());
+
- boolean reg = false;
+
- ScriptEngine existentEngine = _nameEngines.get(name);
+ if (_nameEngines.containsKey(name))
+ throw new IllegalStateException("Multiple script engines for the same name!");
- if (existentEngine != null)
- {
- double engineVer = Double.parseDouble(factory.getEngineVersion());
- double existentEngVer = Double.parseDouble(existentEngine.getFactory().getEngineVersion());
-
- if (engineVer <= existentEngVer)
- {
- continue;
- }
- }
- reg = true;
-
- if (reg)
- {
- _log.info("Script Engine: "+factory.getEngineName()+" "+factory.getEngineVersion()+" - Language: "+
- factory.getLanguageName()+" - Language Version: "+factory.getLanguageVersion());
- }
-
+
- if (!ext.equals("java") || factory.getLanguageName().equals("java"))
- {
- _extEngines.put(ext, engine);
- }
+ if (_extEngines.containsKey(ext))
+ throw new IllegalStateException("Multiple script engines for the same extension!");
+
+
- _log.warn("Failed initializing factory. ", e);
+ _log.warn("Failed initializing factory.", e);
+ context.setAttribute("parentLoader", ClassLoader.getSystemClassLoader(), ScriptContext.ENGINE_SCOPE);
+ context.removeAttribute("parentLoader", ScriptContext.ENGINE_SCOPE);
+ context.setAttribute("parentLoader", ClassLoader.getSystemClassLoader(), ScriptContext.ENGINE_SCOPE);
+ engine.getContext().removeAttribute("parentLoader", ScriptContext.ENGINE_SCOPE);
- String dir = script.getParent();
- String name = script.getName() + ".error.log";
- if (dir != null)
+ _log.warn("Failed executing script: " + script.getPath() + ".");
+
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ pw.println("Error on: " + script.getAbsolutePath());
+ pw.println("Line: " + e.getLineNumber() + " - Column: " + e.getColumnNumber());
+ pw.println();
+ e.printStackTrace(pw);
+ pw.close();
+
+ final String report = sw.toString();
+
+ FileOutputStream fos = null;
+ try
- File file = new File(dir + "/" + name);
-
- FileOutputStream fos = null;
- try
- {
- if (!file.exists())
- {
- file.createNewFile();
- }
-
- fos = new FileOutputStream(file);
- String errorHeader = "Error on: " + file.getCanonicalPath() + "\r\nLine: " + e.getLineNumber() + " - Column: " + e.getColumnNumber()
- + "\r\n\r\n";
- fos.write(errorHeader.getBytes());
- fos.write(e.getMessage().getBytes());
- _log.warn("Failed executing script: " + script.getAbsolutePath() + ". See " + file.getName() + " for details.");
- }
- catch (IOException ioe)
- {
- _log.warn("Failed executing script: " + script.getAbsolutePath() + "\r\n" + e.getMessage()
- + "Additionally failed when trying to write an error report on script directory. Reason: " + ioe.getMessage(), ioe);
- }
- finally
- {
- IOUtils.closeQuietly(fos);
- }
+ String fileName = script.getName() + ".error.log";
+
+ fos = new FileOutputStream(new File(script.getParent(), fileName));
+ fos.write(report.getBytes());
+
+ _log.warn("See " + fileName + " for details.");
- else
+ catch (IOException ioe)
- _log.warn("Failed executing script: " + script.getAbsolutePath() + "\r\n" + e.getMessage()
- + "Additionally failed when trying to write an error report on script directory.");
+ _log.warn("Additionally failed when trying to write an error report on script directory.", ioe);
+ _log.info(report);
+ finally
+ {
+ IOUtils.closeQuietly(fos);
+ }