in src/main/java/org/apache/sling/feature/modelconverter/Main.java [85:140]
public void run() {
try {
if(!provisioningModelsInputDirectory.isDirectory()) { throw new IllegalArgumentException("Input Folder is not a directory"); }
if(!provisioningModelsInputDirectory.canRead()) { throw new IllegalArgumentException("Input Folder is not readable"); }
if(!featureModelsOutputDirectory.exists()) {
File parent = featureModelsOutputDirectory.getParentFile();
if(parent == null || !parent.exists()) { throw new IllegalArgumentException("Parent Folder (" + parent + ") of output folder (" + featureModelsOutputDirectory + ") does not exist"); }
featureModelsOutputDirectory.mkdir();
}
if(!featureModelsOutputDirectory.isDirectory()) { throw new IllegalArgumentException("Output Folder is not a directory"); }
if(!featureModelsOutputDirectory.canWrite()) { throw new IllegalArgumentException("Output Folder is not writable"); }
List<File> provisioningFiles = Arrays.asList(provisioningModelsInputDirectory.listFiles());
Map<String,Object> options = new HashMap<>();
if(groupId != null && !groupId.isEmpty()) { options.put("groupId", groupId); }
if(version != null && !version.isEmpty()) { options.put("version", version); }
// Todo: do we have a way to check the name?
if(name != null && !name.isEmpty()) { options.put("name", name); }
LOGGER.info("Use Provided Version Flag: '{}'", useProvidedVersion);
options.put("useProvidedVersion", useProvidedVersion);
options.put("noProvisioningModelName", noProvisioningModelName);
options.put("dropVariables", dropVariables);
Map<String,Map<String,String>> frameworkPropertiesMap = new HashMap<>();
for(String value: addFrameworkProperties) {
// Separate Model from Property Name Value pair. Create Sub Map if needed and then add
LOGGER.info("Check Add Framework Properties Line: '{}'", value);
Matcher matcher = pattern.matcher(value);
LOGGER.info("Pattern Group Matches: '{}', Count: '{}'", matcher.matches(), matcher.groupCount());
if(matcher.matches() && matcher.groupCount() == 3) {
String modelName = matcher.group(1);
String propName = matcher.group(2);
String propValue = matcher.group(3);
LOGGER.info("Model Name: '{}', Prop Name: '{}', Value: '{}'", modelName, propName, propValue);
Map<String,String> modelMap = frameworkPropertiesMap.get(modelName);
if(modelMap == null) {
modelMap = new HashMap<>();
frameworkPropertiesMap.put(modelName, modelMap);
}
modelMap.put(propName, propValue);
}
}
options.put("addFrameworkProperties", frameworkPropertiesMap);
options.put("excludeBundles", excludeBundles);
LOGGER.info("Excluded Bundles: '{}'", excludeBundles);
options.put("runModes", runModes == null ? new ArrayList<>() : runModes);
LOGGER.info("Runmodes: '{}'", runModes);
// Start the Conversion
for(File file: provisioningFiles) {
LOGGER.info("Handle File: '{}'", file.getAbsolutePath());
ProvisioningToFeature.convert(file, featureModelsOutputDirectory, options);
}
} catch(Throwable t) {
LOGGER.error("Failed to Convert", t);
}
}