Skip to content

Commit 19cc6aa

Browse files
committed
Crash reporter fixups
1 parent 81c9f96 commit 19cc6aa

File tree

9 files changed

+98
-57
lines changed

9 files changed

+98
-57
lines changed

build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ allprojects {
3737
kryoVersion = '3.0.1'
3838
commonsIoVersion = '2.4'
3939
commonsLangVersion = '3.3.2'
40+
commonsExecVersion = '1.3'
4041
guavaVersion = '18.0'
4142
jsoupVersion = '1.8.2'
4243
slf4jVersion = '1.7.12'
@@ -48,7 +49,6 @@ allprojects {
4849
}
4950

5051
repositories {
51-
mavenLocal()
5252
mavenCentral()
5353
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
5454
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
@@ -73,6 +73,7 @@ project(':editor') {
7373
compile "com.esotericsoftware:kryo:$kryoVersion"
7474
compile "commons-io:commons-io:$commonsIoVersion"
7575
compile "org.apache.commons:commons-lang3:$commonsLangVersion"
76+
compile "org.apache.commons:commons-exec:$commonsExecVersion"
7677
compile "net.java.dev.jna:jna:$jnaVersion"
7778
compile "net.java.dev.jna:platform:$jnaPlatformVersion"
7879
compile "com.google.guava:guava:$guavaVersion"
@@ -164,6 +165,7 @@ project(':tools:crash-reporter') {
164165
apply plugin: 'java'
165166

166167
dependencies {
168+
compile "org.apache.commons:commons-exec:$commonsExecVersion"
167169
testCompile "junit:junit:$junitVersion"
168170
}
169171
}

editor/build.gradle

+13-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,20 @@ task copyExtJars (dependsOn: [':plugins:vis-editor-spine:jar', ':plugins:vis-edi
7575
}
7676
}
7777

78+
task copyTools (dependsOn: [':tools:crash-reporter:jar']) {
79+
def reporter = project(':tools:crash-reporter')
7880

79-
task run(dependsOn: copyExtJars, type: JavaExec) {
81+
doLast {
82+
copy {
83+
from reporter.jar
84+
rename("(.*).jar", "crash-reporter.jar")
85+
into sourceSets.main.output.classesDir.path + '/tools/'
86+
}
87+
}
88+
}
89+
90+
//task run(dependsOn: [copyExtJars, copyTools], type: JavaExec) {
91+
task run(dependsOn: [copyExtJars], type: JavaExec) {
8092
main = mainClassName
8193
classpath = sourceSets.main.runtimeClasspath
8294
ignoreExitValue = true

editor/src/com/kotcrab/vis/editor/App.java

-44
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
import com.kotcrab.vis.editor.module.editor.AppFileAccessModule;
2222
import com.kotcrab.vis.editor.module.editor.PluginFilesAccessModule;
2323
import com.kotcrab.vis.editor.util.JarUtils;
24-
import com.kotcrab.vis.editor.util.PlatformUtils;
2524
import com.kotcrab.vis.editor.util.PublicApi;
2625
import org.slf4j.impl.SimpleLogger;
2726

2827
import javax.swing.JOptionPane;
2928
import java.io.File;
3029
import java.io.IOException;
31-
import java.lang.management.ManagementFactory;
3230
import java.lang.reflect.Field;
3331
import java.net.URL;
3432
import java.nio.charset.Charset;
35-
import java.util.List;
3633
import java.util.jar.Attributes;
3734
import java.util.jar.Manifest;
3835

@@ -160,45 +157,4 @@ private static void checkCharset () {
160157
}
161158
}
162159
}
163-
164-
static String getRestartCommand () {
165-
List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
166-
StringBuilder vmArgsOneLine = new StringBuilder();
167-
for (String arg : vmArguments) {
168-
if (arg.contains("-agentlib") == false)
169-
vmArgsOneLine.append(arg).append(" ");
170-
}
171-
172-
final StringBuilder cmd = new StringBuilder(PlatformUtils.getJavaBinPath() + " " + vmArgsOneLine);
173-
174-
String[] mainCommand = System.getProperty("sun.java.command").split(" ");
175-
176-
if (mainCommand[0].endsWith(".jar"))
177-
cmd.append("-jar " + new File(mainCommand[0]).getPath());
178-
else
179-
cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]);
180-
181-
for (int i = 1; i < mainCommand.length; i++) {
182-
cmd.append(" ");
183-
cmd.append(mainCommand[i]);
184-
}
185-
186-
//if launching from idea, not in debug mode
187-
String ideaLauncher = "-Didea.launcher.bin.path=";
188-
int ideaLauncherStart = cmd.indexOf(ideaLauncher);
189-
if (ideaLauncherStart != -1) {
190-
cmd.insert(ideaLauncherStart + ideaLauncher.length(), "\"");
191-
cmd.insert(cmd.indexOf("-cp ", ideaLauncherStart) - 1, "\"");
192-
}
193-
194-
return cmd.toString();
195-
}
196-
197-
static void startNewInstance () {
198-
try {
199-
Runtime.getRuntime().exec(getRestartCommand());
200-
} catch (Exception e) {
201-
Log.exception(e);
202-
}
203-
}
204160
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.kotcrab.vis.editor;
2+
3+
import com.kotcrab.vis.editor.util.PlatformUtils;
4+
import org.apache.commons.exec.CommandLine;
5+
import org.apache.commons.exec.DefaultExecuteResultHandler;
6+
import org.apache.commons.exec.DefaultExecutor;
7+
import org.apache.commons.exec.PumpStreamHandler;
8+
9+
import java.io.File;
10+
import java.lang.management.ManagementFactory;
11+
import java.util.List;
12+
13+
public class ApplicationUtils {
14+
public static String getRestartCommand () {
15+
List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
16+
StringBuilder vmArgsOneLine = new StringBuilder();
17+
for (String arg : vmArguments) {
18+
if (arg.contains("-agentlib") == false)
19+
vmArgsOneLine.append(arg).append(" ");
20+
}
21+
22+
final StringBuilder cmd = new StringBuilder(PlatformUtils.getJavaBinPath() + " " + vmArgsOneLine);
23+
24+
String[] mainCommand = System.getProperty("sun.java.command").split(" ");
25+
26+
if (mainCommand[0].endsWith(".jar"))
27+
cmd.append("-jar " + new File(mainCommand[0]).getPath());
28+
else
29+
cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]);
30+
31+
for (int i = 1; i < mainCommand.length; i++) {
32+
cmd.append(" ");
33+
cmd.append(mainCommand[i]);
34+
}
35+
36+
//if launching from idea, not in debug mode
37+
String ideaLauncher = "-Didea.launcher.bin.path=";
38+
int ideaLauncherStart = cmd.indexOf(ideaLauncher);
39+
if (ideaLauncherStart != -1) {
40+
cmd.insert(ideaLauncherStart + ideaLauncher.length(), "\"");
41+
cmd.insert(cmd.indexOf("-cp ", ideaLauncherStart) - 1, "\"");
42+
}
43+
44+
return cmd.toString();
45+
}
46+
47+
public static void startNewInstance () {
48+
try {
49+
CommandLine cmdLine = CommandLine.parse(getRestartCommand());
50+
DefaultExecutor executor = new DefaultExecutor();
51+
executor.setStreamHandler(new PumpStreamHandler(null, null, null));
52+
executor.execute(cmdLine, new DefaultExecuteResultHandler());
53+
} catch (Exception e) {
54+
Log.exception(e);
55+
}
56+
}
57+
}

editor/src/com/kotcrab/vis/editor/Editor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public void cancel () {
341341
}
342342

343343
private void exit (boolean restartAfterExit) {
344-
if (restartAfterExit) App.startNewInstance();
344+
if (restartAfterExit) ApplicationUtils.startNewInstance();
345345
Gdx.app.exit();
346346
}
347347

editor/src/com/kotcrab/vis/editor/Log.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import com.kotcrab.vis.editor.util.PublicApi;
2525
import com.kotcrab.vis.editor.util.vis.CrashReporter;
2626
import com.kotcrab.vis.ui.widget.file.FileUtils;
27+
import org.apache.commons.exec.CommandLine;
28+
import org.apache.commons.exec.DefaultExecutor;
29+
import org.apache.commons.exec.PumpStreamHandler;
2730

2831
import java.io.*;
2932
import java.text.SimpleDateFormat;
@@ -82,10 +85,14 @@ public static void init () {
8285
if (new File(REPORTING_TOOL_JAR).exists() == false) {
8386
Log.warn("Crash reporting tool not present, skipping crash report sending.");
8487
} else {
85-
Runtime.getRuntime().exec(PlatformUtils.getJavaBinPath() + " " +
86-
"-jar \"" + REPORTING_TOOL_JAR + "\" " +
87-
"\"" + App.getRestartCommand().replace("\"", "%") + "\" " +
88-
"\"" + crashReport.getAbsolutePath() + "\"");
88+
CommandLine cmdLine = new CommandLine(PlatformUtils.getJavaBinPath());
89+
cmdLine.addArgument("-jar");
90+
cmdLine.addArgument(REPORTING_TOOL_JAR);
91+
cmdLine.addArgument(ApplicationUtils.getRestartCommand().replace("\"", "%"));
92+
cmdLine.addArgument(crashReport.getAbsolutePath());
93+
DefaultExecutor executor = new DefaultExecutor();
94+
executor.setStreamHandler(new PumpStreamHandler(null, null, null));
95+
executor.execute(cmdLine);
8996
}
9097
} catch (IOException ex) {
9198
ex.printStackTrace();

tools/crash-reporter/build.gradle

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ archivesBaseName = "vis-editor-crash-reporter"
66
sourceCompatibility = 1.8
77
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
88

9-
sourceSets.main.java.srcDirs = [ "src/" ]
9+
sourceSets.main.java.srcDirs = ["src/"]
1010

1111
processResources {
12-
from ('src/') {
13-
exclude ('**/*.java')
12+
from('src/') {
13+
exclude('**/*.java')
1414
}
1515
}
1616

@@ -30,4 +30,8 @@ jar {
3030
"Main-Class": 'com.kotcrab.vis.editor.CrashReporter'
3131
)
3232
}
33+
34+
from {
35+
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
36+
}
3337
}

tools/crash-reporter/src/com/kotcrab/vis/editor/CrashReporter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import javafx.scene.image.Image;
1313
import javafx.scene.layout.HBox;
1414
import javafx.stage.Stage;
15+
import org.apache.commons.exec.CommandLine;
16+
import org.apache.commons.exec.DefaultExecutor;
1517

1618
import java.awt.Desktop;
1719
import java.io.*;
@@ -96,7 +98,9 @@ private void handleShowReport (ActionEvent event) throws IOException {
9698
private void restart () {
9799
new Thread(() -> {
98100
try {
99-
Runtime.getRuntime().exec(restartCommand);
101+
CommandLine cmdLine = CommandLine.parse(restartCommand);
102+
DefaultExecutor executor = new DefaultExecutor();
103+
executor.execute(cmdLine);
100104
} catch (IOException e) {
101105
e.printStackTrace();
102106
}

tools/crash-reporter/src/com/kotcrab/vis/editor/crash-reporter-layout.fxml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<?import javafx.scene.layout.VBox?>
1212
<?import javafx.scene.text.Font?>
1313

14-
1514
<VBox xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.kotcrab.vis.editor.CrashReporter">
1615
<children>
1716
<Label text="VisEditor Crash Reporter">
@@ -29,7 +28,7 @@
2928
<children>
3029
<Button mnemonicParsing="false" onAction="#handleSend" text="Send" />
3130
<Button mnemonicParsing="false" onAction="#handleRestart" text="Restart" />
32-
<Button mnemonicParsing="false" onAction="#handleSendAndRestart" prefWidth="108.0" text="Send and Restart" />
31+
<Button mnemonicParsing="false" onAction="#handleSendAndRestart" prefWidth="108.0" text="Send and Restart" HBox.hgrow="SOMETIMES" />
3332
</children>
3433
<BorderPane.margin>
3534
<Insets />

0 commit comments

Comments
 (0)