Search in sources :

Example 21 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddConfigurationParameter.

@Test
public void testAddConfigurationParameter() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
    File file = new File("src/test/resources/yaml/rmchains.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        TransformationConfig transformationCfg = command.buildTransformationCfg();
        provider.addTransformationConfig("mychain", null, transformationCfg, false, null, null);
        provider.addConfigurationParameter("testParam", "hello", "imports-cleaner", null, null, null, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("params") && output.contains("testParam") && output.contains("hello"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 22 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddChainTransformation.

@Test
public void testAddChainTransformation() throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("refactoringConfigFile", "src/conf/refactoring-methods.json");
    AddTransformationCommand command = new AddTransformationCommand("walkmod:commons:method-refactor", null, false, null, null, null, params, false);
    File file = new File("src/test/resources/yaml/addchain.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        TransformationConfig transformationCfg = command.buildTransformationCfg();
        provider.addTransformationConfig(null, null, transformationCfg, false, null, null);
        String output = FileUtils.readFileToString(file);
        String desiredOutput = "transformations:\n";
        desiredOutput += "- type: \"walkmod:commons:method-refactor\"\n";
        desiredOutput += "  params:\n";
        desiredOutput += "    refactoringConfigFile: \"src/conf/refactoring-methods.json\"";
        Assert.assertEquals(desiredOutput, output);
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) HashMap(java.util.HashMap) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 23 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddPluginRecursively.

@Test
public void testAddPluginRecursively() throws Exception {
    File dir = new File("src/test/resources/multimoduleyaml");
    dir.mkdirs();
    File module0 = new File(dir, "module0");
    module0.mkdir();
    File moduleCfg = new File(module0, "walkmod.yml");
    File file = new File(dir, "walkmod.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        provider.addModules(Arrays.asList("module0"));
        PluginConfig pluginCfg = new PluginConfigImpl();
        pluginCfg.setGroupId("org.walkmod");
        pluginCfg.setArtifactId("myplugin");
        pluginCfg.setVersion("1.0");
        provider.addPluginConfig(pluginCfg, true);
        String output = FileUtils.readFileToString(moduleCfg);
        String desiredOutput = "plugins:\n";
        desiredOutput += "- \"org.walkmod:myplugin:1.0\"";
        Assert.assertEquals(desiredOutput, output);
    } finally {
        if (dir.exists()) {
            FileUtils.deleteDirectory(dir);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 24 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl 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 25 with ConfigurationImpl

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

Aggregations

ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)50 Configuration (org.walkmod.conf.entities.Configuration)48 Test (org.junit.Test)43 File (java.io.File)36 AddTransformationCommand (org.walkmod.commands.AddTransformationCommand)21 LinkedList (java.util.LinkedList)20 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)20 PluginConfig (org.walkmod.conf.entities.PluginConfig)9 ChainConfig (org.walkmod.conf.entities.ChainConfig)8 HashMap (java.util.HashMap)6 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)4 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)4 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)4 AddCfgProviderCommand (org.walkmod.commands.AddCfgProviderCommand)3 TransformerException (javax.xml.transform.TransformerException)2 AddPluginCommand (org.walkmod.commands.AddPluginCommand)2