From b326d2ab95c94d994f0d7f874befb076ba34578b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 29 Nov 2016 19:56:29 -0800 Subject: [PATCH] Setup builds for lib and maven, and moved Provisioner into lib. --- gradle.properties | 5 ++- gradle/java-setup.gradle | 6 ++-- lib/build.gradle | 13 +++++++ .../diffplug/gradle/spotless/Provisioner.java | 29 +++++++++++++++ .../gradle/spotless/ProvisionerTest.java | 36 +++++++++++++++++++ plugin-gradle/build.gradle | 3 +- ...rovisioner.java => GradleProvisioner.java} | 14 ++------ .../gradle/spotless/java/JavaExtension.java | 6 ++-- .../spotless/java/GoogleJavaFormatTest.java | 4 +-- plugin-maven/build.gradle | 12 +++++++ .../gradle/spotless/MavenProvisioner.java | 25 +++++++++++++ .../gradle/spotless/MavenProvisionerTest.java | 25 +++++++++++++ spotless.license.java => spotless.license | 0 spotlessSelf.gradle | 3 +- 14 files changed, 159 insertions(+), 22 deletions(-) create mode 100644 lib/build.gradle create mode 100644 lib/src/main/java/com/diffplug/gradle/spotless/Provisioner.java create mode 100644 lib/src/test/java/com/diffplug/gradle/spotless/ProvisionerTest.java rename plugin-gradle/src/main/java/com/diffplug/gradle/spotless/{Provisioner.java => GradleProvisioner.java} (76%) create mode 100644 plugin-maven/build.gradle create mode 100644 plugin-maven/src/main/java/com/diffplug/gradle/spotless/MavenProvisioner.java create mode 100644 plugin-maven/src/test/java/com/diffplug/gradle/spotless/MavenProvisionerTest.java rename spotless.license.java => spotless.license (100%) diff --git a/gradle.properties b/gradle.properties index 954c68fb46..3e7968ce16 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ org=diffplug group=com.diffplug.spotless artifactIdLib=spotless-lib artifactIdMaven=spotless-maven-plugin -artifactIdSpotless=spotless-gradle-plugin +artifactIdGradle=spotless-gradle-plugin # Build requirements VER_JAVA=1.8 @@ -23,6 +23,9 @@ VER_FRESHMARK=1.3.1 VER_JGIT=4.5.0.201609210915-r VER_TRIES=2.6.0 +VER_MAVEN_PLUGIN_API=3.0 +VER_MAVEN_PLUGIN_ANNOTATIONS=3.4 + # Testing VER_JUNIT=4.12 VER_ASSERTJ=3.5.2 diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 1c740e6ac5..7b772f70c2 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -89,9 +89,9 @@ javadoc { options.header javadocInfo options.footer javadocInfo // setup links - options.linksOffline('https://docs.oracle.com/javase/8/docs/api/', 'gradle/javadoc/java8') - options.linksOffline("https://docs.gradle.org/2.14/javadoc/", 'gradle/javadoc/gradle') - options.linksOffline("https://diffplug.github.io/durian/javadoc/${verSnapshot(VER_DURIAN)}/", 'gradle/javadoc/durian') + options.linksOffline('https://docs.oracle.com/javase/8/docs/api/', rootProject.file('gradle/javadoc/java8')) + options.linksOffline("https://docs.gradle.org/2.14/javadoc/", rootProject.file('gradle/javadoc/gradle')) + options.linksOffline("https://diffplug.github.io/durian/javadoc/${verSnapshot(VER_DURIAN)}/", rootProject.file('gradle/javadoc/durian')) } task javadocJar(type: Jar, dependsOn: javadoc) { diff --git a/lib/build.gradle b/lib/build.gradle new file mode 100644 index 0000000000..179ec36920 --- /dev/null +++ b/lib/build.gradle @@ -0,0 +1,13 @@ +ext.artifactId = project.artifactIdLib +apply from: rootProject.file('gradle/java-setup.gradle') + +dependencies { + compile "com.diffplug.durian:durian-core:${VER_DURIAN}" + compile "com.diffplug.durian:durian-io:${VER_DURIAN}" + compile "com.diffplug.freshmark:freshmark:${VER_FRESHMARK}" + compile "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" + compile "com.googlecode.concurrent-trees:concurrent-trees:${VER_TRIES}" + testCompile "junit:junit:${VER_JUNIT}" + testCompile "org.assertj:assertj-core:${VER_ASSERTJ}" + testCompile "com.diffplug.durian:durian-testlib:${VER_DURIAN}" +} diff --git a/lib/src/main/java/com/diffplug/gradle/spotless/Provisioner.java b/lib/src/main/java/com/diffplug/gradle/spotless/Provisioner.java new file mode 100644 index 0000000000..34dd901bee --- /dev/null +++ b/lib/src/main/java/com/diffplug/gradle/spotless/Provisioner.java @@ -0,0 +1,29 @@ +/* + * 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.util.Arrays; +import java.util.Collection; +import java.util.Set; + +public interface Provisioner { + Set provisionWithDependencies(Collection mavenCoordinates); + + default Set provisionWithDependencies(String... mavenCoordinates) { + return provisionWithDependencies(Arrays.asList(mavenCoordinates)); + } +} diff --git a/lib/src/test/java/com/diffplug/gradle/spotless/ProvisionerTest.java b/lib/src/test/java/com/diffplug/gradle/spotless/ProvisionerTest.java new file mode 100644 index 0000000000..dea97fcb6b --- /dev/null +++ b/lib/src/test/java/com/diffplug/gradle/spotless/ProvisionerTest.java @@ -0,0 +1,36 @@ +/* + * 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.util.Arrays; +import java.util.stream.Collectors; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +public class ProvisionerTest { + @Test + public void testManipulation() { + Provisioner provisioner = deps -> deps.stream().map(File::new).collect(Collectors.toSet()); + Assertions.assertThat(provisioner.provisionWithDependencies("a")) + .containsExactlyInAnyOrder(new File("a")); + Assertions.assertThat(provisioner.provisionWithDependencies("a", "a")) + .containsExactlyInAnyOrder(new File("a")); + Assertions.assertThat(provisioner.provisionWithDependencies(Arrays.asList("a", "a"))) + .containsExactlyInAnyOrder(new File("a")); + } +} diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index aa4bb69f16..acc0d425fb 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -1,10 +1,11 @@ -ext.artifactId = project.artifactIdSpotless +ext.artifactId = project.artifactIdGradle apply from: rootProject.file('gradle/java-setup.gradle') apply plugin: 'com.gradle.plugin-publish' apply plugin: 'java-gradle-plugin' dependencies { + compile project(':lib') compile "com.diffplug.durian:durian-core:${VER_DURIAN}" compile "com.diffplug.durian:durian-io:${VER_DURIAN}" compile "com.diffplug.freshmark:freshmark:${VER_FRESHMARK}" diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Provisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java similarity index 76% rename from plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Provisioner.java rename to plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index b895c5b63e..f1205d9fc8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Provisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -15,21 +15,13 @@ */ package com.diffplug.gradle.spotless; -import java.io.File; -import java.util.Arrays; -import java.util.Collection; -import java.util.Set; - import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; -public interface Provisioner { - Set provisionWithDependencies(Collection mavenCoordinates); - - default Set provisionWithDependencies(String... mavenCoordinates) { - return provisionWithDependencies(Arrays.asList(mavenCoordinates)); - } +/** Gradle integration for Provisioner. */ +public class GradleProvisioner { + private GradleProvisioner() {} public static Provisioner fromProject(Project project) { return mavenCoords -> { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/java/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/java/JavaExtension.java index 7a829469dd..c4c34fb06e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/java/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/java/JavaExtension.java @@ -24,8 +24,8 @@ import com.diffplug.gradle.spotless.BaseFormatTask; import com.diffplug.gradle.spotless.FormatExtension; +import com.diffplug.gradle.spotless.GradleProvisioner; import com.diffplug.gradle.spotless.LicenseHeaderStep; -import com.diffplug.gradle.spotless.Provisioner; import com.diffplug.gradle.spotless.SerializableFileFilter; import com.diffplug.gradle.spotless.SpotlessExtension; @@ -63,7 +63,7 @@ public void eclipseFormatFile(String eclipseVersion, Object eclipseFormatFile) { getProject().getRepositories().maven(mvn -> { mvn.setUrl("https://dl.bintray.com/diffplug/opensource"); }); - addStep(EclipseFormatter.createStep(eclipseVersion, getProject().file(eclipseFormatFile), Provisioner.fromProject(getProject()))); + addStep(EclipseFormatter.createStep(eclipseVersion, getProject().file(eclipseFormatFile), GradleProvisioner.fromProject(getProject()))); } /** Uses the [google-java-format](https://github.com/google/google-java-format) jar to format source code. */ @@ -78,7 +78,7 @@ public void googleJavaFormat() { * for an workaround for using snapshot versions. */ public void googleJavaFormat(String version) { - addStep(GoogleJavaFormat.createStep(version, Provisioner.fromProject(getProject()))); + addStep(GoogleJavaFormat.createStep(version, GradleProvisioner.fromProject(getProject()))); } /** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/java/GoogleJavaFormatTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/java/GoogleJavaFormatTest.java index daa94ca726..a0d794eb8c 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/java/GoogleJavaFormatTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/java/GoogleJavaFormatTest.java @@ -27,7 +27,7 @@ import com.diffplug.gradle.spotless.CheckFormatTask; import com.diffplug.gradle.spotless.FormatterStep; import com.diffplug.gradle.spotless.GradleIntegrationTest; -import com.diffplug.gradle.spotless.Provisioner; +import com.diffplug.gradle.spotless.GradleProvisioner; public class GoogleJavaFormatTest extends GradleIntegrationTest { @Test @@ -68,7 +68,7 @@ public void testStepEquality() { Project project = ProjectBuilder.builder().withProjectDir(folder.getRoot()).build(); project.getRepositories().mavenCentral(); // copied from JavaExtension.googleJavaFormat - Function create = version -> GoogleJavaFormat.createStep(version, Provisioner.fromProject(project)); + Function create = version -> GoogleJavaFormat.createStep(version, GradleProvisioner.fromProject(project)); Assertions.assertThat(create.apply("1.0")) .isEqualTo(create.apply("1.0")) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle new file mode 100644 index 0000000000..01c48abeab --- /dev/null +++ b/plugin-maven/build.gradle @@ -0,0 +1,12 @@ +ext.artifactId = project.artifactIdMaven +apply from: rootProject.file('gradle/java-setup.gradle') + +dependencies { + compile project(':lib') + compile "org.apache.maven:maven-plugin-api:${VER_MAVEN_PLUGIN_API}" + compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:${VER_MAVEN_PLUGIN_ANNOTATIONS}" + + testCompile "junit:junit:${VER_JUNIT}" + testCompile "org.assertj:assertj-core:${VER_ASSERTJ}" + testCompile "com.diffplug.durian:durian-testlib:${VER_DURIAN}" +} diff --git a/plugin-maven/src/main/java/com/diffplug/gradle/spotless/MavenProvisioner.java b/plugin-maven/src/main/java/com/diffplug/gradle/spotless/MavenProvisioner.java new file mode 100644 index 0000000000..ff4844a6ad --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/gradle/spotless/MavenProvisioner.java @@ -0,0 +1,25 @@ +/* + * 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; + +/** Maven integration for Provisioner. */ +public class MavenProvisioner { + private MavenProvisioner() {} + + public static Provisioner create() { + throw new UnsupportedOperationException(); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/gradle/spotless/MavenProvisionerTest.java b/plugin-maven/src/test/java/com/diffplug/gradle/spotless/MavenProvisionerTest.java new file mode 100644 index 0000000000..4ecda7c061 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/gradle/spotless/MavenProvisionerTest.java @@ -0,0 +1,25 @@ +/* + * 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 org.junit.Test; + +public class MavenProvisionerTest { + @Test + public void test() { + + } +} diff --git a/spotless.license.java b/spotless.license similarity index 100% rename from spotless.license.java rename to spotless.license diff --git a/spotlessSelf.gradle b/spotlessSelf.gradle index 6095b10564..ba48686dec 100644 --- a/spotlessSelf.gradle +++ b/spotlessSelf.gradle @@ -5,7 +5,8 @@ plugins { } spotless { java { - licenseHeaderFile 'spotless.license.java' + target '**/*.java' + licenseHeaderFile 'spotless.license' importOrderFile 'spotless.importorder' eclipseFormatFile 'spotless.eclipseformat.xml' trimTrailingWhitespace()