use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class ConfigurationImpl method preparePlugins.
@Override
public void preparePlugins() {
Collection<PluginConfig> pluginCfg = getPlugins();
HashSet<String> plugins = new HashSet<String>();
HashSet<String> previousPlugins = new HashSet<String>();
if (pluginCfg == null || pluginCfg.isEmpty()) {
pluginCfg = new LinkedList<PluginConfig>();
} else {
for (PluginConfig pc : pluginCfg) {
previousPlugins.add(pc.getGroupId() + ":" + pc.getArtifactId());
}
}
Collection<ChainConfig> chains = getChainConfigs();
if (chains != null) {
Iterator<ChainConfig> it = chains.iterator();
while (it.hasNext()) {
ChainConfig cc = it.next();
composeName(cc.getReaderConfig().getType(), plugins);
composeName(cc.getWalkerConfig().getParserConfig().getType(), plugins);
List<TransformationConfig> trans = cc.getWalkerConfig().getTransformations();
if (trans != null) {
for (TransformationConfig transformation : trans) {
String type = transformation.getType();
if (!type.equals("script") && !type.equals("template")) {
composeName(type, plugins);
}
}
}
composeName(cc.getWriterConfig().getType(), plugins);
}
}
Collection<ProviderConfig> providers = getProviderConfigurations();
if (providers != null) {
for (ProviderConfig provider : providers) {
String type = provider.getType();
composeName(type, plugins);
}
}
Collection<InitializerConfig> initializers = getInitializers();
if (initializers != null) {
for (InitializerConfig initializer : initializers) {
plugins.add(initializer.getPluginGroupId() + ":walkmod-" + initializer.getPluginArtifactId() + "-plugin");
}
}
for (String id : plugins) {
if (!previousPlugins.contains(id)) {
String[] parts = id.split(":");
PluginConfig cfg = new PluginConfigImpl();
cfg.setGroupId(parts[0].trim());
cfg.setArtifactId(parts[1].trim());
cfg.setVersion("latest.integration");
pluginCfg.add(cfg);
}
}
setPlugins(pluginCfg);
}
use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class ConfigurationImpl method setChainConfigs.
public void setChainConfigs(Collection<ChainConfig> chainConfigs) {
this.chainConfigs.clear();
Iterator<ChainConfig> it = chainConfigs.iterator();
while (it.hasNext()) {
ChainConfig current = it.next();
current.setConfiguration(this);
this.chainConfigs.put(current.getName(), current);
}
}
use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class ConfigurationImpl method executeAllChains.
public void executeAllChains(Options options, ChainAdapterFactory apf) {
Collection<ChainConfig> tcgfs = getChainConfigs();
if (tcgfs != null) {
if (options.isVerbose()) {
log.info("** STARTING TRANSFORMATIONS CHAINS **");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
}
long startTime = System.currentTimeMillis();
long endTime = startTime;
DecimalFormat myFormatter = new DecimalFormat("###.###");
DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.US);
int num = 0;
Iterator<ChainConfig> it = tcgfs.iterator();
int pos = 1;
while (it.hasNext()) {
ChainConfig tcfg = it.next();
if (tcgfs.size() > 1) {
if (options.isVerbose()) {
String label = "";
if (tcfg.getName() != null && !tcfg.getName().startsWith("chain_")) {
label = "[" + tcfg.getName() + "](" + pos + "/" + tcgfs.size() + ") ";
} else {
label = "(" + pos + "/" + tcgfs.size() + ")";
}
log.info("TRANSFORMATION CHAIN " + label);
System.out.println();
}
}
try {
if (options.getIncludes() != null) {
String[] includes = options.getIncludes().toArray(new String[options.getIncludes().size()]);
tcfg.getReaderConfig().setIncludes(includes);
}
if (options.getExcludes() != null) {
String[] excludes = options.getExcludes().toArray(new String[options.getExcludes().size()]);
tcfg.getReaderConfig().setExcludes(excludes);
}
ChainAdapter ap = apf.createChainProxy(this, tcfg.getName());
ap.execute();
num += ap.getWalkerAdapter().getWalker().getNumModifications();
pos++;
if (options.isVerbose()) {
if (Summary.getInstance().getWrittenFiles().isEmpty()) {
log.info("**No sources changed**");
}
if (it.hasNext()) {
System.out.println();
}
}
} catch (Throwable e) {
if (options.isVerbose()) {
endTime = System.currentTimeMillis();
double time = 0;
if (endTime > startTime) {
time = (double) (endTime - startTime) / (double) 1000;
}
String timeMsg = myFormatter.format(time);
if (num != 0) {
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
}
log.info("TRANSFORMATION CHAIN FAILS");
System.out.println();
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
log.info("Total time: " + timeMsg + " seconds");
log.info("Finished at: " + df.format(new Date()));
log.info("Final memory: " + (Runtime.getRuntime().freeMemory()) / 1048576 + " M/ " + (Runtime.getRuntime().totalMemory() / 1048576) + " M");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
log.info("Please, see the walkmod log file for details");
if (options.isPrintErrors()) {
log.error("TRANSFORMATION CHAIN (" + tcfg.getName() + ") FAILS", e);
} else {
log.error("TRANSFORMATION CHAIN (" + tcfg.getName() + ") FAILS. Execute walkmod with -e to see the error details.");
}
if (options.isThrowException()) {
RuntimeException re = new RuntimeException();
re.setStackTrace(e.getStackTrace());
throw re;
}
} else {
throw new WalkModException(e);
}
return;
}
if (!it.hasNext()) {
if (tcgfs.size() >= pos) {
LinkedList<ChainConfig> aux = new LinkedList<ChainConfig>(tcgfs);
it = aux.listIterator(pos - 1);
}
}
}
if (options.isVerbose()) {
endTime = System.currentTimeMillis();
double time = 0;
if (endTime > startTime) {
time = (double) (endTime - startTime) / (double) 1000;
}
String timeMsg = myFormatter.format(time);
if (num != 0) {
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
}
System.out.println();
log.info("TRANSFORMATION CHAIN SUCCESS");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
log.info("Total time: " + timeMsg + " seconds");
log.info("Finished at: " + df.format(new Date()));
log.info("Final memory: " + (Runtime.getRuntime().freeMemory()) / 1048576 + " M/ " + (Runtime.getRuntime().totalMemory() / 1048576) + " M");
log.info("Total modified files: " + num);
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
}
}
}
use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class PrintTransformationsCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("transformations");
} else {
if (chain == null) {
chain = new LinkedList<String>();
}
if (chain.isEmpty()) {
chain.add("default");
}
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options());
Configuration cfg = facade.getConfiguration();
if (cfg != null) {
Collection<ChainConfig> chains = cfg.getChainConfigs();
if (chains != null) {
Iterator<ChainConfig> it = chains.iterator();
ChainConfig selected = null;
while (it.hasNext() && selected == null) {
ChainConfig current = it.next();
if (current.getName().equals(chain.get(0))) {
selected = current;
}
}
if (selected != null) {
at = new V2_AsciiTable();
at.addRule();
at.addRow("TRANSFORMATION TYPE", "PARAMETERS", "NAME/ALIAS");
at.addStrongRule();
List<TransformationConfig> transformations = selected.getWalkerConfig().getTransformations();
if (transformations != null) {
for (TransformationConfig transf : transformations) {
Map<String, Object> parameters = transf.getParameters();
if (parameters == null || parameters.isEmpty()) {
at.addRow(transf.getType(), "", transf.getName());
} else {
Set<String> keys = parameters.keySet();
int i = 0;
for (String key : keys) {
if (i == 0) {
String name = transf.getName();
if (name == null) {
name = "";
}
at.addRow(transf.getType(), "-" + key + ":" + parameters.get(key), "");
} else {
at.addRow("", "-" + key + ":" + parameters.get(key), "");
}
i++;
}
}
at.addRule();
}
}
}
}
} else {
log.error("Sorry, the current directory does not contain a walkmod configuration file or it is invalid.");
at = new V2_AsciiTable();
at.addRule();
at.addRow("TRANSFORMATION TYPE", "PARAMETERS", "NAME/ALIAS");
at.addStrongRule();
at.addRule();
}
}
}
use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class DynamicConfigurationProvider method load.
@Override
public void load() throws ConfigurationException {
config.prepareInitializers();
if (chains != null) {
for (String chain : chains) {
if (StringUtils.isNotEmpty(chain)) {
PluginConfig plugin = config.resolvePlugin(chain);
config.getPlugins().add(plugin);
}
}
config.preparePlugins();
}
String path = options.getPath();
if (chains != null) {
for (String chain : chains) {
if (StringUtils.isNotEmpty(chain)) {
ChainConfig cc = config.getChainConfig(chain);
if (cc == null) {
cc = new ChainConfigImpl(new TransformationConfigImpl(chain));
config.addChainConfig(cc);
}
}
}
}
if (StringUtils.isNotEmpty(path)) {
for (ChainConfig cc : config.getChainConfigs()) {
cc.setPath(path);
}
}
}
Aggregations