Skip to content

Commit e29044c

Browse files
calixtuskoppor
andauthored
Bring back MainArchitectureTest (#13462)
* Bring back MainArchitectureTest * Bring back MainArchitectureTest Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * JabLibArchitectureTests by inheritance Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * JabGuiArchitectureTests by inheritance Fix architecture tests Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * Remove architecture tests, add todo Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * Fix issues by httpserver Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * Fix typo Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> --------- Co-authored-by: Carl Christian Snethlage <calixtus@users.noreply.github.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
1 parent 714e3ba commit e29044c

File tree

16 files changed

+221
-16
lines changed

16 files changed

+221
-16
lines changed

build-logic/src/main/kotlin/org.jabref.gradle.base.dependency-rules.gradle.kts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,23 @@ extraJavaModuleInfo {
276276
module("com.github.javaparser:javaparser-symbol-solver-core", "com.github.javaparser.symbolsolver.core")
277277
module("net.sf.jopt-simple:jopt-simple", "net.sf.jopt.simple")
278278

279-
module("com.tngtech.archunit:archunit-junit5-api", "com.tngtech.archunit.junit5.api")
280-
module("com.tngtech.archunit:archunit-junit5-engine", "com.tngtech.archunit.junit5.engine")
281-
module("com.tngtech.archunit:archunit-junit5-engine-api", "com.tngtech.archunit.junit5.engineapi")
279+
module("com.tngtech.archunit:archunit-junit5-api", "com.tngtech.archunit.junit5.api") {
280+
exportAllPackages()
281+
requireAllDefinedDependencies()
282+
}
283+
module("com.tngtech.archunit:archunit-junit5-engine", "com.tngtech.archunit.junit5.engine") {
284+
exportAllPackages()
285+
requireAllDefinedDependencies()
286+
}
287+
module("com.tngtech.archunit:archunit-junit5-engine-api", "com.tngtech.archunit.junit5.engineapi") {
288+
exportAllPackages()
289+
requireAllDefinedDependencies()
290+
}
282291
module("com.tngtech.archunit:archunit", "com.tngtech.archunit") {
283292
exportAllPackages()
293+
requireAllDefinedDependencies()
284294
requires("java.logging")
285-
requires("org.slf4j")
295+
uses("com.tngtech.archunit.lang.extension.ArchUnitExtension")
286296
}
287297

288298
module("org.glassfish.hk2.external:aopalliance-repackaged", "org.aopalliance")

docs/code-howtos/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ Check the directory `jablib/src/main/resources/csl-locales`.
6161
If it is missing or empty, run `git submodule update`.
6262
If still not fixed, run `git reset --hard` **inside that directory**.
6363

64-
### `org.jabref.architecture.MainArchitectureTest restrictStandardStreams` <span style="color:red">FAILED</span>
64+
### `org.jabref.support.CommonArchitectureTest restrictStandardStreams` <span style="color:red">FAILED</span>
6565

6666
Check if you've used `System.out.println(...)` (the standard output stream) to log anything into the console.
6767
This is an architectural violation, as you should use the Logger instead for logging.
6868
More details on [how to log](https://devdocs.jabref.org/code-howtos/logging.html).
6969

70-
### `org.jabref.architecture.MainArchitectureTest doNotUseLogicInModel` <span style="color:red">FAILED</span>
70+
### `org.jabref.support.CommonArchitectureTest doNotUseLogicInModel` <span style="color:red">FAILED</span>
7171

7272
One common case when this test fails is when you put any class purely containing business logic inside the `model` package (i.e., inside the directory `org/jabref/model/`).
7373
To fix this, shift the class to a sub-package within the `logic` package (i.e., the directory`org/jabref/logic/`).

jabgui/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ dependencies {
121121

122122
testImplementation("com.github.javaparser:javaparser-symbol-solver-core")
123123
testImplementation("org.ow2.asm:asm")
124+
125+
testImplementation("com.tngtech.archunit:archunit")
126+
testImplementation("com.tngtech.archunit:archunit-junit5-api")
127+
testRuntimeOnly("com.tngtech.archunit:archunit-junit5-engine")
124128
}
125129

126130
application {
@@ -218,6 +222,9 @@ javaModuleTesting.whitebox(testing.suites["test"]) {
218222

219223
requires.add("wiremock")
220224
requires.add("wiremock.slf4j.spi.shim")
225+
226+
requires.add("com.tngtech.archunit")
227+
requires.add("com.tngtech.archunit.junit5.api")
221228
}
222229

223230
tasks.test {

jabgui/src/main/java/org/jabref/gui/ClipBoardManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
3030

31-
@AllowedToUseAwt("Requires ava.awt.datatransfer.Clipboard")
31+
@AllowedToUseAwt("Requires java.awt.datatransfer.Clipboard")
3232
public class ClipBoardManager {
3333

3434
public static final DataFormat XML = new DataFormat("application/xml");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.jabref.gui;
2+
3+
import org.jabref.support.CommonArchitectureTest;
4+
5+
import com.tngtech.archunit.core.importer.ImportOption;
6+
import com.tngtech.archunit.junit.AnalyzeClasses;
7+
8+
@AnalyzeClasses(packages = "org.jabref", importOptions = ImportOption.DoNotIncludeTests.class)
9+
public class JabGuiArchitectureTests extends CommonArchitectureTest {
10+
}

jablib/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ dependencies {
207207
testImplementation("org.xmlunit:xmlunit-core")
208208
testImplementation("org.xmlunit:xmlunit-matchers")
209209
testImplementation("org.junit.jupiter:junit-jupiter-api")
210-
testRuntimeOnly("com.tngtech.archunit:archunit-junit5-engine")
210+
211+
testImplementation("com.tngtech.archunit:archunit")
211212
testImplementation("com.tngtech.archunit:archunit-junit5-api")
213+
testRuntimeOnly("com.tngtech.archunit:archunit-junit5-engine")
212214

213215
testImplementation("org.hamcrest:hamcrest")
214216

@@ -563,4 +565,7 @@ javaModuleTesting.whitebox(testing.suites["test"]) {
563565
requires.add("org.xmlunit.matchers")
564566
requires.add("wiremock")
565567
requires.add("wiremock.slf4j.spi.shim")
568+
569+
requires.add("com.tngtech.archunit")
570+
requires.add("com.tngtech.archunit.junit5.api")
566571
}

jablib/src/main/java/org/jabref/logic/importer/fetcher/EuropePmcFetcher.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
import kong.unirest.core.json.JSONArray;
2727
import kong.unirest.core.json.JSONException;
2828
import kong.unirest.core.json.JSONObject;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2931

3032
public class EuropePmcFetcher implements IdBasedParserFetcher {
33+
private static final Logger LOGGER = LoggerFactory.getLogger(EuropePmcFetcher.class);
3134

3235
@Override
3336
public URL getUrlForIdentifier(String identifier) throws URISyntaxException, MalformedURLException {
34-
return URI.create("https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=" + identifier + "&resultType=core&format=json").toURL();
37+
return new URI("https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=" + identifier + "&resultType=core&format=json").toURL();
3538
}
3639

3740
@Override
@@ -49,7 +52,7 @@ private BibEntry jsonItemToBibEntry(JSONObject item) throws ParseException {
4952
try {
5053
JSONObject result = item.getJSONObject("resultList").getJSONArray("result").getJSONObject(0);
5154

52-
System.out.println(result.toString(2));
55+
LOGGER.debug(result.toString(2));
5356

5457
EntryType entryType = StandardEntryType.Article;
5558
if (result.has("pubTypeList")) {

jablib/src/main/java/org/jabref/logic/remote/RemotePreferences.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import java.net.InetAddress;
44
import java.net.URI;
5+
import java.net.URISyntaxException;
56
import java.net.UnknownHostException;
67

78
import javafx.beans.property.BooleanProperty;
89
import javafx.beans.property.IntegerProperty;
910
import javafx.beans.property.SimpleBooleanProperty;
1011
import javafx.beans.property.SimpleIntegerProperty;
1112

13+
import org.jspecify.annotations.NonNull;
1214
import org.slf4j.Logger;
1315
import org.slf4j.LoggerFactory;
1416

@@ -75,12 +77,17 @@ public static InetAddress getIpAddress() throws UnknownHostException {
7577
return InetAddress.getByName("localhost");
7678
}
7779

78-
public URI getHttpServerUri() {
80+
public @NonNull URI getHttpServerUri() {
7981
try {
80-
return URI.create("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":23119");
81-
} catch (UnknownHostException e) {
82+
return new URI("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":23119");
83+
} catch (UnknownHostException | URISyntaxException e) {
8284
LOGGER.error("Could not create HTTP server URI. Falling back to default.", e);
83-
return URI.create("http://localhost:23119");
85+
try {
86+
return new URI("http://localhost:23119");
87+
} catch (URISyntaxException ex) {
88+
LOGGER.error("Should never happen, raw string is already valid uri");
89+
throw new RuntimeException(ex);
90+
}
8491
}
8592
}
8693
}

jablib/src/main/java/org/jabref/model/strings/StringUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javafx.util.Pair;
1616

1717
import org.jabref.architecture.AllowedToUseApacheCommonsLang3;
18+
import org.jabref.architecture.AllowedToUseLogic;
1819
import org.jabref.logic.bibtex.FieldWriter;
1920
import org.jabref.logic.os.OS;
2021

@@ -23,6 +24,7 @@
2324

2425
@SuppressWarnings("checkstyle:NoMultipleClosingBracesAtEndOfLine")
2526
@AllowedToUseApacheCommonsLang3("There is no equivalent in Google's Guava")
27+
@AllowedToUseLogic("OS.NewLine is most basic")
2628
public class StringUtil {
2729

2830
// Non-letters which are used to denote accents in LaTeX-commands, e.g., in {\"{a}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.jabref.logic;
2+
3+
import org.jabref.support.CommonArchitectureTest;
4+
5+
import com.tngtech.archunit.core.importer.ImportOption;
6+
import com.tngtech.archunit.junit.AnalyzeClasses;
7+
8+
@AnalyzeClasses(packages = "org.jabref", importOptions = ImportOption.DoNotIncludeTests.class)
9+
public class JabLibArchitectureTests extends CommonArchitectureTest {
10+
}

0 commit comments

Comments
 (0)