-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides groovyGradle formatter as agreed in #115.
- Loading branch information
Frank Vennemeyer
committed
Aug 12, 2017
1 parent
8c0893a
commit 117bdcd
Showing
8 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.gradle.spotless; | ||
|
||
import java.util.Objects; | ||
|
||
import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; | ||
import com.diffplug.spotless.java.ImportOrderStep; | ||
|
||
public class GroovyGradleExtension extends FormatExtension { | ||
private static final String GRADLE_FILE_EXTENSION = "*.gradle"; | ||
static final String NAME = "groovyGradle"; | ||
|
||
public GroovyGradleExtension(SpotlessExtension rootExtension) { | ||
super(rootExtension); | ||
} | ||
|
||
public void importOrder(String... importOrder) { | ||
addStep(ImportOrderStep.createFromOrder(importOrder)); | ||
} | ||
|
||
public void importOrderFile(Object importOrderFile) { | ||
Objects.requireNonNull(importOrderFile); | ||
addStep(ImportOrderStep.createFromFile(getProject().file(importOrderFile))); | ||
} | ||
|
||
public GroovyExtension.GrEclipseConfig greclipse() { | ||
return greclipse(GrEclipseFormatterStep.defaultVersion()); | ||
} | ||
|
||
public GroovyExtension.GrEclipseConfig greclipse(String version) { | ||
return new GroovyExtension.GrEclipseConfig(version, this); | ||
} | ||
|
||
@Override | ||
protected void setupTask(SpotlessTask task) { | ||
if (target == null) { | ||
target = parseTarget(GRADLE_FILE_EXTENSION); | ||
} | ||
super.setupTask(task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.gradle.spotless; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
|
||
public class GroovyGradleExtensionTest extends GradleIntegrationTest { | ||
|
||
private final String HEADER = "//My tests header"; | ||
|
||
@Test | ||
public void defaultTarget() throws IOException { | ||
testTarget(true); | ||
} | ||
|
||
@Test | ||
public void customTarget() throws IOException { | ||
testTarget(false); | ||
} | ||
|
||
private void testTarget(boolean useDefaultTarget) throws IOException { | ||
String target = useDefaultTarget ? "" : "target 'other.gradle'"; | ||
File projectFile = write("build.gradle", | ||
"plugins {", | ||
" id 'com.diffplug.gradle.spotless'", | ||
"}", | ||
"spotless {", | ||
" groovyGradle {", | ||
target, | ||
" licenseHeader('" + HEADER + "', 'plugins')", | ||
" }", | ||
"}"); | ||
|
||
// write appends a line ending so re-read to see what the original currently looks like | ||
String unModified = read(projectFile.toPath()); | ||
|
||
// Run | ||
gradleRunner().withArguments("spotlessApply").build(); | ||
|
||
if (useDefaultTarget) { | ||
Assertions.assertThat(read(projectFile.toPath())).contains(HEADER); | ||
} else { | ||
assertFileContent(unModified, projectFile); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters