forked from xjboss/KCauldronX
升级依赖版本
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user