Skip to content

Commit 53cd7dc

Browse files
add ArchRulesService interface
scaffold out the IntegrationTest a little bit more Co-authored-by: Emily Yuan <[email protected]>
1 parent 1dcc052 commit 53cd7dc

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.netflix.nebula.archrules.core;
2+
3+
import com.tngtech.archunit.lang.ArchRule;
4+
5+
import java.util.Map;
6+
7+
/**
8+
* Interface used to make ArchRules automatically discoverable.
9+
* Implementations should be declared as a {@link java.util.ServiceLoader} service.
10+
*/
11+
public interface ArchRulesService {
12+
/**
13+
* An ArchRulesService implementation will produce a map of rules to be discovered for evaluation.
14+
* The map keys are the IDs of the rules,
15+
* which will be used as display names in reporting and for additional configuration in the Gradle plugin.
16+
*
17+
* @return the rules to evaluate
18+
*/
19+
Map<String, ArchRule> getRules();
20+
}
Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
11
package com.netflix.nebula.archrules.gradle
22

3+
import nebula.test.dsl.*
4+
import nebula.test.dsl.TestKitAssertions.assertThat
5+
import org.gradle.testkit.runner.TaskOutcome
36
import org.junit.jupiter.api.Test
47
import org.junit.jupiter.api.io.TempDir
58
import java.io.File
69

710
internal class IntegrationTest {
811
@TempDir
9-
lateinit var testProjectDir: File
12+
lateinit var projectDir: File
13+
1014
@Test
11-
fun test(){
15+
fun test() {
16+
val runner = testProject(projectDir) {
17+
subProject("library-with-rules") {
18+
// a library that contains production code and rules to go along with it
19+
plugins {
20+
id("java-library")
21+
id("com.netflix.nebula.archrules.library")
22+
}
23+
src {
24+
main {
25+
java(
26+
"com/example/library/LibraryClass.java",
27+
//language=java
28+
"""
29+
package com.example.library;
30+
31+
public class LibraryClass {
32+
33+
}
34+
"""
35+
)
36+
}
37+
}
38+
}
39+
subProject("code-to-check") {
40+
// a project which consumes libraries which should have the rules evaluated against it
41+
plugins {
42+
id("java")
43+
id("com.netflix.nebula.archrules.runner")
44+
}
45+
dependencies(
46+
"""implementation(project(":library-with-rules"))"""
47+
)
48+
}
49+
}
50+
51+
val result = runner.run("check")
52+
53+
assertThat(result.task(":library-with-rules:check"))
54+
.hasOutcome(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE)
55+
assertThat(result.task(":code-to-check:check"))
56+
.hasOutcome(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE)
57+
assertThat(result)
58+
.hasNoMutableStateWarnings()
59+
.hasNoDeprecationWarnings()
1260

61+
assertThat(projectDir.resolve("library-with-rules/build/libs/library-with-rules.jar"))
62+
.`as`("Library Jar is created")
63+
.exists()
1364
}
1465
}

0 commit comments

Comments
 (0)