Skip to content

Commit

Permalink
Setup builds for lib and maven, and moved Provisioner into lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Nov 30, 2016
1 parent 46fc2bb commit b326d2a
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 22 deletions.
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions gradle/java-setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -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}"
}
29 changes: 29 additions & 0 deletions lib/src/main/java/com/diffplug/gradle/spotless/Provisioner.java
Original file line number Diff line number Diff line change
@@ -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<File> provisionWithDependencies(Collection<String> mavenCoordinates);

default Set<File> provisionWithDependencies(String... mavenCoordinates) {
return provisionWithDependencies(Arrays.asList(mavenCoordinates));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
3 changes: 2 additions & 1 deletion plugin-gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> provisionWithDependencies(Collection<String> mavenCoordinates);

default Set<File> 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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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. */
Expand All @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,7 +68,7 @@ public void testStepEquality() {
Project project = ProjectBuilder.builder().withProjectDir(folder.getRoot()).build();
project.getRepositories().mavenCentral();
// copied from JavaExtension.googleJavaFormat
Function<String, FormatterStep> create = version -> GoogleJavaFormat.createStep(version, Provisioner.fromProject(project));
Function<String, FormatterStep> create = version -> GoogleJavaFormat.createStep(version, GradleProvisioner.fromProject(project));

Assertions.assertThat(create.apply("1.0"))
.isEqualTo(create.apply("1.0"))
Expand Down
12 changes: 12 additions & 0 deletions plugin-maven/build.gradle
Original file line number Diff line number Diff line change
@@ -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}"
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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() {

}
}
File renamed without changes.
3 changes: 2 additions & 1 deletion spotlessSelf.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ plugins {
}
spotless {
java {
licenseHeaderFile 'spotless.license.java'
target '**/*.java'
licenseHeaderFile 'spotless.license'
importOrderFile 'spotless.importorder'
eclipseFormatFile 'spotless.eclipseformat.xml'
trimTrailingWhitespace()
Expand Down

0 comments on commit b326d2a

Please sign in to comment.