Search in sources :

Example 31 with Configuration

use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.

the class WalkModFacade method inspectPlugin.

/**
 * Retrieves the bean definitions that contains an specific plugin.
 *
 * @param plugin
 *            Plugin container of bean definitions.
 * @return List of bean definitions.
 */
public List<BeanDefinition> inspectPlugin(PluginConfig plugin) {
    Configuration conf = new ConfigurationImpl();
    Collection<PluginConfig> plugins = new LinkedList<PluginConfig>();
    plugins.add(plugin);
    conf.setPlugins(plugins);
    ConfigurationManager manager = new ConfigurationManager(conf, false, locateConfigurationProvider());
    manager.executeConfigurationProviders();
    return conf.getAvailableBeans(plugin);
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) ConfigurationManager(org.walkmod.conf.ConfigurationManager) LinkedList(java.util.LinkedList)

Example 32 with Configuration

use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.

the class WalkModFacade method run.

private void run(List<File> result, WalkmodCommand command, ExecutionModeEnum execMode, String... chains) throws InvalidConfigurationException {
    userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
    System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
    Configuration config = null;
    if (cfg.exists()) {
        if (options.isVerbose()) {
            log.info(cfg.getAbsoluteFile() + " [ok]");
        }
        config = readConfig(locateConfigurationProvider(), new ExecutionModeProvider(execMode));
    } else {
        config = createConfig(chains, locateConfigurationProvider(), new ExecutionModeProvider(execMode));
    }
    try {
        config.executeModuleChains(options, command, chains);
    } catch (Exception e) {
        System.setProperty("user.dir", userDir);
        if (options.isVerbose()) {
            if (!options.isPrintErrors()) {
                log.error(cfg.getAbsolutePath() + " is invalid. Please, execute walkmod with -e to see the details.");
            } else {
                log.error("Invalid configuration", e);
            }
            if (options.isThrowException()) {
                RuntimeException re = new RuntimeException();
                re.setStackTrace(e.getStackTrace());
                throw re;
            }
        } else {
            throw new InvalidConfigurationException(e);
        }
    }
    config.execute(userDir, options, chains);
    result.addAll(Summary.getInstance().getWrittenFiles());
    System.setProperty("user.dir", userDir);
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) File(java.io.File) ExecutionModeProvider(org.walkmod.conf.providers.ExecutionModeProvider) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException)

Example 33 with Configuration

use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.

the class WalkModFacade method createConfig.

private Configuration createConfig(String[] chains, ConfigurationProvider... cp) throws InvalidConfigurationException {
    Configuration config = new ConfigurationImpl();
    try {
        DynamicConfigurationProvider prov = new DynamicConfigurationProvider(options, chains);
        prov.init(config);
        prov.load();
        ConfigurationManager cfgManager = new ConfigurationManager(config, cp);
        DynamicModulesConfigurationProvider prov2 = new DynamicModulesConfigurationProvider();
        prov2.init(config);
        prov2.load();
        config = cfgManager.getConfiguration();
        config.setParameters(options.getMutableCopyOfDynamicArgs());
    } catch (Exception e) {
        printConfigError(e);
    }
    return config;
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) DynamicConfigurationProvider(org.walkmod.conf.providers.DynamicConfigurationProvider) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) ConfigurationManager(org.walkmod.conf.ConfigurationManager) DynamicModulesConfigurationProvider(org.walkmod.conf.providers.DynamicModulesConfigurationProvider) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException)

Example 34 with Configuration

use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.

the class PrintModulesCommand method execute.

@Override
public void execute() throws Exception {
    if (help) {
        command.usage("modules");
    } else {
        WalkModFacade facade = new WalkModFacade(OptionsBuilder.options());
        Configuration cfg = facade.getConfiguration();
        if (cfg == null) {
            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("MODULE");
        at.addRule();
        if (cfg != null) {
            List<String> modules = cfg.getModules();
            if (modules != null) {
                for (String module : modules) {
                    at.addRow(module);
                }
            }
        }
        at.addRule();
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) V2_AsciiTable(de.vandermeer.asciitable.v2.V2_AsciiTable) WalkModFacade(org.walkmod.WalkModFacade)

Example 35 with Configuration

use of org.walkmod.conf.entities.Configuration 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)

Aggregations

Configuration (org.walkmod.conf.entities.Configuration)58 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)48 Test (org.junit.Test)43 File (java.io.File)38 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)23 LinkedList (java.util.LinkedList)21 AddTransformationCommand (org.walkmod.commands.AddTransformationCommand)21 ChainConfig (org.walkmod.conf.entities.ChainConfig)11 PluginConfig (org.walkmod.conf.entities.PluginConfig)10 HashMap (java.util.HashMap)6 WalkModException (org.walkmod.exceptions.WalkModException)6 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)5 IOException (java.io.IOException)5 WalkModFacade (org.walkmod.WalkModFacade)5 ConfigurationManager (org.walkmod.conf.ConfigurationManager)5 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)5 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)5 Document (org.w3c.dom.Document)4 NodeList (org.w3c.dom.NodeList)4 InvalidConfigurationException (org.walkmod.exceptions.InvalidConfigurationException)4