-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7c4b83
commit 463ad17
Showing
15 changed files
with
139 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.jvm") | ||
id("convention") | ||
id("com.autonomousapps.dependency-analysis") | ||
} | ||
|
||
group = "com.autonomousapps" | ||
version = "0.1" | ||
|
||
kotlin { | ||
explicitApi() | ||
} | ||
|
||
dagp { | ||
version(version) | ||
pom { | ||
name.set("Graph Support Library") | ||
description.set("A graph support library for the JVM") | ||
url.set("https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin") | ||
inceptionYear.set("2022") | ||
} | ||
publishTaskDescription("Publishes to Maven Central and promotes.") | ||
} | ||
|
||
// We only use the Jupiter platform (JUnit 5) | ||
configurations.all { | ||
exclude(mapOf("group" to "junit", "module" to "junit")) | ||
exclude(mapOf("group" to "org.junit.vintage", "module" to "junit-vintage-engine")) | ||
} | ||
|
||
dependencies { | ||
api(libs.guava) { | ||
because("Graphs") | ||
} | ||
|
||
testImplementation(platform(libs.junit.bom)) | ||
testImplementation(libs.junit.api) | ||
testImplementation(libs.junit.params) | ||
testImplementation(libs.truth) | ||
testRuntimeOnly(libs.junit.engine) | ||
|
||
testImplementation(libs.truth) | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
useJUnitPlatform() | ||
} |
This file contains 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 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
32 changes: 32 additions & 0 deletions
32
graph-support/src/main/kotlin/com/autonomousapps/graph/Graphs.kt
This file contains 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,32 @@ | ||
package com.autonomousapps.graph | ||
|
||
import com.google.common.graph.Graph | ||
import com.google.common.graph.Graphs as GuavaGraphs | ||
|
||
@Suppress("UnstableApiUsage") // Guava graphs | ||
public object Graphs { | ||
|
||
public fun <N : Any> Graph<N>.reachableNodes(node: N, excludeSelf: Boolean = true): Set<N> { | ||
val reachable = GuavaGraphs.reachableNodes(this, node) | ||
return if (excludeSelf) { | ||
reachable.filterNotTo(HashSet()) { it == node } | ||
} else { | ||
reachable | ||
} | ||
} | ||
|
||
public fun <N : Any> Graph<N>.parents(node: N): Set<N> = predecessors(node) | ||
|
||
public fun <N : Any> Graph<N>.children(node: N): Set<N> = successors(node) | ||
|
||
/** | ||
* Returns an ordered list of nodes if there is a path from [source] to [target]. If there is no path, returns an | ||
* empty list. | ||
*/ | ||
public fun <N : Any> Graph<N>.shortestPath(source: N, target: N): Iterable<N> { | ||
val path = ShortestPath(this, source) | ||
return path.pathTo(target) | ||
} | ||
|
||
public fun <N : Any> Graph<N>.topological(source: N): Iterable<N> = Topological(this, source).order | ||
} |
This file contains 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
6 changes: 3 additions & 3 deletions
6
...onomousapps/internal/graph/Topological.kt → ...n/com/autonomousapps/graph/Topological.kt
This file contains 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 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 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 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
33 changes: 0 additions & 33 deletions
33
src/main/kotlin/com/autonomousapps/internal/graph/Graphs.kt
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.