Skip to content

Commit

Permalink
Add configuration for plugins to avoid use of deprecated raw arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw authored and slachiewicz committed Dec 13, 2023
1 parent b2b207e commit 075c6a2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@ public abstract class AbstractJavaGeneratorMojo extends AbstractJaxbMojo {
@Parameter(defaultValue = "false")
protected boolean readOnly;

/**
* <p>List of plugins that should be enabled.</p>
* <pre>
* <code>
* &lt;configuration&gt;
* ...
* &lt;plugins&gt;
* &lt;plugin&gt;fluent-api&lt;/plugin&gt;
* &lt;plugin&gt;inheritance&lt;/plugin&gt;
* &lt;/plugins&gt;
* &lt;/configuration&gt;
* </code>
* </pre>
* <p>The arguments configured above yields the following extra arguments to the XJC command:
* <code>-Xfluent-api -Xinheritance</code></p>
*
* @since 3.2
*/
protected List<String> plugins;

/**
* <p>List of ordered extra arguments to the XJC command. Each extra argument is interpreted as a word, intended
* to be copied verbatim to the XJC argument list with spaces in between:</p>
Expand Down Expand Up @@ -634,6 +654,10 @@ private String[] getXjcArguments(final String classPath, final String episodeFil
builder.withNamedArgument("catalog", FileSystemUtilities.getCanonicalPath(catalog));
}

if (plugins != null) {
builder.withPrefixedArguments("X", plugins);
}

if (arguments != null) {
builder.withPreCompiledArguments(arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ public ArgumentBuilder withNamedArgument(final String name, final String value)
return this;
}

/**
* Adds the supplied prefixed arguments in the same order as they were given.
*
* @param prefix The prefix to add.
* @param values A non-null List holding arguments.
* @return This ArgumentBuilder, for chaining.
*/
public ArgumentBuilder withPrefixedArguments(String prefix, final List<String> values) {

// Check sanity
Validate.notNull(prefix, "prefix");
Validate.notNull(values, "arguments");

// Add the arguments in the exact order they were given.
synchronized (lock) {
for (String value : values) {
String trimmedValue = value.trim();
arguments.add("-" + prefix + trimmedValue);
}
}

// All done.
return this;
}

/**
* Adds the supplied pre-compiled arguments in the same order as they were given.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

/**
* @author <a href="mailto:[email protected]">Lennart J&ouml;relid</a>
*/
Expand Down Expand Up @@ -86,4 +88,24 @@ public void validateMixedArguments() {
Assert.assertEquals("value1", result[1]);
Assert.assertEquals("-flag2", result[2]);
}

@Test
public void validatePrefixedArgument() {

// Assemble
final ArgumentBuilder unitUnderTest = new ArgumentBuilder();

// Act
final String[] result = unitUnderTest
.withPrefixedArguments("X", Arrays.asList("plugin1", "plugin2"))
.withPrefixedArguments("X", Arrays.asList("plugin3", "plugin4"))
.build();

// Assert
Assert.assertEquals(4, result.length);
Assert.assertEquals("-Xplugin1", result[0]);
Assert.assertEquals("-Xplugin2", result[1]);
Assert.assertEquals("-Xplugin3", result[2]);
Assert.assertEquals("-Xplugin4", result[3]);
}
}

0 comments on commit 075c6a2

Please sign in to comment.