-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
324 additions
and
3 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
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
47 changes: 47 additions & 0 deletions
47
plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.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,47 @@ | ||
/* | ||
* Copyright 2020 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.spotless.maven.groovy; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.extra.EclipseBasedStepBuilder; | ||
import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
|
||
public class GrEclipse implements FormatterStepFactory { | ||
|
||
@Parameter | ||
private String file; | ||
|
||
@Parameter | ||
private String version; | ||
|
||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { | ||
EclipseBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner()); | ||
grEclipseConfig.setVersion(version == null ? GrEclipseFormatterStep.defaultVersion() : version); | ||
if (null != file) { | ||
File settingsFile = stepConfig.getFileLocator().locateFile(file); | ||
grEclipseConfig.setPreferences(Arrays.asList(settingsFile)); | ||
} | ||
return grEclipseConfig.build(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.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,52 @@ | ||
/* | ||
* Copyright 2020 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.spotless.maven.groovy; | ||
|
||
import java.util.Set; | ||
|
||
import com.diffplug.common.collect.ImmutableSet; | ||
import com.diffplug.spotless.maven.FormatterFactory; | ||
import com.diffplug.spotless.maven.generic.LicenseHeader; | ||
|
||
/** | ||
* A {@link FormatterFactory} implementation that corresponds to {@code <groovy>...</groovy>} configuration element. | ||
* <p> | ||
* It defines a formatter for groovy source files that can execute both language agnostic (e.g. {@link LicenseHeader}) | ||
* and groovy-specific (e.g. {@link GrEclipse}) steps. | ||
*/ | ||
public class Groovy extends FormatterFactory { | ||
|
||
private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy", "src/main/java/**/*.java", "src/test/java/**/*.java"); | ||
private static final String LICENSE_HEADER_DELIMITER = "package "; | ||
|
||
@Override | ||
public Set<String> defaultIncludes() { | ||
return DEFAULT_INCLUDES; | ||
} | ||
|
||
@Override | ||
public String licenseHeaderDelimiter() { | ||
return LICENSE_HEADER_DELIMITER; | ||
} | ||
|
||
public void addGreclipse(GrEclipse greclipse) { | ||
addStepFactory(greclipse); | ||
} | ||
|
||
public void addImportOrder(ImportOrder importOrder) { | ||
addStepFactory(importOrder); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/ImportOrder.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,49 @@ | ||
/* | ||
* Copyright 2020 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.spotless.maven.groovy; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.java.ImportOrderStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
|
||
public class ImportOrder implements FormatterStepFactory { | ||
@Parameter | ||
private String file; | ||
|
||
@Parameter | ||
private String order; | ||
|
||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig config) { | ||
if (file != null ^ order != null) { | ||
if (file != null) { | ||
File importsFile = config.getFileLocator().locateFile(file); | ||
return ImportOrderStep.forGroovy().createFrom(importsFile); | ||
} else { | ||
return ImportOrderStep.forGroovy().createFrom(order.split(",")); | ||
} | ||
} else if (file == null && order == null) { | ||
return ImportOrderStep.forGroovy().createFrom(); | ||
} else { | ||
throw new IllegalArgumentException("Must specify exactly one of 'file' or 'order'."); | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.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,38 @@ | ||
/* | ||
* Copyright 2020 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.spotless.maven.groovy; | ||
|
||
import org.junit.Test; | ||
|
||
import com.diffplug.spotless.maven.MavenIntegrationHarness; | ||
|
||
public class GrEclipseTest extends MavenIntegrationHarness { | ||
|
||
@Test | ||
public void testEclipse() throws Exception { | ||
writePomWithGroovySteps( | ||
"<greclipse>", | ||
" <file>${basedir}/greclipse.properties</file>", | ||
" <version>4.12.0</version>", | ||
"</greclipse>"); | ||
setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties"); | ||
|
||
String path = "src/main/groovy/test.groovy"; | ||
setFile(path).toResource("groovy/greclipse/format/unformatted.test"); | ||
mavenRunner().withArguments("spotless:apply").runNoError(); | ||
assertFile(path).sameAsResource("groovy/greclipse/format/formatted.test"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/ImportOrderTest.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,58 @@ | ||
/* | ||
* Copyright 2020 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.spotless.maven.groovy; | ||
|
||
import org.junit.Test; | ||
|
||
import com.diffplug.spotless.maven.MavenIntegrationHarness; | ||
|
||
public class ImportOrderTest extends MavenIntegrationHarness { | ||
@Test | ||
public void file() throws Exception { | ||
setFile("import.properties").toResource("java/importsorter/import.properties"); | ||
writePomWithGroovySteps( | ||
"<importOrder>", | ||
" <file>${basedir}/import.properties</file>", | ||
"</importOrder>"); | ||
runTest(); | ||
} | ||
|
||
@Test | ||
public void order() throws Exception { | ||
writePomWithGroovySteps( | ||
"<importOrder>", | ||
" <order>java,javax,org,\\#com</order>", | ||
"</importOrder>"); | ||
runTest(); | ||
} | ||
|
||
@Test | ||
public void standard() throws Exception { | ||
writePomWithGroovySteps("<importOrder />"); | ||
runTest("java/importsorter/GroovyCodeSortedMisplacedImportsDefault.test"); | ||
} | ||
|
||
private void runTest() throws Exception { | ||
runTest("java/importsorter/GroovyCodeSortedMisplacedImports.test"); | ||
} | ||
|
||
private void runTest(String expectedResource) throws Exception { | ||
String path = "src/main/groovy/test.groovy"; | ||
setFile(path).toResource("java/importsorter/GroovyCodeUnsortedMisplacedImports.test"); | ||
mavenRunner().withArguments("spotless:apply").runNoError(); | ||
assertFile(path).sameAsResource(expectedResource); | ||
} | ||
} |
Oops, something went wrong.