diff --git a/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java b/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java index 8ac585073..ddecf1501 100755 --- a/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java +++ b/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java @@ -57,8 +57,8 @@ public boolean isDumpGcActivity() { @Internal protected T getProjectParser() { - if(gpp == null) { - if(extension == null) { + if (gpp == null) { + if (extension == null) { throw new IllegalArgumentException("Must configure extension"); } if (resolveDependenciesTask == null) { diff --git a/plugin/src/main/java/org/openrewrite/gradle/DefaultRewriteExtension.java b/plugin/src/main/java/org/openrewrite/gradle/DefaultRewriteExtension.java index 5f31d93b4..a8856d872 100644 --- a/plugin/src/main/java/org/openrewrite/gradle/DefaultRewriteExtension.java +++ b/plugin/src/main/java/org/openrewrite/gradle/DefaultRewriteExtension.java @@ -38,7 +38,7 @@ public class DefaultRewriteExtension implements RewriteExtension { private File configFile; private Provider checkstyleConfigProvider; - private Provider> checkstylePropertiesProvider; + private Provider> checkstylePropertiesProvider; private File checkstyleConfigFile; private String metricsUri = magicalMetricsLogString; private boolean enableExperimentalGradleBuildScriptParsing = true; @@ -98,10 +98,10 @@ public void setCheckstyleConfigFile(File configFile) { @Override @Nullable public File getCheckstyleConfigFile() { - if(checkstyleConfigFile == null && checkstyleConfigProvider != null) { + if (checkstyleConfigFile == null && checkstyleConfigProvider != null) { try { return checkstyleConfigProvider.get(); - } catch(Exception e) { + } catch (Exception e) { return null; } } @@ -110,7 +110,7 @@ public File getCheckstyleConfigFile() { @Override public Map getCheckstyleProperties() { - if(checkstyleConfigProvider == null) { + if (checkstyleConfigProvider == null) { return emptyMap(); } return checkstylePropertiesProvider.get(); @@ -195,11 +195,11 @@ public List getActiveRecipes() { } private Properties getVersionProps() { - if(versionProps == null) { - try(InputStream is = DefaultRewriteExtension.class.getResourceAsStream("/rewrite/versions.properties")) { + if (versionProps == null) { + try (InputStream is = DefaultRewriteExtension.class.getResourceAsStream("/rewrite/versions.properties")) { versionProps = new Properties(); versionProps.load(is); - } catch(IOException e) { + } catch (IOException e) { throw new RuntimeException(e); } } @@ -211,7 +211,7 @@ private Properties getVersionProps() { */ @Override public String getRewriteVersion() { - if(rewriteVersion == null) { + if (rewriteVersion == null) { return getVersionProps().getProperty("org.openrewrite:rewrite-core"); } return rewriteVersion; @@ -219,7 +219,7 @@ public String getRewriteVersion() { @Override public String getRewritePolyglotVersion() { - if(rewriteVersion == null) { + if (rewriteVersion == null) { return getVersionProps().getProperty("org.openrewrite:rewrite-polyglot"); } return rewriteVersion; @@ -228,7 +228,7 @@ public String getRewritePolyglotVersion() { private String rewriteGradleModelVersion; @Override public String getRewriteGradleModelVersion() { - if(rewriteGradleModelVersion == null) { + if (rewriteGradleModelVersion == null) { rewriteGradleModelVersion = getVersionProps().getProperty("org.openrewrite.gradle.tooling:model"); } return rewriteGradleModelVersion; @@ -237,7 +237,7 @@ public String getRewriteGradleModelVersion() { private String rewriteKotlinVersion; @Override public String getRewriteKotlinVersion() { - if(rewriteKotlinVersion == null) { + if (rewriteKotlinVersion == null) { rewriteKotlinVersion = getVersionProps().getProperty("org.openrewrite:rewrite-kotlin"); } return rewriteKotlinVersion; @@ -384,7 +384,7 @@ public String getJacksonModuleKotlinVersion() { @Override public boolean getThrowOnParseFailures() { - if(project.getProperties().containsKey("rewrite.throwOnParseFailures")) { + if (project.getProperties().containsKey("rewrite.throwOnParseFailures")) { return true; } return throwOnParseFailures; diff --git a/plugin/src/main/java/org/openrewrite/gradle/DelegatingProjectParser.java b/plugin/src/main/java/org/openrewrite/gradle/DelegatingProjectParser.java index 77ae7fac4..2b33d8726 100755 --- a/plugin/src/main/java/org/openrewrite/gradle/DelegatingProjectParser.java +++ b/plugin/src/main/java/org/openrewrite/gradle/DelegatingProjectParser.java @@ -54,7 +54,7 @@ public DelegatingProjectParser(Project project, RewriteExtension extension, Set< .getResource("/org/openrewrite/gradle/isolated/DefaultProjectParser.class") .toString()); classpathUrls.add(currentJar); - if(rewriteClassLoader == null || !classpathUrls.equals(rewriteClasspath)) { + if (rewriteClassLoader == null || !classpathUrls.equals(rewriteClasspath)) { if (rewriteClassLoader != null) { rewriteClassLoader.close(); } diff --git a/plugin/src/main/java/org/openrewrite/gradle/SanitizedMarkerPrinter.java b/plugin/src/main/java/org/openrewrite/gradle/SanitizedMarkerPrinter.java index 0d89b75af..131c01f41 100644 --- a/plugin/src/main/java/org/openrewrite/gradle/SanitizedMarkerPrinter.java +++ b/plugin/src/main/java/org/openrewrite/gradle/SanitizedMarkerPrinter.java @@ -29,7 +29,7 @@ public class SanitizedMarkerPrinter implements PrintOutputCapture.MarkerPrinter { @Override public String beforeSyntax(Marker marker, Cursor cursor, UnaryOperator commentWrapper) { - if(marker instanceof SearchResult) { + if (marker instanceof SearchResult) { return DEFAULT.beforeSyntax(marker, cursor, commentWrapper); } return ""; @@ -37,7 +37,7 @@ public String beforeSyntax(Marker marker, Cursor cursor, UnaryOperator c @Override public String afterSyntax(Marker marker, Cursor cursor, UnaryOperator commentWrapper) { - if(marker instanceof SearchResult) { + if (marker instanceof SearchResult) { return DEFAULT.afterSyntax(marker, cursor, commentWrapper); } return ""; diff --git a/plugin/src/main/java/org/openrewrite/gradle/TimeUtils.java b/plugin/src/main/java/org/openrewrite/gradle/TimeUtils.java index 063101748..271c5194b 100644 --- a/plugin/src/main/java/org/openrewrite/gradle/TimeUtils.java +++ b/plugin/src/main/java/org/openrewrite/gradle/TimeUtils.java @@ -27,39 +27,39 @@ public static String prettyPrint(Duration duration) { StringBuilder result = new StringBuilder(); long days = duration.getSeconds() / SECONDS_PER_DAY; boolean startedPrinting = false; - if(days > 0) { + if (days > 0) { startedPrinting = true; result.append(days); result.append(" day"); - if(days != 1) { + if (days != 1) { result.append("s"); } result.append(" "); } - long hours = duration.toHours() % 24; - if(startedPrinting || hours > 0) { + long hours = duration.toHours() % 24; + if (startedPrinting || hours > 0) { startedPrinting = true; result.append(hours); result.append(" hour"); - if(hours != 1) { + if (hours != 1) { result.append("s"); } result.append(" "); } long minutes = (duration.getSeconds() / SECONDS_PER_MINUTE) % MINUTES_PER_HOUR; - if(startedPrinting || minutes > 0) { + if (startedPrinting || minutes > 0) { result.append(minutes); result.append(" minute"); - if(minutes != 1) { + if (minutes != 1) { result.append("s"); } result.append(" "); } long seconds = duration.getSeconds() % SECONDS_PER_MINUTE; - if(startedPrinting || seconds > 0) { + if (startedPrinting || seconds > 0) { result.append(seconds); result.append(" second"); if (seconds != 1) { @@ -71,7 +71,7 @@ public static String prettyPrint(Duration duration) { long millis = duration.getNano() / 1000_000; result.append(millis); result.append(" millisecond"); - if(millis != 1) { + if (millis != 1) { result.append("s"); } diff --git a/plugin/src/main/kotlin/org/openrewrite/gradle/GradleProjectSpec.kt b/plugin/src/main/kotlin/org/openrewrite/gradle/GradleProjectSpec.kt index a0acd9647..6b147d45e 100644 --- a/plugin/src/main/kotlin/org/openrewrite/gradle/GradleProjectSpec.kt +++ b/plugin/src/main/kotlin/org/openrewrite/gradle/GradleProjectSpec.kt @@ -77,51 +77,51 @@ class GradleProjectSpec( fun build(): GradleProjectSpec { dir.mkdirs() - if(settingsGradle != null) { + if (settingsGradle != null) { File(dir, "settings.gradle").writeText(settingsGradle!!) } - if(groovyBuildScript != null) { + if (groovyBuildScript != null) { File(dir, "build.gradle").writeText(groovyBuildScript!!) } - if(rewriteYaml != null) { + if (rewriteYaml != null) { File(dir, "rewrite.yml").writeText(rewriteYaml!!) } - if(checkstyleXml != null) { - File(dir, "config/checkstyle/checkstyle.xml").apply { + if (checkstyleXml != null) { + File(dir, "config/checkstyle/checkstyle.xml").apply{ parentFile.mkdirs() writeText(checkstyleXml!!) } } - for(props in propertiesFiles.entries) { - File(dir, props.key).apply { + for (props in propertiesFiles.entries) { + File(dir, props.key).apply{ parentFile.mkdirs() writeText(props.value) } } - for(text in textFiles.entries) { - File(dir, text.key).apply { + for (text in textFiles.entries) { + File(dir, text.key).apply{ parentFile.mkdirs() writeText(text.value) } } - for(sourceSet in sourceSets) { + for (sourceSet in sourceSets) { sourceSet.build(File(dir, "src")) } val settings = File(dir, "settings.gradle") val settingsText = "rootProject.name = \"${dir.name}\"\n" - if(subprojects.isEmpty()) { + if (subprojects.isEmpty()) { settings.writeText("rootProject.name = \"${dir.name}\"\n") } else { - val subprojectsDeclarations = subprojects.joinToString("\n") { subproject -> "include('${subproject.dir.name}')" } + val subprojectsDeclarations = subprojects.joinToString("\n") { subproject -> "include('${subproject.dir.name}')" } settings.writeText(settingsText + subprojectsDeclarations) - for(subproject in subprojects) { + for (subproject in subprojects) { subproject.build() } } @@ -161,8 +161,8 @@ class GradleSourceSetSpec( @Suppress("RegExpSimplifiable") fun build(dir: File): GradleSourceSetSpec { dir.mkdirs() - for(javaSource in javaSources) { - val peckage = if(javaSource.startsWith("package")) { + for (javaSource in javaSources) { + val peckage = if (javaSource.startsWith("package")) { "package\\s+([a-zA-Z0-9.]+);".toRegex(RegexOption.MULTILINE) .find(javaSource)!! .groupValues[1] @@ -170,18 +170,18 @@ class GradleSourceSetSpec( "" }.replace(".", "/") val clazz = ".*(class|interface|enum)\\s+([a-zA-Z0-9-_]+)".toRegex(RegexOption.MULTILINE).find(javaSource)!!.groupValues[2] - val path = if(peckage.isEmpty()) { + val path = if (peckage.isEmpty()) { "$name/java/$clazz.java" } else { "$name/java/$peckage/$clazz.java" } - File(dir, path).apply { + File(dir, path).apply{ parentFile.mkdirs() writeText(javaSource) } } - for(kotlinSource in kotlinSources) { - val peckage = if(kotlinSource.startsWith("package")) { + for (kotlinSource in kotlinSources) { + val peckage = if (kotlinSource.startsWith("package")) { "package\\s+([a-zA-Z0-9.]+)".toRegex(RegexOption.MULTILINE) .find(kotlinSource)!! .groupValues[1] @@ -189,18 +189,18 @@ class GradleSourceSetSpec( "" }.replace(".", "/") val clazz = ".*(class|interface|enum)\\s+([a-zA-Z0-9-_]+)".toRegex(RegexOption.MULTILINE).find(kotlinSource)!!.groupValues[2] - val path = if(peckage.isEmpty()) { + val path = if (peckage.isEmpty()) { "$name/kotlin/$clazz.kt" } else { "$name/kotlin/$peckage/$clazz.kt" } - File(dir, path).apply { + File(dir, path).apply{ parentFile.mkdirs() writeText(kotlinSource) } } - for(groovySource in groovyClasses) { - val peckage = if(groovySource.startsWith("package")) { + for (groovySource in groovyClasses) { + val peckage = if (groovySource.startsWith("package")) { "package\\s+([a-zA-Z0-9.]+);?".toRegex(RegexOption.MULTILINE) .find(groovySource)!! .groupValues[1] @@ -208,27 +208,27 @@ class GradleSourceSetSpec( "" }.replace(".", "/") val clazz = ".*(class|interface|enum)\\s+([a-zA-Z0-9-_]+)".toRegex(RegexOption.MULTILINE).find(groovySource)!!.groupValues[2] - val path = if(peckage.isEmpty()) { + val path = if (peckage.isEmpty()) { "$name/groovy/$clazz.groovy" } else { "$name/groovy/$peckage/$clazz.groovy" } - File(dir, path).apply { + File(dir, path).apply{ parentFile.mkdirs() writeText(groovySource) } } - if(propertiesFiles.isNotEmpty()) { - for(props in propertiesFiles.entries) { - File(dir, "$name/resources/${props.key}").apply { + if (propertiesFiles.isNotEmpty()) { + for (props in propertiesFiles.entries) { + File(dir, "$name/resources/${props.key}").apply{ parentFile.mkdirs() writeText(props.value) } } } - if(yamlFiles.isNotEmpty()) { - for(yaml in yamlFiles.entries) { - File(dir, "$name/resources/${yaml.key}").apply { + if (yamlFiles.isNotEmpty()) { + for (yaml in yamlFiles.entries) { + File(dir, "$name/resources/${yaml.key}").apply{ parentFile.mkdirs() writeText(yaml.value) } diff --git a/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDiscoverTest.kt b/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDiscoverTest.kt index f2bd14a59..0e17b2d89 100644 --- a/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDiscoverTest.kt +++ b/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDiscoverTest.kt @@ -28,7 +28,7 @@ class RewriteDiscoverTest : RewritePluginTest { fun `rewriteDiscover prints recipes from external dependencies`( @TempDir projectDir: File ) { - gradleProject(projectDir) { + gradleProject(projectDir) { buildGradle(""" plugins { id("java") diff --git a/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDryRunTest.kt b/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDryRunTest.kt index 7a2d37da7..254e17772 100644 --- a/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDryRunTest.kt +++ b/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteDryRunTest.kt @@ -35,7 +35,7 @@ class RewriteDryRunTest : RewritePluginTest { }public static void main(String[] args) { sayGoodbye(); } } """.trimIndent() - gradleProject(projectDir) { + gradleProject(projectDir) { rewriteYaml(""" type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.gradle.SayHello @@ -65,7 +65,7 @@ class RewriteDryRunTest : RewritePluginTest { activeRecipe("org.openrewrite.gradle.SayHello", "org.openrewrite.java.format.AutoFormat") } """) - sourceSet("main") { + sourceSet("main") { java(helloWorld) } } @@ -82,7 +82,7 @@ class RewriteDryRunTest : RewritePluginTest { fun `A recipe with optional configuration can be activated directly`( @TempDir projectDir: File ) { - gradleProject(projectDir) { + gradleProject(projectDir) { buildGradle(""" plugins { id("java") @@ -97,7 +97,7 @@ class RewriteDryRunTest : RewritePluginTest { } } """) - sourceSet("main") { + sourceSet("main") { java(""" package org.openrewrite.before; @@ -127,7 +127,7 @@ class RewriteDryRunTest : RewritePluginTest { @DisabledIf("lessThanGradle6_1") @Test fun testMultiplatform(@TempDir projectDir: File) { - gradleProject(projectDir) { + gradleProject(projectDir) { buildGradle(""" plugins { id("java") @@ -177,7 +177,7 @@ class RewriteDryRunTest : RewritePluginTest { } rootProject.name = "example" """) - sourceSet("commonMain") { + sourceSet("commonMain") { kotlin(""" class HelloWorld { fun sayHello() { diff --git a/plugin/src/test/kotlin/org/openrewrite/gradle/RewritePluginTest.kt b/plugin/src/test/kotlin/org/openrewrite/gradle/RewritePluginTest.kt index 7ff56fb66..d2b7f9e9b 100644 --- a/plugin/src/test/kotlin/org/openrewrite/gradle/RewritePluginTest.kt +++ b/plugin/src/test/kotlin/org/openrewrite/gradle/RewritePluginTest.kt @@ -29,7 +29,7 @@ interface RewritePluginTest { GradleRunner.create() .withDebug(ManagementFactory.getRuntimeMXBean().inputArguments.toString().indexOf("-agentlib:jdwp") > 0) .withProjectDir(testDir) - .apply { + .apply{ if (gradleVersion != null) { withGradleVersion(gradleVersion) } diff --git a/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteRunTest.kt b/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteRunTest.kt index fd3052a85..d77f32793 100644 --- a/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteRunTest.kt +++ b/plugin/src/test/kotlin/org/openrewrite/gradle/RewriteRunTest.kt @@ -40,7 +40,7 @@ class RewriteRunTest : RewritePluginTest { // Gradle provides no control over how it arbitrarily orders its classpath // So even if isolation isn't working at all, this could pass if it happens to put the rewrite's required version // of jackson first on the classpath. - gradleProject(projectDir) { + gradleProject(projectDir) { buildGradle(""" buildscript { repositories { @@ -69,7 +69,7 @@ class RewriteRunTest : RewritePluginTest { activeRecipe("org.openrewrite.java.format.AutoFormat") } """) - sourceSet("test") { + sourceSet("test") { java(""" package com.foo; @@ -89,7 +89,7 @@ class RewriteRunTest : RewritePluginTest { fun `rewriteRun will alter the source file according to the provided active recipe`( @TempDir projectDir: File ) { - gradleProject(projectDir) { + gradleProject(projectDir) { rewriteYaml(""" type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.gradle.SayHello @@ -119,7 +119,7 @@ class RewriteRunTest : RewritePluginTest { activeRecipe("org.openrewrite.gradle.SayHello", "org.openrewrite.java.format.AutoFormat") } """) - sourceSet("main") { + sourceSet("main") { java(""" package org.openrewrite.before; @@ -170,7 +170,7 @@ class RewriteRunTest : RewritePluginTest { public void passes() { } } """.trimIndent() - gradleProject(projectDir) { + gradleProject(projectDir) { rewriteYaml(""" type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.FormatAndAddProperty @@ -212,8 +212,8 @@ class RewriteRunTest : RewritePluginTest { } } """) - subproject("a") { - sourceSet("test") { + subproject("a") { + sourceSet("test") { java(""" package com.foo; @@ -228,8 +228,8 @@ class RewriteRunTest : RewritePluginTest { propertiesFile("test.properties", "foo=baz\n") } } - subproject("b") { - sourceSet("test") { + subproject("b") { + sourceSet("test") { java(bTestClassExpected) } } @@ -265,7 +265,7 @@ class RewriteRunTest : RewritePluginTest { fun `Checkstyle configuration is applied as a style`( @TempDir projectDir: File ) { - gradleProject(projectDir) { + gradleProject(projectDir) { checkstyleXml("""