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

DI-1 #687

Closed
wants to merge 32 commits into from
Closed

DI-1 #687

Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
418abad
Migrate BibEntryTypesManager
calixtus May 22, 2024
a72a5ab
Fix deprecation
calixtus May 23, 2024
fcc1b86
Migrate UndoManager
calixtus May 23, 2024
da9b991
Remove BibEntryTypesManager from Globals
calixtus May 23, 2024
f174227
Migrate PreferencesService
calixtus May 23, 2024
e358d17
Migrate DialogService
calixtus May 23, 2024
7bae500
Migrate ThemeManager
calixtus May 23, 2024
6d34bae
Migrate StateManager
calixtus May 23, 2024
3d58c7f
Migrate TaskExecutor
calixtus May 23, 2024
513d577
Migrate KeyBindingRepository WIP
calixtus May 23, 2024
b1a7a68
Fix StringToList conversion
calixtus May 23, 2024
f11d97c
Migrate KeyBindingRepository
calixtus May 23, 2024
5530353
Fix some tests
calixtus May 23, 2024
37fa15b
Checkstyle
calixtus May 23, 2024
a5674f4
Rewrite
calixtus May 23, 2024
1a572c9
Checkstyle
calixtus May 23, 2024
7ec1dbc
Fix tests
calixtus May 24, 2024
4b5b72e
Migrate ProtectedTermsLoader
calixtus May 24, 2024
7d93569
Refactor Launcher and extract logging initialization
calixtus May 24, 2024
555824c
Migrate JournalAbbreviationsRepository
calixtus May 24, 2024
fd17b7a
Move initialization to initialize
calixtus May 26, 2024
efc6767
Migrate ClipBoardManager
calixtus May 26, 2024
103a718
Migrate RemoteListenerServerManager
calixtus May 26, 2024
8bac78a
Migrate BuildInfo
calixtus May 26, 2024
55a1345
Merge remote-tracking branch 'refs/remotes/upstream/main' into di
calixtus May 27, 2024
9aa8cc4
Fix merge errors
calixtus May 27, 2024
5a085e1
Add some text on DI
koppor May 27, 2024
5d55857
Migrate FileUpdateMonitor and DirectoryMonitor, Remove Globals
calixtus May 27, 2024
7154f80
Remove DefaultInjector
calixtus May 27, 2024
3f0a318
Merge remote-tracking branch 'koppor/di' into di
calixtus May 27, 2024
56bc88a
Fix JavaDoc error
calixtus May 27, 2024
1c72950
Fix JavaDoc comment
calixtus May 27, 2024
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
Prev Previous commit
Next Next commit
Refactor Launcher and extract logging initialization
calixtus committed May 24, 2024
commit 7d93569ececf3c8f648b969745c9a3ffff26283e
60 changes: 26 additions & 34 deletions src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jabref.gui.JabRefGUI;
import org.jabref.logic.UiCommand;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.net.ProxyAuthenticator;
import org.jabref.logic.net.ProxyPreferences;
import org.jabref.logic.net.ProxyRegisterer;
@@ -48,26 +49,11 @@
*/
public class Launcher {
private static Logger LOGGER;
private static boolean isDebugEnabled;

public static void main(String[] args) {
routeLoggingToSlf4J();
initLogging(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(args);
isDebugEnabled = jabRefCLI.isDebugLogging();
} catch (ParseException e) {
isDebugEnabled = false;
}

addLogToDisk();
try {
Injector.setModelOrService(BibEntryTypesManager.class, new BibEntryTypesManager());
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class);

// Initialize preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();
Injector.setModelOrService(PreferencesService.class, preferences);
@@ -77,12 +63,17 @@ public static void main(String[] args) {
return;
}

BibEntryTypesManager entryTypesManager = preferences.getCustomEntryTypesRepository();
Injector.setModelOrService(BibEntryTypesManager.class, entryTypesManager);

PreferencesMigrations.runMigrations(preferences, entryTypesManager);

// Initialize rest of preferences
Injector.setModelOrService(JournalAbbreviationRepository.class, JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences()));
Injector.setModelOrService(ProtectedTermsLoader.class, new ProtectedTermsLoader(preferences.getProtectedTermsPreferences()));

configureProxy(preferences.getProxyPreferences());
configureSSL(preferences.getSSLPreferences());
initGlobals(preferences);

clearOldSearchIndices();

try {
@@ -115,17 +106,26 @@ public static void main(String[] args) {
}
}

private static void routeLoggingToSlf4J() {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}

/**
* 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.
* is not possible to alter the log configuration programmatically anymore.
*/
private static void addLogToDisk() {
private 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
// argument parsing workflow to parse logging options .e.g. --debug
boolean isDebugEnabled;
try {
JabRefCLI jabRefCLI = new JabRefCLI(args);
isDebugEnabled = jabRefCLI.isDebugLogging();
} catch (ParseException e) {
isDebugEnabled = false;
}

// addLogToDisk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment no action needed:

Here, we see different coding styles. I used method names to avoid comments and to enable grouping of related statements. For you, it seemed that grouping is too fine grained and you wanted to group using lines. -- For me having the single line comment // addLogToDisk spanning statements separated by empty lines was unclear (also because there is the comment The "Shared File Writer" ....

Path directory = OS.getNativeDesktop().getLogDirectory();
try {
Files.createDirectories(directory);
@@ -184,14 +184,6 @@ private static boolean handleMultipleAppInstances(String[] args, RemotePreferenc
return true;
}

private static void initGlobals(PreferencesService preferences) {
// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationRepository = JournalAbbreviationLoader
.loadRepository(preferences.getJournalAbbreviationPreferences());
Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository());
Injector.setModelOrService(ProtectedTermsLoader.class, new ProtectedTermsLoader(preferences.getProtectedTermsPreferences()));
}

private static void configureProxy(ProxyPreferences proxyPreferences) {
ProxyRegisterer.register(proxyPreferences);
if (proxyPreferences.shouldUseProxy() && proxyPreferences.shouldUseAuthentication()) {