Search in sources :

Example 1 with AddTransformationCommand

use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testAddTransformationRecursively.

@Test
public void testAddTransformationRecursively() throws Exception {
    File aux = new File("src/test/resources/modulesxml");
    File aux1 = new File(aux, "module1");
    File aux2 = new File(aux, "module2");
    aux.mkdirs();
    aux1.mkdir();
    aux2.mkdir();
    File xml = new File(aux, "walkmod.xml");
    File xml1 = new File(aux1, "walkmod.xml");
    File xml2 = new File(aux2, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        prov.createConfig();
        List<String> modules = new LinkedList<String>();
        modules.add("module1");
        modules.add("module2");
        prov.addModules(modules);
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, true);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), true, null, null);
        String content = FileUtils.readFileToString(xml);
        Assert.assertTrue(!content.contains("imports-cleaner"));
        content = FileUtils.readFileToString(xml1);
        Assert.assertTrue(content.contains("imports-cleaner"));
        content = FileUtils.readFileToString(xml2);
        Assert.assertTrue(content.contains("imports-cleaner"));
    } finally {
        FileUtils.deleteDirectory(aux);
    }
}
Also used : AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with AddTransformationCommand

use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testAddTransformationWithPath.

@Test
public void testAddTransformationWithPath() 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 {
        prov.createConfig();
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, "src", null, null, false);
        prov.addTransformationConfig(null, "src", command.buildTransformationCfg(), false, null, null);
        String content = FileUtils.readFileToString(xml);
        Assert.assertTrue(content.contains("imports-cleaner") && content.contains("src"));
    } finally {
        xml.delete();
    }
}
Also used : AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) Test(org.junit.Test)

Example 3 with AddTransformationCommand

use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testAddTransformationAfterMultipleInDefaultChain.

@Test
public void testAddTransformationAfterMultipleInDefaultChain() 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 {
        prov.createConfig();
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
        command = new AddTransformationCommand("setter-getter", null, false, null, null, null, null, false, null, null);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
        command = new AddTransformationCommand("setter-getter", "common", false, null, null, null, null, false, null, "default");
        prov.addTransformationConfig("common", null, command.buildTransformationCfg(), false, null, "default");
        String content = FileUtils.readFileToString(xml);
        System.out.println(content);
        Assert.assertTrue(content.contains("imports-cleaner"));
        Assert.assertTrue(content.contains("common"));
        Assert.assertTrue(content.contains("setter-getter"));
        Assert.assertTrue(content.indexOf("common") < content.indexOf("default"));
    } finally {
        xml.delete();
    }
}
Also used : AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) Test(org.junit.Test)

Example 4 with AddTransformationCommand

use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testRemoveTransformationsRecursively.

@Test
public void testRemoveTransformationsRecursively() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("imports-cleaner");
    File aux = new File("src/test/resources/xmlmultimodule");
    aux.mkdirs();
    File module0 = new File(aux, "module0");
    File module1 = new File(aux, "module1");
    File cfg0 = new File(module0, "walkmod.xml");
    File cfg1 = new File(module1, "walkmod.xml");
    module0.mkdir();
    module1.mkdir();
    File xml = new File(aux, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        Configuration conf = new ConfigurationImpl();
        prov.init(conf);
        prov.createConfig();
        prov.addModules(Arrays.asList("module0", "module1"));
        AddTransformationCommand command0 = new AddTransformationCommand("license-applier", "mychain", false, null, null, null, null, true);
        prov.addTransformationConfig("mychain", null, command0.buildTransformationCfg(), true, null, null);
        String output = FileUtils.readFileToString(cfg0);
        System.out.println(output);
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, true);
        prov.addTransformationConfig("mychain", null, command.buildTransformationCfg(), true, null, null);
        output = FileUtils.readFileToString(cfg0);
        System.out.println(output);
        prov.removeTransformations("mychain", list, true);
        output = FileUtils.readFileToString(cfg0);
        Assert.assertTrue(!output.contains("imports-cleaner"));
        Assert.assertTrue(output.contains("license-applier"));
        output = FileUtils.readFileToString(cfg1);
        Assert.assertTrue(!output.contains("imports-cleaner"));
        Assert.assertTrue(output.contains("license-applier"));
    } finally {
        if (aux.exists()) {
            FileUtils.deleteDirectory(aux);
        }
    }
}
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 5 with AddTransformationCommand

use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testRemoveTranformation.

@Test
public void testRemoveTranformation() 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 command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
        prov.removeTransformations(null, list, false);
        String output = FileUtils.readFileToString(xml);
        Assert.assertTrue(!output.contains("imports-cleaner"));
    } 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)

Aggregations

AddTransformationCommand (org.walkmod.commands.AddTransformationCommand)52 File (java.io.File)51 Test (org.junit.Test)51 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)36 Configuration (org.walkmod.conf.entities.Configuration)21 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)21 LinkedList (java.util.LinkedList)8 HashMap (java.util.HashMap)5 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 RenderedTable (de.vandermeer.asciitable.v2.RenderedTable)1 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)1 V2_AsciiTableRenderer (de.vandermeer.asciitable.v2.render.V2_AsciiTableRenderer)1 AddCfgProviderCommand (org.walkmod.commands.AddCfgProviderCommand)1 AddExcludesCommand (org.walkmod.commands.AddExcludesCommand)1 AddIncludesCommand (org.walkmod.commands.AddIncludesCommand)1 AddModuleCommand (org.walkmod.commands.AddModuleCommand)1 AddPluginCommand (org.walkmod.commands.AddPluginCommand)1 ApplyCommand (org.walkmod.commands.ApplyCommand)1 AsciiTableAware (org.walkmod.commands.AsciiTableAware)1