Skip to content

Commit

Permalink
Merge pull request #232 from JabRef/architecture
Browse files Browse the repository at this point in the history
Architecture
  • Loading branch information
simonharrer committed Oct 14, 2015
2 parents d66c234 + 3a8c25c commit 1c98520
Show file tree
Hide file tree
Showing 94 changed files with 387 additions and 327 deletions.
75 changes: 75 additions & 0 deletions src/main/java/net/sf/jabref/ArchitectureTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.sf.jabref;

import com.google.common.base.Charsets;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RunWith(Parameterized.class)
public class ArchitectureTests {

public static final String PACKAGE_JAVAX_SWING = "javax.swing";
public static final String PACKAGE_JAVA_AWT = "java.awt";
public static final String PACKAGE_NET_SF_JABREF_GUI = "net.sf.jabref.gui";

private final String firstPackage;
private final String secondPackage;

public ArchitectureTests(String firstPackage, String secondPackage) {
this.firstPackage = firstPackage;
this.secondPackage = secondPackage;
}

@Parameterized.Parameters(name = "{index} -- is {0} independent of {1}?")
public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][] {
{"net.sf.jabref.logic", PACKAGE_JAVA_AWT},
{"net.sf.jabref.logic", PACKAGE_JAVAX_SWING},
{"net.sf.jabref.logic", PACKAGE_NET_SF_JABREF_GUI},
{"net.sf.jabref.model", PACKAGE_JAVA_AWT},
{"net.sf.jabref.model", PACKAGE_JAVAX_SWING},
{"net.sf.jabref.model", PACKAGE_NET_SF_JABREF_GUI}
}
);
}



@Test
public void testLogicIndependentOfSwingAndGui() throws IOException {
assertIndependenceOfPackages(firstPackage, secondPackage);
}

private void assertIndependenceOfPackages(String firstPackage, String secondPackage) throws IOException {
List<Path> files = Files.walk(Paths.get("src"))
.filter(p -> p.toString().endsWith(".java"))
.filter(p -> {
try {
return Files.readAllLines(p, Charsets.UTF_8).stream().filter(s -> s.startsWith("package " + firstPackage)).findAny().isPresent();
} catch (IOException e) {
return false;
}
}).filter(p -> {
try {
return Files.readAllLines(p, Charsets.UTF_8).stream().filter(s -> s.startsWith("import " + secondPackage)).findAny().isPresent();
} catch (IOException e) {
return false;
}
}).collect(Collectors.toList());

if(!files.isEmpty()) {
Assert.fail(files.toString());
}
}

}
4 changes: 3 additions & 1 deletion src/main/java/net/sf/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

public class Globals {

private static final Log LOGGER = LogFactory.getLog(Globals.class);
public static final String FILE_FIELD = "file";
public static final String FOLDER_FIELD = "folder";

private static final Log LOGGER = LogFactory.getLog(Globals.class);
// JabRef version info
public static final BuildInfo BUILD_INFO = new BuildInfo();
// Signature written at the top of the .bib file.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/JabRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public Vector<ParserResult> processArguments(String[] args, boolean initialStart
}
MetaData metaData = pr.getMetaData();
metaData.setFile(theFile);
Globals.prefs.fileDirForDatabase = metaData.getFileDirectory(GUIGlobals.FILE_FIELD);
Globals.prefs.fileDirForDatabase = metaData.getFileDirectory(Globals.FILE_FIELD);
Globals.prefs.databaseFile = metaData.getFile();
System.out.println(Localization.lang("Exporting") + ": " + data[0]);
IExportFormat format = ExportFormats.getExportFormat(data[1]);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import net.sf.jabref.gui.preftabs.ImportSettingsTab;
import net.sf.jabref.importer.fileformat.ImportFormat;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelPattern.AbstractLabelPattern;
import net.sf.jabref.logic.labelPattern.GlobalLabelPattern;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.model.entry.CustomEntryType;
Expand Down Expand Up @@ -841,14 +840,14 @@ private JabRefPreferences() {
defaults.put(USE_CASE_KEEPER_ON_SEARCH, Boolean.TRUE);
defaults.put(USE_UNIT_FORMATTER_ON_SEARCH, Boolean.TRUE);

defaults.put(USER_FILE_DIR, GUIGlobals.FILE_FIELD + "Directory");
defaults.put(USER_FILE_DIR, Globals.FILE_FIELD + "Directory");
try {
defaults.put(USER_FILE_DIR_IND_LEGACY, GUIGlobals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER) + '@' + InetAddress.getLocalHost().getHostName()); // Legacy setting name - was a bug: @ not allowed inside BibTeX comment text. Retained for backward comp.
defaults.put(USER_FILE_DIR_INDIVIDUAL, GUIGlobals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER) + '-' + InetAddress.getLocalHost().getHostName()); // Valid setting name
defaults.put(USER_FILE_DIR_IND_LEGACY, Globals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER) + '@' + InetAddress.getLocalHost().getHostName()); // Legacy setting name - was a bug: @ not allowed inside BibTeX comment text. Retained for backward comp.
defaults.put(USER_FILE_DIR_INDIVIDUAL, Globals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER) + '-' + InetAddress.getLocalHost().getHostName()); // Valid setting name
} catch (UnknownHostException ex) {
LOGGER.info("Hostname not found.", ex);
defaults.put(USER_FILE_DIR_IND_LEGACY, GUIGlobals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER));
defaults.put(USER_FILE_DIR_INDIVIDUAL, GUIGlobals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER));
defaults.put(USER_FILE_DIR_IND_LEGACY, Globals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER));
defaults.put(USER_FILE_DIR_INDIVIDUAL, Globals.FILE_FIELD + "Directory" + '-' + get(DEFAULT_OWNER));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex;
package net.sf.jabref.bibtex;

import net.sf.jabref.gui.BibtexFields;
import net.sf.jabref.Globals;
Expand All @@ -25,7 +25,6 @@
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.BibtexEntry;
import net.sf.jabref.model.entry.BibtexEntryType;
import net.sf.jabref.model.entry.BibtexEntryTypes;

import java.io.IOException;
import java.io.Writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex;
package net.sf.jabref.bibtex;

import net.sf.jabref.model.entry.AuthorList;
import net.sf.jabref.model.database.BibtexDatabase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex;
package net.sf.jabref.bibtex;

import net.sf.jabref.model.entry.BibtexEntry;
import net.sf.jabref.model.database.DatabaseChangeEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex.comparator;
package net.sf.jabref.bibtex.comparator;

import net.sf.jabref.model.entry.BibtexString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex.comparator;
package net.sf.jabref.bibtex.comparator;

import net.sf.jabref.model.entry.BibtexEntry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex.comparator;
package net.sf.jabref.bibtex.comparator;

import net.sf.jabref.gui.BibtexFields;
import net.sf.jabref.model.entry.AuthorList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex.comparator;
package net.sf.jabref.bibtex.comparator;

import net.sf.jabref.gui.BibtexFields;
import net.sf.jabref.gui.MainTableFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.logic.bibtex.comparator;
package net.sf.jabref.bibtex.comparator;

import java.util.Comparator;
import java.util.List;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.importer.OpenDatabaseAction;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.logic.bibtex.DuplicateCheck;
import net.sf.jabref.logic.bibtex.EntrySorter;
import net.sf.jabref.logic.bibtex.comparator.EntryComparator;
import net.sf.jabref.bibtex.DuplicateCheck;
import net.sf.jabref.bibtex.EntrySorter;
import net.sf.jabref.bibtex.comparator.EntryComparator;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/collab/EntryChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.undo.NamedCompound;
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.logic.bibtex.DuplicateCheck;
import net.sf.jabref.bibtex.DuplicateCheck;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/collab/EntryDeleteChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import net.sf.jabref.gui.PreviewPanel;
import net.sf.jabref.gui.undo.NamedCompound;
import net.sf.jabref.gui.undo.UndoableRemoveEntry;
import net.sf.jabref.logic.bibtex.DuplicateCheck;
import net.sf.jabref.bibtex.DuplicateCheck;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/sf/jabref/exporter/ExportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.MnemonicAwareAction;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibtexEntry;

Expand Down Expand Up @@ -209,7 +208,7 @@ public void actionPerformed(ActionEvent e) {
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.basePanel().metaData()
.getFileDirectory(GUIGlobals.FILE_FIELD);
.getFileDirectory(Globals.FILE_FIELD);
// Also store the database's file in a global variable:
Globals.prefs.databaseFile = frame.basePanel().metaData().getFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.Globals;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -103,7 +102,7 @@ public void run() {
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.basePanel().metaData()
.getFileDirectory(GUIGlobals.FILE_FIELD);
.getFileDirectory(Globals.FILE_FIELD);
// Also store the database's file in a global variable:
Globals.prefs.databaseFile = frame.basePanel().metaData().getFile();

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/exporter/FileActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

import net.sf.jabref.*;
import net.sf.jabref.gui.BibtexFields;
import net.sf.jabref.logic.bibtex.BibtexEntryWriter;
import net.sf.jabref.logic.bibtex.comparator.BibtexStringComparator;
import net.sf.jabref.logic.bibtex.comparator.CrossRefEntryComparator;
import net.sf.jabref.logic.bibtex.comparator.FieldComparator;
import net.sf.jabref.logic.bibtex.comparator.FieldComparatorStack;
import net.sf.jabref.bibtex.BibtexEntryWriter;
import net.sf.jabref.bibtex.comparator.BibtexStringComparator;
import net.sf.jabref.bibtex.comparator.CrossRefEntryComparator;
import net.sf.jabref.bibtex.comparator.FieldComparator;
import net.sf.jabref.bibtex.comparator.FieldComparatorStack;
import net.sf.jabref.logic.config.SaveOrderConfig;
import net.sf.jabref.logic.id.IdComparator;
import net.sf.jabref.logic.l10n.Localization;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/exporter/OOCalcDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import net.sf.jabref.exporter.layout.format.RemoveBrackets;
import net.sf.jabref.exporter.layout.format.RemoveWhitespace;

import net.sf.jabref.logic.bibtex.comparator.FieldComparator;
import net.sf.jabref.logic.bibtex.comparator.FieldComparatorStack;
import net.sf.jabref.bibtex.comparator.FieldComparator;
import net.sf.jabref.bibtex.comparator.FieldComparatorStack;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
import org.w3c.dom.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import net.sf.jabref.exporter.layout.format.RemoveBrackets;
import net.sf.jabref.exporter.layout.format.RemoveWhitespace;

import net.sf.jabref.logic.bibtex.comparator.FieldComparator;
import net.sf.jabref.logic.bibtex.comparator.FieldComparatorStack;
import net.sf.jabref.bibtex.comparator.FieldComparator;
import net.sf.jabref.bibtex.comparator.FieldComparatorStack;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
import org.w3c.dom.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.File;

import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.Globals;
import net.sf.jabref.exporter.layout.ParamLayoutFormatter;
import net.sf.jabref.gui.FileListEntry;
Expand Down Expand Up @@ -72,7 +71,7 @@ public String format(String field) {
if (Globals.prefs.fileDirForDatabase != null) {
dirs = Globals.prefs.fileDirForDatabase;
} else {
dirs = new String[] {Globals.prefs.get(GUIGlobals.FILE_FIELD + "Directory")};
dirs = new String[] {Globals.prefs.get(Globals.FILE_FIELD + "Directory")};
}

File f = FileUtil.expandFilename(link, dirs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.sf.jabref.gui.FileListTableModel;
import net.sf.jabref.gui.FileListEntry;
import net.sf.jabref.Globals;
import net.sf.jabref.gui.GUIGlobals;

import java.util.*;
import java.io.File;
Expand Down Expand Up @@ -147,7 +146,7 @@ public String format(String field) {
if (Globals.prefs.fileDirForDatabase != null) {
dirs = Globals.prefs.fileDirForDatabase;
} else {
dirs = new String[] {Globals.prefs.get(GUIGlobals.FILE_FIELD + "Directory")};
dirs = new String[] {Globals.prefs.get(Globals.FILE_FIELD + "Directory")};
}

File f = FileUtil.expandFilename(flEntry.getLink(), dirs);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/sf/jabref/external/AttachFileAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sf.jabref.external;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.*;
import net.sf.jabref.gui.actions.BaseAction;
import net.sf.jabref.gui.undo.UndoableFieldChange;
Expand Down Expand Up @@ -34,16 +35,16 @@ public void action() {
editor.setVisible(true, true);
if (editor.okPressed()) {
FileListTableModel model = new FileListTableModel();
String oldVal = entry.getField(GUIGlobals.FILE_FIELD);
String oldVal = entry.getField(Globals.FILE_FIELD);
if (oldVal != null) {
model.setContent(oldVal);
}
model.addEntry(model.getRowCount(), flEntry);
String newVal = model.getStringRepresentation();

UndoableFieldChange ce = new UndoableFieldChange(entry, GUIGlobals.FILE_FIELD,
UndoableFieldChange ce = new UndoableFieldChange(entry, Globals.FILE_FIELD,
oldVal, newVal);
entry.setField(GUIGlobals.FILE_FIELD, newVal);
entry.setField(Globals.FILE_FIELD, newVal);
panel.undoManager.addEdit(ce);
panel.markBaseChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.sf.jabref.*;
import net.sf.jabref.gui.FileListEntry;
import net.sf.jabref.gui.FileListEntryEditor;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.net.MonitoredURLDownload;
import net.sf.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -354,7 +353,7 @@ private String getSuffix(final String link) {
}

private String[] getFileDirectory(String link) {
return metaData.getFileDirectory(GUIGlobals.FILE_FIELD);
return metaData.getFileDirectory(Globals.FILE_FIELD);
}


Expand Down
Loading

0 comments on commit 1c98520

Please sign in to comment.