From 3ba88103bc85c7c5dedb35e228ec87ccc46a8f99 Mon Sep 17 00:00:00 2001
From: jnbdz <237008+jnbdz@users.noreply.github.com>
Date: Mon, 16 Nov 2026 22:09:07 -0500
Subject: [PATCH] Skip the transform goals on request and when the classes
directory is missing
Both goals get a skip parameter, smallrye.ffm.skip. transform-test also
honours maven.test.skip. A missing classes directory, as in a module without
tests or without sources, is logged and no longer fails the build.
---
maven-plugin/pom.xml | 5 +
.../ffm/maven/AbstractTransformMojo.java | 22 +++
.../smallrye/ffm/maven/TestTransformMojo.java | 11 ++
.../ffm/maven/TransformMojoSkipTest.java | 158 ++++++++++++++++++
4 files changed, 196 insertions(+)
create mode 100644 maven-plugin/src/test/java/io/smallrye/ffm/maven/TransformMojoSkipTest.java
diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml
index 52f9546..518ecb1 100644
--- a/maven-plugin/pom.xml
+++ b/maven-plugin/pom.xml
@@ -86,6 +86,11 @@
maven-settings
provided
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
diff --git a/maven-plugin/src/main/java/io/smallrye/ffm/maven/AbstractTransformMojo.java b/maven-plugin/src/main/java/io/smallrye/ffm/maven/AbstractTransformMojo.java
index 2fcae7c..518bff8 100644
--- a/maven-plugin/src/main/java/io/smallrye/ffm/maven/AbstractTransformMojo.java
+++ b/maven-plugin/src/main/java/io/smallrye/ffm/maven/AbstractTransformMojo.java
@@ -9,6 +9,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Parameter;
import io.smallrye.classfile.ClassFile;
import io.smallrye.classfile.ClassModel;
@@ -19,6 +20,12 @@
public abstract class AbstractTransformMojo extends AbstractMojo {
private static final ClassFile cf = ClassFile.of(ClassFile.StackMapsOption.STACK_MAPS_WHEN_REQUIRED);
+ /**
+ * Skip the transformation.
+ */
+ @Parameter(defaultValue = "false", property = "smallrye.ffm.skip")
+ private boolean skip;
+
/**
* Construct a new instance.
*/
@@ -26,7 +33,15 @@ public abstract class AbstractTransformMojo extends AbstractMojo {
}
public void execute() throws MojoExecutionException, MojoFailureException {
+ if (skip || skipped()) {
+ getLog().info("Skipping the transformation");
+ return;
+ }
Path classes = classesDirectory().toPath();
+ if (!Files.isDirectory(classes)) {
+ getLog().info("Nothing to transform: " + classes + " does not exist");
+ return;
+ }
getLog().info("Transforming classes in path: " + classes);
int cnt = processPath(classes);
switch (cnt) {
@@ -74,4 +89,11 @@ private int processPath(final Path path) throws MojoFailureException {
}
abstract File classesDirectory();
+
+ /**
+ * {@return {@code true} if the goal has its own reason to skip, beyond the {@code skip} parameter}
+ */
+ boolean skipped() {
+ return false;
+ }
}
diff --git a/maven-plugin/src/main/java/io/smallrye/ffm/maven/TestTransformMojo.java b/maven-plugin/src/main/java/io/smallrye/ffm/maven/TestTransformMojo.java
index e79c9d2..ee5fe45 100644
--- a/maven-plugin/src/main/java/io/smallrye/ffm/maven/TestTransformMojo.java
+++ b/maven-plugin/src/main/java/io/smallrye/ffm/maven/TestTransformMojo.java
@@ -17,6 +17,12 @@ public final class TestTransformMojo extends AbstractTransformMojo {
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true, property = "smallrye-ffm.testClassesDirectory")
private File classesDirectory;
+ /**
+ * Skip the transformation of the test classes when the build skips the tests and their compilation.
+ */
+ @Parameter(defaultValue = "false", property = "maven.test.skip")
+ private boolean mavenTestSkip;
+
/**
* Construct a new instance.
*/
@@ -26,4 +32,9 @@ public TestTransformMojo() {
File classesDirectory() {
return classesDirectory;
}
+
+ @Override
+ boolean skipped() {
+ return mavenTestSkip;
+ }
}
diff --git a/maven-plugin/src/test/java/io/smallrye/ffm/maven/TransformMojoSkipTest.java b/maven-plugin/src/test/java/io/smallrye/ffm/maven/TransformMojoSkipTest.java
new file mode 100644
index 0000000..dee1c06
--- /dev/null
+++ b/maven-plugin/src/test/java/io/smallrye/ffm/maven/TransformMojoSkipTest.java
@@ -0,0 +1,158 @@
+package io.smallrye.ffm.maven;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.plugin.logging.Log;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * The transform goals skip on request and do nothing for a missing classes directory.
+ */
+public final class TransformMojoSkipTest {
+
+ @TempDir
+ Path dir;
+
+ public TransformMojoSkipTest() {
+ }
+
+ @Test
+ public void testMissingClassesDirectoryIsNotAnError() throws Exception {
+ CapturingLog log = new CapturingLog();
+ TransformMojo mojo = mojo(new TransformMojo(), dir.resolve("classes").toFile(), log);
+ mojo.execute();
+ assertTrue(log.contains("does not exist"), log.lines.toString());
+ }
+
+ @Test
+ public void testMissingTestClassesDirectoryIsNotAnError() throws Exception {
+ CapturingLog log = new CapturingLog();
+ TestTransformMojo mojo = mojo(new TestTransformMojo(), dir.resolve("test-classes").toFile(), log);
+ mojo.execute();
+ assertTrue(log.contains("does not exist"), log.lines.toString());
+ }
+
+ @Test
+ public void testSkipParameter() throws Exception {
+ CapturingLog log = new CapturingLog();
+ TransformMojo mojo = mojo(new TransformMojo(), dir.toFile(), log);
+ set(mojo, AbstractTransformMojo.class, "skip", true);
+ mojo.execute();
+ assertTrue(log.contains("Skipping"), log.lines.toString());
+ }
+
+ @Test
+ public void testTestGoalHonoursMavenTestSkip() throws Exception {
+ CapturingLog log = new CapturingLog();
+ TestTransformMojo mojo = mojo(new TestTransformMojo(), dir.toFile(), log);
+ set(mojo, TestTransformMojo.class, "mavenTestSkip", true);
+ mojo.execute();
+ assertTrue(log.contains("Skipping"), log.lines.toString());
+ }
+
+ @Test
+ public void testEmptyDirectoryIsTransformed() throws Exception {
+ CapturingLog log = new CapturingLog();
+ TransformMojo mojo = mojo(new TransformMojo(), dir.toFile(), log);
+ mojo.execute();
+ assertTrue(log.contains("No classes transformed"), log.lines.toString());
+ }
+
+ private static M mojo(M mojo, File classes, Log log) throws Exception {
+ set(mojo, mojo.getClass(), "classesDirectory", classes);
+ mojo.setLog(log);
+ return mojo;
+ }
+
+ private static void set(Object target, Class> owner, String name, Object value) throws Exception {
+ Field field = owner.getDeclaredField(name);
+ field.setAccessible(true);
+ field.set(target, value);
+ }
+
+ /**
+ * A log that keeps every message.
+ */
+ static final class CapturingLog implements Log {
+ final List lines = new ArrayList<>();
+
+ boolean contains(String text) {
+ return lines.stream().anyMatch(line -> line.contains(text));
+ }
+
+ private void add(CharSequence content) {
+ lines.add(String.valueOf(content));
+ }
+
+ public boolean isDebugEnabled() {
+ return true;
+ }
+
+ public void debug(CharSequence content) {
+ add(content);
+ }
+
+ public void debug(CharSequence content, Throwable error) {
+ add(content);
+ }
+
+ public void debug(Throwable error) {
+ add(String.valueOf(error));
+ }
+
+ public boolean isInfoEnabled() {
+ return true;
+ }
+
+ public void info(CharSequence content) {
+ add(content);
+ }
+
+ public void info(CharSequence content, Throwable error) {
+ add(content);
+ }
+
+ public void info(Throwable error) {
+ add(String.valueOf(error));
+ }
+
+ public boolean isWarnEnabled() {
+ return true;
+ }
+
+ public void warn(CharSequence content) {
+ add(content);
+ }
+
+ public void warn(CharSequence content, Throwable error) {
+ add(content);
+ }
+
+ public void warn(Throwable error) {
+ add(String.valueOf(error));
+ }
+
+ public boolean isErrorEnabled() {
+ return true;
+ }
+
+ public void error(CharSequence content) {
+ add(content);
+ }
+
+ public void error(CharSequence content, Throwable error) {
+ add(content);
+ }
+
+ public void error(Throwable error) {
+ add(String.valueOf(error));
+ }
+ }
+}