Fixed several launch bugs.

- Program exiting before GUI launch.
- Moved java modal warnings to compile phase rather than version selection phase.
- Removed some unused commented code and methods.
This commit is contained in:
Nothixal 2024-01-15 20:24:34 +11:00 committed by md_5
parent 135c113102
commit 3591c955f2
No known key found for this signature in database
GPG key ID: E8E901AC7C617C11
6 changed files with 53 additions and 53 deletions

View file

@ -33,25 +33,25 @@ public class Bootstrap
} }
} }
JavaVersion javaVersion = JavaVersion.getCurrentVersion();
if ( javaVersion.isUnknown() )
{
System.err.println( "*** WARNING *** Unsupported Java detected (" + System.getProperty( "java.class.version" ) + "). BuildTools has only been tested up to Java 21. Use of development Java versions is not supported." );
System.err.println( "*** WARNING *** You may use java -version to double check your Java version." );
}
long memoryMb = Runtime.getRuntime().maxMemory() >> 20;
if ( memoryMb < 448 ) // Older JVMs (including Java 8) report less than Xmx here. Allow some slack for people actually using -Xmx512M
{
System.err.println( "BuildTools requires at least 512M of memory to run (1024M recommended), but has only detected " + memoryMb + "M." );
System.err.println( "This can often occur if you are running a 32-bit system, or one with low RAM." );
System.err.println( "Please re-run BuildTools with manually specified memory, e.g: java -Xmx1024M -jar BuildTools.jar " + Joiner.on( ' ' ).join( args ) );
System.exit( 1 );
}
if ( !guiEnabled ) if ( !guiEnabled )
{ {
JavaVersion javaVersion = JavaVersion.getCurrentVersion();
if ( javaVersion.isUnknown() )
{
System.err.println( "*** WARNING *** Unsupported Java detected (" + System.getProperty( "java.class.version" ) + "). BuildTools has only been tested up to Java 21. Use of development Java versions is not supported." );
System.err.println( "*** WARNING *** You may use java -version to double check your Java version." );
}
long memoryMb = Runtime.getRuntime().maxMemory() >> 20;
if ( memoryMb < 448 ) // Older JVMs (including Java 8) report less than Xmx here. Allow some slack for people actually using -Xmx512M
{
System.err.println( "BuildTools requires at least 512M of memory to run (1024M recommended), but has only detected " + memoryMb + "M." );
System.err.println( "This can often occur if you are running a 32-bit system, or one with low RAM." );
System.err.println( "Please re-run BuildTools with manually specified memory, e.g: java -Xmx1024M -jar BuildTools.jar " + Joiner.on( ' ' ).join( args ) );
System.exit( 1 );
}
Builder.logOutput( System.out, System.err ); Builder.logOutput( System.out, System.err );
Builder.main( args ); Builder.main( args );
} }

View file

@ -95,7 +95,7 @@ public final class BuildData {
* *
* @param buildSettings the buildSettings used to get the current selected spigot version * @param buildSettings the buildSettings used to get the current selected spigot version
*/ */
public void updateJavaExecutable(final BuildSettings buildSettings) { public CompletableFuture<Boolean> updateJavaExecutable(final BuildSettings buildSettings, boolean showModal) {
String checkVersion = buildSettings.getVersion(); String checkVersion = buildSettings.getVersion();
if (checkVersion.equals("experimental")) { if (checkVersion.equals("experimental")) {
String mostRecent = versions.get(2); String mostRecent = versions.get(2);
@ -106,12 +106,7 @@ public final class BuildData {
checkVersion = mostRecent; checkVersion = mostRecent;
} }
builds.get(checkVersion).whenComplete((BuildInfo info, Throwable throwable) -> { return builds.get(checkVersion).thenApply((BuildInfo info) -> {
if (throwable != null) {
MessageModal.displayError(Utils.getReadableStacktrace(throwable));
return;
}
if (info.getJavaVersions() == null) { if (info.getJavaVersions() == null) {
info.setJavaVersions(new int[]{ info.setJavaVersions(new int[]{
JavaVersion.JAVA_7.getVersion(), JavaVersion.JAVA_7.getVersion(),
@ -125,7 +120,7 @@ public final class BuildData {
final JavaInstallation primary = javaInstallationManager.getPrimaryInstallation(); final JavaInstallation primary = javaInstallationManager.getPrimaryInstallation();
if (primary.getVersion().getClassFileMajorVersion() >= min.getVersion() && primary.getVersion().getClassFileMajorVersion() <= max.getVersion()) { if (primary.getVersion().getClassFileMajorVersion() >= min.getVersion() && primary.getVersion().getClassFileMajorVersion() <= max.getVersion()) {
javaInstallationManager.setSelectedInstallation(primary); javaInstallationManager.setSelectedInstallation(primary);
return; return true;
} }
JavaInstallation newInstallation = null; JavaInstallation newInstallation = null;
@ -143,27 +138,34 @@ public final class BuildData {
} }
if (newInstallation == null) { if (newInstallation == null) {
String style = Utils.getFileContentsFromResource("web/reset.css"); if (showModal) {
String message = Utils.getFileContentsFromResource("web/insufficient_java.html"); String style = Utils.getFileContentsFromResource("web/reset.css");
message = message.replace("%STYLESHEET%", "<style>" + style + "</style>"); String message = Utils.getFileContentsFromResource("web/insufficient_java.html");
message = message.replace("%JAVA_VERSION_MIN%", min.getName()); message = message.replace("%STYLESHEET%", "<style>" + style + "</style>");
message = message.replace("%JAVA_VERSION_MAX%", max.getName()); message = message.replace("%JAVA_VERSION_MIN%", min.getName());
message = message.replace("%VERSION%", buildSettings.getVersion()); message = message.replace("%JAVA_VERSION_MAX%", max.getName());
message = message.replace("%OPENJDK_LINK%", Constants.DOWNLOAD_OPENJDK); message = message.replace("%VERSION%", buildSettings.getVersion());
message = message.replace("%AZUL_LINK%", Constants.DOWNLOAD_AZUL); message = message.replace("%OPENJDK_LINK%", Constants.DOWNLOAD_OPENJDK);
message = message.replace("%ORACLE_LINK%", Constants.DOWNLOAD_ORACLE); message = message.replace("%AZUL_LINK%", Constants.DOWNLOAD_AZUL);
message = message.replace("%ORACLE_LINK%", Constants.DOWNLOAD_ORACLE);
MessageModal.displayError(message); MessageModal.displayError(message);
return; }
return false;
} }
javaInstallationManager.setSelectedInstallation(newInstallation); javaInstallationManager.setSelectedInstallation(newInstallation);
return true;
}).whenComplete((Boolean completed, Throwable throwable) -> {
if (throwable != null) {
MessageModal.displayError(Utils.getReadableStacktrace(throwable));
}
}); });
} }
/** /**
* @return a copy of the versions list. * @return a copy of the versions list.
* */ */
public List<String> getVersions() { public List<String> getVersions() {
return new ArrayList<>(versions); return new ArrayList<>(versions);
} }

View file

@ -1,6 +1,7 @@
package org.spigotmc.gui.panels.general; package org.spigotmc.gui.panels.general;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutionException;
import org.spigotmc.gui.BuildToolsProcess; import org.spigotmc.gui.BuildToolsProcess;
import org.spigotmc.gui.attributes.Lockable; import org.spigotmc.gui.attributes.Lockable;
import org.spigotmc.gui.data.BuildSettings; import org.spigotmc.gui.data.BuildSettings;
@ -149,6 +150,15 @@ public class GeneralPanel extends JPanel implements Lockable {
} }
private void buildButtonActionPerformed(ActionEvent event) { private void buildButtonActionPerformed(ActionEvent event) {
try {
if (!buildData.updateJavaExecutable(buildSettings, true).get()) {
return;
}
} catch (InterruptedException | ExecutionException e) {
MessageModal.displayError(Utils.getReadableStacktrace(e));
return;
}
cancelButton.setEnabled(true); cancelButton.setEnabled(true);
consolePane.updateConsoleAreaText(new ArrayList<>()); consolePane.updateConsoleAreaText(new ArrayList<>());

View file

@ -193,7 +193,7 @@ public class SettingsPanel extends JPanel implements Lockable, Themeable {
buildSettings.setVersion(selected); buildSettings.setVersion(selected);
if (!buildSettings.isOverrideJavaExecutable()) { if (!buildSettings.isOverrideJavaExecutable()) {
buildData.updateJavaExecutable(buildSettings); buildData.updateJavaExecutable(buildSettings, false);
} }
consolePane.updateConsoleAreaText(buildData.generatePreCompilationText(buildSettings)); consolePane.updateConsoleAreaText(buildData.generatePreCompilationText(buildSettings));

View file

@ -441,7 +441,7 @@ public class OptionsPanel extends JPanel {
this.detectJavaButton.setEnabled(false); this.detectJavaButton.setEnabled(false);
this.javaSelectionButton.setEnabled(false); this.javaSelectionButton.setEnabled(false);
buildSettings.setOverrideJavaExecutable(false); buildSettings.setOverrideJavaExecutable(false);
buildData.updateJavaExecutable(buildSettings); buildData.updateJavaExecutable(buildSettings, false);
} }
// Text Fields // Text Fields

View file

@ -91,19 +91,7 @@ public class Utils {
} }
public static boolean isRanFromCommandLine() { public static boolean isRanFromCommandLine() {
// If a console is available, we're definitely running from command line. return System.console() != null;
if (System.console() != null) {
return true;
}
// Naive check for running from command line on Windows.
// If ran from command line or inside most IDEs, the SESSIONNAME environment variable will be set to "Console".
// It will be unset when double-clicking the .jar or when using other OSes
if ("Console".equals(System.getenv("SESSIONNAME"))) {
return true;
}
return false;
} }
public static boolean isValidPR(String input, Repository repository) { public static boolean isValidPR(String input, Repository repository) {