Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .springjavaformatconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indentation-style=spaces
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ dependencies {
implementation("org.gradlex:java-module-testing:1.7")
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.4")
implementation("org.gradle.toolchains:foojay-resolver:1.0.0")
implementation("io.spring.javaformat:io.spring.javaformat.gradle.plugin:0.0.47")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("io.spring.javaformat")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ plugins {
id("org.jabref.gradle.feature.test")
id("org.jabref.gradle.check.checkstyle")
id("org.jabref.gradle.check.modernizer")
id("org.jabref.gradle.check.spring-javaformat")
}
4 changes: 4 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<module name="Checker">
<property name="charset" value="UTF-8"/>

<module name="io.spring.javaformat.checkstyle.SpringChecks">
<property name="excludes" value="io.spring.javaformat.checkstyle.check.SpringAvoidStaticImportCheck" />
</module>

<module name="Header">
<property name="header" value=""/>
</module>
Expand Down
73 changes: 41 additions & 32 deletions jabgui/src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@
/// - Handle the command line arguments
/// - Start the JavaFX application
public class Launcher {

private static Logger LOGGER;

public enum MultipleInstanceAction {
CONTINUE,
SHUTDOWN,
FOCUS

CONTINUE, SHUTDOWN, FOCUS

}

public static void main(String[] args) {
Expand All @@ -57,20 +58,20 @@ public static void main(String[] args) {

final JabRefGuiPreferences preferences = JabRefGuiPreferences.getInstance();

ArgumentProcessor argumentProcessor = new ArgumentProcessor(
args,
ArgumentProcessor.Mode.INITIAL_START,
ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START,
preferences);

if (!argumentProcessor.getGuiCli().usageHelpRequested) {
Injector.setModelOrService(CliPreferences.class, preferences);
Injector.setModelOrService(GuiPreferences.class, preferences);

// Early exit in case another instance is already running
MultipleInstanceAction instanceAction = handleMultipleAppInstances(args, preferences.getRemotePreferences());
MultipleInstanceAction instanceAction = handleMultipleAppInstances(args,
preferences.getRemotePreferences());
if (instanceAction == MultipleInstanceAction.SHUTDOWN) {
systemExit();
} else if (instanceAction == MultipleInstanceAction.FOCUS) {
}
else if (instanceAction == MultipleInstanceAction.FOCUS) {
// Send focus command to running instance
RemotePreferences remotePreferences = preferences.getRemotePreferences();
RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort());
Expand Down Expand Up @@ -99,42 +100,40 @@ public static void main(String[] args) {
}

/**
* This needs to be called as early as possible. After the first log write, it
* is not possible to alter the log configuration programmatically anymore.
* This needs to be called as early as possible. After the first log write, it is not
* possible to alter the log configuration programmatically anymore.
*/
public static void initLogging(String[] args) {
// routeLoggingToSlf4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();

// We must configure logging as soon as possible, which is why we cannot wait for the usual
// 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
Level logLevel = Arrays.stream(args).anyMatch("--debug"::equalsIgnoreCase)
? Level.DEBUG
: Level.INFO;
Level logLevel = Arrays.stream(args).anyMatch("--debug"::equalsIgnoreCase) ? Level.DEBUG : Level.INFO;

// addLogToDisk
// We cannot use `Injector.instantiateModelOrService(BuildInfo.class).version` here, because this initializes logging
// We cannot use `Injector.instantiateModelOrService(BuildInfo.class).version`
// here, because this initializes logging
Path directory = Directories.getLogDirectory(new BuildInfo().version);
try {
Files.createDirectories(directory);
} catch (IOException e) {
}
catch (IOException e) {
LOGGER = LoggerFactory.getLogger(Launcher.class);
LOGGER.error("Could not create log directory {}", directory, e);
return;
}

// The "Shared File Writer" is explained at
// https://tinylog.org/v2/configuration/#shared-file-writer
Map<String, String> configuration = Map.of(
"level", logLevel.name().toLowerCase(),
"writerFile", "rolling file",
Map<String, String> configuration = Map.of("level", logLevel.name().toLowerCase(), "writerFile", "rolling file",
"writerFile.level", logLevel.name().toLowerCase(),
// We need to manually join the path, because ".resolve" does not work on Windows, because ":" is not allowed in file names on Windows
// We need to manually join the path, because ".resolve" does not work on
// Windows, because ":" is not allowed in file names on Windows
"writerFile.file", directory + File.separator + "log_{date:yyyy-MM-dd_HH-mm-ss}.txt",
"writerFile.charset", "UTF-8",
"writerFile.policies", "startup",
"writerFile.backups", "30");
"writerFile.charset", "UTF-8", "writerFile.policies", "startup", "writerFile.backups", "30");
configuration.forEach(Configuration::set);

LOGGER = LoggerFactory.getLogger(Launcher.class);
Expand All @@ -148,9 +147,11 @@ private static void systemExit() {
}

/**
* @return MultipleInstanceAction: CONTINUE if JabRef should continue starting up, SHUTDOWN if it should quit, FOCUS if it should focus the existing instance.
* @return MultipleInstanceAction: CONTINUE if JabRef should continue starting up,
* SHUTDOWN if it should quit, FOCUS if it should focus the existing instance.
*/
private static MultipleInstanceAction handleMultipleAppInstances(String[] args, RemotePreferences remotePreferences) {
private static MultipleInstanceAction handleMultipleAppInstances(String[] args,
RemotePreferences remotePreferences) {
LOGGER.trace("Checking for remote handling...");

if (remotePreferences.useRemoteServer()) {
Expand All @@ -159,24 +160,31 @@ private static MultipleInstanceAction handleMultipleAppInstances(String[] args,
if (remoteClient.ping()) {
LOGGER.debug("Pinging other instance succeeded.");
if (args.length == 0) {
// There is already a server out there, avoid showing log "Passing arguments" while no arguments are provided.
// There is already a server out there, avoid showing log "Passing
// arguments" while no arguments are provided.
LOGGER.warn("A JabRef instance is already running. Switching to that instance.");
return MultipleInstanceAction.FOCUS;
} else {
// We are not alone, there is already a server out there, send command line arguments to other instance
}
else {
// We are not alone, there is already a server out there, send command
// line arguments to other instance
LOGGER.debug("Passing arguments passed on to running JabRef...");
if (remoteClient.sendCommandLineArguments(args)) {
// So we assume it's all taken care of, and quit.
// Output to both to the log and the screen. Therefore, we do not have an additional System.out.println.
// Output to both to the log and the screen. Therefore, we do not
// have an additional System.out.println.
LOGGER.info("Arguments passed on to running JabRef instance. Shutting down.");
return MultipleInstanceAction.SHUTDOWN;
} else {
}
else {
LOGGER.warn("Could not communicate with other running JabRef instance.");
}
}
// We do not launch a new instance in presence if there is another instance running
// We do not launch a new instance in presence if there is another
// instance running
return MultipleInstanceAction.SHUTDOWN;
} else {
}
else {
LOGGER.debug("Could not ping JabRef instance.");
}
}
Expand All @@ -193,4 +201,5 @@ private static void configureProxy(ProxyPreferences proxyPreferences) {
private static void configureSSL(SSLPreferences sslPreferences) {
TrustStoreManager.createTruststoreFileIfNotExist(Path.of(sslPreferences.getTruststorePath()));
}

}
22 changes: 16 additions & 6 deletions jabgui/src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@
import picocli.CommandLine;

public class ArgumentProcessor {

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

public enum Mode { INITIAL_START, REMOTE_START }
public enum Mode {

INITIAL_START, REMOTE_START

}

private final Mode startupMode;

private final GuiPreferences preferences;

private final GuiCommandLine guiCli;

private final CommandLine cli;

private final List<UiCommand> uiCommands = new ArrayList<>();

private boolean guiNeeded = true;

public ArgumentProcessor(String[] args,
Mode startupMode,
GuiPreferences preferences) {
public ArgumentProcessor(String[] args, Mode startupMode, GuiPreferences preferences) {
this.startupMode = startupMode;
this.preferences = preferences;
this.guiCli = new GuiCommandLine();
Expand Down Expand Up @@ -74,7 +81,8 @@ public List<UiCommand> processArguments() {
if (guiCli.libraries != null && !guiCli.libraries.isEmpty()) {
if (guiCli.append) {
uiCommands.add(new UiCommand.AppendToCurrentLibrary(guiCli.libraries));
} else {
}
else {
uiCommands.add(new UiCommand.OpenLibraries(guiCli.libraries));
}
}
Expand All @@ -93,7 +101,8 @@ private void resetPreferences() {
System.out.println(Localization.lang("Setting all preferences to default values."));
preferences.clear();
new SharedDatabasePreferences().clear();
} catch (BackingStoreException e) {
}
catch (BackingStoreException e) {
System.err.println(Localization.lang("Unable to clear preferences."));
LOGGER.error("Unable to clear preferences", e);
}
Expand All @@ -106,4 +115,5 @@ public boolean shouldShutDown() {
public GuiCommandLine getGuiCli() {
return guiCli;
}

}
36 changes: 17 additions & 19 deletions jabgui/src/main/java/org/jabref/cli/CliImportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
/// @deprecated used by the browser extension only
@Deprecated
public class CliImportHelper {

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

/**
* Reads URIs as input
*
* @param location URL or file path to import
*/
public static Optional<ParserResult> importFile(String location,
CliPreferences cliPreferences,
boolean porcelain) {
public static Optional<ParserResult> importFile(String location, CliPreferences cliPreferences, boolean porcelain) {
LOGGER.debug("Importing file from locaiton {}", location);
String[] data = location.split(",");

Expand All @@ -41,15 +39,18 @@ public static Optional<ParserResult> importFile(String location,
// Download web resource to temporary file
try {
file = new URLDownload(address).toTemporaryFile();
} catch (FetcherException |
MalformedURLException e) {
System.err.println(Localization.lang("Problem downloading from %0: %1", address, e.getLocalizedMessage()));
}
catch (FetcherException | MalformedURLException e) {
System.err
.println(Localization.lang("Problem downloading from %0: %1", address, e.getLocalizedMessage()));
return Optional.empty();
}
} else {
}
else {
if (OS.WINDOWS) {
file = Path.of(address);
} else {
}
else {
file = Path.of(address.replace("~", System.getProperty("user.home")));
}
}
Expand All @@ -63,25 +64,22 @@ public static Optional<ParserResult> importFile(String location,
return importResult;
}

public static Optional<ParserResult> importFile(Path file,
CliPreferences cliPreferences,
boolean porcelain) {
public static Optional<ParserResult> importFile(Path file, CliPreferences cliPreferences, boolean porcelain) {
try {
ImportFormatReader importFormatReader = new ImportFormatReader(
cliPreferences.getImporterPreferences(),
cliPreferences.getImportFormatPreferences(),
cliPreferences.getCitationKeyPatternPreferences(),
new DummyFileUpdateMonitor()
);
ImportFormatReader importFormatReader = new ImportFormatReader(cliPreferences.getImporterPreferences(),
cliPreferences.getImportFormatPreferences(), cliPreferences.getCitationKeyPatternPreferences(),
new DummyFileUpdateMonitor());

if (!porcelain) {
System.out.println(Localization.lang("Importing %0", file));
}
ParserResult result = importFormatReader.importFromFile("bibtex", file);
return Optional.of(result);
} catch (ImportException ex) {
}
catch (ImportException ex) {
LOGGER.error("Error opening file '{}'", file, ex);
return Optional.empty();
}
}

}
21 changes: 12 additions & 9 deletions jabgui/src/main/java/org/jabref/cli/GuiCommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,40 @@

@Command(name = "jabref", mixinStandardHelpOptions = true)
public class GuiCommandLine {

@Parameters(paramLabel = "<FILE>", description = "File(s) to be imported.")
public List<Path> libraries;

@Option(names = {"-a", "--add"}, description = "Add to currently opened library.")
@Option(names = { "-a", "--add" }, description = "Add to currently opened library.")
public boolean append;

/// @deprecated used by the browser extension
@Deprecated
@Option(names = {"--importBibtex"}, description = "Import bibtex string")
@Option(names = { "--importBibtex" }, description = "Import bibtex string")
public String importBibtex;

/// @deprecated used by the browser extension
@Deprecated
@Option(names = {"-importToOpen", "--importToOpen"}, description = "Same as --import, but will be imported to the opened tab")
@Option(names = { "-importToOpen", "--importToOpen" },
description = "Same as --import, but will be imported to the opened tab")
public String importToOpen;

@Option(names = {"--reset"}, description = "Reset all preferences to default values.")
@Option(names = { "--reset" }, description = "Reset all preferences to default values.")
public boolean resetPreferences;

@Option(names = {"-v", "--version"}, versionHelp = true, description = "Display version info.")
@Option(names = { "-v", "--version" }, versionHelp = true, description = "Display version info.")
public boolean versionInfoRequested;

@Option(names = {"?", "-h", "--help"}, usageHelp = true, description = "Display this help message.")
@Option(names = { "?", "-h", "--help" }, usageHelp = true, description = "Display this help message.")
public boolean usageHelpRequested;

@Option(names = {"--debug"}, description = "Enable debug logging.")
@Option(names = { "--debug" }, description = "Enable debug logging.")
public boolean debugLogging;

@Option(names = {"-b", "--blank"}, description = "Start with an empty library.")
@Option(names = { "-b", "--blank" }, description = "Start with an empty library.")
public boolean blank;

@Option(names = {"-j", "--jumpToKey"}, description = "Jump to the entry of the given citation key.")
@Option(names = { "-j", "--jumpToKey" }, description = "Jump to the entry of the given citation key.")
public String jumpToKey;

}
2 changes: 2 additions & 0 deletions jabgui/src/main/java/org/jabref/gui/AbstractViewModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui;

public class AbstractViewModel {

// empty

}
Loading