Skip to content

Commit

Permalink
Use jcabi-log to reduce startup time: Logger.debug(this, ...) instead…
Browse files Browse the repository at this point in the history
… of LOGGER.debug(...)
  • Loading branch information
koppor committed Jul 15, 2017
1 parent e909d6a commit 4045be0
Show file tree
Hide file tree
Showing 185 changed files with 673 additions and 1,035 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,20 @@ dependencies {
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
compile 'org.fxmisc.richtext:richtextfx:0.7-M5'


// Logging
compile 'commons-logging:commons-logging:1.2'
compile 'org.apache.logging.log4j:log4j-jcl:2.8.2'
compile 'org.apache.logging.log4j:log4j-api:2.8.2'
compile 'org.apache.logging.log4j:log4j-core:2.8.2'
compile 'com.jcabi:jcabi-log:0.17.2'

// TODO: This should be replaced with Google Guava
compile 'org.apache.commons:commons-lang3:3.6'

compile 'org.jsoup:jsoup:1.10.3'
compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'info.debatty:java-string-similarity:0.24'

compile 'org.apache.logging.log4j:log4j-jcl:2.8.2'
compile 'org.apache.logging.log4j:log4j-api:2.8.2'
compile 'org.apache.logging.log4j:log4j-core:2.8.2'
compile 'org.xmlunit:xmlunit-core:2.3.0'
compile 'org.xmlunit:xmlunit-matchers:2.3.0'

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/jabref/JabRefException.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.jabref;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.jcabi.log.Logger;

public class JabRefException extends Exception {

private static final Log LOGGER = LogFactory.getLog(JabRefException.class);
private String localizedMessage;

public JabRefException(String message) {
Expand Down Expand Up @@ -33,7 +31,7 @@ public JabRefException(Throwable cause) {
@Override
public String getLocalizedMessage() {
if (localizedMessage == null) {
LOGGER.debug("No localized message exception message defined. Falling back to getMessage().");
Logger.debug(this, "No localized message exception message defined. Falling back to getMessage().");
return getMessage();
} else {
return localizedMessage;
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/jabref/JabRefExecutorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jcabi.log.Logger;

/**
* Responsible for managing of all threads (except Swing threads) in JabRef
*/
public class JabRefExecutorService implements Executor {

public static final JabRefExecutorService INSTANCE = new JabRefExecutorService();
private static final Log LOGGER = LogFactory.getLog(JabRefExecutorService.class);
private final ExecutorService executorService = Executors.newCachedThreadPool(r -> {
Thread thread = new Thread(r);
thread.setName("JabRef CachedThreadPool");
Expand All @@ -41,7 +38,7 @@ private JabRefExecutorService() { }
@Override
public void execute(Runnable command) {
if (command == null) {
LOGGER.debug("Received null as command for execution");
Logger.debug(this, "Received null as command for execution");
return;
}

Expand All @@ -50,7 +47,7 @@ public void execute(Runnable command) {

public void executeAndWait(Runnable command) {
if (command == null) {
LOGGER.debug("Received null as command for execution");
Logger.debug(this, "Received null as command for execution");
return;
}

Expand All @@ -62,14 +59,14 @@ public void executeAndWait(Runnable command) {
} catch (InterruptedException ignored) {
// Ignored
} catch (ExecutionException e) {
LOGGER.error("Problem executing command", e);
Logger.error(this, "Problem executing command", e);
}
}
}

public boolean executeAndWait(Callable command) {
if (command == null) {
LOGGER.debug("Received null as command for execution");
Logger.debug(this, "Received null as command for execution");
return false;
}

Expand All @@ -81,7 +78,7 @@ public boolean executeAndWait(Callable command) {
} catch (InterruptedException ignored) {
// Ignored
} catch (ExecutionException e) {
LOGGER.error("Problem executing command", e);
Logger.error(this, "Problem executing command", e);
return false;
}
}
Expand All @@ -97,7 +94,7 @@ public void executeInterruptableTask(final Runnable runnable, String taskName) {

public void executeInterruptableTaskAndWait(Runnable runnable) {
if (runnable == null) {
LOGGER.debug("Received null as command for execution");
Logger.debug(this, "Received null as command for execution");
return;
}

Expand All @@ -109,7 +106,7 @@ public void executeInterruptableTaskAndWait(Runnable runnable) {
} catch (InterruptedException ignored) {
// Ignored
} catch (ExecutionException e) {
LOGGER.error("Problem executing command", e);
Logger.error(this, "Problem executing command", e);
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.shared.exception.NotASharedDatabaseException;

import com.jcabi.log.Logger;
import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.theme.SkyBluer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class JabRefGUI {
private static final Log LOGGER = LogFactory.getLog(JabRefGUI.class);

private static JabRefFrame mainFrame;

Expand Down Expand Up @@ -96,7 +94,7 @@ private void openWindow() {

GUIGlobals.init();

LOGGER.debug("Initializing frame");
Logger.debug(this, "Initializing frame");
JabRefGUI.mainFrame = new JabRefFrame();

// Add all bibDatabases databases to the frame:
Expand All @@ -120,7 +118,7 @@ private void openWindow() {
pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file
pr.getDatabase().clearSharedDatabaseID();

LOGGER.error("Connection error", e);
Logger.error(this, "Connection error", e);
JOptionPane.showMessageDialog(mainFrame,
e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."),
Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
Expand Down Expand Up @@ -182,7 +180,7 @@ private void openWindow() {
OpenDatabaseAction.performPostOpenActions(panel, pr);
}

LOGGER.debug("Finished adding panels");
Logger.debug(this, "Finished adding panels");

if (!bibDatabases.isEmpty()) {
JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus();
Expand Down Expand Up @@ -211,7 +209,7 @@ private void openLastEditedDatabases() {
Globals.prefs.getImportFormatPreferences());

if (parsedDatabase.isEmpty()) {
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
Logger.error(this, Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
} else {
bibDatabases.add(parsedDatabase);
}
Expand All @@ -238,7 +236,7 @@ private void setLookAndFeel() {
if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
// Metal L&F
lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
LOGGER.warn(
Logger.warn(this,
"There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
} else {
lookFeel = systemLookFeel;
Expand Down Expand Up @@ -269,11 +267,11 @@ private void setLookAndFeel() {
Localization
.lang("Unable to find the requested look and feel and thus the default one is used."),
Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
LOGGER.warn("Unable to find requested look and feel", e);
Logger.warn(this, "Unable to find requested look and feel", e);
}
}
} catch (Exception e) {
LOGGER.warn("Look and feel could not be set", e);
Logger.warn(this, "Look and feel could not be set", e);
}

// In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@
import org.jabref.preferences.SearchPreferences;
import org.jabref.shared.prefs.SharedDatabasePreferences;

import com.jcabi.log.Logger;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ArgumentProcessor {

private static final Log LOGGER = LogFactory.getLog(ArgumentProcessor.class);
private final JabRefCLI cli;
private final List<ParserResult> parserResults;
private final Mode startupMode;
Expand Down Expand Up @@ -210,13 +208,13 @@ private List<ParserResult> processArguments() {
}
}

LOGGER.debug("Finished export");
Logger.debug(this, "Finished export");

if (cli.isPreferencesExport()) {
try {
Globals.prefs.exportPreferences(cli.getPreferencesExport());
} catch (JabRefException ex) {
LOGGER.error("Cannot export preferences", ex);
Logger.error(this, "Cannot export preferences", ex);
}
}

Expand Down Expand Up @@ -470,7 +468,7 @@ private void importPreferences() {
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
Logger.error(this, "Cannot import preferences", ex);
}
}

Expand All @@ -482,7 +480,7 @@ private void resetPreferences(String value) {
new SharedDatabasePreferences().clear();
} catch (BackingStoreException e) {
System.err.println(Localization.lang("Unable to clear preferences."));
LOGGER.error("Unable to clear preferences", e);
Logger.error(this, "Unable to clear preferences", e);
}
} else {
String[] keys = value.split(",");
Expand All @@ -500,7 +498,7 @@ private void resetPreferences(String value) {
private void automaticallySetFileLinks(List<ParserResult> loaded) {
for (ParserResult parserResult : loaded) {
BibDatabase database = parserResult.getDatabase();
LOGGER.info(Localization.lang("Automatically setting file links"));
Logger.info(this, Localization.lang("Automatically setting file links"));
AutoSetLinks.autoSetLinks(database.getEntries(), parserResult.getDatabaseContext());
}
}
Expand All @@ -511,15 +509,15 @@ private void regenerateBibtexKeys(List<ParserResult> loaded) {

MetaData metaData = parserResult.getMetaData();
if (metaData != null) {
LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata"));
Logger.info(this, Localization.lang("Regenerating BibTeX keys according to metadata"));
for (BibEntry entry : database.getEntries()) {
// try to make a new label
BibtexKeyPatternUtil.makeAndSetLabel(
metaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
database, entry, Globals.prefs.getBibtexKeyPatternPreferences());
}
} else {
LOGGER.info(Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys"));
Logger.info(this, Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys"));
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
import org.jabref.logic.exporter.ExportFormats;
import org.jabref.logic.l10n.Localization;

import com.jcabi.log.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class JabRefCLI {

private static final Log LOGGER = LogFactory.getLog(JabRefCLI.class);

private List<String> leftOver;
private final CommandLine cl;
Expand All @@ -32,7 +30,7 @@ public JabRefCLI(String[] args) {
this.cl = new DefaultParser().parse(options, args);
this.leftOver = Arrays.asList(cl.getArgs());
} catch (ParseException e) {
LOGGER.warn("Problem parsing arguments", e);
Logger.warn(this, "Problem parsing arguments", e);

this.printUsage();
throw new RuntimeException();
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.metadata.MetaData;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.jcabi.log.Logger;

public class ChangeScanner implements Runnable {
private static final Log LOGGER = LogFactory.getLog(ChangeScanner.class);

private static final String[] SORT_BY = new String[] {FieldName.YEAR, FieldName.AUTHOR, FieldName.TITLE};

Expand Down Expand Up @@ -115,7 +113,7 @@ public void run() {
scanGroups(metadataInTemp, metadataOnDisk);

} catch (IOException ex) {
LOGGER.warn("Problem running", ex);
Logger.warn(this, "Problem running", ex);
}
}

Expand Down Expand Up @@ -155,7 +153,7 @@ private void storeTempDatabase() {
SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(databaseInTemp, metadataInTemp, defaults), prefs);
ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle()));
} catch (SaveException ex) {
LOGGER.warn("Problem updating tmp file after accepting external changes", ex);
Logger.warn(this, "Problem updating tmp file after accepting external changes", ex);
}
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/jabref/collab/EntryChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.jcabi.log.Logger;

class EntryChange extends Change {

private static final Log LOGGER = LogFactory.getLog(EntryChange.class);

public EntryChange(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskEntry) {
super();
Expand All @@ -42,7 +40,7 @@ public EntryChange(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskEntry) {
// in the same way. Check for this, too.
boolean modificationsAgree = (DuplicateCheck.compareEntriesStrictly(memEntry, diskEntry) > 1);

LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("<no BibTeX key set>")
Logger.debug(this, "Modified entry: " + memEntry.getCiteKeyOptional().orElse("<no BibTeX key set>")
+ "\n Modified locally: " + isModifiedLocally + " Modifications agree: " + modificationsAgree);

Set<String> allFields = new TreeSet<>();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/jabref/collab/EntryDeleteChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.jcabi.log.Logger;

class EntryDeleteChange extends Change {

private static final Log LOGGER = LogFactory.getLog(EntryDeleteChange.class);
private final BibEntry memEntry;
private final BibEntry tmpEntry;

Expand All @@ -36,7 +34,7 @@ public EntryDeleteChange(BibEntry memEntry, BibEntry tmpEntry) {
// Check if it has been modified locally, since last tempfile was saved.
boolean isModifiedLocally = (matchWithTmp <= 1);

LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("<no BibTeX key set>")
Logger.debug(this, "Modified entry: " + memEntry.getCiteKeyOptional().orElse("<no BibTeX key set>")
+ "\n Modified locally: " + isModifiedLocally);

PreviewPanel pp = new PreviewPanel(null, memEntry, null);
Expand Down
Loading

0 comments on commit 4045be0

Please sign in to comment.