diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ConditionalOnPlatformVersion.java b/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ConditionalOnPlatformVersion.java index 3c6accb6..678daf37 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ConditionalOnPlatformVersion.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ConditionalOnPlatformVersion.java @@ -22,6 +22,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import io.spring.initializr.generator.version.VersionRange; + import org.springframework.context.annotation.Conditional; /** @@ -38,8 +40,8 @@ import org.springframework.context.annotation.Conditional; public @interface ConditionalOnPlatformVersion { /** - * The version ranges to check. The condition matches when at least one range matches - * the platform version. + * The {@linkplain VersionRange version ranges} to check. The condition matches when + * at least one range matches the platform version. * @return the version ranges to check */ String[] value(); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ProjectGenerationCondition.java b/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ProjectGenerationCondition.java index 55eaf748..58a1436c 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ProjectGenerationCondition.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/condition/ProjectGenerationCondition.java @@ -23,7 +23,8 @@ import org.springframework.context.annotation.ConditionContext; import org.springframework.core.type.AnnotatedTypeMetadata; /** - * Base class for all project generation {@link Condition Conditions}. + * Base class for project generation {@link Condition Conditions} that rely on the state + * of the {@link ProjectDescription}. * * @author Andy Wilkinson */ diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriter.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriter.java index 73ac39ab..24015ba4 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriter.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriter.java @@ -37,24 +37,47 @@ public class IndentingWriter extends Writer { private boolean prependIndent = false; + /** + * Create a new instance with the specified {@linkplain Writer writer} using a default + * indent strategy of 4 spaces. + * @param out the writer to use + */ public IndentingWriter(Writer out) { this(out, new SimpleIndentStrategy(" ")); } + /** + * Create a new instance with the specified {@linkplain Writer writer} and indent + * strategy. + * @param out the writer to use + * @param indentStrategy a function that provides the ident to use based on a + * indentation level + */ public IndentingWriter(Writer out, Function indentStrategy) { this.out = out; this.indentStrategy = indentStrategy; } + /** + * Write the specified text. + * @param string the content to write + */ public void print(String string) { write(string.toCharArray(), 0, string.length()); } + /** + * Write the specified text and append a new line. + * @param string the content to write + */ public void println(String string) { write(string.toCharArray(), 0, string.length()); println(); } + /** + * Write a new line. + */ public void println() { String separator = System.lineSeparator(); try { @@ -66,17 +89,28 @@ public class IndentingWriter extends Writer { this.prependIndent = true; } + /** + * Increase the indentation level and execute the {@link Runnable}. Decrease the + * indentation level on completion. + * @param runnable the code to execute withing an extra indentation level + */ public void indented(Runnable runnable) { indent(); runnable.run(); outdent(); } + /** + * Increase the indentation level. + */ private void indent() { this.level++; refreshIndent(); } + /** + * Decrease the indentation level. + */ private void outdent() { this.level--; refreshIndent(); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriterFactory.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriterFactory.java index 9b5e8ad0..ea437a31 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriterFactory.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/IndentingWriterFactory.java @@ -53,7 +53,8 @@ public final class IndentingWriterFactory { } /** - * Create an {@link IndentingWriterFactory} with default settings. + * Create an {@link IndentingWriterFactory} with a default indentation strategy of 4 + * spaces. * @return an {@link IndentingWriterFactory} with default settings */ public static IndentingWriterFactory withDefaultSettings() { @@ -99,7 +100,7 @@ public final class IndentingWriterFactory { * Register an indenting strategy for the specified content. * @param contentId the identifier of the content to configure * @param indentingStrategy the indent strategy for that particular content - * @return this builder + * @return this for method chaining * @see #createIndentingWriter(String, Writer) */ public Builder indentingStrategy(String contentId, Function indentingStrategy) { diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/SimpleIndentStrategy.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/SimpleIndentStrategy.java index a8a991a8..d8d61d32 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/SimpleIndentStrategy.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/SimpleIndentStrategy.java @@ -31,7 +31,7 @@ public class SimpleIndentStrategy implements Function { /** * Create a new instance with the indent style to apply. - * @param indent the indent to apply for a single level + * @param indent the indent to apply for each indent level */ public SimpleIndentStrategy(String indent) { Assert.notNull(indent, "Indent must be provided"); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/template/MustacheTemplateRenderer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/template/MustacheTemplateRenderer.java index 06af1a85..3b1765b4 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/template/MustacheTemplateRenderer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/template/MustacheTemplateRenderer.java @@ -34,7 +34,8 @@ import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; /** - * A {@link TemplateRenderer} using Mustache. + * A {@link TemplateRenderer} using Mustache with a configurable resource prefix. + * Templates should have an {@code mustache} extension. * * @author Stephane Nicoll */ @@ -46,6 +47,13 @@ public class MustacheTemplateRenderer implements TemplateRenderer { private final Cache templateCache; + /** + * Create a new instance with the resource prefix and the {@link Cache} to use. + * @param resourcePrefix the resource prefix to apply to locate a template based on + * its name + * @param templateCache the cache to use for compiled templates (can be {@code null} + * to not use caching) + */ public MustacheTemplateRenderer(String resourcePrefix, Cache templateCache) { String prefix = (resourcePrefix.endsWith("/") ? resourcePrefix : resourcePrefix + "/"); this.mustache = Mustache.compiler().withLoader(mustacheTemplateLoader(prefix)).escapeHTML(false); @@ -53,6 +61,12 @@ public class MustacheTemplateRenderer implements TemplateRenderer { this.templateCache = templateCache; } + /** + * Create a new instance with the resource prefix to use. + * @param resourcePrefix the resource prefix to apply to locate a template based on + * its name + * @see #MustacheTemplateRenderer(String, Cache) + */ public MustacheTemplateRenderer(String resourcePrefix) { this(resourcePrefix, null); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/BulletedSection.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/BulletedSection.java index db9c2634..8815268b 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/BulletedSection.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/BulletedSection.java @@ -27,7 +27,8 @@ import java.util.Map; import io.spring.initializr.generator.io.template.TemplateRenderer; /** - * {@link Section} for list of items using a {@link TemplateRenderer}. + * {@link Section} for list of items using a {@link TemplateRenderer}. The template is + * rendered with the registered items set in the model with a configurable item name. * * @param the type of the item in the bullets * @author Madhura Bhave @@ -42,25 +43,49 @@ public class BulletedSection implements Section { private List items = new ArrayList<>(); + /** + * Create a new instance adding items in the model with the {@code items} key. + * @param templateRenderer the {@linkplain TemplateRenderer template renderer} to use + * @param templateName the name of the template + */ public BulletedSection(TemplateRenderer templateRenderer, String templateName) { this(templateRenderer, templateName, "items"); } + /** + * Create a new instance. + * @param templateRenderer the {@linkplain TemplateRenderer template renderer} to use + * @param templateName the name of the template + * @param itemName the key of the items in the model + */ public BulletedSection(TemplateRenderer templateRenderer, String templateName, String itemName) { this.templateRenderer = templateRenderer; this.templateName = templateName; this.itemName = itemName; } + /** + * Add an item to the list. + * @param item the item to add + * @return this for method chaining + */ public BulletedSection addItem(T item) { this.items.add(item); return this; } + /** + * Specify whether this section is empty. + * @return {@code true} if no item is registered + */ public boolean isEmpty() { return this.items.isEmpty(); } + /** + * Return an immutable list of the registered items. + * @return the registered items + */ public List getItems() { return Collections.unmodifiableList(this.items); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/MustacheSection.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/MustacheSection.java index d18c04cd..b9b82ab0 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/MustacheSection.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/MustacheSection.java @@ -36,6 +36,13 @@ public class MustacheSection implements Section { private final Map model; + /** + * Create a new instance. + * @param templateRenderer the {@link MustacheTemplateRenderer template renderer} to + * use + * @param templateName the name of the template + * @param model the initial model + */ public MustacheSection(MustacheTemplateRenderer templateRenderer, String templateName, Map model) { this.templateRenderer = templateRenderer; this.templateName = templateName; diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/Section.java b/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/Section.java index a9d5d0ee..07057b48 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/Section.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/io/text/Section.java @@ -27,6 +27,11 @@ import java.io.PrintWriter; */ public interface Section { + /** + * Write the content of the section to the specified {@link PrintWriter writer}. + * @param writer the writer to use + * @throws IOException if writing the section failed + */ void write(PrintWriter writer) throws IOException; } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/MultipleResourcesProjectContributor.java b/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/MultipleResourcesProjectContributor.java index cb142c21..85439ba1 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/MultipleResourcesProjectContributor.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/MultipleResourcesProjectContributor.java @@ -42,6 +42,12 @@ public class MultipleResourcesProjectContributor implements ProjectContributor { private final Predicate executable; + /** + * Create a new instance with the {@code rootResource} to use to locate resources to + * copy to the project structure. + * @param rootResource the root resource path + * @see PathMatchingResourcePatternResolver#getResources(String) + */ public MultipleResourcesProjectContributor(String rootResource) { this(rootResource, (filename) -> false); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/SingleResourceProjectContributor.java b/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/SingleResourceProjectContributor.java index bb97d83d..283bdceb 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/SingleResourceProjectContributor.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/project/contributor/SingleResourceProjectContributor.java @@ -36,18 +36,26 @@ public class SingleResourceProjectContributor implements ProjectContributor { private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - private final String filename; + private final String relativePath; private final String resourcePattern; - public SingleResourceProjectContributor(String filename, String resourcePattern) { - this.filename = filename; + /** + * Create a new instance. + * @param relativePath the {@linkplain Path#resolve(String) relative path} in the + * generated structure. + * @param resourcePattern the pattern to use to locate the resource to copy to the + * project structure + * @see PathMatchingResourcePatternResolver#getResource(String) + */ + public SingleResourceProjectContributor(String relativePath, String resourcePattern) { + this.relativePath = relativePath; this.resourcePattern = resourcePattern; } @Override public void contribute(Path projectRoot) throws IOException { - Path output = projectRoot.resolve(this.filename); + Path output = projectRoot.resolve(this.relativePath); if (!Files.exists(output)) { Files.createDirectories(output.getParent()); Files.createFile(output);