Pass classpath by environment variable
This commit is contained in:
@@ -621,6 +621,11 @@ public final class LauncherHelper {
|
|||||||
|
|
||||||
LOG.info("Launched process: " + command);
|
LOG.info("Launched process: " + command);
|
||||||
|
|
||||||
|
String classpath = process.getClasspath();
|
||||||
|
if (classpath != null) {
|
||||||
|
LOG.info("Process CLASSPATH: " + classpath);
|
||||||
|
}
|
||||||
|
|
||||||
if (showLogs)
|
if (showLogs)
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
logWindow = new LogWindow();
|
logWindow = new LogWindow();
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ public class DefaultLauncher extends Launcher {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedProcess launch() throws IOException, InterruptedException {
|
public ManagedProcess launch() throws IOException, InterruptedException {
|
||||||
File nativeFolder = null;
|
File nativeFolder;
|
||||||
if (options.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER) {
|
if (options.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER) {
|
||||||
nativeFolder = repository.getNativeDirectory(version.getId(), options.getJava().getPlatform());
|
nativeFolder = repository.getNativeDirectory(version.getId(), options.getJava().getPlatform());
|
||||||
} else {
|
} else {
|
||||||
@@ -362,7 +362,15 @@ public class DefaultLauncher extends Launcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
|
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
|
||||||
List<String> rawCommandLine = generateCommandLine(nativeFolder).asList();
|
List<String> rawCommandLine = generateCommandLine(nativeFolder).asMutableList();
|
||||||
|
|
||||||
|
// Pass classpath using the environment variable, to reduce the command length
|
||||||
|
String classpath = null;
|
||||||
|
final int cpIndex = rawCommandLine.indexOf("-cp");
|
||||||
|
if (cpIndex >= 0 && cpIndex < rawCommandLine.size() - 1) {
|
||||||
|
rawCommandLine.remove(cpIndex); // remove "-cp"
|
||||||
|
classpath = rawCommandLine.remove(cpIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (rawCommandLine.stream().anyMatch(StringUtils::isBlank)) {
|
if (rawCommandLine.stream().anyMatch(StringUtils::isBlank)) {
|
||||||
throw new IllegalStateException("Illegal command line " + rawCommandLine);
|
throw new IllegalStateException("Illegal command line " + rawCommandLine);
|
||||||
@@ -388,13 +396,14 @@ public class DefaultLauncher extends Launcher {
|
|||||||
}
|
}
|
||||||
String appdata = options.getGameDir().getAbsoluteFile().getParent();
|
String appdata = options.getGameDir().getAbsoluteFile().getParent();
|
||||||
if (appdata != null) builder.environment().put("APPDATA", appdata);
|
if (appdata != null) builder.environment().put("APPDATA", appdata);
|
||||||
|
if (classpath != null) builder.environment().put("CLASSPATH", classpath);
|
||||||
builder.environment().putAll(getEnvVars());
|
builder.environment().putAll(getEnvVars());
|
||||||
process = builder.start();
|
process = builder.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ProcessCreationException(e);
|
throw new ProcessCreationException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagedProcess p = new ManagedProcess(process, rawCommandLine);
|
ManagedProcess p = new ManagedProcess(process, rawCommandLine, classpath);
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
startMonitors(p, listener, daemon);
|
startMonitors(p, listener, daemon);
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ public final class CommandBuilder {
|
|||||||
return raw.stream().map(i -> i.arg).collect(Collectors.toList());
|
return raw.stream().map(i -> i.arg).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> asMutableList() {
|
||||||
|
return raw.stream().map(i -> i.arg).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
}
|
||||||
|
|
||||||
private static class Item {
|
private static class Item {
|
||||||
String arg;
|
String arg;
|
||||||
boolean parse;
|
boolean parse;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class ManagedProcess {
|
|||||||
|
|
||||||
private final Process process;
|
private final Process process;
|
||||||
private final List<String> commands;
|
private final List<String> commands;
|
||||||
|
private final String classpath;
|
||||||
private final Map<String, Object> properties = new HashMap<>();
|
private final Map<String, Object> properties = new HashMap<>();
|
||||||
private final Queue<String> lines = new ConcurrentLinkedQueue<>();
|
private final Queue<String> lines = new ConcurrentLinkedQueue<>();
|
||||||
private final List<Thread> relatedThreads = new LinkedList<>();
|
private final List<Thread> relatedThreads = new LinkedList<>();
|
||||||
@@ -44,6 +45,20 @@ public class ManagedProcess {
|
|||||||
public ManagedProcess(Process process, List<String> commands) {
|
public ManagedProcess(Process process, List<String> commands) {
|
||||||
this.process = process;
|
this.process = process;
|
||||||
this.commands = Collections.unmodifiableList(new ArrayList<>(commands));
|
this.commands = Collections.unmodifiableList(new ArrayList<>(commands));
|
||||||
|
this.classpath = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param process the raw system process that this instance manages.
|
||||||
|
* @param commands the command line of {@code process}.
|
||||||
|
* @param classpath the classpath of java process
|
||||||
|
*/
|
||||||
|
public ManagedProcess(Process process, List<String> commands, String classpath) {
|
||||||
|
this.process = process;
|
||||||
|
this.commands = Collections.unmodifiableList(new ArrayList<>(commands));
|
||||||
|
this.classpath = classpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,6 +79,15 @@ public class ManagedProcess {
|
|||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The classpath.
|
||||||
|
*
|
||||||
|
* @return classpath
|
||||||
|
*/
|
||||||
|
public String getClasspath() {
|
||||||
|
return classpath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To save some information you need.
|
* To save some information you need.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user