From 0db41c87b083b6590b8b01225603ecaee1fb6899 Mon Sep 17 00:00:00 2001 From: Dimitry Polivaev Date: Wed, 14 Feb 2024 19:13:16 +0100 Subject: [PATCH 1/5] replace non-ascii character Signed-off-by: Dimitry Polivaev Signed-off-by: Dimitry Polivaev --- .../archunit/lang/syntax/elements/ClassesShouldConjunction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java index 4ee609b18..67c016ee9 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java @@ -34,7 +34,7 @@ * * * The semantics of the new condition will be {@code (public OR private) AND haveNameMatching} - * – and not {@code public || (private && haveNameMatching)}. + * - and not {@code public || (private && haveNameMatching)}. *

* Thus, for more complex conditions please consider explicitly joining {@link ArchConditions preconfigured conditions} * or custom {@link ArchCondition conditions} via {@link ArchCondition#and(ArchCondition)} and {@link ArchCondition#or(ArchCondition)} From 7bfb09bd343cf98e630eaeed4d973b0d82f2c108 Mon Sep 17 00:00:00 2001 From: Dimitry Polivaev Date: Thu, 15 Feb 2024 19:41:18 +0100 Subject: [PATCH 2/5] add toClassDependencies() Signed-off-by: Dimitry Polivaev Signed-off-by: Dimitry Polivaev --- .../java/com/tngtech/archunit/core/domain/JavaAccess.java | 8 ++++++++ .../archunit/library/dependencies/SliceDependency.java | 6 ++++++ .../com/tngtech/archunit/core/domain/JavaAccessTest.java | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaAccess.java b/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaAccess.java index da4906952..5182dcdd0 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaAccess.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaAccess.java @@ -107,6 +107,14 @@ String additionalToStringFields() { return ""; } + /** + * @return all matching class dependencies. + */ + @PublicAPI(usage = ACCESS) + public Set toClassDependencies() { + return Dependency.tryCreateFromAccess(this); + } + @Override @PublicAPI(usage = ACCESS) public String getDescription() { diff --git a/archunit/src/main/java/com/tngtech/archunit/library/dependencies/SliceDependency.java b/archunit/src/main/java/com/tngtech/archunit/library/dependencies/SliceDependency.java index b71e9b296..ca312114a 100644 --- a/archunit/src/main/java/com/tngtech/archunit/library/dependencies/SliceDependency.java +++ b/archunit/src/main/java/com/tngtech/archunit/library/dependencies/SliceDependency.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -62,6 +63,11 @@ public Slice getTarget() { return target; } + @PublicAPI(usage = ACCESS) + public Set toClassDependencies() { + return relevantDependencies; + } + @Override @PublicAPI(usage = ACCESS) public String getDescription() { diff --git a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java index f604c69f8..c947f6954 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java @@ -5,8 +5,10 @@ import com.tngtech.archunit.core.domain.JavaAccess.Functions.Get; import com.tngtech.archunit.core.importer.testexamples.SomeClass; import com.tngtech.archunit.core.importer.testexamples.SomeEnum; +import org.assertj.core.api.Assertions; import org.junit.Test; +import static com.google.common.collect.Iterables.getOnlyElement; import static com.tngtech.archunit.base.DescribedPredicate.alwaysFalse; import static com.tngtech.archunit.core.domain.TestUtils.importClassWithContext; import static com.tngtech.archunit.core.domain.TestUtils.importClassesWithContext; @@ -14,6 +16,7 @@ import static com.tngtech.archunit.core.domain.TestUtils.resolvedTargetFrom; import static com.tngtech.archunit.core.domain.TestUtils.simulateCall; import static com.tngtech.archunit.testutil.Assertions.assertThat; +import static com.tngtech.archunit.testutil.Assertions.assertThatType; public class JavaAccessTest { @Test @@ -23,6 +26,9 @@ public void when_the_origin_is_an_inner_class_the_toplevel_class_is_displayed_as .inLineNumber(7); assertThat(access.getDescription()).contains("(SomeClass.java:7)"); + Dependency dependency = getOnlyElement(access.toClassDependencies()); + assertThatType(dependency.getTargetClass()).as("target class").isEqualTo(access.getTargetOwner()); + Assertions.assertThat(dependency.getDescription()).as("description").isEqualTo(access.getDescription()); } @Test From dc4da28cfdb5aeffa6af5275ab068187fbf9d176 Mon Sep 17 00:00:00 2001 From: Dimitry Polivaev Date: Fri, 16 Feb 2024 14:20:29 +0100 Subject: [PATCH 3/5] Revert "replace non-ascii character" This reverts commit a95c7c3368c5533eab57a97765e3f57d638412f0. Signed-off-by: Dimitry Polivaev Signed-off-by: Dimitry Polivaev --- .../archunit/lang/syntax/elements/ClassesShouldConjunction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java index 67c016ee9..4ee609b18 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldConjunction.java @@ -34,7 +34,7 @@ * * * The semantics of the new condition will be {@code (public OR private) AND haveNameMatching} - * - and not {@code public || (private && haveNameMatching)}. + * – and not {@code public || (private && haveNameMatching)}. *

* Thus, for more complex conditions please consider explicitly joining {@link ArchConditions preconfigured conditions} * or custom {@link ArchCondition conditions} via {@link ArchCondition#and(ArchCondition)} and {@link ArchCondition#or(ArchCondition)} From f46ca506a6a8e13f3ce4196cd7a2b565c2fc48cb Mon Sep 17 00:00:00 2001 From: Dimitry Polivaev Date: Fri, 16 Feb 2024 14:26:22 +0100 Subject: [PATCH 4/5] Configure javadoc encoding to resolve build errors Signed-off-by: Dimitry Polivaev Signed-off-by: Dimitry Polivaev --- buildSrc/src/main/groovy/archunit.java-conventions.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/buildSrc/src/main/groovy/archunit.java-conventions.gradle b/buildSrc/src/main/groovy/archunit.java-conventions.gradle index 2df21f6a4..941691f22 100644 --- a/buildSrc/src/main/groovy/archunit.java-conventions.gradle +++ b/buildSrc/src/main/groovy/archunit.java-conventions.gradle @@ -15,4 +15,5 @@ tasks.withType(JavaCompile) { Task task -> javadoc { options.addBooleanOption('html5', true) + options.encoding = UTF_8.toString() } \ No newline at end of file From 2d879146d684536a833103f972a6680315c147b1 Mon Sep 17 00:00:00 2001 From: Dimitry Polivaev Date: Fri, 16 Feb 2024 14:35:27 +0100 Subject: [PATCH 5/5] Create dedicated test for JavaAccess.toClassDependencies() Signed-off-by: Dimitry Polivaev Signed-off-by: Dimitry Polivaev --- .../com/tngtech/archunit/core/domain/JavaAccessTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java index c947f6954..119d9d7db 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaAccessTest.java @@ -26,7 +26,13 @@ public void when_the_origin_is_an_inner_class_the_toplevel_class_is_displayed_as .inLineNumber(7); assertThat(access.getDescription()).contains("(SomeClass.java:7)"); + } + @Test + public void java_access_transforms_to_class_dependency() { + TestJavaAccess access = anyAccess(); Dependency dependency = getOnlyElement(access.toClassDependencies()); + + assertThatType(dependency.getOriginClass()).as("origin class").isEqualTo(access.getOriginOwner()); assertThatType(dependency.getTargetClass()).as("target class").isEqualTo(access.getTargetOwner()); Assertions.assertThat(dependency.getDescription()).as("description").isEqualTo(access.getDescription()); }