Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Eclipse formatter (behind -Pcom.palantir.baseline-format.eclipse feature flag) #707

Merged
merged 11 commits into from
Jul 31, 2019
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-707.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Use the Eclipse formatter in Spotless
links:
- https://github.com/palantir/gradle-baseline/pull/707
318 changes: 318 additions & 0 deletions gradle-baseline-java-config/resources/spotless/eclipse.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.palantir.baseline.plugins;

import com.diffplug.gradle.spotless.SpotlessExtension;
import java.nio.file.Paths;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.ConfigurableFileCollection;
Expand Down Expand Up @@ -46,14 +47,12 @@ public void apply(Project project) {
// use empty string to specify one group for all non-static imports
java.importOrder("");
java.trimTrailingWhitespace();
java.indentWithSpaces(4);
java.endWithNewline();

java.eclipse().configFile(
project.file(Paths.get(getConfigDir(), "spotless/eclipse.xml").toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid OS-specific paths. (or does gradle convert / internally?)


// No empty lines at start of blocks
java.replaceRegex("Block starts with blank lines", "\\) \\{\n+", ") {\n");

// No dangling parentheses - closing paren must be on the same line as the expression
java.replaceRegex("Dangling closing parenthesis", "(\n\\s+)+\\)", ")");
});

// necessary because SpotlessPlugin creates tasks in an afterEvaluate block
Expand All @@ -65,4 +64,5 @@ public void apply(Project project) {
});
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.gradle.testkit.runner.TaskOutcome
* This test relies on running ./gradlew :gradle-baseline-java-config:publishToMavenLocal.
*/
class BaselineConfigIntegrationTest extends AbstractPluginTest {
def projectVersion = "git describe --tags --first-parent --dirty=.dirty".execute().text.trim()
def projectVersion = "git describe --tags --first-parent --dirty=.dirty --abbrev=7".execute().text.trim()
def standardBuildFile = """
plugins {
id 'com.palantir.baseline-config'
Expand All @@ -46,7 +46,9 @@ class BaselineConfigIntegrationTest extends AbstractPluginTest {

then:
with('--stacktrace', '--info', 'baselineUpdateConfig').build()
directory('.baseline').list().toList().toSet() == ['checkstyle', 'copyright', 'eclipse', 'idea'].toSet()
directory('.baseline').list().toList().toSet() == [
'checkstyle', 'copyright', 'eclipse', 'idea', 'spotless'
].toSet()
directory('project').list().toList().isEmpty()
}

Expand All @@ -65,7 +67,9 @@ class BaselineConfigIntegrationTest extends AbstractPluginTest {

then:
with('--stacktrace', '--info', 'baselineUpdateConfig').build()
directory('.baseline').list().toList().toSet() == ['checkstyle', 'copyright', 'eclipse', 'idea'].toSet()
directory('.baseline').list().toList().toSet() == [
'checkstyle', 'copyright', 'eclipse', 'idea', 'spotless'
].toSet()
directory('project').list().toList().toSet() == ['scalastyle_config.xml'].toSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@

package com.palantir.baseline

import org.apache.commons.io.FileUtils
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome

class BaselineFormatIntegrationTest extends AbstractPluginTest {

def setup() {
FileUtils.copyDirectory(
new File("../gradle-baseline-java-config/resources"),
new File(projectDir, ".baseline"))
}

def standardBuildFile = '''
plugins {
id 'java'
Expand All @@ -36,14 +43,17 @@ class BaselineFormatIntegrationTest extends AbstractPluginTest {

def validJavaFile = '''
package test;
public class Test { void test() {
int x = 1;
System.out.println(
"Hello");
Optional.of("hello").orElseGet(() -> {
return "Hello World";
});
} }

public class Test {
void test() {
int x = 1;
System.out.println(
"Hello");
Optional.of("hello").orElseGet(() -> {
return "Hello World";
});
}
}
'''.stripIndent()

def invalidJavaFile = '''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class BaselineFormatTest extends Specification {

def setup() {
project = ProjectBuilder.builder().build()
project.buildscript {
repositories {
mavenCentral()
}
}
project.plugins.apply 'java'
project.plugins.apply BaselineFormat
project.evaluate()
Expand Down