Review Gradle build Javadoc

This commit is contained in:
Stephane Nicoll
2019-10-03 14:21:22 +02:00
parent 42976ca9f7
commit e0b274c383
12 changed files with 155 additions and 16 deletions

View File

@@ -23,7 +23,7 @@ import io.spring.initializr.generator.buildsystem.BuildItemResolver;
import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSettings.Builder;
/**
* Gradle build configuration for a project.
* Gradle-specific {@linkplain Build build configuration}.
*
* @author Andy Wilkinson
* @author Jean-Baptiste Nizet
@@ -40,10 +40,17 @@ public class GradleBuild extends Build {
private final GradleBuildscript.Builder buildscript = new GradleBuildscript.Builder();
/**
* Create a new Gradle build using the specified {@link BuildItemResolver}.
* @param buildItemResolver the build item resolved to use
*/
public GradleBuild(BuildItemResolver buildItemResolver) {
super(buildItemResolver);
}
/**
* Create a new Gradle build without a build item resolver.
*/
public GradleBuild() {
this(null);
}
@@ -58,22 +65,44 @@ public class GradleBuild extends Build {
return this.settings.build();
}
/**
* Return the {@link GradlePluginContainer plugin container} to use to configure
* plugins.
* @return the {@link GradlePluginContainer}
*/
public GradlePluginContainer plugins() {
return this.plugins;
}
/**
* Return the {@link GradleConfigurationContainer configuration container} to use for
* configuration customizations.
* @return the {@link GradleConfigurationContainer}
*/
public GradleConfigurationContainer configurations() {
return this.configurations;
}
/**
* Return the {@link GradleTaskContainer task container} to use to configure tasks.
* @return the {@link GradleTaskContainer}
*/
public GradleTaskContainer tasks() {
return this.tasks;
}
/**
* Customize the {@code buildscript} of the build using the specified consumer.
* @param buildscript a consumer of the current buildscript
*/
public void buildscript(Consumer<GradleBuildscript.Builder> buildscript) {
buildscript.accept(this.buildscript);
}
/**
* Return the {@link GradleBuildscript buildscript} of this build.
* @return the buildscript to use
*/
public GradleBuildscript getBuildscript() {
return this.buildscript.build();
}

View File

@@ -19,7 +19,7 @@ package io.spring.initializr.generator.buildsystem.gradle;
import io.spring.initializr.generator.buildsystem.BuildSettings;
/**
* Gradle {@link BuildSettings}.
* Gradle-specific {@linkplain BuildSettings build settings}.
*
* @author Stephane Nicoll
*/
@@ -47,11 +47,20 @@ public class GradleBuildSettings extends BuildSettings {
private String sourceCompatibility;
/**
* Set the java version compatibility to use when compiling Java source.
* @param sourceCompatibility java version compatibility
* @return this for method chaining
*/
public Builder sourceCompatibility(String sourceCompatibility) {
this.sourceCompatibility = sourceCompatibility;
return self();
}
/**
* Build a {@link GradleBuildSettings} with the current state of this builder.
* @return a {@link GradleBuildSettings}
*/
public GradleBuildSettings build() {
return new GradleBuildSettings(this);
}

View File

@@ -52,6 +52,13 @@ import io.spring.initializr.generator.version.VersionProperty;
*/
public abstract class GradleBuildWriter {
/**
* Write a {@linkplain GradleBuild build.gradle} using the specified
* {@linkplain IndentingWriter writer}.
* @param writer the writer to use
* @param build the gradle build to write
* @throws IOException if the writer fails to write the build
*/
public final void writeTo(IndentingWriter writer, GradleBuild build) throws IOException {
GradleBuildSettings settings = build.getSettings();
writeImports(writer, build.tasks());
@@ -67,8 +74,6 @@ public abstract class GradleBuildWriter {
writeDependencies(writer, build);
writeBoms(writer, build);
writeTasks(writer, build.tasks());
// writeTasksWithTypeCustomizations(writer, build);
// writeTaskCustomizations(writer, build);
}
private void writeImports(IndentingWriter writer, GradleTaskContainer tasks) {

View File

@@ -68,11 +68,21 @@ public class GradleBuildscript {
return this;
}
public Builder ext(String key, String value) {
this.ext.put(key, value);
/**
* Set a {@code ext} property.
* @param name the name of the property
* @param value the value of the property
* @return this for method chaining
*/
public Builder ext(String name, String value) {
this.ext.put(name, value);
return this;
}
/**
* Build a {@link GradleBuildscript} with the current state of this builder.
* @return a {@link GradleBuildscript}
*/
public GradleBuildscript build() {
return new GradleBuildscript(this);
}

View File

@@ -21,7 +21,8 @@ import java.util.LinkedHashSet;
import java.util.Set;
/**
* Custom {@code gradle} configuration.
* A custom Gradle configuration that can be associated to a {@linkplain GradleBuild
* build}.
*
* @author Stephane Nicoll
*/
@@ -45,8 +46,8 @@ public class GradleConfiguration {
}
/**
* Return the names that this configuration should extend from.
* @return the names that this configuration should extend from
* Return the configuration names that this configuration should extend from.
* @return the configuration names that this configuration should extend from
*/
public Set<String> getExtendsFrom() {
return this.extendsFrom;
@@ -58,15 +59,26 @@ public class GradleConfiguration {
private Set<String> extendsFrom = new LinkedHashSet<>();
public Builder(String name) {
protected Builder(String name) {
this.name = name;
}
/**
* Add a configuration name that this configuration should extend from. Does
* nothing if such configuration is already present.
* @param configurationName the name of a configuration this configuration should
* extend from
* @return this for method chaining
*/
public Builder extendsFrom(String configurationName) {
this.extendsFrom.add(configurationName);
return this;
}
/**
* Build a {@link GradleConfiguration} with the current state of this builder.
* @return a {@link GradleConfiguration}
*/
public GradleConfiguration build() {
return new GradleConfiguration(this);
}

View File

@@ -26,7 +26,7 @@ import java.util.stream.Stream;
import io.spring.initializr.generator.buildsystem.gradle.GradleConfiguration.Builder;
/**
* A container for custom configuration and {@link GradleConfiguration configuration
* A container for custom configuration and {@linkplain GradleConfiguration configuration
* customizations}.
*
* @author Stephane Nicoll

View File

@@ -17,9 +17,10 @@
package io.spring.initializr.generator.buildsystem.gradle;
import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.DependencyScope;
/**
* A {@link Dependency} with specific settings for the Gradle build system.
* Gradle-specific {@link Dependency}.
*
* @author Stephane Nicoll
*/
@@ -27,19 +28,37 @@ public class GradleDependency extends Dependency {
private final String configuration;
public GradleDependency(Builder builder) {
protected GradleDependency(Builder builder) {
super(builder);
this.configuration = builder.configuration;
}
/**
* Initialize a new dependency {@link Builder} with the specified coordinates.
* @param groupId the group ID of the dependency
* @param artifactId the artifact ID of the dependency
* @return a new builder
*/
public static Builder withCoordinates(String groupId, String artifactId) {
return new Builder(groupId, artifactId);
}
/**
* Initialize a new dependency {@link Builder} with the state of the specified
* {@link Dependency}.
* @param dependency the dependency to use to initialize the builder
* @return a new builder initialized with the same state as the {@code dependency}
*/
public static Builder from(Dependency dependency) {
return new Builder(dependency.getGroupId(), dependency.getArtifactId()).initialize(dependency);
}
/**
* Return the configuration to use for the dependency. If not set, a default
* configuration is inferred from the {@linkplain #getScope() scope} of the
* dependency.
* @return the custom configuration name to use or {@code null}
*/
public String getConfiguration() {
return this.configuration;
}
@@ -57,6 +76,12 @@ public class GradleDependency extends Dependency {
super(groupId, artifactId);
}
/**
* Specify the configuration to use for the dependency. Overrides the
* {@linkplain DependencyScope scope}.
* @param configuration the name of the configuration to use
* @return this for method chaining
*/
public Builder configuration(String configuration) {
this.configuration = configuration;
return self();

View File

@@ -27,15 +27,28 @@ public class GradlePlugin {
private final boolean apply;
/**
* Create a new instance.
* @param id the id of the plugin
* @param apply whether the plugin should be applied or not
*/
public GradlePlugin(String id, boolean apply) {
this.id = id;
this.apply = apply;
}
/**
* Return the plugin identifier.
* @return the plugin id
*/
public String getId() {
return this.id;
}
/**
* Return whether the plugin should be applied.
* @return {@code true} to use {@code apply}, {@code false} to register it
*/
public boolean isApply() {
return this.apply;
}

View File

@@ -23,7 +23,7 @@ import java.util.function.Function;
import java.util.stream.Stream;
/**
* A container for {@link GradlePlugin}s.
* A container for {@linkplain GradlePlugin gradle plugins}.
*
* @author HaiTao Zhang
*/

View File

@@ -22,7 +22,7 @@ import io.spring.initializr.generator.buildsystem.MavenRepository;
import io.spring.initializr.generator.io.IndentingWriter;
/**
* {@link GradleBuild} settings abstraction.
* {@link GradleBuild} settings writer abstraction.
*
* @author Andy Wilkinson
* @author Jean-Baptiste Nizet
@@ -31,6 +31,13 @@ import io.spring.initializr.generator.io.IndentingWriter;
*/
public abstract class GradleSettingsWriter {
/**
* Write a {@linkplain GradleBuild settings.gradle} using the specified
* {@linkplain IndentingWriter writer}.
* @param writer the writer to use
* @param build the gradle build to write
* @throws IOException if the writer fails to write the build
*/
public final void writeTo(IndentingWriter writer, GradleBuild build) throws IOException {
writePluginManagement(writer, build);
writer.println("rootProject.name = " + wrapWithQuotes(build.getSettings().getArtifact()));

View File

@@ -120,18 +120,39 @@ public class GradleTask {
this(name, null);
}
/**
* Add a task attribute.
* @param target the name of the attribute
* @param value the value
*/
public void attribute(String target, String value) {
this.attributes.put(target, value);
}
/**
* Invoke a task method.
* @param target the name of the method
* @param arguments the arguments
*/
public void invoke(String target, String... arguments) {
this.invocations.add(new Invocation(target, Arrays.asList(arguments)));
}
/**
* Customize a nested task for the specified property. If such nested task has
* already been added, the consumer can be used to further tune the existing task
* configuration.
* @param property a task property
* @param customizer a {@link Consumer} to customize the nested task
*/
public void nested(String property, Consumer<Builder> customizer) {
customizer.accept(this.nested.computeIfAbsent(property, (name) -> new Builder(property)));
}
/**
* Build a {@link GradleTask} with the current state of this builder.
* @return a {@link GradleTask}
*/
public GradleTask build() {
return new GradleTask(this);
}
@@ -152,10 +173,18 @@ public class GradleTask {
this.arguments = arguments;
}
/**
* Return the name of the method.
* @return the method name
*/
public String getTarget() {
return this.target;
}
/**
* Return the arguments (can be empty).
* @return the method arguments
*/
public List<String> getArguments() {
return this.arguments;
}

View File

@@ -29,7 +29,7 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
* A container for {@link GradleTask Gradle tasks}.
* A container for {@linkplain GradleTask Gradle tasks}.
*
* @author Stephane Nicoll
*/