Search in sources :

Example 11 with ChainConfig

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);
}
Also used : ProviderConfig(org.walkmod.conf.entities.ProviderConfig) InitializerConfig(org.walkmod.conf.entities.InitializerConfig) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ChainConfig(org.walkmod.conf.entities.ChainConfig) PluginConfig(org.walkmod.conf.entities.PluginConfig) HashSet(java.util.HashSet)

Example 12 with ChainConfig

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);
    }
}
Also used : ChainConfig(org.walkmod.conf.entities.ChainConfig)

Example 13 with ChainConfig

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("----------------------------------------");
        }
    }
}
Also used : WalkModException(org.walkmod.exceptions.WalkModException) DecimalFormat(java.text.DecimalFormat) Date(java.util.Date) LinkedList(java.util.LinkedList) ChainConfig(org.walkmod.conf.entities.ChainConfig) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ChainAdapter(org.walkmod.ChainAdapter) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with ChainConfig

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();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ChainConfig(org.walkmod.conf.entities.ChainConfig) V2_AsciiTable(de.vandermeer.asciitable.v2.V2_AsciiTable) WalkModFacade(org.walkmod.WalkModFacade)

Example 15 with ChainConfig

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);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig)

Aggregations

ChainConfig (org.walkmod.conf.entities.ChainConfig)22 Configuration (org.walkmod.conf.entities.Configuration)11 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)11 LinkedList (java.util.LinkedList)8 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)8 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)8 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)6 Test (org.junit.Test)5 Element (org.w3c.dom.Element)5 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 PluginConfig (org.walkmod.conf.entities.PluginConfig)4 Document (org.w3c.dom.Document)3 ChainAdapter (org.walkmod.ChainAdapter)3 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)3 ReaderConfig (org.walkmod.conf.entities.ReaderConfig)3 WriterConfig (org.walkmod.conf.entities.WriterConfig)3 WalkModException (org.walkmod.exceptions.WalkModException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)2