This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-converter.git
The following commit(s) were added to refs/heads/master by this push:
new 6defbb2 Include Velocity templates by default
6defbb2 is described below
commit 6defbb25d89f5c35bee73b84417f1d8ed86ae963
Author: Konrad Windszus <[email protected]>
AuthorDate: Mon Dec 1 20:59:15 2025 +0100
Include Velocity templates by default
Exclude optionally via CLI argument "excludeVelocity"
The converted doxia source files which were originally a VCL template
are having the ".vm" extension also for the output file name
(in case directories are being used)
---
.../org/apache/maven/doxia/DefaultConverter.java | 32 +++++++++++++++++----
.../org/apache/maven/doxia/cli/CLIManager.java | 7 +++++
.../org/apache/maven/doxia/cli/ConverterCli.java | 3 +-
.../maven/doxia/wrapper/InputFileWrapper.java | 33 ++++++++++++++++++++--
4 files changed, 67 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/maven/doxia/DefaultConverter.java
b/src/main/java/org/apache/maven/doxia/DefaultConverter.java
index 9a4ffae..83384fe 100644
--- a/src/main/java/org/apache/maven/doxia/DefaultConverter.java
+++ b/src/main/java/org/apache/maven/doxia/DefaultConverter.java
@@ -88,6 +88,9 @@ import static java.lang.String.format;
@Named
public class DefaultConverter implements Converter {
+ /** Filename suffix used for Doxia source files being preprocessed by
Velocity */
+ private static final String VELOCITY_TEMPLATE_EXTENSION = ".vm";
+
/** Macro formatter for different Doxia formats.
* @see <a href="https://maven.apache.org/doxia/macros/index.html">Doxia
Macros</a>
*/
@@ -342,7 +345,7 @@ public class DefaultConverter implements Converter {
try {
files = FileUtils.getFiles(
input.getFile(),
- "**/*." + input.getFormat().getExtension(),
+
getFileNamePatterns(input.getFormat().getExtension(),
!input.isExcludeVelocityTemplates()),
StringUtils.join(FileUtils.getDefaultExcludes(),
", "));
} catch (IOException e) {
throw new ConverterException("IOException: " +
e.getMessage(), e);
@@ -372,6 +375,15 @@ public class DefaultConverter implements Converter {
}
}
+ static String getFileNamePatterns(String extension, boolean
includeVelocityTemplates) {
+ StringBuilder patterns = new StringBuilder("**/*." + extension);
+ if (includeVelocityTemplates) {
+ patterns.append(",");
+
patterns.append("**/*.").append(extension).append(VELOCITY_TEMPLATE_EXTENSION);
+ }
+ return patterns.toString();
+ }
+
private void postProcessFile(File inputFile, File outputFile) throws
IOException, InterruptedException {
switch (postProcess) {
case REMOVE_AFTER_CONVERSION:
@@ -540,6 +552,7 @@ public class DefaultConverter implements Converter {
LOGGER.debug("Auto detected encoding: '{}'", inputEncoding);
}
+ boolean isVelocityTemplate =
inputFile.getName().endsWith(VELOCITY_TEMPLATE_EXTENSION);
Parser parser;
try {
parser = parserFormat.getParser(plexus,
MacroFormatter.forFormat(output.getFormat()));
@@ -553,10 +566,19 @@ public class DefaultConverter implements Converter {
|| relativeOutputDirectory != null) {
// assume it is a directory
outputDirectoryOrFile.mkdirs();
- outputFile = new File(
- outputDirectoryOrFile,
- FileUtils.removeExtension(inputFile.getName()) + "."
- + output.getFormat().getExtension());
+ final String outputFileName;
+ if (isVelocityTemplate) {
+ outputFileName = FileUtils.removeExtension(inputFile
+ .getName()
+ .substring(0, inputFile.getName().length() -
VELOCITY_TEMPLATE_EXTENSION.length()))
+ + "."
+ + output.getFormat().getExtension()
+ + VELOCITY_TEMPLATE_EXTENSION;
+ } else {
+ outputFileName =
FileUtils.removeExtension(inputFile.getName()) + "."
+ + output.getFormat().getExtension();
+ }
+ outputFile = new File(outputDirectoryOrFile, outputFileName);
} else {
outputDirectoryOrFile.getParentFile().mkdirs();
outputFile = output.getFile();
diff --git a/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
b/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
index 603a3c6..9e94efa 100644
--- a/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
+++ b/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
@@ -75,6 +75,8 @@ class CLIManager {
/** e character */
static final String ERRORS = "e";
+ static final String EXCLUDE_VELOCITY_TEMPLATES = "excludeVm";
+
public static final String AUTO_FORMAT = "auto";
private static final Options OPTIONS;
@@ -127,6 +129,11 @@ class CLIManager {
.desc("Output file encoding. If not specified, use the input
encoding (or autodetected).")
.hasArg()
.build());
+ OPTIONS.addOption(Option.builder(EXCLUDE_VELOCITY_TEMPLATES)
+ .longOpt("excludeVelocity")
+ .desc(
+ "Exclude Velocity templates (ending with .vm) from
conversion. Only relevant when giving an input directory.")
+ .build());
OPTIONS.addOption(Option.builder(DEBUG)
.longOpt("debug")
.desc("Produce execution debug output.")
diff --git a/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
b/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
index 0cebc1b..ac9ba4f 100644
--- a/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
+++ b/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
@@ -145,7 +145,8 @@ public class ConverterCli {
input = InputFileWrapper.valueOf(
commandLine.getOptionValue(CLIManager.IN),
parserFormat,
- commandLine.getOptionValue(CLIManager.INENCODING));
+ commandLine.getOptionValue(CLIManager.INENCODING),
+
commandLine.hasOption(CLIManager.EXCLUDE_VELOCITY_TEMPLATES));
output = OutputFileWrapper.valueOf(
commandLine.getOptionValue(CLIManager.OUT),
sinkFormat,
diff --git a/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java
b/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java
index a0dab50..15e3ce7 100644
--- a/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java
+++ b/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java
@@ -34,6 +34,7 @@ public class InputFileWrapper extends AbstractFileWrapper {
static final long serialVersionUID = 6510443036267371188L;
private final DefaultConverter.DoxiaFormat format;
+ private final boolean excludeVelocityTemplates;
/**
* Private constructor.
@@ -41,14 +42,20 @@ public class InputFileWrapper extends AbstractFileWrapper {
* @param absolutePath not null
* @param format not null
* @param charsetName could be null
+ * @param excludeVelocityTemplates {@code true} to not consider velocity
templates (ending with .vm) (only relevant when absolutePath is a directory)
* @throws UnsupportedEncodingException if the encoding is unsupported.
* @throws FileNotFoundException if the file for absolutePath is not found.
*/
- private InputFileWrapper(String absolutePath, DefaultConverter.DoxiaFormat
format, String charsetName)
+ private InputFileWrapper(
+ String absolutePath,
+ DefaultConverter.DoxiaFormat format,
+ String charsetName,
+ boolean excludeVelocityTemplates)
throws UnsupportedEncodingException, FileNotFoundException {
super(absolutePath, charsetName);
this.format = format;
+ this.excludeVelocityTemplates = excludeVelocityTemplates;
if (!getFile().exists()) {
throw new FileNotFoundException("The file '" +
getFile().getAbsolutePath() + "' doesn't exist.");
}
@@ -77,10 +84,32 @@ public class InputFileWrapper extends AbstractFileWrapper {
*/
public static InputFileWrapper valueOf(String absolutePath,
DefaultConverter.DoxiaFormat format, String charsetName)
throws UnsupportedEncodingException, FileNotFoundException {
- return new InputFileWrapper(absolutePath, format, charsetName);
+ return valueOf(absolutePath, format, charsetName, false);
+ }
+
+ /**
+ * @param absolutePath for a wanted file or a wanted directory, not null.
+ * @param format not null
+ * @param charsetName could be null
+ * @param excludeVelocityTemplates {@code true} to not consider velocity
templates (ending with .vm)
+ * @return a type safe input reader
+ * @throws UnsupportedEncodingException if the encoding is unsupported.
+ * @throws FileNotFoundException if the file for absolutePath is not found.
+ */
+ public static InputFileWrapper valueOf(
+ String absolutePath,
+ DefaultConverter.DoxiaFormat format,
+ String charsetName,
+ boolean excludeVelocityTemplates)
+ throws UnsupportedEncodingException, FileNotFoundException {
+ return new InputFileWrapper(absolutePath, format, charsetName,
excludeVelocityTemplates);
}
public DefaultConverter.DoxiaFormat getFormat() {
return format;
}
+
+ public boolean isExcludeVelocityTemplates() {
+ return excludeVelocityTemplates;
+ }
}