Compare commits

..
3 Commits
Author SHA1 Message Date
huangyuhui ca627b8a2d Update Gradle 2017-10-18 19:27:35 +08:00
huanghongxun a0c619a747 Ignore RejectedExecutionException 2017-10-11 20:03:17 +08:00
huanghongxun 5386ae3736 Removed log4j support 2017-10-11 19:54:08 +08:00
5 changed files with 60 additions and 32 deletions

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
if (buildnumber == null)
buildnumber = System.getenv("BUILD_NUMBER")
if (buildnumber == null)
buildnumber = "40"
buildnumber = "42"
def versionroot = System.getenv("VERSION_ROOT")
if (versionroot == null)
@@ -77,7 +77,7 @@ public class LaunchingUIDaemon {
PipedOutputStream os = new PipedOutputStream();
monitor.setTag(obj);
try {
logHandler = new Log4jHandler(monitor, os);
logHandler = new Log4jHandler(monitor, os, false);
logHandler.addForbiddenToken(obj.getLoginResult().getAccessToken(), "<access token>");
logHandler.addForbiddenToken(obj.getLoginResult().getSession(), "<session>");
logHandler.addForbiddenToken(obj.getLoginResult().getUserId(), "<uuid>");
@@ -177,9 +177,6 @@ public class LaunchingUIDaemon {
public void accept(PrintlnEvent t) {
String log = t.getLine();
if (!t.isError() && logHandler != null) {
if (!log.trim().startsWith("<")) { // without logging configuration.
log = "<![CDATA[" + log.replace("]]>", "") + "]]>";
}
logHandler.newLogLine(log + C.LINE_SEPARATOR);
}
else System.err.println(t.getLine());
@@ -29,6 +29,7 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.xml.parsers.ParserConfigurationException;
import org.jackhuang.hmcl.api.HMCLApi;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.api.event.process.JavaProcessStoppedEvent;
import org.jackhuang.hmcl.api.func.Consumer;
import org.jackhuang.hmcl.ui.LogWindow;
@@ -54,12 +55,14 @@ public class Log4jHandler extends Thread implements Consumer<JavaProcessStoppedE
List<Pair<String, String>> forbiddenTokens = new LinkedList<>();
AtomicBoolean interrupted = new AtomicBoolean(false);
ExecutorService executorService = Executors.newSingleThreadExecutor();
boolean enabled = true;
public Log4jHandler(ProcessMonitor monitor, PipedOutputStream outputStream) throws ParserConfigurationException, IOException, SAXException {
public Log4jHandler(ProcessMonitor monitor, PipedOutputStream outputStream, boolean enabled) throws ParserConfigurationException, IOException, SAXException {
reader = XMLReaderFactory.createXMLReader();
inputStream = new PipedInputStream(outputStream);
this.outputStream = outputStream;
this.monitor = monitor;
this.enabled = enabled;
HMCLApi.EVENT_BUS.channel(JavaProcessStoppedEvent.class).register((Consumer<JavaProcessStoppedEvent>) this);
}
@@ -72,7 +75,8 @@ public class Log4jHandler extends Thread implements Consumer<JavaProcessStoppedE
public void run() {
try {
setName("log4j-handler");
newLogLine("<output>");
if (enabled)
newLogLine("<output>");
reader.setContentHandler(new Log4jHandlerImpl());
reader.parse(new InputSource(inputStream));
} catch (InterruptedIOException e) {
@@ -89,14 +93,24 @@ public class Log4jHandler extends Thread implements Consumer<JavaProcessStoppedE
if (!interrupted.get())
return;
if (t.getSource() == monitor) {
executorService.submit(() -> {
if (!interrupted.get()) {
newLogLine("</output>").get();
outputStream.close();
join();
}
return null;
});
try {
executorService.submit(() -> {
if (!interrupted.get()) {
if (enabled) {
Future f = newLogLine("</output>");
if (f != null)
f.get();
}
outputStream.close();
join();
}
return null;
}).get();
} catch (Exception e) {
HMCLog.err("Please contact author", e);
} finally {
executorService.shutdown();
}
}
}
@@ -112,18 +126,29 @@ public class Log4jHandler extends Thread implements Consumer<JavaProcessStoppedE
* @param content The content to be written to the log
*/
public Future newLogLine(String content) {
return executorService.submit(() -> {
try {
outputStream.write(content
.replace("log4j:Event", "log4j_Event")
.replace("log4j:Message", "log4j_Message")
.replace("log4j:Throwable", "log4j_Throwable")
.getBytes());
outputStream.flush();
} catch (IOException ignore) { // won't happen
throw new Error(ignore);
}
});
try {
return executorService.submit(() -> {
if (enabled)
try {
String log = content;
if (!log.trim().startsWith("<")) { // without logging configuration.
log = "<![CDATA[" + log.replace("]]>", "") + "]]>";
}
outputStream.write(log
.replace("log4j:Event", "log4j_Event")
.replace("log4j:Message", "log4j_Message")
.replace("log4j:Throwable", "log4j_Throwable")
.getBytes());
outputStream.flush();
} catch (IOException ignore) { // won't happen
throw new Error(ignore);
}
else
printlnImpl(content, Level.guessLevel(content));
});
} catch (RejectedExecutionException e) {
return null;
}
}
class Log4jHandlerImpl extends DefaultHandler {
@@ -180,10 +205,14 @@ public class Log4jHandler extends Thread implements Consumer<JavaProcessStoppedE
}
public void println(String message, Level l) {
for (Pair<String, String> entry : forbiddenTokens)
message = message.replace(entry.key, entry.value);
if (LogWindow.outputStream != null)
LogWindow.outputStream.log(message, l);
printlnImpl(message, l);
}
}
private void printlnImpl(String message, Level l) {
for (Pair<String, String> entry : forbiddenTokens)
message = message.replace(entry.key, entry.value);
if (LogWindow.outputStream != null)
LogWindow.outputStream.log(message, l);
}
}
@@ -115,12 +115,14 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
list.add("-Dminecraft.client.jar=" + version.getJar(service.baseDirectory()).getAbsolutePath());
/*
if (version.logging != null && version.logging.containsKey("client")) {
LoggingInfo logging = version.logging.get("client");
File file = service.asset().getLoggingObject(version.getAssetsIndex().getId(), logging);
if (file.exists())
list.add(logging.argument.replace("${path}", file.getAbsolutePath()));
}
*/
}
private final IAssetProvider DEFAULT_ASSET_PROVIDER = (t, allow) -> {
+1 -1
View File
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-4.2.1-bin.zip