Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netflix.nebula.archrules.core;

import com.tngtech.archunit.lang.ArchRule;

import java.util.Map;

/**
* Interface used to make ArchRules automatically discoverable.
* Implementations should be declared as a {@link java.util.ServiceLoader} service.
*/
public interface ArchRulesService {
/**
* An ArchRulesService implementation will produce a map of rules to be discovered for evaluation.
* The map keys are the IDs of the rules,
* which will be used as display names in reporting and for additional configuration in the Gradle plugin.
*
* @return the rules to evaluate
*/
Map<String, ArchRule> getRules();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,65 @@
package com.netflix.nebula.archrules.gradle

import nebula.test.dsl.*
import nebula.test.dsl.TestKitAssertions.assertThat
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File

internal class IntegrationTest {
@TempDir
lateinit var testProjectDir: File
lateinit var projectDir: File

@Test
fun test(){
fun test() {
val runner = testProject(projectDir) {
subProject("library-with-rules") {
// a library that contains production code and rules to go along with it
plugins {
id("java-library")
id("com.netflix.nebula.archrules.library")
}
src {
main {
java(
"com/example/library/LibraryClass.java",
//language=java
"""
package com.example.library;

public class LibraryClass {

}
"""
)
}
}
}
subProject("code-to-check") {
// a project which consumes libraries which should have the rules evaluated against it
plugins {
id("java")
id("com.netflix.nebula.archrules.runner")
}
dependencies(
"""implementation(project(":library-with-rules"))"""
)
}
}

val result = runner.run("check")

assertThat(result.task(":library-with-rules:check"))
.hasOutcome(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE)
assertThat(result.task(":code-to-check:check"))
.hasOutcome(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE)
assertThat(result)
.hasNoMutableStateWarnings()
.hasNoDeprecationWarnings()

assertThat(projectDir.resolve("library-with-rules/build/libs/library-with-rules.jar"))
.`as`("Library Jar is created")
.exists()
}
}