Skip to content

Commit

Permalink
Merge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Apr 5, 2016
2 parents cb1a3e6 + 8e323eb commit d446d4b
Show file tree
Hide file tree
Showing 52 changed files with 547 additions and 692 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
id "com.github.youribonnaffe.gradle.format" version "1.3"
id "com.coverity.ondemand" version "1.5.61"
id "net.ltgt.errorprone" version "0.0.8"
id 'me.champeau.gradle.jmh' version '0.3.0'
}

apply plugin: "java"
Expand All @@ -27,6 +28,7 @@ apply plugin: "project-report"
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'install4j'
apply plugin: 'me.champeau.gradle.jmh'

apply plugin: 'checkstyle'

Expand Down Expand Up @@ -368,3 +370,8 @@ task getdeps(type: Copy) {
into 'build/tmp/alldeps/'
}

jmh {
warmupIterations = 5
iterations = 10
fork = 2
}
91 changes: 91 additions & 0 deletions src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package net.sf.jabref.benchmarks;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import net.sf.jabref.*;
import net.sf.jabref.exporter.BibDatabaseWriter;
import net.sf.jabref.exporter.SaveException;
import net.sf.jabref.exporter.SavePreferences;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.search.SearchQuery;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.BibDatabaseModeDetection;
import net.sf.jabref.model.entry.BibEntry;
import org.openjdk.jmh.Main;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.RunnerException;

@State(Scope.Thread)
public class Benchmarks {

StringReader bibtexStringReader;
BibDatabase database = new BibDatabase();

@Setup
public void init() throws IOException, SaveException {
Globals.prefs = JabRefPreferences.getInstance();

Random randomizer = new Random();
for (int i = 0; i < 1000; i++) {
BibEntry entry = new BibEntry();
entry.setCiteKey("id" + i);
entry.setField("title", "This is my title " + i);
entry.setField("author", "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i);
entry.setField("journal", "Journal Title " + i);
entry.setField("year", "1" + i);
entry.setField("rnd", "2" + randomizer.nextInt());
database.insertEntry(entry);
}
BibDatabaseWriter databaseWriter = new BibDatabaseWriter();
StringWriter stringWriter = new StringWriter();

databaseWriter.writePartOfDatabase(stringWriter,
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(),
new SavePreferences());
String bibtexString = stringWriter.toString();
bibtexStringReader = new StringReader(bibtexString);
}

@Benchmark
public ParserResult parse() throws IOException {
BibtexParser parser = new BibtexParser(bibtexStringReader);
return parser.parse();
}

@Benchmark
public String write() throws IOException {
StringWriter stringWriter = new StringWriter();

BibDatabaseWriter databaseWriter = new BibDatabaseWriter();
databaseWriter.writePartOfDatabase(stringWriter,
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(),
new SavePreferences());
return stringWriter.toString();
}

@Benchmark
public List<BibEntry> search() {
// FIXME: Reuse SearchWorker here
SearchQuery searchQuery = new SearchQuery("Journal Title 500", false, false);
List<BibEntry> matchedEntries = new ArrayList<>();
matchedEntries.addAll(database.getEntries().stream().filter(searchQuery::isMatch).collect(Collectors.toList()));
return matchedEntries;
}

@Benchmark
public BibDatabaseMode inferBibDatabaseMode() {
return BibDatabaseModeDetection.inferMode(database);
}

public static void main(String[] args) throws IOException, RunnerException {
Main.main(args);
}
}
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jabref/BibDatabaseContext.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.sf.jabref;

import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.BibDatabaseModeDetection;

import java.io.File;
import java.util.Objects;
import java.util.Optional;

import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.BibDatabaseModeDetection;

/**
* Represents everything related to a .bib file.
* <p>
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/net/sf/jabref/JabRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@
*/
package net.sf.jabref;

import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.net.Authenticator;
import java.nio.charset.Charset;
import java.util.*;
import java.util.prefs.BackingStoreException;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.theme.SkyBluer;
import net.sf.jabref.bibtex.InternalBibtexFields;
import net.sf.jabref.cli.AuxCommandLine;
import net.sf.jabref.exporter.*;
import net.sf.jabref.gui.*;
import net.sf.jabref.gui.remote.JabRefMessageHandler;
Expand Down Expand Up @@ -45,22 +57,9 @@
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.util.Util;
import net.sf.jabref.bibtex.InternalBibtexFields;
import net.sf.jabref.cli.AuxCommandLine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.Authenticator;
import java.nio.charset.Charset;
import java.util.*;
import java.util.List;
import java.util.prefs.BackingStoreException;

/**
* JabRef Main Class - The application gets started here.
*/
Expand Down Expand Up @@ -242,7 +241,7 @@ public Optional<Vector<ParserResult>> processArguments(String[] args, boolean in
BibDatabase newBase = new DatabaseSearcher(query, dataBase).getDatabaseFromMatches(); //newBase contains only match entries

//export database
if ((newBase != null) && (!newBase.hasNoEntries())) {
if ((newBase != null) && newBase.hasEntries()) {
String formatName;

//read in the export format, take default format if no format entered
Expand Down Expand Up @@ -388,7 +387,7 @@ public Optional<Vector<ParserResult>> processArguments(String[] args, boolean in
boolean notSavedMsg = false;

// write an output, if something could be resolved
if ((newBase != null) && !newBase.hasNoEntries()) {
if ((newBase != null) && newBase.hasEntries()) {
String subName = StringUtil.getCorrectFileName(data[1], "bib");

try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ChangeScanner implements Runnable {
public ChangeScanner(JabRefFrame frame, BasePanel bp, File file) {
this.panel = bp;
this.frame = frame;
this.inMem = bp.database();
this.inMem = bp.getDatabase();
this.mdInMem = bp.getBibDatabaseContext().getMetaData();
this.f = file;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jabref/collab/EntryAddChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package net.sf.jabref.collab;

import javax.swing.*;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.MetaData;
Expand All @@ -27,8 +29,6 @@
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.IdGenerator;

import javax.swing.*;

class EntryAddChange extends Change {

private final BibEntry diskEntry;
Expand All @@ -47,9 +47,9 @@ public EntryAddChange(BibEntry diskEntry) {
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
diskEntry.setId(IdGenerator.next());
panel.database().insertEntry(diskEntry);
panel.getDatabase().insertEntry(diskEntry);
secondary.insertEntry(diskEntry);
undoEdit.addEdit(new UndoableInsertEntry(panel.database(), diskEntry, panel));
undoEdit.addEdit(new UndoableInsertEntry(panel.getDatabase(), diskEntry, panel));
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jabref/collab/EntryDeleteChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package net.sf.jabref.collab;

import javax.swing.*;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.MetaData;
Expand All @@ -29,8 +31,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;

class EntryDeleteChange extends Change {

private final BibEntry memEntry;
Expand Down Expand Up @@ -61,8 +61,8 @@ public EntryDeleteChange(BibEntry memEntry, BibEntry tmpEntry) {

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
panel.database().removeEntry(memEntry);
undoEdit.addEdit(new UndoableRemoveEntry(panel.database(), memEntry, panel));
panel.getDatabase().removeEntry(memEntry);
undoEdit.addEdit(new UndoableRemoveEntry(panel.getDatabase(), memEntry, panel));
secondary.removeEntry(tmpEntry);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/collab/GroupChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound
// the group tree is now appled to a different BibDatabase than it was created
// for, which affects groups such as ExplicitGroup (which links to BibEntry objects).
// We must traverse the tree and refresh all groups:
root.refreshGroupsForNewDatabase(panel.database());
root.refreshGroupsForNewDatabase(panel.getDatabase());
}

if (panel.getGroupSelector().getGroupTreeRoot() == root) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/collab/PreambleChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public PreambleChange(String mem, String disk) {

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
panel.database().setPreamble(disk);
undoEdit.addEdit(new UndoablePreambleChange(panel.database(), panel, mem, disk));
panel.getDatabase().setPreamble(disk);
undoEdit.addEdit(new UndoablePreambleChange(panel.getDatabase(), panel, mem, disk));
secondary.setPreamble(disk);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/collab/StringAddChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public StringAddChange(BibtexString string) {
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {

if (panel.database().hasStringLabel(string.getName())) {
if (panel.getDatabase().hasStringLabel(string.getName())) {
// The name to change to is already in the database, so we can't comply.
LOGGER.info("Cannot add string '" + string.getName() + "' because the name "
+ "is already in use.");
}

try {
panel.database().addString(string);
undoEdit.addEdit(new UndoableInsertString(panel, panel.database(), string));
panel.getDatabase().addString(string);
undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), string));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/sf/jabref/collab/StringChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound
String newId = IdGenerator.next();
BibtexString bs = new BibtexString(newId, label, disk);
try {
panel.database().addString(bs);
undoEdit.addEdit(new UndoableInsertString(panel, panel.database(), bs));
panel.getDatabase().addString(bs);
undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
}
} else {
string.setContent(disk);
undoEdit.addEdit(new UndoableStringChange(panel, string, false, mem, disk));
// Update tmp databse:

}

// Update tmp database:
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/collab/StringNameChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public StringNameChange(BibtexString string, BibtexString tmpString,
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {

if (panel.database().hasStringLabel(disk)) {
if (panel.getDatabase().hasStringLabel(disk)) {
// The name to change to is already in the database, so we can't comply.
LOGGER.info("Cannot rename string '" + mem + "' to '" + disk + "' because the name "
+ "is already in use.");
Expand All @@ -67,8 +67,8 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound
String newId = IdGenerator.next();
BibtexString bs = new BibtexString(newId, disk, content);
try {
panel.database().addString(bs);
undoEdit.addEdit(new UndoableInsertString(panel, panel.database(), bs));
panel.getDatabase().addString(bs);
undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/collab/StringRemoveChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public StringRemoveChange(BibtexString string, BibtexString tmpString, BibtexStr
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {

try {
panel.database().removeString(inMem.getId());
undoEdit.addEdit(new UndoableRemoveString(panel, panel.database(), string));
panel.getDatabase().removeString(inMem.getId());
undoEdit.addEdit(new UndoableRemoveString(panel, panel.getDatabase(), string));
} catch (Exception ex) {
LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/exporter/ExportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void actionPerformed(ActionEvent e) {
@Override
public void run() {
try {
format.performExport(frame.getCurrentBasePanel().database(),
format.performExport(frame.getCurrentBasePanel().getDatabase(),
frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData(),
finFile.getPath(), frame
.getCurrentBasePanel().getEncoding(), finEntries);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/external/DroppedFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void handleDroppedfile(String fileName, ExternalFileType fileType, BibEnt
}

// Show dialog
if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.database())) {
if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.getDatabase())) {
return;
}

Expand Down Expand Up @@ -186,7 +186,7 @@ public void linkPdfToEntry(String fileName, BibEntry entry) {

ExternalFileType fileType = optFileType.get();
// Show dialog
if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.database())) {
if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.getDatabase())) {
return;
}

Expand Down
Loading

0 comments on commit d446d4b

Please sign in to comment.