-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Bring back MainArchitectureTest #13462
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce9a7f8
Bring back MainArchitectureTest
calixtus dc029de
Bring back MainArchitectureTest
calixtus 5d2cefc
JabLibArchitectureTests by inheritance
calixtus e92c345
JabGuiArchitectureTests by inheritance
calixtus 2d6ecdd
Remove architecture tests, add todo
calixtus f9fdde1
Merge remote-tracking branch 'upstream/main' into MainArchitectureTest
calixtus 03c0c3d
Fix issues by httpserver
calixtus 475e1cd
Fix typo
calixtus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
jabgui/src/test/java/org/jabref/gui/JabGuiArchitectureTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.jabref.gui; | ||
|
|
||
| import org.jabref.support.CommonArchitectureTest; | ||
|
|
||
| import com.tngtech.archunit.core.importer.ImportOption; | ||
| import com.tngtech.archunit.junit.AnalyzeClasses; | ||
|
|
||
| @AnalyzeClasses(packages = "org.jabref", importOptions = ImportOption.DoNotIncludeTests.class) | ||
| public class JabGuiArchitectureTests extends CommonArchitectureTest { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
jablib/src/test/java/org/jabref/logic/JabLibArchitectureTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.jabref.logic; | ||
|
|
||
| import org.jabref.support.CommonArchitectureTest; | ||
|
|
||
| import com.tngtech.archunit.core.importer.ImportOption; | ||
| import com.tngtech.archunit.junit.AnalyzeClasses; | ||
|
|
||
| @AnalyzeClasses(packages = "org.jabref", importOptions = ImportOption.DoNotIncludeTests.class) | ||
| public class JabLibArchitectureTests extends CommonArchitectureTest { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
test-support/src/main/java/org/jabref/support/CommonArchitectureTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package org.jabref.support; | ||
|
|
||
| import java.net.URI; | ||
| import java.nio.file.Paths; | ||
|
|
||
| import org.jabref.architecture.AllowedToUseApacheCommonsLang3; | ||
| import org.jabref.architecture.AllowedToUseAwt; | ||
| import org.jabref.architecture.AllowedToUseClassGetResource; | ||
| import org.jabref.architecture.AllowedToUseLogic; | ||
| import org.jabref.architecture.AllowedToUseStandardStreams; | ||
| import org.jabref.architecture.AllowedToUseSwing; | ||
|
|
||
| import com.tngtech.archunit.core.domain.JavaClasses; | ||
| import com.tngtech.archunit.core.importer.ImportOption; | ||
| import com.tngtech.archunit.junit.AnalyzeClasses; | ||
| import com.tngtech.archunit.junit.ArchTest; | ||
| import com.tngtech.archunit.lang.syntax.ArchRuleDefinition; | ||
| import com.tngtech.archunit.library.GeneralCodingRules; | ||
|
|
||
| /** | ||
| * This class checks JabRef's shipped classes for architecture quality. | ||
| * Does not analyze test classes. Hint from <a href="https://stackoverflow.com/a/44681895/873282">StackOverflow</a> | ||
| */ | ||
| @AnalyzeClasses(packages = "org.jabref", importOptions = ImportOption.DoNotIncludeTests.class) | ||
| public class CommonArchitectureTest { | ||
|
|
||
| private static final String PACKAGE_JAVAX_SWING = "javax.swing.."; | ||
| private static final String PACKAGE_JAVA_AWT = "java.awt.."; | ||
| private static final String PACKAGE_ORG_JABREF_GUI = "org.jabref.gui.."; | ||
| private static final String PACKAGE_ORG_JABREF_LOGIC = "org.jabref.logic.."; | ||
| private static final String PACKAGE_ORG_JABREF_MODEL = "org.jabref.model.."; | ||
| private static final String PACKAGE_ORG_JABREF_CLI = "org.jabref.cli.."; | ||
|
|
||
| @ArchTest | ||
| public void doNotUseApacheCommonsLang3(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().that().areNotAnnotatedWith(AllowedToUseApacheCommonsLang3.class) | ||
| .should().accessClassesThat().resideInAPackage("org.apache.commons.lang3") | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void doNotUseSwing(JavaClasses classes) { | ||
calixtus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // This checks for all Swing packages, but not the UndoManager | ||
| ArchRuleDefinition.noClasses().that().areNotAnnotatedWith(AllowedToUseSwing.class) | ||
| .should().accessClassesThat() | ||
| .resideInAnyPackage("javax.swing", | ||
| "javax.swing.border..", | ||
| "javax.swing.colorchooser..", | ||
| "javax.swing.event..", | ||
| "javax.swing.filechooser..", | ||
| "javax.swing.plaf..", | ||
| "javax.swing.table..", | ||
| "javax.swing.text..", | ||
| "javax.swing.tree..") | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void doNotUseAssertJ(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().should().accessClassesThat().resideInAPackage("org.assertj..") | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void doNotUseJavaAWT(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().that().areNotAnnotatedWith(AllowedToUseAwt.class) | ||
| .should().accessClassesThat().resideInAPackage(PACKAGE_JAVA_AWT) | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void doNotUsePaths(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().should() | ||
| .accessClassesThat() | ||
| .belongToAnyOf(Paths.class) | ||
| .because("Path.of(...) should be used instead") | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void useStreamsOfResources(JavaClasses classes) { | ||
| // Reason: https://github.com/oracle/graal/issues/7682#issuecomment-1786704111 | ||
| ArchRuleDefinition.noClasses().that().haveNameNotMatching(".*Test") | ||
| .and().areNotAnnotatedWith(AllowedToUseClassGetResource.class) | ||
| .and().areNotAssignableFrom("org.jabref.logic.importer.fileformat.ImporterTestEngine") | ||
| .should() | ||
| .callMethod(Class.class, "getResource", String.class) | ||
| .because("getResourceAsStream(...) should be used instead") | ||
| .check(classes); | ||
| } | ||
|
|
||
| // TODO: no org.jabref.gui package may reside in org.jabref.logic | ||
|
|
||
| @ArchTest | ||
| public void doNotUseLogicInModel(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().that().resideInAPackage(PACKAGE_ORG_JABREF_MODEL) | ||
| .and().areNotAnnotatedWith(AllowedToUseLogic.class) | ||
| .should().dependOnClassesThat().resideInAPackage(PACKAGE_ORG_JABREF_LOGIC) | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void restrictUsagesInModel(JavaClasses classes) { | ||
| // Until we switch to Lucene, we need to access Globals.stateManager().getActiveDatabase() from the search classes, | ||
| // because the PDFSearch needs to access the index of the corresponding database | ||
| ArchRuleDefinition.noClasses().that().areNotAssignableFrom("org.jabref.model.search.rules.ContainBasedSearchRule") | ||
| .and().areNotAssignableFrom("org.jabref.model.search.rules.RegexBasedSearchRule") | ||
| .and().areNotAssignableFrom("org.jabref.model.search.rules.GrammarBasedSearchRule") | ||
| .and().resideInAPackage(PACKAGE_ORG_JABREF_MODEL) | ||
| .should().dependOnClassesThat().resideInAPackage(PACKAGE_JAVAX_SWING) | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void restrictUsagesInLogic(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().that().resideInAPackage(PACKAGE_ORG_JABREF_LOGIC) | ||
| .and().areNotAnnotatedWith(AllowedToUseSwing.class) | ||
| .and().areNotAssignableFrom("org.jabref.logic.search.DatabaseSearcherWithBibFilesTest") | ||
| .should().dependOnClassesThat().resideInAPackage(PACKAGE_JAVAX_SWING) | ||
| .check(classes); | ||
| } | ||
|
|
||
| @ArchTest | ||
| public void restrictStandardStreams(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses().that().resideOutsideOfPackages(PACKAGE_ORG_JABREF_CLI) | ||
| .and().resideOutsideOfPackages("org.jabref.gui.openoffice..") // Uses LibreOffice SDK | ||
| .and().areNotAnnotatedWith(AllowedToUseStandardStreams.class) | ||
| .should(GeneralCodingRules.ACCESS_STANDARD_STREAMS) | ||
| .because("logging framework should be used instead or the class be marked explicitly as @AllowedToUseStandardStreams") | ||
| .check(classes); | ||
| } | ||
|
|
||
| /// Use constructor new URI(...) instead | ||
| @ArchTest | ||
| public void shouldNotCallUriCreateMethod(JavaClasses classes) { | ||
| ArchRuleDefinition.noClasses() | ||
| .that() | ||
| .resideInAPackage("org.jabref..") | ||
| .should().callMethod(URI.class, "create", String.class) | ||
| .check(classes); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.