Skip to content

Commit

Permalink
refactor: Spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider and TeamModerne committed Sep 26, 2023
1 parent 01707ca commit e34bcf0
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public boolean isDumpGcActivity() {

@Internal
protected <T extends GradleProjectParser> T getProjectParser() {
if(gpp == null) {
if(extension == null) {
if (gpp == null) {
if (extension == null) {
throw new IllegalArgumentException("Must configure extension");
}
if (resolveDependenciesTask == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DefaultRewriteExtension implements RewriteExtension {
private File configFile;

private Provider<File> checkstyleConfigProvider;
private Provider<Map<String,Object>> checkstylePropertiesProvider;
private Provider<Map<String, Object>> checkstylePropertiesProvider;
private File checkstyleConfigFile;
private String metricsUri = magicalMetricsLogString;
private boolean enableExperimentalGradleBuildScriptParsing = true;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -110,7 +110,7 @@ public File getCheckstyleConfigFile() {

@Override
public Map<String, Object> getCheckstyleProperties() {
if(checkstyleConfigProvider == null) {
if (checkstyleConfigProvider == null) {
return emptyMap();
}
return checkstylePropertiesProvider.get();
Expand Down Expand Up @@ -195,11 +195,11 @@ public List<String> 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);
}
}
Expand All @@ -211,15 +211,15 @@ private Properties getVersionProps() {
*/
@Override
public String getRewriteVersion() {
if(rewriteVersion == null) {
if (rewriteVersion == null) {
return getVersionProps().getProperty("org.openrewrite:rewrite-core");
}
return rewriteVersion;
}

@Override
public String getRewritePolyglotVersion() {
if(rewriteVersion == null) {
if (rewriteVersion == null) {
return getVersionProps().getProperty("org.openrewrite:rewrite-polyglot");
}
return rewriteVersion;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
public class SanitizedMarkerPrinter implements PrintOutputCapture.MarkerPrinter {
@Override
public String beforeSyntax(Marker marker, Cursor cursor, UnaryOperator<String> commentWrapper) {
if(marker instanceof SearchResult) {
if (marker instanceof SearchResult) {
return DEFAULT.beforeSyntax(marker, cursor, commentWrapper);
}
return "";
}

@Override
public String afterSyntax(Marker marker, Cursor cursor, UnaryOperator<String> commentWrapper) {
if(marker instanceof SearchResult) {
if (marker instanceof SearchResult) {
return DEFAULT.afterSyntax(marker, cursor, commentWrapper);
}
return "";
Expand Down
18 changes: 9 additions & 9 deletions plugin/src/main/java/org/openrewrite/gradle/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
}

Expand Down
62 changes: 31 additions & 31 deletions plugin/src/main/kotlin/org/openrewrite/gradle/GradleProjectSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -161,74 +161,74 @@ 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]
} else {
""
}.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]
} else {
""
}.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]
} else {
""
}.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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit e34bcf0

Please sign in to comment.