From c35d8e38470bf751f1e05e258ea0709cdf8ab986 Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Wed, 8 Jan 2025 10:21:28 -0800 Subject: [PATCH] :art: format --- .../javaagent/otel/MergeServiceFiles.kt | 11 +++++--- .../JavaagentJibExtensionFunctionalTest.kt | 6 ++--- .../JavaagentApplicationDistributionPlugin.kt | 15 +++++------ .../JavaagentApplicationRunPlugin.kt | 8 +++--- .../JavaagentAwareStartScriptGenerator.kt | 19 ++++++++------ .../javaagent/JavaagentJibExtension.kt | 25 +++++++++++++------ .../com/ryandens/javaagent/JavaagentPlugin.kt | 4 +-- .../ryandens/javaagent/JavaagentTestPlugin.kt | 11 ++++---- .../javaagent/JavaagentTestPluginTest.kt | 16 ++++++++++-- 9 files changed, 70 insertions(+), 45 deletions(-) diff --git a/otel/src/main/kotlin/com/ryandens/javaagent/otel/MergeServiceFiles.kt b/otel/src/main/kotlin/com/ryandens/javaagent/otel/MergeServiceFiles.kt index 6b9f151..1414d27 100644 --- a/otel/src/main/kotlin/com/ryandens/javaagent/otel/MergeServiceFiles.kt +++ b/otel/src/main/kotlin/com/ryandens/javaagent/otel/MergeServiceFiles.kt @@ -29,8 +29,9 @@ import javax.inject.Inject @CacheableTask abstract class MergeServiceFiles @Inject - constructor(private val fileSystemOperations: FileSystemOperations) : - DefaultTask() { + constructor( + private val fileSystemOperations: FileSystemOperations, + ) : DefaultTask() { @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) abstract val inputFiles: ConfigurableFileCollection @@ -41,7 +42,8 @@ abstract class MergeServiceFiles @TaskAction fun execute() { val serviceFiles: Set = - inputFiles.asFileTree.matching { f -> f.include("META-INF/services/**").include("inst/META-INF/services/**") } + inputFiles.asFileTree + .matching { f -> f.include("META-INF/services/**").include("inst/META-INF/services/**") } .files val outputDir: File = outputDirectory.get().dir("META-INF/services").asFile fileSystemOperations.delete { @@ -49,7 +51,8 @@ abstract class MergeServiceFiles } outputDir.mkdirs() val perService: Map> = - serviceFiles.stream() + serviceFiles + .stream() .collect(Collectors.groupingBy(File::getName)) for ((serviceType, files) in perService) { val mergedServiceFile = File(outputDir, serviceType) diff --git a/plugin/src/functionalTest/kotlin/com/ryandens/javaagent/JavaagentJibExtensionFunctionalTest.kt b/plugin/src/functionalTest/kotlin/com/ryandens/javaagent/JavaagentJibExtensionFunctionalTest.kt index 34213d9..596d6d9 100644 --- a/plugin/src/functionalTest/kotlin/com/ryandens/javaagent/JavaagentJibExtensionFunctionalTest.kt +++ b/plugin/src/functionalTest/kotlin/com/ryandens/javaagent/JavaagentJibExtensionFunctionalTest.kt @@ -48,8 +48,7 @@ class JavaagentJibExtensionFunctionalTest { assertTrue(File(functionalTestDir, JIB_IMAGE).exists()) FileInputStream(File(functionalTestDir, JIB_IMAGE)).use { fis -> - ArchiveStreamFactory().createArchiveInputStream>(ArchiveStreamFactory.TAR, fis).use { - ais -> + ArchiveStreamFactory().createArchiveInputStream>(ArchiveStreamFactory.TAR, fis).use { ais -> var entry = ais.nextEntry while (entry != null) { if ("config.json" == entry.name) { @@ -76,8 +75,7 @@ class JavaagentJibExtensionFunctionalTest { // verify the agent was added to entrypoint assertTrue(File(functionalTestDir, JIB_IMAGE).exists()) FileInputStream(File(functionalTestDir, JIB_IMAGE)).use { fis -> - ArchiveStreamFactory().createArchiveInputStream>(ArchiveStreamFactory.TAR, fis).use { - ais -> + ArchiveStreamFactory().createArchiveInputStream>(ArchiveStreamFactory.TAR, fis).use { ais -> var entry = ais.nextEntry while (entry != null) { if ("config.json" == entry.name) { diff --git a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationDistributionPlugin.kt b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationDistributionPlugin.kt index 651a889..c0a6a6c 100644 --- a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationDistributionPlugin.kt +++ b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationDistributionPlugin.kt @@ -15,21 +15,23 @@ import org.gradle.api.tasks.application.CreateStartScripts * the [ApplicationPlugin] to include javaagents and configure the [ApplicationPlugin.TASK_START_SCRIPTS_NAME] to * automatically include the `-javaagent` flag when running the distribution. */ -class JavaagentApplicationDistributionPlugin : Plugin, JavaagentPlugin { +class JavaagentApplicationDistributionPlugin : + Plugin, + JavaagentPlugin { /** * Destination directory for dependencies as specified by the [ApplicationPlugin] */ private val destinationDirectory = "agent-libs" - override fun dependentProjectPlugins(): Collection>> { - return setOf(ApplicationPlugin::class.java) - } + override fun dependentProjectPlugins(): Collection>> = setOf(ApplicationPlugin::class.java) override fun applyAfterJavaagentSetup( project: Project, javaagentConfiguration: NamedDomainObjectProvider, ) { - project.extensions.getByType(DistributionContainer::class.java).named(DistributionPlugin.MAIN_DISTRIBUTION_NAME) + project.extensions + .getByType(DistributionContainer::class.java) + .named(DistributionPlugin.MAIN_DISTRIBUTION_NAME) .configure { distribution -> distribution.contents { copy -> copy.from(javaagentConfiguration) { @@ -52,8 +54,7 @@ class JavaagentApplicationDistributionPlugin : Plugin, JavaagentPlugin // custom start script generator that replaces the placeholder it.unixStartScriptGenerator = JavaagentAwareStartScriptGenerator( - javaagentConfiguration.map { - configuration -> + javaagentConfiguration.map { configuration -> configuration.files }, ) diff --git a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationRunPlugin.kt b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationRunPlugin.kt index 3cea568..4910f37 100644 --- a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationRunPlugin.kt +++ b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentApplicationRunPlugin.kt @@ -10,10 +10,10 @@ import org.gradle.api.tasks.JavaExec /** * Configures a project that leverages the [ApplicationPlugin] to easily integrate a javaagent into its tasks and outputs. */ -class JavaagentApplicationRunPlugin : Plugin, JavaagentPlugin { - override fun dependentProjectPlugins(): Collection>> { - return setOf(ApplicationPlugin::class.java) - } +class JavaagentApplicationRunPlugin : + Plugin, + JavaagentPlugin { + override fun dependentProjectPlugins(): Collection>> = setOf(ApplicationPlugin::class.java) override fun applyAfterJavaagentSetup( project: Project, diff --git a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentAwareStartScriptGenerator.kt b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentAwareStartScriptGenerator.kt index bdb6d35..247a0fa 100644 --- a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentAwareStartScriptGenerator.kt +++ b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentAwareStartScriptGenerator.kt @@ -26,8 +26,9 @@ class JavaagentAwareStartScriptGenerator( inner.generateScript(details, Fake(destination, javaagentConfiguration)) } - private class FakeTransformer(private val inner: StartScriptTemplateBindingFactory) : - Transformer, JavaAppStartScriptGenerationDetails> by inner { + private class FakeTransformer( + private val inner: StartScriptTemplateBindingFactory, + ) : Transformer, JavaAppStartScriptGenerationDetails> by inner { override fun transform(`in`: JavaAppStartScriptGenerationDetails): MutableMap { val result = inner.transform(`in`) val jvmOpts = result["defaultJvmOpts"] ?: "" @@ -42,7 +43,10 @@ class JavaagentAwareStartScriptGenerator( } } - private class Fake(private val inner: Writer, private val javaagentFiles: Provider>) : Writer() { + private class Fake( + private val inner: Writer, + private val javaagentFiles: Provider>, + ) : Writer() { override fun close() { inner.close() } @@ -64,10 +68,11 @@ class JavaagentAwareStartScriptGenerator( val replace = if (files.isEmpty()) { // handles case gracefully where there is a trailing space that needs to be removed if ogther default jvm opts are supplied - str.replace( - "-javaagent:COM_RYANDENS_JAVAAGENTS_PLACEHOLDER.jar ", - "", - ).replace("-javaagent:COM_RYANDENS_JAVAAGENTS_PLACEHOLDER.jar", "") + str + .replace( + "-javaagent:COM_RYANDENS_JAVAAGENTS_PLACEHOLDER.jar ", + "", + ).replace("-javaagent:COM_RYANDENS_JAVAAGENTS_PLACEHOLDER.jar", "") } else { str.replace( "-javaagent:COM_RYANDENS_JAVAAGENTS_PLACEHOLDER.jar", diff --git a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentJibExtension.kt b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentJibExtension.kt index 82d12a8..210aa4f 100644 --- a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentJibExtension.kt +++ b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentJibExtension.kt @@ -23,10 +23,10 @@ import java.util.Optional * with the javaagent in it and a modified [ContainerBuildPlan.entrypoint] that specifies the `javaagent` flag. */ @ExperimentalStdlibApi -class JavaagentJibExtension : JibGradlePluginExtension, JavaagentPlugin { - override fun getExtraConfigType(): Optional> { - return Optional.empty() - } +class JavaagentJibExtension : + JibGradlePluginExtension, + JavaagentPlugin { + override fun getExtraConfigType(): Optional> = Optional.empty() override fun extendContainerBuildPlan( buildPlan: ContainerBuildPlan?, @@ -41,9 +41,13 @@ class JavaagentJibExtension : JibGradlePluginExtension, JavaagentPlugin { val localAgentPaths = checkNotNull( - gradleData?.project?.plugins?.getPlugin( - JavaagentJibExtension::class.java, - )?.javaagentPathProvider?.invoke(), + gradleData + ?.project + ?.plugins + ?.getPlugin( + JavaagentJibExtension::class.java, + )?.javaagentPathProvider + ?.invoke(), ) val planBuilder = buildPlan.toBuilder() @@ -61,7 +65,12 @@ class JavaagentJibExtension : JibGradlePluginExtension, JavaagentPlugin { FileEntriesLayer.DEFAULT_MODIFICATION_TIME, ) } - val javaagentLayer = FileEntriesLayer.builder().setName("javaagent").setEntries(javaagentFileEntries).build() + val javaagentLayer = + FileEntriesLayer + .builder() + .setName("javaagent") + .setEntries(javaagentFileEntries) + .build() val layers = buildList { add(javaagentLayer) diff --git a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentPlugin.kt b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentPlugin.kt index 01451d0..3978a0c 100644 --- a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentPlugin.kt +++ b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentPlugin.kt @@ -13,9 +13,7 @@ interface JavaagentPlugin : Plugin { * Plugins that the implementing class expects to be applied before [applyAfterJavaagentSetup] runs. By default, * this returns an empty [Collection] */ - fun dependentProjectPlugins(): Collection>> { - return emptySet() - } + fun dependentProjectPlugins(): Collection>> = emptySet() /** * Initial setup for any plugin that wants to configure a javaagent for a project, followed by delegating to the diff --git a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentTestPlugin.kt b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentTestPlugin.kt index 6d7ce8e..5d57ee7 100644 --- a/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentTestPlugin.kt +++ b/plugin/src/main/kotlin/com/ryandens/javaagent/JavaagentTestPlugin.kt @@ -8,14 +8,14 @@ import org.gradle.api.plugins.JavaPlugin import org.gradle.api.provider.Provider import org.gradle.api.tasks.testing.Test -class JavaagentTestPlugin : Plugin, JavaagentPlugin { +class JavaagentTestPlugin : + Plugin, + JavaagentPlugin { companion object { const val CONFIGURATION_NAME = "testJavaagent" } - override fun dependentProjectPlugins(): Collection>> { - return setOf(JavaPlugin::class.java) - } + override fun dependentProjectPlugins(): Collection>> = setOf(JavaPlugin::class.java) override fun applyAfterJavaagentSetup( project: Project, @@ -38,8 +38,7 @@ class JavaagentTestPlugin : Plugin, JavaagentPlugin { if (enabled.get()) { JavaForkOptionsConfigurer.configureJavaForkOptions( it, - javaagentTestConfiguration.map { - configuration -> + javaagentTestConfiguration.map { configuration -> configuration.files }, ) diff --git a/plugin/src/test/kotlin/com/ryandens/javaagent/JavaagentTestPluginTest.kt b/plugin/src/test/kotlin/com/ryandens/javaagent/JavaagentTestPluginTest.kt index c2db987..79d1851 100644 --- a/plugin/src/test/kotlin/com/ryandens/javaagent/JavaagentTestPluginTest.kt +++ b/plugin/src/test/kotlin/com/ryandens/javaagent/JavaagentTestPluginTest.kt @@ -22,7 +22,13 @@ class JavaagentTestPluginTest { } @Test fun `plugin adds jvm argument provider for javaagent`() { - assertEquals(1, project.tasks.named("test", org.gradle.api.tasks.testing.Test::class.java).get().jvmArgumentProviders.size) + assertEquals( + 1, + project.tasks + .named("test", org.gradle.api.tasks.testing.Test::class.java) + .get() + .jvmArgumentProviders.size, + ) } @Test fun `plugin javaagent test configuration can be disabled`() { @@ -30,6 +36,12 @@ class JavaagentTestPluginTest { it.enabled.set(false) } - assertEquals(0, project.tasks.named("test", org.gradle.api.tasks.testing.Test::class.java).get().jvmArgumentProviders.size) + assertEquals( + 0, + project.tasks + .named("test", org.gradle.api.tasks.testing.Test::class.java) + .get() + .jvmArgumentProviders.size, + ) } }