+ * Useful if you want a different relative or absolute path, than the default of src/main/string-template for a + * string, or different directory or file, at a URL or in local filesystem. + *
+ * A STGroupString will be used if source containing "::=" and can contain multiple templates. The template(s) text
+ * should be wrapped like
+ * or << multiple-lines
+ * >>], to avoid having to use XML escaping for
<
and
+ * >
.
+ *
+ * An STGroupFile will be used if source doesn't contain "::=" and ends in ".stg". STGroupFile only supports ".stg" + * files. + *
+ * An STGroupDir will be used if source doesn't contain "::=" and doesn't end in ".stg". STGroupDir supports ".st" + * and ".stg" files. + *
+ * If source is not a valid URL, it will the converted to a file then converted to a URL. + *
+ * Default is ${string-template.source} + */ + @SuppressWarnings("CanBeFinal") + @Parameter(defaultValue ="${string-template.source}") + public String source = DEFAULT_DIR; + /** + * The name of the charset encoding of any .st or .stg files, if different from the project source encoding. + *
+ * Default is ${project.build.sourceEncoding}, or the default charset name.
+ */
+ @Parameter(defaultValue = "${project.build.sourceEncoding}")
+ public String encoding;
+ /**
+ * A map of type name to AttributeRenders class name; key = name of Class object to be rendered, value = name of
+ * AttributeRender class to have an instance registered.
+ *
+ * @see AttributeRenderer
+ * @see Attribute Renderers
+ */
+ @SuppressWarnings("unused")
+ @Parameter
+ public Map
+ * Default is false
+ */
+ @SuppressWarnings("CanBeFinal")
+ @Parameter(defaultValue = "${string-template.failFast}")
+ public boolean failFast = false;
+ /**
+ * If true, render templates concurrently, using all the CPU cores.
+ *
+ * Default is false
+ * Disabled until ST concurrency bugs in ST4.3.1 are fixed.
+ */
+ @SuppressWarnings({"unused", "FieldCanBeLocal"})
+ //@Parameter(defaultValue = "${string-template.renderTemplatesConcurrently}")
+ private final boolean renderTemplatesConcurrently = false;
+ /**
+ * A java.util.concurrent.TimeUnit for timeout of this.call().
+ *
+ * If a reference AttributeRender or ModelAdapter classes are not found in the dependencies, the whole of src/main/java
+ * will be compiled once, to attempt to make the class available, then the lookup retried, all later failed class
+ * lookups will not be retried. It is probably better for these classes to be provided via one, or more, "provided"
+ * scope dependency, for user projects of this plugin.
+ *
+ */
+@SuppressWarnings("ALL")
+@Mojo(name = "render", defaultPhase = GENERATE_SOURCES, threadSafe = true)
+public final class RenderMojo extends AbstractMojo {
+
+ /**
+ * A relative directory path under "${project}/src/main", or an absolute directory path, to be used as the base
+ * directory for template groups.
+ *
+ * Default is "string-template" for "src/main/string-template";
+ */
+ @Parameter(defaultValue = "${project.basedir}/src/main/string-template")
+ public String templateSrcDir;
+ /**
+ * If true, stop rendering Groups when the first Group fails or timeouts.
+ *
+ * Default is false
+ */
+ @Parameter(defaultValue = "${string-template.failFast}")
+ public boolean failFast = false;
+
+ /**
+ * If true, render groups concurrently, using all the CPU cores.
+ *
+ * Default is false
+ */
+ @Parameter(defaultValue = "${string-template.renderGroupsConcurrently}")
+ public boolean renderGroupsConcurrently;
+
+ /**
+ * The array of groups for use by Templates.
+ *
+ * At least one must be provided for Template use.
+ */
+ @Parameter(required = true)
+ public Group[] groups;
+
+ /**
+ * The array of Templates to render.
+ */
+ @Parameter(required = true)
+ public Template[] templates;
+
+ /**
+ * The Maven Project Object
+ */
+ @Parameter(defaultValue = "${project}", readonly = true)
+ MavenProject project;
+
+ /**
+ * The Maven Session Object
+ */
+ @Parameter(defaultValue = "${session}", readonly = true)
+ MavenSession session;
+
+ @Override
+ public synchronized String toString() {
+ final ToStringBuilder ts = new ToStringBuilder("RenderMojo", true);
+ ts.add("project", project);
+ ts.add("session", session);
+ ts.add("groups", groups);
+ ts.complete();
+ return ts.toString();
+ }
+
+ /**
+ * 1. Initilises and validate Groups.
+ *
+ * 2. Initilises and validate Templates, and attaches them to the reference Group.
+ *
+ * 3. Executes all the Groups, to execute their attached Templates, to get and render ST4 templates to target
+ * files.
+ *
+ * If any operation fails the Maven build should fail.
+ */
+ @Override
+ @SuppressWarnings("UseSpecificCatch")
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ final Log log = getLog();
+ try {
+ try (final RenderContext ctx = RenderContext.of(this)) { // Ensure that stStateMap saved
+ final Map
+ * The path to the output file, can be a relative or absolute path.
+ *
+ * I can't use Path, because there doesn't appear to be support for Path Mojo properties.
+ *
+ * If a relative path and name ends in .java, then will treated as a path in directory
+ * "${basedir}/target/generated-sources/java", unless path starts with "target/generated-sources/java".
+ *
+ * Else if a relative path and name doesn't end in .java, then will be a path in directory "${basedir}"
+ */
+ @Parameter(required = true)
+ public String target;
+ /**
+ * The charset name for encoding the template generated characters to bytes, to be written to the target file. Bye,
+ * bye damned FileWriter!
+ *
+ * Default is ${project.build.sourceEncoding}, or the default charset name.
+ */
+ @Parameter(defaultValue = "${project.build.sourceEncoding}")
+ public String targetEncoding;
+ /**
+ * If true, don't fail on a NO_SUCH_PROPERTY error.
+ *
+ * Default is ${string-template.allowNoSuchProperty}
+ */
+ @Parameter(defaultValue = "${string-template.allowNoSuchProperty}")
+ public boolean allowNoSuchProperty;
+ /**
+ * If true add Unicode BOM bytes at start of target file
+ *
+ * Default is false
+ */
+ @Parameter
+ public boolean withUnicodeBOM;
+
+ //
+ // Transient variables
+ //
+ /**
+ * If false don't appendMap render text
+ *
+ * Default is true
+ */
+ @Parameter
+ public boolean autoIndent = true;
+
+ /**
+ * A java.util.concurrent.TimeUnit for timeout of this.call()
+ *