-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure startup #4054
Restructure startup #4054
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,16 +36,21 @@ | |
* JabRef MainClass | ||
*/ | ||
public class JabRefMain extends Application { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefMain.class); | ||
|
||
private static String[] arguments; | ||
|
||
public static void main(String[] args) { | ||
arguments = args; | ||
|
||
launch(arguments); | ||
} | ||
|
||
@Override | ||
public void start(Stage mainStage) throws Exception { | ||
Platform.setImplicitExit(false); | ||
SwingUtilities.invokeLater(() -> start(arguments)); | ||
} | ||
|
||
/** | ||
* Tests if we are running an acceptable Java and terminates JabRef when we are sure the version is not supported. | ||
* This test uses the requirements for the Java version as specified in <code>gradle.build</code>. It is possible to | ||
|
@@ -93,58 +98,43 @@ private static void ensureCorrectJavaVersion() { | |
} | ||
|
||
private static void start(String[] args) { | ||
// Fail on unsupported Java versions | ||
ensureCorrectJavaVersion(); | ||
FallbackExceptionHandler.installExceptionHandler(); | ||
|
||
// Init preferences | ||
JabRefPreferences preferences = JabRefPreferences.getInstance(); | ||
final JabRefPreferences preferences = JabRefPreferences.getInstance(); | ||
Globals.prefs = preferences; | ||
// Perform Migrations | ||
// Perform checks and changes for users with a preference set from an older JabRef version. | ||
PreferencesMigrations.upgradePrefsToOrgJabRef(); | ||
PreferencesMigrations.upgradeSortOrder(); | ||
PreferencesMigrations.upgradeFaultyEncodingStrings(); | ||
PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern(); | ||
PreferencesMigrations.upgradeImportFileAndDirePatterns(); | ||
PreferencesMigrations.upgradeStoredCustomEntryTypes(); | ||
PreferencesMigrations.upgradeKeyBindingsToJavaFX(); | ||
PreferencesMigrations.addCrossRefRelatedFieldsForAutoComplete(); | ||
PreferencesMigrations.upgradeObsoleteLookAndFeels(); | ||
// Perform migrations | ||
migratePreferences(); | ||
|
||
FallbackExceptionHandler.installExceptionHandler(); | ||
|
||
ensureCorrectJavaVersion(); | ||
|
||
ProxyPreferences proxyPreferences = preferences.getProxyPreferences(); | ||
ProxyRegisterer.register(proxyPreferences); | ||
if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) { | ||
Authenticator.setDefault(new ProxyAuthenticator()); | ||
} | ||
configureProxy(preferences.getProxyPreferences()); | ||
|
||
Globals.startBackgroundTasks(); | ||
|
||
// Update handling of special fields based on preferences | ||
InternalBibtexFields | ||
.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS)); | ||
// Update name of the time stamp field based on preferences | ||
InternalBibtexFields.updateTimeStampField(Globals.prefs.getTimestampPreferences().getTimestampField()); | ||
// Update which fields should be treated as numeric, based on preferences: | ||
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); | ||
|
||
// Read list(s) of journal names and abbreviations | ||
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); | ||
|
||
/* Build list of Import and Export formats */ | ||
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), | ||
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor()); | ||
EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), | ||
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX)); | ||
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader); | ||
applyPreferences(preferences); | ||
|
||
// Process arguments | ||
ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START); | ||
|
||
// Initialize protected terms loader | ||
Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences()); | ||
|
||
// Check for running JabRef | ||
if (!allowMultipleAppInstances(args)) { | ||
return; | ||
} | ||
|
||
// See if we should shut down now | ||
if (argumentProcessor.shouldShutDown()) { | ||
Globals.shutdownThreadPools(); | ||
Platform.exit(); | ||
return; | ||
} | ||
|
||
// If not, start GUI | ||
SwingUtilities | ||
.invokeLater(() -> new JabRefGUI(argumentProcessor.getParserResults(), argumentProcessor.isBlank())); | ||
} | ||
|
||
private static boolean allowMultipleAppInstances(String[] args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename that to |
||
RemotePreferences remotePreferences = Globals.prefs.getRemotePreferences(); | ||
if (remotePreferences.useRemoteServer()) { | ||
Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort()); | ||
|
@@ -158,34 +148,60 @@ private static void start(String[] args) { | |
Globals.shutdownThreadPools(); | ||
// needed to tell JavaFx to stop | ||
Platform.exit(); | ||
return; | ||
return false; | ||
} | ||
} | ||
// we are alone, we start the server | ||
Globals.REMOTE_LISTENER.start(); | ||
} | ||
return true; | ||
} | ||
|
||
private static void applyPreferences(JabRefPreferences preferences) { | ||
// Update handling of special fields based on preferences | ||
InternalBibtexFields.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS)); | ||
// Update name of the time stamp field based on preferences | ||
InternalBibtexFields.updateTimeStampField(Globals.prefs.getTimestampPreferences().getTimestampField()); | ||
// Update which fields should be treated as numeric, based on preferences: | ||
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); | ||
|
||
// Read list(s) of journal names and abbreviations | ||
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); | ||
|
||
/* Build list of Import and Export formats */ | ||
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), | ||
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor()); | ||
EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), | ||
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX)); | ||
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader); | ||
|
||
// Initialize protected terms loader | ||
Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences()); | ||
|
||
// override used newline character with the one stored in the preferences | ||
// The preferences return the system newline character sequence as default | ||
OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE); | ||
} | ||
|
||
// See if we should shut down now | ||
if (argumentProcessor.shouldShutDown()) { | ||
Globals.shutdownThreadPools(); | ||
Platform.exit(); | ||
return; | ||
private static void configureProxy(ProxyPreferences proxyPreferences) { | ||
ProxyRegisterer.register(proxyPreferences); | ||
if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) { | ||
Authenticator.setDefault(new ProxyAuthenticator()); | ||
} | ||
|
||
// If not, start GUI | ||
SwingUtilities | ||
.invokeLater(() -> new JabRefGUI(argumentProcessor.getParserResults(), | ||
argumentProcessor.isBlank())); | ||
} | ||
|
||
@Override | ||
public void start(Stage mainStage) throws Exception { | ||
Platform.setImplicitExit(false); | ||
SwingUtilities.invokeLater(() -> start(arguments) | ||
); | ||
/** | ||
* Perform checks and changes for users with a preference set from an older JabRef version. | ||
*/ | ||
private static void migratePreferences() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to |
||
PreferencesMigrations.upgradePrefsToOrgJabRef(); | ||
PreferencesMigrations.upgradeSortOrder(); | ||
PreferencesMigrations.upgradeFaultyEncodingStrings(); | ||
PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern(); | ||
PreferencesMigrations.upgradeImportFileAndDirePatterns(); | ||
PreferencesMigrations.upgradeStoredCustomEntryTypes(); | ||
PreferencesMigrations.upgradeKeyBindingsToJavaFX(); | ||
PreferencesMigrations.addCrossRefRelatedFieldsForAutoComplete(); | ||
PreferencesMigrations.upgradeObsoleteLookAndFeels(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is appearing twice, too. Can it be moved to
shutdownCurrentInstance()
?Alternatively, change line this line to
if (!allowMultipleAppInstances(args) || argumentProcessor.shouldShutDown()) {
and remove the shutdown code from
allowMultipleAppInstances
.