mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-27 06:35:51 +08:00
Polish Javadoc
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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<Integer, String> 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();
|
||||
|
||||
@@ -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<Integer, String> indentingStrategy) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SimpleIndentStrategy implements Function<Integer, String> {
|
||||
|
||||
/**
|
||||
* 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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 <T> the type of the item in the bullets
|
||||
* @author Madhura Bhave
|
||||
@@ -42,25 +43,49 @@ public class BulletedSection<T> implements Section {
|
||||
|
||||
private List<T> 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<T> getItems() {
|
||||
return Collections.unmodifiableList(this.items);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,13 @@ public class MustacheSection implements Section {
|
||||
|
||||
private final Map<String, Object> 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<String, Object> model) {
|
||||
this.templateRenderer = templateRenderer;
|
||||
this.templateName = templateName;
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,12 @@ public class MultipleResourcesProjectContributor implements ProjectContributor {
|
||||
|
||||
private final Predicate<String> 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user