forked from autonomousapps/dependency-analysis-gradle-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improvements relating to generating project graphs.
1. improve output of ProjectGraphTask. 2. generate merged graph of all variants in a project. 3. generate merged graph for entire build. 4. incubating support for generating work plan.
- Loading branch information
1 parent
c77c27b
commit 6e8d8d5
Showing
22 changed files
with
639 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ local.properties | |
.DS_STORE | ||
|
||
.bash_history | ||
*.salive |
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
26 changes: 26 additions & 0 deletions
26
src/functionalTest/groovy/com/autonomousapps/jvm/WorkPlanSpec.groovy
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,26 @@ | ||
package com.autonomousapps.jvm | ||
|
||
import com.autonomousapps.jvm.projects.WorkPlanProject | ||
import spock.lang.PendingFeature | ||
|
||
import static com.autonomousapps.utils.Runner.build | ||
import static com.google.common.truth.Truth.assertThat | ||
|
||
final class WorkPlanSpec extends AbstractJvmSpec { | ||
|
||
@PendingFeature | ||
def "can generate work plan (#gradleVersion)"() { | ||
given: | ||
def project = new WorkPlanProject() | ||
gradleProject = project.gradleProject | ||
when: | ||
build(gradleVersion, gradleProject.rootDir, ':generateWorkPlan') | ||
then: | ||
assertThat(true).isFalse() | ||
where: | ||
gradleVersion << gradleVersions() | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/functionalTest/groovy/com/autonomousapps/jvm/projects/WorkPlanProject.groovy
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,91 @@ | ||
package com.autonomousapps.jvm.projects | ||
|
||
import com.autonomousapps.AbstractProject | ||
import com.autonomousapps.kit.GradleProject | ||
|
||
import static com.autonomousapps.kit.gradle.Dependency.implementation | ||
import static com.autonomousapps.kit.gradle.Dependency.project | ||
|
||
final class WorkPlanProject extends AbstractProject { | ||
|
||
final GradleProject gradleProject | ||
|
||
WorkPlanProject() { | ||
this.gradleProject = build() | ||
} | ||
|
||
private GradleProject build() { | ||
return newGradleProjectBuilder() | ||
// alpha | ||
.withSubproject('alpha:app') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaApp + plugins.javaTestFixtures | ||
bs.dependencies = [ | ||
project('implementation', ':alpha:lib'), | ||
project('implementation', ':beta:app').onTestFixtures(), | ||
] | ||
} | ||
} | ||
.withSubproject('alpha:lib') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
bs.dependencies = [ | ||
project('api', ':alpha:core'), | ||
] | ||
} | ||
} | ||
.withSubproject('alpha:core') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
bs.dependencies(implementation('com.squareup.misk:misk:2023.10.18.080259-adcfb84')) | ||
} | ||
} | ||
|
||
// beta | ||
.withSubproject('beta:app') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaApp + plugins.javaTestFixtures | ||
bs.dependencies = [ | ||
project('implementation', ':beta:lib'), | ||
] | ||
} | ||
} | ||
.withSubproject('beta:lib') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
bs.dependencies = [ | ||
project('api', ':beta:core'), | ||
] | ||
} | ||
} | ||
.withSubproject('beta:core') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
} | ||
} | ||
|
||
// gamma | ||
.withSubproject('gamma:app') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaApp + plugins.javaTestFixtures | ||
bs.dependencies = [ | ||
project('implementation', ':gamma:lib'), | ||
] | ||
} | ||
} | ||
.withSubproject('gamma:lib') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
bs.dependencies = [ | ||
project('api', ':gamma:core'), | ||
] | ||
} | ||
} | ||
.withSubproject('gamma:core') { p -> | ||
p.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
} | ||
} | ||
.write() | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/com/autonomousapps/internal/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,65 @@ | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
package com.autonomousapps.internal.graph | ||
|
||
import com.autonomousapps.model.Coordinates | ||
import com.autonomousapps.model.IncludedBuildCoordinates | ||
import com.autonomousapps.model.ProjectCoordinates | ||
import com.google.common.graph.ElementOrder | ||
import com.google.common.graph.Graph | ||
import com.google.common.graph.GraphBuilder | ||
import com.google.common.graph.ImmutableGraph | ||
|
||
internal operator fun <T> Graph<T>.plus(other: Graph<T>): Graph<T> where T : Any { | ||
val builder = newGraphBuilder<T>() | ||
|
||
nodes().forEach { builder.addNode(it) } | ||
edges().forEach { edge -> builder.putEdge(edge.source(), edge.target()) } | ||
other.nodes().forEach { builder.addNode(it) } | ||
other.edges().forEach { edge -> builder.putEdge(edge.source(), edge.target()) } | ||
|
||
return builder.build() | ||
} | ||
|
||
/** | ||
* Flattens a graph by stripping out the | ||
* [GradleVariantIdentification][com.autonomousapps.model.GradleVariantIdentification], which essentially combines nodes | ||
* to different variants of a module into a single node. This simplifies reporting on certain scenarios where the module | ||
* itself is the unit of analysis, rather than the variant. | ||
*/ | ||
internal fun Graph<Coordinates>.stripVariants(buildPath: String): Graph<Coordinates> { | ||
val builder = newGraphBuilder<Coordinates>() | ||
|
||
nodes().forEach { builder.addNode(it.maybeProjectCoordinates(buildPath).flatten()) } | ||
edges().forEach { edge -> | ||
val source = edge.source().maybeProjectCoordinates(buildPath).flatten() | ||
val target = edge.target().maybeProjectCoordinates(buildPath).flatten() | ||
|
||
// In the un-flattened graphs, self-loops are sort of possible because nodes with different capabilities are | ||
// different. | ||
if (source != target) { | ||
builder.putEdge(source, target) | ||
} | ||
} | ||
|
||
return builder.build() | ||
} | ||
|
||
internal fun <T> newGraphBuilder(): ImmutableGraph.Builder<T> { | ||
return GraphBuilder.directed() | ||
.allowsSelfLoops(false) | ||
.incidentEdgeOrder(ElementOrder.stable<T>()) | ||
.immutable() | ||
} | ||
|
||
/** | ||
* Might transform [this][Coordinates] into [ProjectCoordinates], if it is an [IncludedBuildCoordinates] that is from | ||
* "this" build (with buildPath == [buildPath]). | ||
*/ | ||
internal fun Coordinates.maybeProjectCoordinates(buildPath: String): Coordinates { | ||
return if (this is IncludedBuildCoordinates && isForBuild(buildPath)) resolvedProject else this | ||
} | ||
|
||
private fun Coordinates.flatten(): Coordinates { | ||
return if (this is ProjectCoordinates) flatten() else this | ||
} |
Oops, something went wrong.