Skip to content
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

Removed mainapplication layer #10895

Merged
merged 9 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deployment-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
shell: bash
run: |
jpackage \
--module org.jabref/org.jabref.cli.Launcher \
--module org.jabref/org.jabref.Launcher \
--module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \
--add-modules org.jabref,org.jabref.merged.module \
--dest build/distribution \
Expand All @@ -129,7 +129,7 @@ jobs:
shell: bash
run: |
jpackage \
--module org.jabref/org.jabref.cli.Launcher \
--module org.jabref/org.jabref.Launcher \
--module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \
--add-modules org.jabref,org.jabref.merged.module \
--dest build/distribution \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
shell: bash
run: |
jpackage \
--module org.jabref/org.jabref.cli.Launcher \
--module org.jabref/org.jabref.Launcher \
--module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \
--add-modules org.jabref,org.jabref.merged.module \
--dest build/distribution \
Expand All @@ -141,7 +141,7 @@ jobs:
shell: bash
run: |
jpackage \
--module org.jabref/org.jabref.cli.Launcher \
--module org.jabref/org.jabref.Launcher \
--module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \
--add-modules org.jabref,org.jabref.merged.module \
--dest build/distribution \
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ java {
}

application {
mainClass.set('org.jabref.cli.Launcher')
mainClass.set('org.jabref.Launcher')
mainModule.set('org.jabref')
}

Expand Down
2 changes: 1 addition & 1 deletion docs/code-howtos/jpackage.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Sometimes issues with modularity only arise in the installed version and do not
3. Modify the `build\image\JabRef\runtime\bin\Jabref.bat` file, replace the last line with

```shell
pushd %DIR% & %JAVA_EXEC% -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -p "%~dp0/../app" -m org.jabref/org.jabref.cli.Launcher %* & popd
pushd %DIR% & %JAVA_EXEC% -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -p "%~dp0/../app" -m org.jabref/org.jabref.Launcher %* & popd
```

4. Open your IDE and add a "Remote Debugging Configuration" for `localhost:8000`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Always make sure your Eclipse installation us up to date.
3. Open or import the existing project in Eclipse as Java project.
* Remark: Importing it as gradle project will not work correctly.
* Refresh the project in Eclipse
4. Create a run/debug configuration for the main class `org.jabref.cli.Launcher` and/or for `org.jabref.gui.JabRefMain` (both can be used equivalently)
4. Create a run/debug configuration for the main class `org.jabref.Launcher` and/or for `org.jabref.gui.JabRefMain` (both can be used equivalently)
* Remark: The run/debug configuration needs to be added by right-clicking the class (e.g. `Launcher` or JabRefMain) otherwise it will not work.

![Creating the run/debug configuration by right-clicking on the class](../../images/eclipse-create-run-config.png)
Expand Down
2 changes: 1 addition & 1 deletion snap/local/JabRef-launcher
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/sh
DIR="$SNAP/lib/runtime/bin"
"$DIR/java" -p "$DIR/../app" -m org.jabref/org.jabref.cli.Launcher "$@"
"$DIR/java" -p "$DIR/../app" -m org.jabref/org.jabref.Launcher "$@"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.cli;
package org.jabref;

import java.io.File;
import java.io.IOException;
Expand All @@ -11,8 +11,10 @@
import java.util.List;
import java.util.Map;

import org.jabref.cli.ArgumentProcessor;
import org.jabref.cli.JabRefCLI;
import org.jabref.gui.Globals;
import org.jabref.gui.MainApplication;
import org.jabref.gui.JabRefGUI;
import org.jabref.logic.UiCommand;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.predatory.PredatoryJournalListLoader;
Expand Down Expand Up @@ -47,18 +49,16 @@
*/
public class Launcher {
private static Logger LOGGER;
private static String[] ARGUMENTS;
private static boolean isDebugEnabled;

public static void main(String[] args) {
routeLoggingToSlf4J();
ARGUMENTS = args;

// We must configure logging as soon as possible, which is why we cannot wait for the usual
// argument parsing workflow to parse logging options .e.g. --debug
JabRefCLI jabRefCLI;
try {
jabRefCLI = new JabRefCLI(ARGUMENTS);
jabRefCLI = new JabRefCLI(args);
isDebugEnabled = jabRefCLI.isDebugLogging();
} catch (ParseException e) {
isDebugEnabled = false;
Expand All @@ -73,7 +73,7 @@ public static void main(String[] args) {
final JabRefPreferences preferences = JabRefPreferences.getInstance();

// Early exit in case another instance is already running
if (!handleMultipleAppInstances(ARGUMENTS, preferences.getRemotePreferences())) {
if (!handleMultipleAppInstances(args, preferences.getRemotePreferences())) {
return;
}

Expand All @@ -91,7 +91,7 @@ public static void main(String[] args) {

// Process arguments
ArgumentProcessor argumentProcessor = new ArgumentProcessor(
ARGUMENTS,
args,
ArgumentProcessor.Mode.INITIAL_START,
preferences,
fileUpdateMonitor,
Expand All @@ -105,7 +105,8 @@ public static void main(String[] args) {
}

List<UiCommand> uiCommands = new ArrayList<>(argumentProcessor.getUiCommands());
MainApplication.main(uiCommands, preferences, fileUpdateMonitor, ARGUMENTS);
JabRefGUI.setup(uiCommands, preferences, fileUpdateMonitor);
JabRefGUI.launch(JabRefGUI.class, args);
} catch (ParseException e) {
LOGGER.error("Problem parsing arguments", e);
JabRefCLI.printUsage(preferences);
Expand Down Expand Up @@ -148,7 +149,7 @@ private static void addLogToDisk() {
}

private static void initializeLogger() {
LOGGER = LoggerFactory.getLogger(MainApplication.class);
LOGGER = LoggerFactory.getLogger(JabRefGUI.class);
}

/**
Expand All @@ -167,7 +168,7 @@ private static boolean handleMultipleAppInstances(String[] args, RemotePreferenc
if (remoteClient.sendCommandLineArguments(args)) {
// So we assume it's all taken care of, and quit.
LOGGER.debug("Arguments passed on to running JabRef instance.");
System.out.println(Localization.lang("Arguments passed on to running JabRef instance. Shutting down."));
LOGGER.info(Localization.lang("Arguments passed on to running JabRef instance. Shutting down."));
return false;
} else {
LOGGER.warn("Could not communicate with other running JabRef instance.");
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.OutputPrinter;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.SearchBasedFetcher;
Expand Down Expand Up @@ -156,8 +155,7 @@ private Optional<ParserResult> importFile(String argument) {
Optional<ParserResult> importResult = importFile(file, importFormat);
importResult.ifPresent(result -> {
if (result.hasWarnings()) {
OutputPrinter printer = new SystemOutputPrinter();
printer.showMessage(result.getErrorMessage());
System.out.println(result.getErrorMessage());
}
});
return importResult;
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/org/jabref/cli/SystemOutputPrinter.java

This file was deleted.

42 changes: 28 additions & 14 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Optional;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
Expand All @@ -13,6 +14,7 @@
import org.jabref.gui.help.VersionWorker;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.TextInputKeyBindings;
import org.jabref.gui.openoffice.OOBibBaseConnect;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.logic.UiCommand;
import org.jabref.logic.l10n.Localization;
Expand All @@ -21,7 +23,7 @@
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.GuiPreferences;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.JabRefPreferences;

import com.tobiasdiez.easybind.EasyBind;
import impl.org.controlsfx.skin.DecorationPane;
Expand All @@ -31,29 +33,34 @@
/**
* Represents the outer stage and the scene of the JabRef window.
*/
public class JabRefGUI {
public class JabRefGUI extends Application {

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);

private static List<UiCommand> uiCommands;
private static JabRefPreferences preferencesService;
private static FileUpdateMonitor fileUpdateMonitor;
private static JabRefFrame mainFrame;
private static DialogService dialogService;
private static ThemeManager themeManager;

private final Stage mainStage;
private final PreferencesService preferencesService;
private boolean correctedWindowPos = false;
private Stage mainStage;

private final List<UiCommand> uiCommands;
private boolean correctedWindowPos;
public static void setup(List<UiCommand> uiCommands,
JabRefPreferences preferencesService,
FileUpdateMonitor fileUpdateMonitor) {
JabRefGUI.uiCommands = uiCommands;
JabRefGUI.preferencesService = preferencesService;
JabRefGUI.fileUpdateMonitor = fileUpdateMonitor;
}

public JabRefGUI(Stage mainStage,
List<UiCommand> uiCommands,
PreferencesService preferencesService,
FileUpdateMonitor fileUpdateMonitor) {
this.mainStage = mainStage;
this.uiCommands = uiCommands;
this.preferencesService = preferencesService;
@Override
public void start(Stage stage) {
this.mainStage = stage;

this.correctedWindowPos = false;
FallbackExceptionHandler.installExceptionHandler();
Globals.startBackgroundTasks();

WebViewStore.init();

Expand Down Expand Up @@ -90,6 +97,13 @@ public JabRefGUI(Stage mainStage,
setupProxy();
}

@Override
public void stop() {
OOBibBaseConnect.closeOfficeConnection();
Globals.stopBackgroundTasks();
Globals.shutdownThreadPools();
}

private void setupProxy() {
if (!preferencesService.getProxyPreferences().shouldUseProxy()
|| !preferencesService.getProxyPreferences().shouldUseAuthentication()) {
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/org/jabref/gui/MainApplication.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.io.IOException;
import java.nio.file.Path;

import org.jabref.Launcher;
import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.cli.Launcher;
import org.jabref.gui.DialogService;
import org.jabref.preferences.FilePreferences;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.util.Locale;
import java.util.Optional;

import org.jabref.Launcher;
import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.cli.Launcher;
import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefExecutorService;
import org.jabref.gui.externalfiletype.ExternalFileType;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

import org.jabref.cli.Launcher;
import org.jabref.Launcher;
import org.jabref.gui.DialogService;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.OS;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/desktop/os/OSX.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.nio.file.Path;
import java.util.Optional;

import org.jabref.Launcher;
import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.cli.Launcher;
import org.jabref.gui.DialogService;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.nio.file.Path;
import java.util.Optional;

import org.jabref.cli.Launcher;
import org.jabref.Launcher;
import org.jabref.gui.DialogService;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down Expand Up @@ -94,7 +94,7 @@ public Path getDefaultFileChooserDirectory() {
return Path.of(Shell32Util.getFolderPath(ShlObj.CSIDL_MYDOCUMENTS));
}
} catch (Win32Exception e) {
// needs to be non-static because of org.jabref.cli.Launcher.addLogToDisk
// needs to be non-static because of org.jabref.Launcher.addLogToDisk
LoggerFactory.getLogger(Windows.class).error("Error accessing folder", e);
return Path.of(System.getProperty("user.home"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/util/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class OS {
// No LOGGER may be initialized directly
// Otherwise, org.jabref.cli.Launcher.addLogToDisk will fail, because tinylog's properties are frozen
// Otherwise, org.jabref.Launcher.addLogToDisk will fail, because tinylog's properties are frozen

public static final String NEWLINE = System.lineSeparator();

Expand Down
Loading