Update to Java 10.

This commit is contained in:
MobiusDev
2018-08-07 13:40:25 +00:00
parent c97536b0a4
commit bb816ba617
133 changed files with 677 additions and 1110 deletions

View File

@@ -255,7 +255,7 @@ public final class Rnd
public ThreadLocalRandom()
{
_seedLocal = new ThreadLocal<Seed>()
_seedLocal = new ThreadLocal<>()
{
@Override
public final Seed initialValue()
@@ -267,7 +267,7 @@ public final class Rnd
public ThreadLocalRandom(long seed)
{
_seedLocal = new ThreadLocal<Seed>()
_seedLocal = new ThreadLocal<>()
{
@Override
public final Seed initialValue()

View File

@@ -205,7 +205,7 @@ public class GameServer
}
// load script engines
printSection("Scripting Engines");
printSection("Scripting Engine");
EventDispatcher.getInstance();
ScriptEngineManager.getInstance();

View File

@@ -74,7 +74,7 @@ public class EventMethodNotification
private void invoke(Object instance) throws Exception
{
final boolean wasAccessible = _method.isAccessible();
final boolean wasAccessible = _method.canAccess(instance);
if (!wasAccessible)
{
_method.setAccessible(true);

View File

@@ -149,7 +149,7 @@ public final class ScriptEngineManager implements IGameXmlReader
private Properties loadProperties()
{
Properties props = null;
try (FileInputStream fis = new FileInputStream("config/ScriptEngines.ini"))
try (FileInputStream fis = new FileInputStream("config/ScriptEngine.ini"))
{
props = new Properties();
props.load(fis);
@@ -157,7 +157,7 @@ public final class ScriptEngineManager implements IGameXmlReader
catch (Exception e)
{
props = null;
LOGGER.warning("Couldn't load ScriptEngines.properties: " + e.getMessage());
LOGGER.warning("Couldn't load ScriptEngine.ini: " + e.getMessage());
}
return props;
}

View File

@@ -30,9 +30,9 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject;
import org.openjavac.tools.Diagnostic;
import org.openjavac.tools.DiagnosticCollector;
import org.openjavac.tools.JavaFileObject;
import com.l2jmobius.gameserver.scripting.AbstractExecutionContext;
import com.l2jmobius.gameserver.scripting.annotations.Disabled;
@@ -44,9 +44,41 @@ public final class JavaExecutionContext extends AbstractExecutionContext<JavaScr
{
private static final Logger LOGGER = Logger.getLogger(JavaExecutionContext.class.getName());
private static final List<String> _options = new LinkedList<>();
JavaExecutionContext(JavaScriptingEngine engine)
{
super(engine);
// Set options.
addOptionIfNotNull(_options, getProperty("source"), "-source");
addOptionIfNotNull(_options, getProperty("sourcepath"), "-sourcepath");
if (!addOptionIfNotNull(_options, getProperty("cp"), "-cp") && !addOptionIfNotNull(_options, getProperty("classpath"), "-classpath"))
{
addOptionIfNotNull(_options, System.getProperty("java.class.path"), "-cp");
}
addOptionIfNotNull(_options, getProperty("g"), "-g:");
// We always set the target JVM to the current running version.
final String targetVersion = System.getProperty("java.specification.version");
if (!targetVersion.contains("."))
{
_options.add("-target");
_options.add(targetVersion);
}
else
{
final String[] versionSplit = targetVersion.split("\\.");
if (versionSplit.length > 1)
{
_options.add("-target");
_options.add(versionSplit[0] + '.' + versionSplit[1]);
}
else
{
throw new JavaCompilerException("Could not determine target version!");
}
}
}
private boolean addOptionIfNotNull(List<String> list, String nullChecked, String before)
@@ -109,37 +141,7 @@ public final class JavaExecutionContext extends AbstractExecutionContext<JavaScr
try (ScriptingFileManager fileManager = new ScriptingFileManager(getScriptingEngine().getCompiler().getStandardFileManager(fileManagerDiagnostics, null, StandardCharsets.UTF_8)))
{
final List<String> options = new LinkedList<>();
addOptionIfNotNull(options, getProperty("source"), "-source");
addOptionIfNotNull(options, getProperty("sourcepath"), "-sourcepath");
if (!addOptionIfNotNull(options, getProperty("cp"), "-cp") && !addOptionIfNotNull(options, getProperty("classpath"), "-classpath"))
{
addOptionIfNotNull(options, System.getProperty("java.class.path"), "-cp");
}
addOptionIfNotNull(options, getProperty("g"), "-g:");
// we always add the target JVM to the current running version
final String targetVersion = System.getProperty("java.specification.version");
if (!targetVersion.contains("."))
{
options.add("-target");
options.add(targetVersion);
}
else
{
final String[] versionSplit = targetVersion.split("\\.");
if (versionSplit.length > 1)
{
options.add("-target");
options.add(versionSplit[0] + '.' + versionSplit[1]);
}
else
{
throw new JavaCompilerException("Could not determine target version!");
}
}
// we really need an iterable of files or strings
// We really need an iterable of files or strings.
final List<String> sourcePathStrings = new LinkedList<>();
for (Path sourcePath : sourcePaths)
{
@@ -148,7 +150,7 @@ public final class JavaExecutionContext extends AbstractExecutionContext<JavaScr
final StringWriter strOut = new StringWriter();
final PrintWriter out = new PrintWriter(strOut);
final boolean compilationSuccess = getScriptingEngine().getCompiler().getTask(out, fileManager, compilationDiagnostics, options, null, fileManager.getJavaFileObjectsFromStrings(sourcePathStrings)).call();
final boolean compilationSuccess = getScriptingEngine().getCompiler().getTask(out, fileManager, compilationDiagnostics, _options, null, fileManager.getJavaFileObjectsFromStrings(sourcePathStrings)).call();
if (!compilationSuccess)
{
out.println();

View File

@@ -17,19 +17,17 @@
package com.l2jmobius.gameserver.scripting.java;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ServiceLoader;
import javax.lang.model.SourceVersion;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.openjavac.tools.JavaCompiler;
import org.openjavac.tools.javac.api.JavacTool;
import com.l2jmobius.gameserver.scripting.AbstractScriptingEngine;
import com.l2jmobius.gameserver.scripting.IExecutionContext;
/**
* @author HorridoJoho
* @author HorridoJoho, Mobius
*/
public final class JavaScriptingEngine extends AbstractScriptingEngine
{
@@ -37,64 +35,20 @@ public final class JavaScriptingEngine extends AbstractScriptingEngine
public JavaScriptingEngine()
{
super("L2J Java Engine", "1.0", "java");
super("Java Engine", "10", "java");
}
private void determineCompilerOrThrow()
{
final String preferedCompiler = getProperty("preferedCompiler");
LinkedList<JavaCompiler> allCompilers = null;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler != null)
if (_compiler == null)
{
if ((preferedCompiler == null) || compiler.getClass().getName().equals(preferedCompiler))
{
_compiler = compiler;
return;
}
allCompilers = new LinkedList<>();
allCompilers.add(compiler);
_compiler = JavacTool.create();
}
final ServiceLoader<JavaCompiler> thirdPartyCompilers = ServiceLoader.load(JavaCompiler.class);
Iterator<JavaCompiler> compilersIterator = thirdPartyCompilers.iterator();
while (compilersIterator.hasNext())
if (_compiler == null)
{
compiler = compilersIterator.next();
if ((preferedCompiler == null) || compiler.getClass().getName().equals(preferedCompiler))
{
_compiler = compiler;
return;
}
if (allCompilers == null)
{
allCompilers = new LinkedList<>();
}
allCompilers.add(compilersIterator.next());
throw new IllegalStateException("No JavaCompiler service installed!");
}
if (allCompilers != null)
{
compilersIterator = allCompilers.iterator();
while (compilersIterator.hasNext())
{
compiler = compilersIterator.next();
if ((preferedCompiler == null) || compiler.getClass().getName().equals(preferedCompiler))
{
break;
}
}
}
if (compiler == null)
{
throw new IllegalStateException("No javax.tools.JavaCompiler service installed!");
}
_compiler = compiler;
}
private void ensureCompilerOrThrow()

View File

@@ -24,10 +24,10 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
import javax.tools.StandardJavaFileManager;
import org.openjavac.tools.FileObject;
import org.openjavac.tools.JavaFileObject;
import org.openjavac.tools.JavaFileObject.Kind;
import org.openjavac.tools.StandardJavaFileManager;
/**
* @author HorridoJoho

View File

@@ -26,7 +26,8 @@ import java.nio.file.Path;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileObject;
import org.openjavac.tools.JavaFileObject;
/**
* @author HorridoJoho