Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,10 @@
}

final int start = text.indexOf('{');
final int end = text.indexOf('}');
// the macro block always ends with the closing brace, so look for the last one:
// parameter values may contain braces themselves (e.g. unresolved Velocity references
// such as ${project.build.directory} when the raw source of a *.apt.vm file is parsed)
final int end = text.lastIndexOf('}');

String s = text.substring(start + 1, end);

Expand All @@ -2398,7 +2401,7 @@

// getBasedir() does not work in multi-module builds, see DOXIA-373
// the basedir should be injected from here, see DOXIA-224
MacroRequest request = new MacroRequest(sourceContent, new AptParser(), parameters, getBasedir());

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated

Check warning on line 2404 in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

getBasedir() in org.apache.maven.doxia.parser.AbstractParser has been deprecated
try {
AptParser.this.executeMacro(macroId, request, sink);
} catch (MacroExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.maven.doxia.parser.AbstractParser;
import org.apache.maven.doxia.parser.AbstractParserTest;
Expand Down Expand Up @@ -75,6 +77,29 @@ void snippetMacro() throws Exception {
assertTrue(macro.contains("<modelVersion\\>4.0.0\\</modelVersion\\>"));
}

/**
* A macro parameter value may contain braces itself, for example an unresolved Velocity
* reference when the raw source of a {@code *.apt.vm} file is parsed. The macro block ends
* with the last brace on the line, not the first one.
*/
@Test
void macroWithBracesInParameterValue() throws Exception {
Map<String, Object> parameters = new LinkedHashMap<>();

AbstractParser parser = createParser();
parser.setMacroExecutor((id, request, sink) -> {
assertEquals("snippet", id);
parameters.putAll(request.getParameters());
});

try (Reader reader = getTestReader("test/macro-braces-in-parameter")) {
parser.parse(reader, new SinkEventTestingSink());
}

assertEquals("superpom", parameters.get("id"));
assertEquals("${project.build.directory}/test-classes/pom-4.0.0.xml", parameters.get("file"));
}

@Test
void commentsBeforeTitle() throws Exception {
String comments = parseFileToAptSink("test/comments");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----
Braces in macro parameters
-----

Braces in macro parameters

%{snippet|id=superpom|file=${project.build.directory}/test-classes/pom-4.0.0.xml}
Loading