urls[0] = archetypeArtifact.getFile().toURI().toURL();
URLClassLoader archetypeJarLoader = new URLClassLoader(urls);
Thread.currentThread().setContextClassLoader(archetypeJarLoader);
for (Iterator i = archetype.getTemplates().iterator(); i.hasNext();) {
final Template template = (Template) i.next();
// Check the optional 'condition' property on the template.
// If present and the variable it points to is 'true', then
// continue processing. If it's false, then skip.
// If condition is not specified, assume the template should
// be processed.
boolean shouldProcess = true;
String condition = template.getDependsOnVar();
String requiredValue=null;
List options = new ArrayList();
if (StringUtils.isNotEmpty(condition)) {
//Crappy logic processing -- for now
boolean not=false;
//Allow very simple matching logic to match templates against variable values
int x = condition.indexOf("!=");
getLogger().debug("Processing Condition : " + condition);
if(x > -1) {
not=true;
requiredValue = condition.substring(x+2).trim();
options = getListOfValues(requiredValue);
condition = condition.substring(0, x).trim();
}
else {
x = condition.indexOf("=");
if(x > -1) {
requiredValue = condition.substring(x+1);
options = getListOfValues(requiredValue);
condition = condition.substring(0, x);
}
}
getLogger().debug("Not Expr: " + not);
getLogger().debug("Condition Value: '" + condition + "'");
getLogger().debug("Required Value: '" + requiredValue + "'");
final Variable var = (Variable) findVariable(condition, variables);
if (var != null) {
final String strValue = (String) context.get(var.getName());
getLogger().debug("Variable Value is: '" + strValue + "'");
if(requiredValue==null)
{
if (!Boolean.valueOf(strValue).booleanValue()) {
shouldProcess = false;
}
} else {
if(!options.contains(strValue))
{
shouldProcess = false;
}
}
} else {
getLogger().debug("Variable Value is: null");
shouldProcess=false;
}
if(not) {
shouldProcess = !shouldProcess;
}
}
if (shouldProcess) {
processTemplate(template, outputDirectory, context);
} else {
getLogger().debug("Condition not met, skipping " + template.getOutput());
}
}
}
catch (MalformedURLException mfe) {