升级依赖版本
This commit is contained in:
parent
25059860e9
commit
1038198442
@ -131,16 +131,16 @@ dependencies {
|
||||
libraries 'org.scala-lang:scala-xml_2.11:1.0.2'
|
||||
libraries 'net.sf.jopt-simple:jopt-simple:4.7'
|
||||
libraries 'lzma:lzma:0.0.1'
|
||||
libraries 'org.yaml:snakeyaml:1.9'
|
||||
libraries 'org.yaml:snakeyaml:1.15'
|
||||
libraries 'commons-lang:commons-lang:2.6'
|
||||
libraries 'org.avaje:ebean:2.7.3'
|
||||
libraries 'jline:jline:2.6'
|
||||
libraries 'jline:jline:2.12.1'
|
||||
libraries 'net.md-5:SpecialSource:1.7.3'
|
||||
libraries 'net.sourceforge.argo:argo:2.25'
|
||||
libraries 'org.fusesource.jansi:jansi:1.8'
|
||||
libraries 'com.googlecode.json-simple:json-simple:1.1'
|
||||
libraries 'org.xerial:sqlite-jdbc:3.7.2'
|
||||
libraries 'mysql:mysql-connector-java:5.1.14'
|
||||
libraries 'mysql:mysql-connector-java:5.1.42'
|
||||
libraries 'javax.persistence:persistence-api:1.0.2'
|
||||
libraries 'net.minecraft:server:1.7.10'
|
||||
libraries 'pw.prok:KImagine:0.2.0@jar'
|
||||
|
@ -22,7 +22,7 @@
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
@@ -33,10 +17,45 @@
|
||||
@@ -33,10 +17,46 @@
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
@ -42,6 +42,7 @@
|
||||
+import org.bukkit.craftbukkit.util.Waitable;
|
||||
+import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||
+import org.bukkit.event.world.WorldSaveEvent;
|
||||
+import org.fusesource.jansi.AnsiConsole;
|
||||
+
|
||||
+import com.google.common.base.Charsets;
|
||||
+import com.mojang.authlib.GameProfile;
|
||||
@ -69,7 +70,7 @@
|
||||
import net.minecraft.command.ServerCommandManager;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -50,9 +69,11 @@
|
||||
@@ -50,9 +70,11 @@
|
||||
import net.minecraft.profiler.PlayerUsageSnooper;
|
||||
import net.minecraft.profiler.Profiler;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
@ -81,7 +82,7 @@
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
@@ -63,19 +84,20 @@
|
||||
@@ -63,19 +85,20 @@
|
||||
import net.minecraft.world.MinecraftException;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldManager;
|
||||
@ -107,7 +108,7 @@
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
@@ -85,13 +107,13 @@
|
||||
@@ -85,13 +108,13 @@
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
public static final File field_152367_a = new File("usercache.json");
|
||||
private static MinecraftServer mcServer;
|
||||
@ -124,7 +125,7 @@
|
||||
private final ServerStatusResponse field_147147_p = new ServerStatusResponse();
|
||||
private final Random field_147146_q = new Random();
|
||||
@SideOnly(Side.SERVER)
|
||||
@@ -135,8 +157,42 @@
|
||||
@@ -135,8 +158,42 @@
|
||||
private long field_147142_T = 0L;
|
||||
private final GameProfileRepository field_152365_W;
|
||||
private final PlayerProfileCache field_152366_X;
|
||||
@ -167,7 +168,7 @@
|
||||
public MinecraftServer(File p_i45281_1_, Proxy p_i45281_2_)
|
||||
{
|
||||
this.field_152366_X = new PlayerProfileCache(this, field_152367_a);
|
||||
@@ -149,10 +205,72 @@
|
||||
@@ -149,10 +206,72 @@
|
||||
this.field_152364_T = new YggdrasilAuthenticationService(p_i45281_2_, UUID.randomUUID().toString());
|
||||
this.field_147143_S = this.field_152364_T.createMinecraftSessionService();
|
||||
this.field_152365_W = this.field_152364_T.createProfileRepository();
|
||||
@ -241,7 +242,7 @@
|
||||
protected void convertMapIfNeeded(String p_71237_1_)
|
||||
{
|
||||
if (this.getActiveAnvilConverter().isOldMapFormat(p_71237_1_))
|
||||
@@ -172,6 +290,7 @@
|
||||
@@ -172,6 +291,7 @@
|
||||
MinecraftServer.logger.info("Converting... " + p_73718_1_ + "%");
|
||||
}
|
||||
}
|
||||
@ -249,7 +250,7 @@
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void resetProgressAndMessage(String p_73721_1_) {}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -195,10 +314,17 @@
|
||||
@@ -195,10 +315,17 @@
|
||||
|
||||
protected void loadAllWorlds(String p_71247_1_, String p_71247_2_, long p_71247_3_, WorldType p_71247_5_, String p_71247_6_)
|
||||
{
|
||||
@ -269,7 +270,7 @@
|
||||
WorldSettings worldsettings;
|
||||
|
||||
if (worldinfo == null)
|
||||
@@ -215,11 +341,79 @@
|
||||
@@ -215,11 +342,79 @@
|
||||
{
|
||||
worldsettings.enableBonusChest();
|
||||
}
|
||||
@ -352,7 +353,7 @@
|
||||
world.addWorldAccess(new WorldManager(this, world));
|
||||
|
||||
if (!this.isSinglePlayer())
|
||||
@@ -227,12 +421,14 @@
|
||||
@@ -227,12 +422,14 @@
|
||||
world.getWorldInfo().setGameType(this.getGameType());
|
||||
}
|
||||
|
||||
@ -370,7 +371,7 @@
|
||||
}
|
||||
|
||||
protected void initialWorldChunkLoad()
|
||||
@@ -244,9 +440,12 @@
|
||||
@@ -244,9 +441,12 @@
|
||||
int i = 0;
|
||||
this.setUserMessage("menu.generatingTerrain");
|
||||
byte b0 = 0;
|
||||
@ -383,7 +384,7 @@
|
||||
long j = getSystemTimeMillis();
|
||||
|
||||
for (int k = -192; k <= 192 && this.isServerRunning(); k += 16)
|
||||
@@ -265,7 +464,8 @@
|
||||
@@ -265,7 +465,8 @@
|
||||
worldserver.theChunkProviderServer.loadChunk(chunkcoordinates.posX + k >> 4, chunkcoordinates.posZ + l >> 4);
|
||||
}
|
||||
}
|
||||
@ -393,7 +394,7 @@
|
||||
this.clearCurrentTask();
|
||||
}
|
||||
|
||||
@@ -292,19 +492,17 @@
|
||||
@@ -292,19 +493,17 @@
|
||||
{
|
||||
this.currentTask = null;
|
||||
this.percentDone = 0;
|
||||
@ -418,7 +419,7 @@
|
||||
|
||||
if (worldserver != null)
|
||||
{
|
||||
@@ -313,25 +511,41 @@
|
||||
@@ -313,25 +512,41 @@
|
||||
logger.info("Saving chunks for level \'" + worldserver.getWorldInfo().getWorldName() + "\'/" + worldserver.provider.getDimensionName());
|
||||
}
|
||||
|
||||
@ -465,7 +466,7 @@
|
||||
if (this.func_147137_ag() != null)
|
||||
{
|
||||
this.func_147137_ag().terminateEndpoints();
|
||||
@@ -347,7 +561,14 @@
|
||||
@@ -347,7 +562,14 @@
|
||||
if (this.worldServers != null)
|
||||
{
|
||||
logger.info("Saving worlds");
|
||||
@ -481,7 +482,7 @@
|
||||
|
||||
for (int i = 0; i < this.worldServers.length; ++i)
|
||||
{
|
||||
@@ -380,6 +601,13 @@
|
||||
@@ -380,6 +602,13 @@
|
||||
this.serverRunning = false;
|
||||
}
|
||||
|
||||
@ -495,7 +496,7 @@
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
@@ -392,45 +620,41 @@
|
||||
@@ -392,45 +621,41 @@
|
||||
this.field_147147_p.func_151315_a(new ChatComponentText(this.motd));
|
||||
this.field_147147_p.func_151321_a(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.7.10", 5));
|
||||
this.func_147138_a(this.field_147147_p);
|
||||
@ -562,7 +563,7 @@
|
||||
FMLCommonHandler.instance().handleServerStopping();
|
||||
FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
|
||||
}
|
||||
@@ -448,6 +672,14 @@
|
||||
@@ -448,6 +673,14 @@
|
||||
catch (Throwable throwable1)
|
||||
{
|
||||
logger.error("Encountered an unexpected exception", throwable1);
|
||||
@ -577,7 +578,7 @@
|
||||
CrashReport crashreport = null;
|
||||
|
||||
if (throwable1 instanceof ReportedException)
|
||||
@@ -477,6 +709,7 @@
|
||||
@@ -477,6 +710,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -585,7 +586,7 @@
|
||||
this.stopServer();
|
||||
this.serverStopped = true;
|
||||
}
|
||||
@@ -486,6 +719,16 @@
|
||||
@@ -486,6 +720,16 @@
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -602,7 +603,7 @@
|
||||
FMLCommonHandler.instance().handleServerStopped();
|
||||
this.serverStopped = true;
|
||||
this.systemExitNow();
|
||||
@@ -532,8 +775,11 @@
|
||||
@@ -532,8 +776,11 @@
|
||||
|
||||
public void tick()
|
||||
{
|
||||
@ -614,7 +615,7 @@
|
||||
++this.tickCounter;
|
||||
|
||||
if (this.startProfiling)
|
||||
@@ -562,12 +808,21 @@
|
||||
@@ -562,12 +809,21 @@
|
||||
this.field_147147_p.func_151318_b().func_151330_a(agameprofile);
|
||||
}
|
||||
|
||||
@ -638,7 +639,7 @@
|
||||
}
|
||||
|
||||
this.theProfiler.startSection("tallying");
|
||||
@@ -575,25 +830,57 @@
|
||||
@@ -575,25 +831,57 @@
|
||||
this.theProfiler.endSection();
|
||||
this.theProfiler.startSection("snooper");
|
||||
|
||||
@ -698,7 +699,7 @@
|
||||
int i;
|
||||
|
||||
Integer[] ids = DimensionManager.getIDs(this.tickCounter % 200 == 0);
|
||||
@@ -602,19 +889,21 @@
|
||||
@@ -602,19 +890,21 @@
|
||||
int id = ids[x];
|
||||
long j = System.nanoTime();
|
||||
|
||||
@ -723,7 +724,7 @@
|
||||
|
||||
this.theProfiler.startSection("tick");
|
||||
FMLCommonHandler.instance().onPreWorldTick(worldserver);
|
||||
@@ -622,22 +911,46 @@
|
||||
@@ -622,22 +912,46 @@
|
||||
|
||||
try
|
||||
{
|
||||
@ -772,7 +773,7 @@
|
||||
worldserver.addWorldInfoToCrashReport(crashreport);
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
@@ -645,10 +958,13 @@
|
||||
@@ -645,10 +959,13 @@
|
||||
FMLCommonHandler.instance().onPostWorldTick(worldserver);
|
||||
this.theProfiler.endSection();
|
||||
this.theProfiler.startSection("tracker");
|
||||
@ -787,7 +788,7 @@
|
||||
|
||||
worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - j;
|
||||
}
|
||||
@@ -656,15 +972,21 @@
|
||||
@@ -656,15 +973,21 @@
|
||||
this.theProfiler.endStartSection("dim_unloading");
|
||||
DimensionManager.unloadWorlds(worldTickTimes);
|
||||
this.theProfiler.endStartSection("connection");
|
||||
@ -809,7 +810,7 @@
|
||||
|
||||
this.theProfiler.endSection();
|
||||
}
|
||||
@@ -699,6 +1021,13 @@
|
||||
@@ -699,6 +1022,13 @@
|
||||
|
||||
public WorldServer worldServerForDimension(int p_71218_1_)
|
||||
{
|
||||
@ -823,7 +824,7 @@
|
||||
WorldServer ret = DimensionManager.getWorld(p_71218_1_);
|
||||
if (ret == null)
|
||||
{
|
||||
@@ -784,13 +1113,14 @@
|
||||
@@ -784,13 +1114,14 @@
|
||||
|
||||
public List getPossibleCompletions(ICommandSender p_71248_1_, String p_71248_2_)
|
||||
{
|
||||
@ -842,7 +843,7 @@
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
@@ -798,40 +1128,25 @@
|
||||
@@ -798,40 +1129,25 @@
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
@ -891,7 +892,7 @@
|
||||
}
|
||||
|
||||
public static MinecraftServer getServer()
|
||||
@@ -1034,7 +1349,7 @@
|
||||
@@ -1034,7 +1350,7 @@
|
||||
|
||||
public boolean isServerInOnlineMode()
|
||||
{
|
||||
@ -900,7 +901,7 @@
|
||||
}
|
||||
|
||||
public void setOnlineMode(boolean p_71229_1_)
|
||||
@@ -1124,7 +1439,7 @@
|
||||
@@ -1124,7 +1440,7 @@
|
||||
|
||||
public NetworkSystem func_147137_ag()
|
||||
{
|
||||
@ -909,7 +910,7 @@
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -1259,8 +1574,11 @@
|
||||
@@ -1259,8 +1575,11 @@
|
||||
{
|
||||
Bootstrap.func_151354_b();
|
||||
|
||||
@ -921,7 +922,7 @@
|
||||
boolean flag = true;
|
||||
String s = null;
|
||||
String s1 = ".";
|
||||
@@ -1356,16 +1674,34 @@
|
||||
@@ -1356,16 +1675,34 @@
|
||||
{
|
||||
dedicatedserver.setGuiEnabled();
|
||||
}
|
||||
@ -962,7 +963,7 @@
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -1400,15 +1736,70 @@
|
||||
@@ -1400,15 +1737,70 @@
|
||||
@SideOnly(Side.SERVER)
|
||||
public String getPlugins()
|
||||
{
|
||||
@ -1038,7 +1039,7 @@
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
@@ -1455,9 +1846,220 @@
|
||||
@@ -1455,9 +1847,222 @@
|
||||
return this.serverStopped;
|
||||
}
|
||||
|
||||
@ -1178,6 +1179,8 @@
|
||||
+ if (!useJline) {
|
||||
+ // This ensures the terminal literal will always match the jline implementation
|
||||
+ System.setProperty(jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName());
|
||||
+ }else{
|
||||
+ AnsiConsole.systemInstall(); // install Windows JNI library
|
||||
+ }
|
||||
+
|
||||
+
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009 the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* MODIFICATIONS: methods to deal with wrapping the output stream.
|
||||
*/
|
||||
|
||||
package jline;
|
||||
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.fusesource.jansi.AnsiOutputStream;
|
||||
import org.fusesource.jansi.WindowsAnsiOutputStream;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* ANSI-supported {@link WindowsTerminal}.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class AnsiWindowsTerminal
|
||||
extends WindowsTerminal
|
||||
{
|
||||
private final boolean ansiSupported = detectAnsiSupport();
|
||||
|
||||
@Override
|
||||
public OutputStream wrapOutIfNeeded(OutputStream out) {
|
||||
return wrapOutputStream(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ansi output stream handler. We return whatever was
|
||||
* passed if we determine we cannot handle ansi based on Kernel32 calls.
|
||||
*
|
||||
* @return an @{link AltWindowAnsiOutputStream} instance or the passed
|
||||
* stream.
|
||||
*/
|
||||
private static OutputStream wrapOutputStream(final OutputStream stream) {
|
||||
String os = System.getProperty("os.name");
|
||||
if( os.startsWith("Windows") ) {
|
||||
// On windows we know the console does not interpret ANSI codes..
|
||||
try {
|
||||
return new WindowsAnsiOutputStream(stream);
|
||||
} catch (Throwable ignore) {
|
||||
// this happens when JNA is not in the path.. or
|
||||
// this happens when the stdout is being redirected to a file.
|
||||
}
|
||||
// Use the ANSIOutputStream to strip out the ANSI escape sequences.
|
||||
return new AnsiOutputStream(stream);
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
private static boolean detectAnsiSupport() {
|
||||
AnsiConsole.systemInstall(); // CraftBukkit - install Windows JNI library
|
||||
OutputStream out = AnsiConsole.wrapOutputStream(new ByteArrayOutputStream());
|
||||
try {
|
||||
out.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore;
|
||||
}
|
||||
return out instanceof WindowsAnsiOutputStream;
|
||||
}
|
||||
|
||||
public AnsiWindowsTerminal() throws Exception {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnsiSupported() {
|
||||
return ansiSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWeirdWrap() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,227 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved.
|
||||
*
|
||||
* This software is distributable under the BSD license. See the terms of the
|
||||
* BSD license in the documentation provided with this software.
|
||||
*/
|
||||
|
||||
package jline.internal;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Provides access to terminal line settings via <tt>stty</tt>.
|
||||
*
|
||||
* @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a>
|
||||
* @author <a href="mailto:dwkemp@gmail.com">Dale Kemp</a>
|
||||
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
|
||||
* @author <a href="mailto:jbonofre@apache.org">Jean-Baptiste Onofré</a>
|
||||
* @since 2.0
|
||||
*/
|
||||
public final class TerminalLineSettings
|
||||
{
|
||||
public static final String JLINE_STTY = "jline.stty";
|
||||
|
||||
public static final String DEFAULT_STTY = "stty";
|
||||
|
||||
public static final String JLINE_SH = "jline.sh";
|
||||
|
||||
public static final String DEFAULT_SH = "sh";
|
||||
|
||||
private String sttyCommand;
|
||||
|
||||
private String shCommand;
|
||||
|
||||
private String config;
|
||||
|
||||
private long configLastFetched;
|
||||
|
||||
public TerminalLineSettings() throws IOException, InterruptedException {
|
||||
sttyCommand = Configuration.getString(JLINE_STTY, DEFAULT_STTY);
|
||||
shCommand = Configuration.getString(JLINE_SH, DEFAULT_SH);
|
||||
config = get("-a");
|
||||
configLastFetched = System.currentTimeMillis();
|
||||
|
||||
Log.debug("Config: ", config);
|
||||
|
||||
// sanity check
|
||||
if (config.length() == 0) {
|
||||
throw new IOException(MessageFormat.format("Unrecognized stty code: {0}", config));
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void restore() throws IOException, InterruptedException {
|
||||
set("sane");
|
||||
}
|
||||
|
||||
public String get(final String args) throws IOException, InterruptedException {
|
||||
return stty(args);
|
||||
}
|
||||
|
||||
public void set(final String args) throws IOException, InterruptedException {
|
||||
stty(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Get the value of a stty property, including the management of a cache.
|
||||
* </p>
|
||||
*
|
||||
* @param name the stty property.
|
||||
* @return the stty property value.
|
||||
*/
|
||||
public int getProperty(String name) {
|
||||
assert name != null;
|
||||
// CraftBukkit start
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
// tty properties are cached so we don't have to worry too much about getting term widht/height
|
||||
if (config == null || currentTime - configLastFetched > 1000) {
|
||||
config = get("-a");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.debug("Failed to query stty ", name, "\n", e);
|
||||
}
|
||||
|
||||
// always update the last fetched time and try to parse the output
|
||||
if (currentTime - configLastFetched > 1000) {
|
||||
configLastFetched = currentTime;
|
||||
}
|
||||
|
||||
return this.getProperty(name, config);
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Parses a stty output (provided by stty -a) and return the value of a given property.
|
||||
* </p>
|
||||
*
|
||||
* @param name property name.
|
||||
* @param stty string resulting of stty -a execution.
|
||||
* @return value of the given property.
|
||||
*/
|
||||
protected static int getProperty(String name, String stty) {
|
||||
// try the first kind of regex
|
||||
Pattern pattern = Pattern.compile(name + "\\s+=\\s+([^;]*)[;\\n\\r]");
|
||||
Matcher matcher = pattern.matcher(stty);
|
||||
if (!matcher.find()) {
|
||||
// try a second kind of regex
|
||||
pattern = Pattern.compile(name + "\\s+([^;]*)[;\\n\\r]");
|
||||
matcher = pattern.matcher(stty);
|
||||
if (!matcher.find()) {
|
||||
// try a second try of regex
|
||||
pattern = Pattern.compile("(\\S*)\\s+" + name);
|
||||
matcher = pattern.matcher(stty);
|
||||
if (!matcher.find()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return parseControlChar(matcher.group(1));
|
||||
}
|
||||
|
||||
private static int parseControlChar(String str) {
|
||||
// under
|
||||
if ("<undef>".equals(str)) {
|
||||
return -1;
|
||||
}
|
||||
// octal
|
||||
if (str.charAt(0) == '0') {
|
||||
return Integer.parseInt(str, 8);
|
||||
}
|
||||
// decimal
|
||||
if (str.charAt(0) >= '1' && str.charAt(0) <= '9') {
|
||||
return Integer.parseInt(str, 10);
|
||||
}
|
||||
// control char
|
||||
if (str.charAt(0) == '^') {
|
||||
if (str.charAt(1) == '?') {
|
||||
return 127;
|
||||
} else {
|
||||
return str.charAt(1) - 64;
|
||||
}
|
||||
} else if (str.charAt(0) == 'M' && str.charAt(1) == '-') {
|
||||
if (str.charAt(2) == '^') {
|
||||
if (str.charAt(3) == '?') {
|
||||
return 127 + 128;
|
||||
} else {
|
||||
return str.charAt(3) - 64 + 128;
|
||||
}
|
||||
} else {
|
||||
return str.charAt(2) + 128;
|
||||
}
|
||||
} else {
|
||||
return str.charAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
private String stty(final String args) throws IOException, InterruptedException {
|
||||
assert args != null;
|
||||
return exec(String.format("%s %s < /dev/tty", sttyCommand, args));
|
||||
}
|
||||
|
||||
private String exec(final String cmd) throws IOException, InterruptedException {
|
||||
assert cmd != null;
|
||||
return exec(shCommand, "-c", cmd);
|
||||
}
|
||||
|
||||
private String exec(final String... cmd) throws IOException, InterruptedException {
|
||||
assert cmd != null;
|
||||
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
|
||||
Log.trace("Running: ", cmd);
|
||||
|
||||
Process p = Runtime.getRuntime().exec(cmd);
|
||||
|
||||
InputStream in = null;
|
||||
InputStream err = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
int c;
|
||||
in = p.getInputStream();
|
||||
while ((c = in.read()) != -1) {
|
||||
bout.write(c);
|
||||
}
|
||||
err = p.getErrorStream();
|
||||
while ((c = err.read()) != -1) {
|
||||
bout.write(c);
|
||||
}
|
||||
out = p.getOutputStream();
|
||||
p.waitFor();
|
||||
}
|
||||
finally {
|
||||
close(in, out, err);
|
||||
}
|
||||
|
||||
String result = bout.toString();
|
||||
|
||||
Log.trace("Result: ", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void close(final Closeable... closeables) {
|
||||
for (Closeable c : closeables) {
|
||||
try {
|
||||
c.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,286 +0,0 @@
|
||||
package org.fusesource.hawtjni.runtime;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Library{
|
||||
|
||||
static final String SLASH=System.getProperty("file.separator");
|
||||
private final String name;
|
||||
private final String version;
|
||||
private final ClassLoader classLoader;
|
||||
private boolean loaded;
|
||||
|
||||
public Library(String name){
|
||||
this(name,null,null);
|
||||
}
|
||||
|
||||
public Library(String name,Class<?> clazz){
|
||||
this(name,version(clazz),clazz.getClassLoader());
|
||||
}
|
||||
|
||||
public Library(String name,String version){
|
||||
this(name,version,null);
|
||||
}
|
||||
|
||||
public Library(String name,String version,ClassLoader classLoader){
|
||||
if(name==null){
|
||||
throw new IllegalArgumentException("name cannot be null");
|
||||
}
|
||||
this.name=name;
|
||||
this.version=version;
|
||||
this.classLoader=classLoader;
|
||||
}
|
||||
|
||||
private static String version(Class<?> clazz){
|
||||
try{
|
||||
return clazz.getPackage().getImplementationVersion();
|
||||
}catch(Throwable e){
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getOperatingSystem(){
|
||||
String name=System.getProperty("os.name").toLowerCase().trim();
|
||||
if(name.startsWith("linux")){
|
||||
return "linux";
|
||||
}
|
||||
if(name.startsWith("mac os x")){
|
||||
return "osx";
|
||||
}
|
||||
if(name.startsWith("win")){
|
||||
return "windows";
|
||||
}
|
||||
return name.replaceAll("\\W+","_");
|
||||
}
|
||||
|
||||
public static String getPlatform(){
|
||||
return getOperatingSystem()+getBitModel();
|
||||
}
|
||||
|
||||
public static int getBitModel(){
|
||||
String prop=System.getProperty("sun.arch.data.model");
|
||||
if(prop==null){
|
||||
prop=System.getProperty("com.ibm.vm.bitmode");
|
||||
}
|
||||
if(prop!=null){
|
||||
return Integer.parseInt(prop);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public synchronized void load(){
|
||||
if(this.loaded){
|
||||
return;
|
||||
}
|
||||
doLoad();
|
||||
this.loaded=true;
|
||||
}
|
||||
|
||||
private void doLoad(){
|
||||
String version=System.getProperty("library."+this.name+".version");
|
||||
if(version==null){
|
||||
version=this.version;
|
||||
}
|
||||
ArrayList<String> errors=new ArrayList();
|
||||
|
||||
String customPath=System.getProperty("library."+this.name+".path");
|
||||
if(customPath!=null){
|
||||
if(version!=null){
|
||||
if(load(errors,file(new String[]{customPath,map(this.name+"-"+version)}))){
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(load(errors,file(new String[]{customPath,map(this.name)}))){
|
||||
return;
|
||||
}
|
||||
}
|
||||
if((version!=null)&&(load(errors,this.name+getBitModel()+"-"+version))){
|
||||
return;
|
||||
}
|
||||
if((version!=null)&&(load(errors,this.name+"-"+version))){
|
||||
return;
|
||||
}
|
||||
if(load(errors,this.name)){
|
||||
return;
|
||||
}
|
||||
if(this.classLoader!=null){
|
||||
if(exractAndLoad(errors,version,customPath,getPlatformSpecifcResourcePath())){
|
||||
return;
|
||||
}
|
||||
if(exractAndLoad(errors,version,customPath,getOperatingSystemSpecifcResourcePath())){
|
||||
return;
|
||||
}
|
||||
if(exractAndLoad(errors,version,customPath,getResorucePath())){
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new UnsatisfiedLinkError("Could not load library. Reasons: "+errors.toString());
|
||||
}
|
||||
|
||||
public final String getOperatingSystemSpecifcResourcePath(){
|
||||
return getPlatformSpecifcResourcePath(getOperatingSystem());
|
||||
}
|
||||
|
||||
public final String getPlatformSpecifcResourcePath(){
|
||||
return getPlatformSpecifcResourcePath(getPlatform());
|
||||
}
|
||||
|
||||
public final String getPlatformSpecifcResourcePath(String platform){
|
||||
return "META-INF/native/"+platform+"/"+map(this.name);
|
||||
}
|
||||
|
||||
public final String getResorucePath(){
|
||||
return "META-INF/native/"+map(this.name);
|
||||
}
|
||||
|
||||
public final String getLibraryFileName(){
|
||||
return map(this.name);
|
||||
}
|
||||
|
||||
private boolean exractAndLoad(ArrayList<String> errors,String version,String customPath,String resourcePath){
|
||||
URL resource=this.classLoader.getResource(resourcePath);
|
||||
if(resource!=null){
|
||||
String libName=this.name+"-"+getBitModel();
|
||||
if(version!=null){
|
||||
libName=libName+"-"+version;
|
||||
}
|
||||
String[] libNameParts=map(libName).split("\\.");
|
||||
String prefix=libNameParts[0]+"-";
|
||||
String suffix="."+libNameParts[1];
|
||||
if(customPath!=null){
|
||||
File target=extract(errors,resource,prefix,suffix,file(new String[]{customPath}));
|
||||
if((target!=null)&&
|
||||
(load(errors,target))){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
customPath=System.getProperty("java.io.tmpdir");
|
||||
File target=extract(errors,resource,prefix,suffix,file(new String[]{customPath}));
|
||||
if((target!=null)&&
|
||||
(load(errors,target))){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private File extract(ArrayList<String> errors,URL source,String prefix,String suffix,File directory){
|
||||
File target=null;
|
||||
try{
|
||||
FileOutputStream os=null;
|
||||
InputStream is=null;
|
||||
try{
|
||||
target=File.createTempFile(prefix,suffix,directory);
|
||||
is=source.openStream();
|
||||
byte[] buffer;
|
||||
if(is!=null){
|
||||
buffer=new byte[64];
|
||||
os=new FileOutputStream(target);
|
||||
int read;
|
||||
while((read=is.read(buffer))!=-1){
|
||||
os.write(buffer,0,read);
|
||||
}
|
||||
chmod("755",target);
|
||||
}
|
||||
target.deleteOnExit();
|
||||
}finally{
|
||||
close(os,is);
|
||||
}
|
||||
}catch(Throwable e){
|
||||
if(target!=null){
|
||||
target.delete();
|
||||
}
|
||||
errors.add(e.getMessage());
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
private static void close(Closeable...pStreams){
|
||||
for(Closeable sStream : pStreams){
|
||||
if(sStream!=null){
|
||||
try{
|
||||
sStream.close();
|
||||
}catch(Exception ignore){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File file(String...paths){
|
||||
File rc=null;
|
||||
for(String path : paths){
|
||||
if(rc==null){
|
||||
rc=new File(path);
|
||||
}else{
|
||||
rc=new File(rc,path);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
private String map(String libName){
|
||||
libName=System.mapLibraryName(libName);
|
||||
String ext=".dylib";
|
||||
if(libName.endsWith(ext)){
|
||||
libName=libName.substring(0,libName.length()-ext.length())+".jnilib";
|
||||
}
|
||||
return libName;
|
||||
}
|
||||
|
||||
private boolean isStale(URL source,File target){
|
||||
if(source.getProtocol().equals("jar")){
|
||||
try{
|
||||
String[] parts=source.getFile().split(Pattern.quote("!"));
|
||||
source=new URL(parts[0]);
|
||||
}catch(MalformedURLException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File sourceFile=null;
|
||||
if(source.getProtocol().equals("file")){
|
||||
sourceFile=new File(source.getFile());
|
||||
}
|
||||
if((sourceFile!=null)&&(sourceFile.exists())&&
|
||||
(sourceFile.lastModified()>target.lastModified())){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void chmod(String permision,File path){
|
||||
if(getPlatform().startsWith("windows")){
|
||||
return;
|
||||
}
|
||||
try{
|
||||
Runtime.getRuntime().exec(new String[]{"chmod",permision,path.getCanonicalPath()}).waitFor();
|
||||
}catch(Throwable e){
|
||||
}
|
||||
}
|
||||
|
||||
private boolean load(ArrayList<String> errors,File lib){
|
||||
try{
|
||||
System.load(lib.getPath());
|
||||
return true;
|
||||
}catch(UnsatisfiedLinkError e){
|
||||
errors.add(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean load(ArrayList<String> errors,String lib){
|
||||
try{
|
||||
System.loadLibrary(lib);
|
||||
return true;
|
||||
}catch(UnsatisfiedLinkError e){
|
||||
errors.add(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user