Search in sources :

Example 41 with Configuration

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

the class XMLConfigurationProviderTest method testAddPluginRecursively.

@Test
public void testAddPluginRecursively() throws Exception {
    File aux = new File("src/test/resources/multmodulexml");
    aux.mkdirs();
    File module0 = new File(aux, "module0");
    module0.mkdir();
    File xml = new File(aux, "walkmod.xml");
    File modulexml = new File(module0, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        Configuration conf = new ConfigurationImpl();
        prov.init(conf);
        prov.createConfig();
        prov.addModules(Arrays.asList("module0"));
        List<String> plugins = new LinkedList<String>();
        plugins.add("org.walkmod:imports-cleaner");
        AddPluginCommand command = new AddPluginCommand(plugins);
        List<PluginConfig> pluginCfgs = command.build();
        prov.addPluginConfig(pluginCfgs.get(0), true);
        String output = FileUtils.readFileToString(modulexml);
        System.out.println(output);
        Assert.assertTrue(output.contains("imports-cleaner"));
    } finally {
        if (aux.exists()) {
            FileUtils.deleteQuietly(aux);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) AddPluginCommand(org.walkmod.commands.AddPluginCommand) Test(org.junit.Test)

Example 42 with Configuration

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

the class XMLConfigurationProviderTest method testSetReader.

@Test
public void testSetReader() throws Exception {
    File aux = new File("src/test/resources/xml");
    aux.mkdirs();
    File xml = new File(aux, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        Configuration conf = new ConfigurationImpl();
        prov.init(conf);
        prov.createConfig();
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
        prov.setReader(null, "walkmod:commons:file-reader", null, false, null);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("walkmod:commons:file-reader"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 43 with Configuration

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

the class XMLConfigurationProviderTest method testSetWriter.

@Test
public void testSetWriter() throws Exception {
    File aux = new File("src/test/resources/xml");
    aux.mkdirs();
    File xml = new File(aux, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        Configuration conf = new ConfigurationImpl();
        prov.init(conf);
        prov.createConfig();
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
        prov.setWriter(null, "javalang:string-writer", null, false, null);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("javalang:string-writer"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 44 with Configuration

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

the class XMLConfigurationProviderTest method testRemoveChainTransformations.

@Test
public void testRemoveChainTransformations() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("imports-cleaner");
    File aux = new File("src/test/resources/xml");
    aux.mkdirs();
    File xml = new File(aux, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        Configuration conf = new ConfigurationImpl();
        prov.init(conf);
        prov.createConfig();
        AddTransformationCommand command0 = new AddTransformationCommand("license-applier", "mychain", false, null, null, null, null, false);
        prov.addTransformationConfig("mychain", null, command0.buildTransformationCfg(), false, null, null);
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
        prov.addTransformationConfig("mychain", null, command.buildTransformationCfg(), false, null, null);
        prov.removeTransformations("mychain", list, false);
        String output = FileUtils.readFileToString(xml);
        Assert.assertTrue(!output.contains("imports-cleaner"));
        Assert.assertTrue(output.contains("license-applier"));
        list.add("license-applier");
        prov.removeTransformations("mychain", list, false);
        output = FileUtils.readFileToString(xml);
        Assert.assertTrue(!output.contains("chain"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 45 with Configuration

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

the class YAMLConfigurationProviderTest method testAddChainTransformationWithExistingChain.

@Test
public void testAddChainTransformationWithExistingChain() 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", "mychain", 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("mychain", null, transformationCfg, false, null, null);
        command = new AddTransformationCommand("walkmod:commons:class-refactor", "mychain", false, null, null, null, params, false);
        transformationCfg = command.buildTransformationCfg();
        provider.addTransformationConfig("mychain", null, transformationCfg, false, null, null);
        String output = FileUtils.readFileToString(file);
        Assert.assertTrue(output.contains("walkmod:commons:class-refactor") && !output.contains("default"));
    } 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)

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