Skip to content

Commit f8b69ae

Browse files
committed
feat(maven-plugin): make execution-root-only rendering opt-out
Adds figlet.executionRootOnly (default true) so a module can still render its own banner when explicitly configured, instead of always being skipped in favor of the reactor's execution-root project.
1 parent 7468abf commit f8b69ae

3 files changed

Lines changed: 54 additions & 9 deletions

File tree

figlet-maven-plugin/src/main/java/io/github/spannm/figlet/maven/plugin/RenderMojo.java

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
* wrapped in one {@code <figletFont>} tag referencing that font.
3737
*
3838
* <h2>Minimal configuration</h2>
39+
* An {@code <execution>} is required to bind the goal into the build — a plugin
40+
* merely listed in {@code <build><plugins>} without one is never invoked
41+
* automatically. No {@code <phase>} is needed inside it, though: the goal
42+
* defaults to the {@code validate} phase (see {@link LifecyclePhase#VALIDATE}).
43+
* To avoid repeating the {@code <execution>} block in every module, declare it
44+
* once in a shared parent POM instead.
3945
* <pre>{@code
4046
* <plugin>
4147
* <groupId>io.github.spannm</groupId>
@@ -63,10 +69,16 @@
6369
* }</pre>
6470
*
6571
* <h2>Multi-module builds</h2>
66-
* This goal only executes for the execution-root project (the module Maven
67-
* was invoked on) and is a no-op for every other module in the reactor, even
68-
* if bound in a child module's own {@code pom.xml}. This prevents the same
69-
* banner from being printed once per module.
72+
* By default, this goal only executes for the execution-root project (the
73+
* module Maven was invoked on) and is a no-op for every other module in the
74+
* reactor, even if bound in a child module's own {@code pom.xml}. This
75+
* prevents the same banner from being printed once per module when the
76+
* execution is inherited from a shared parent POM.
77+
* <p>
78+
* Some use cases do want a banner per module (e.g. a distinct name per
79+
* artifact). Set {@code executionRootOnly} to {@code false} — typically
80+
* overridden in a specific module's own {@code <configuration>}, not
81+
* globally in the parent — to render there too.
7082
*
7183
* @since 1.0.0
7284
*/
@@ -102,7 +114,8 @@ public class RenderMojo extends AbstractFontMojo {
102114
*/
103115
@Parameter(property = "figlet.content",
104116
defaultValue = "<lineBreak/><figletFont name=\"standard\">${project.name}</figletFont><lineBreak/><preserveWhitespace> v${project.version}</preserveWhitespace><lineBreak/>",
105-
required = true, alias = "content")
117+
required = true,
118+
alias = "content")
106119
private String parmContent;
107120

108121
/**
@@ -112,16 +125,31 @@ public class RenderMojo extends AbstractFontMojo {
112125
* When {@code false}, unsupported characters are silently replaced by
113126
* {@code '?'}, and unresolved placeholders are left as-is (with a warning logged).
114127
*/
115-
@Parameter(property = "figlet.strict", defaultValue = "true", alias = "strict")
128+
@Parameter(property = "figlet.strict",
129+
defaultValue = "true",
130+
alias = "strict")
116131
private boolean parmStrict;
117132

118133
/**
119134
* Where to output the ASCII art banner.<br>
120135
* Supported values are: {@code info}, {@code debug}, {@code stdout}, {@code stderr}.
121136
*/
122-
@Parameter(property = "figlet.target", defaultValue = "info", alias = "target")
137+
@Parameter(property = "figlet.target",
138+
defaultValue = "info",
139+
alias = "target")
123140
private String parmTarget;
124141

142+
/**
143+
* When {@code true} (the default), this goal only runs for the
144+
* execution-root project and is a no-op in every other reactor module —
145+
* see the class Javadoc for why. Set to {@code false} in a module that
146+
* should render its own banner regardless of reactor position.
147+
*/
148+
@Parameter(property = "figlet.executionRootOnly",
149+
defaultValue = "true",
150+
alias = "executionRootOnly")
151+
private boolean parmExecutionRootOnly;
152+
125153
/** The current Maven project, injected automatically. */
126154
@Parameter(defaultValue = "${project}", readonly = true, required = true, alias = "project")
127155
private MavenProject parmProject;
@@ -132,8 +160,9 @@ int getWidth() {
132160

133161
@Override
134162
protected void executeImpl() throws MojoExecutionException, MojoFailureException {
135-
if (!parmProject.isExecutionRoot()) {
136-
getLog().debug("Skipping figlet rendering: project is not the execution root");
163+
if (parmExecutionRootOnly && !parmProject.isExecutionRoot()) {
164+
getLog().debug("Skipping figlet rendering: project is not the execution root "
165+
+ "(set executionRootOnly=false to render in this module too)");
137166
return;
138167
}
139168

figlet-maven-plugin/src/main/resources/figlet-help.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ GOALS
2222
figlet.width Output width (default: 72)
2323
figlet.strict Fail on unknown chars (default: true)
2424
figlet.target Output target: info/debug/stdout/stderr (default: info)
25+
figlet.executionRootOnly
26+
Only render for the execution-root project, skip in
27+
other reactor modules (default: true)
2528
figlet.skip Skip this goal (default: false)
2629

2730
figlet:list-fonts (no default phase — run standalone)

figlet-maven-plugin/src/test/java/io/github/spannm/figlet/maven/plugin/RenderMojoTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void setUp() {
4040
setField(mojo, "parmWidth", 200);
4141
setField(mojo, "parmStrict", false);
4242
setField(mojo, "parmProject", createMinimalProject("test-artifact", "test-name", "0.8.15"));
43+
setField(mojo, "parmExecutionRootOnly", true);
4344
}
4445

4546
@Test
@@ -210,6 +211,18 @@ void execute_notExecutionRoot_shouldSkipRendering() throws Exception {
210211
assertThat(log.debugContains("Skipping figlet rendering")).isTrue();
211212
}
212213

214+
@Test
215+
void execute_notExecutionRoot_executionRootOnlyFalse_shouldRender() throws Exception {
216+
MavenProject project = (MavenProject) getField(mojo, "parmProject");
217+
project.setExecutionRoot(false);
218+
setField(mojo, "parmExecutionRootOnly", false);
219+
setField(mojo, "parmContent", "Hello");
220+
221+
mojo.execute();
222+
223+
assertThat(log.infoMessages).isNotEmpty();
224+
}
225+
213226
@Test
214227
void execute_invalidFont_shouldThrowMojoExecutionException() {
215228
setField(mojo, "parmFont", "invalid-font-name-xyz");

0 commit comments

Comments
 (0)