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
36 changes: 34 additions & 2 deletions modello-core/src/main/java/org/codehaus/modello/ModelloCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
*/

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.XmlStreamReader;
Expand Down Expand Up @@ -106,19 +108,49 @@ public static void parseArgumentsFromCommandLine(String[] args) throws Exception
System.exit(1);
}

if (StringUtils.equalsIgnoreCase(javaSource, "true") || StringUtils.equalsIgnoreCase(javaSource, "false")) {
// The old useJava5 parameter at this position
System.err.println("Missing required parameter: Java Source (replacing the old \"Use Java5\" parameter)");

usage();

System.exit(1);
}

parameters.put(ModelloParameterConstants.OUTPUT_JAVA_SOURCE, javaSource);

if (args.length > 6) {
parameters.put(ModelloParameterConstants.ENCODING, args[6]);
}

if (args.length > 7) {
parameters.put(ModelloParameterConstants.DOM_AS_XPP3, args[7]);
}

if (args.length > 8) {
parameters.put(ModelloParameterConstants.VELOCITY_BASEDIR, args[8]);
}

if (args.length > 9) {
parameters.put(ModelloParameterConstants.VELOCITY_TEMPLATES, args[9]);
}

if (args.length > 10 && StringUtils.isNotEmpty(args[10])) {
parameters.put(ModelloParameterConstants.VELOCITY_PARAMETERS, (HashMap<String, String>)
Arrays.stream(args[10].split(","))
.filter(s -> s.contains("="))
.map(s -> s.split("=", 2))
.collect(Collectors.toMap(e -> e[0], e -> e[1])));
}
}

// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------

private static void usage() {
System.err.println("Usage: modello <model> <outputType> <output directory> <modelVersion> <packageWithVersion>"
+ "<javaSource> [<encoding>]");
System.err.println(
"Usage: modello <model> <outputType> <output directory> <modelVersion> <packageWithVersion>"
+ " <javaSource> [<encoding> [<domAsXpp3> [<velocityBaseDir> <velocityTemplates> <velocityParameters>]]] ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,20 @@ public class ModelloParameterConstants {
*/
public static final String PLURAL_EXCEPTIONS = "modello.plural.exceptions";

/**
* @since 2.8.2
*/
public static final String VELOCITY_BASEDIR = "modello.velocity.basedir";

/**
* @since 2.8.2
*/
public static final String VELOCITY_TEMPLATES = "modello.velocity.templates";

/**
* @since 2.8.2
*/
public static final String VELOCITY_PARAMETERS = "modello.velocity.parameters";

private ModelloParameterConstants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.modello.ModelloParameterConstants;
import org.codehaus.modello.core.ModelloCore;
import org.codehaus.modello.plugin.velocity.VelocityGenerator;
import org.codehaus.plexus.build.BuildContext;

/**
Expand Down Expand Up @@ -103,10 +103,11 @@ protected void customizeParameters(Map<String, Object> parameters) {
.collect(Collectors.toMap(
s -> s.substring(0, s.indexOf('=')), s -> s.substring(s.indexOf('=') + 1)));

parameters.put(VelocityGenerator.VELOCITY_BASEDIR, velocityBasedir.getAbsolutePath());
parameters.put(ModelloParameterConstants.VELOCITY_BASEDIR, velocityBasedir.getAbsolutePath());

parameters.put(VelocityGenerator.VELOCITY_TEMPLATES, templates.stream().collect(Collectors.joining(",")));
parameters.put(VelocityGenerator.VELOCITY_PARAMETERS, params);
parameters.put(
ModelloParameterConstants.VELOCITY_TEMPLATES, templates.stream().collect(Collectors.joining(",")));
parameters.put(ModelloParameterConstants.VELOCITY_PARAMETERS, params);
}

protected boolean producesCompilableResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,22 @@

@Named("velocity")
public class VelocityGenerator extends AbstractModelloGenerator {
public static final String VELOCITY_BASEDIR = "modello.velocity.basedir";

public static final String VELOCITY_TEMPLATES = "modello.velocity.templates";

public static final String VELOCITY_PARAMETERS = "modello.velocity.parameters";

public static final String MODELLO_VELOCITY_OUTPUT = "#MODELLO-VELOCITY#SAVE-OUTPUT-TO ";

@Override
@SuppressWarnings("unchecked")
public void generate(Model model, Map<String, Object> parameters) throws ModelloException {
initialize(model, parameters);
try {
Map<String, String> params =
(Map<String, String>) Objects.requireNonNull(parameters.get(VELOCITY_PARAMETERS));
String templates = requireParameter(parameters, VELOCITY_TEMPLATES);
Map<String, String> params = (Map<String, String>)
Objects.requireNonNull(parameters.get(ModelloParameterConstants.VELOCITY_PARAMETERS));
String templates = requireParameter(parameters, ModelloParameterConstants.VELOCITY_TEMPLATES);
String output = requireParameter(parameters, ModelloParameterConstants.OUTPUT_DIRECTORY);

Properties props = new Properties();
props.put("resource.loader.file.path", requireParameter(parameters, VELOCITY_BASEDIR));
props.put(
"resource.loader.file.path",
requireParameter(parameters, ModelloParameterConstants.VELOCITY_BASEDIR));
RuntimeInstance velocity = new RuntimeInstance();
velocity.init(props);

Expand Down