From d5a3a851b4b9bb479854cd71f80474194355edcf Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Wed, 1 Apr 2020 23:02:09 +0100 Subject: [PATCH] dead code and dependency removal --- build.gradle.kts | 31 +------- .../MyFirstPluginPluginFunctionalTest.kt | 38 ---------- .../plugins/DependencyExportPlugin.kt | 74 ------------------- .../plugins/DependencyExportPluginTest.kt | 1 - 4 files changed, 2 insertions(+), 142 deletions(-) delete mode 100644 src/functionalTest/kotlin/my/first/plugin/MyFirstPluginPluginFunctionalTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index ba01471..e43d9fe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,21 +19,13 @@ configure { dependencies { -// classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") - // Align versions of all Kotlin components implementation(platform("org.jetbrains.kotlin:kotlin-bom")) // Use the Kotlin JDK 8 standard library. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - implementation("net.woggioni:worth:1.0") - // Use the Kotlin test library. -// testImplementation("org.jetbrains.kotlin:kotlin-test") - - // Use the Kotlin JUnit integration. -// testImplementation("org.jetbrains.kotlin:kotlin-test-junit") testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2") testImplementation(gradleTestKit()) @@ -41,31 +33,12 @@ dependencies { } gradlePlugin { - // Define the plugin - val my_first_plugin by plugins.creating { + val dependencyExportPlugin by plugins.creating { id = "net.woggioni.plugins.dependency-export" implementationClass = "net.woggioni.plugins.DependencyExportPlugin" } } -// Add a source set for the functional test suite -//val functionalTestSourceSet = sourceSets.create("functionalTest") { -//} -// -//gradlePlugin.testSourceSets(functionalTestSourceSet) -//configurations.getByName("functionalTestImplementation").extendsFrom(configurations.getByName("testImplementation")) - -// Add a task to run the functional tests -//val functionalTest by tasks.creating(Test::class) { -// testClassesDirs = functionalTestSourceSet.output.classesDirs -// classpath = functionalTestSourceSet.runtimeClasspath -//} -// -//val check by tasks.getting(Task::class) { -// // Run the functional tests as part of `check` -// dependsOn(functionalTest) -//} - tasks.withType().configureEach { useJUnitPlatform() systemProperty("plugin.build.dir", tasks.withType().first().destinationDir) @@ -74,7 +47,7 @@ tasks.withType().configureEach { } tasks.withType().configureEach { - gradleVersion = "6.1.1" + gradleVersion = "6.3" distributionType = Wrapper.DistributionType.ALL } diff --git a/src/functionalTest/kotlin/my/first/plugin/MyFirstPluginPluginFunctionalTest.kt b/src/functionalTest/kotlin/my/first/plugin/MyFirstPluginPluginFunctionalTest.kt deleted file mode 100644 index 4937e02..0000000 --- a/src/functionalTest/kotlin/my/first/plugin/MyFirstPluginPluginFunctionalTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This Kotlin source file was generated by the Gradle 'init' task. - */ -package my.first.plugin - -import java.io.File -import org.gradle.testkit.runner.GradleRunner -import org.junit.Assert -import org.junit.Test - -/** - * A simple functional test for the 'my.first.plugin.greeting' plugin. - */ -class MyFirstPluginPluginFunctionalTest { - @Test - fun `can run task`() { - // Setup the test build - val projectDir = File("build/functionalTest") - projectDir.mkdirs() - projectDir.resolve("settings.gradle").writeText("") - projectDir.resolve("build.gradle").writeText(""" - plugins { - id('my.first.plugin.greeting') - } - """) - - // Run the build - val runner = GradleRunner.create() - runner.forwardOutput() - runner.withPluginClasspath() - runner.withArguments("greeting") - runner.withProjectDir(projectDir) - val result = runner.build(); - - // Verify the result - Assert.assertTrue(result.output.contains("Hello from plugin 'my.first.plugin.greeting'")) - } -} diff --git a/src/main/kotlin/net/woggioni/plugins/DependencyExportPlugin.kt b/src/main/kotlin/net/woggioni/plugins/DependencyExportPlugin.kt index 5d5aa05..4e08b95 100644 --- a/src/main/kotlin/net/woggioni/plugins/DependencyExportPlugin.kt +++ b/src/main/kotlin/net/woggioni/plugins/DependencyExportPlugin.kt @@ -3,14 +3,6 @@ */ package net.woggioni.plugins -import net.woggioni.jwo.JWO -import net.woggioni.jwo.tree.StackContext -import net.woggioni.jwo.tree.TreeNode -import net.woggioni.jwo.tree.TreeNodeVisitor -import net.woggioni.jwo.tree.TreeWalker -import net.woggioni.worth.serialization.json.JSONDumper -import net.woggioni.worth.value.ObjectValue -import net.woggioni.worth.xface.Value import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.component.ModuleComponentIdentifier @@ -21,7 +13,6 @@ import org.gradle.api.artifacts.result.UnresolvedDependencyResult import java.io.BufferedWriter import java.io.OutputStreamWriter import java.nio.file.Files -import java.nio.file.Paths open class DependencyExportPluginExtension { var configurationName: String = "default" @@ -92,71 +83,6 @@ object DependencyExporter { } } -class DependencyTreeNode(val component: ResolvedComponentResult) : TreeNode { - override fun children(): Iterator { - return object : Iterator { - val it = component.dependencies.iterator() - override fun hasNext(): Boolean { - return it.hasNext() - } - - override fun next(): DependencyTreeNode { - val dependency = it.next() - return when (dependency) { - is ResolvedDependencyResult -> { - DependencyTreeNode(dependency.selected) - } - is UnresolvedDependencyResult -> { - throw dependency.failure - } - else -> { - throw NotImplementedError("${dependency::class}") - } - } - } - } - } -} - -fun export(project: Project) { - val cfg = Value.Configuration.builder() - .serializeReferences(true) - .objectValueImplementation(ObjectValue.Implementation.ArrayList) - .build() - val result = ObjectValue.newInstance(cfg) - project.configurations.all { configuration -> - if (configuration.isCanBeResolved) { - val configDeps = ObjectValue.newInstance(cfg) - val visitor = object : TreeNodeVisitor { - override fun visitPre(stack: MutableList>): TreeNodeVisitor.VisitOutcome { - val stackElement = JWO.tail(stack) - stackElement.context = ObjectValue.newInstance(cfg) - val id = stackElement.node.component.id - if (stack.size == 1) { - configDeps.put(id.displayName, stackElement.context) - } else if (stack.size > 1) { - val parentStackElement = JWO.tail(stack, -2) - parentStackElement.context.put(id.displayName, stackElement.context) - } - return TreeNodeVisitor.VisitOutcome.CONTINUE - } -// override fun visitPost(stack: MutableList>?) { -// val stackElement = JWO.tail(stack) -// if(stack.size > 1) { -// val parentStackElement = JWO.tail(stack, -2) -// parentStackElement.context.add(StringValue(stackElement.node.component.toString())) -// } -// } - } - TreeWalker(visitor).walk(DependencyTreeNode(configuration.incoming.resolutionResult.root)) - result.put(configuration.name, configDeps) - } - } - BufferedWriter(OutputStreamWriter(Files.newOutputStream(Paths.get("/tmp/dependencies.json")))).use { - JSONDumper.newInstance(cfg).dump(result, it) - } -} - class DependencyExportPlugin : Plugin { override fun apply(project: Project) { val extension = DependencyExportPluginExtension() diff --git a/src/test/kotlin/net/woggioni/plugins/DependencyExportPluginTest.kt b/src/test/kotlin/net/woggioni/plugins/DependencyExportPluginTest.kt index fd387d9..42a143d 100644 --- a/src/test/kotlin/net/woggioni/plugins/DependencyExportPluginTest.kt +++ b/src/test/kotlin/net/woggioni/plugins/DependencyExportPluginTest.kt @@ -3,7 +3,6 @@ */ package net.woggioni.plugins -import net.woggioni.plugins.installResource import org.gradle.testkit.runner.GradleRunner import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test