Search in sources :

Example 21 with AddTransformationCommand

use of org.walkmod.commands.AddTransformationCommand 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 22 with AddTransformationCommand

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

the class WalkModDispatcher method execute.

public void execute(JCommander jcommander, String[] args) throws Exception {
    commands.put("add", new AddTransformationCommand(jcommander));
    commands.put("add-excludes", new AddExcludesCommand(jcommander));
    commands.put("add-includes", new AddIncludesCommand(jcommander));
    commands.put("add-module", new AddModuleCommand(jcommander));
    commands.put("add-plugin", new AddPluginCommand(jcommander));
    commands.put("add-provider", new AddCfgProviderCommand(jcommander));
    commands.put("apply", new ApplyCommand(jcommander));
    commands.put("chains", new PrintChainsCommand(jcommander));
    commands.put("check", new CheckCommand(jcommander));
    commands.put("init", new InitCommand(jcommander));
    commands.put("inspect", new InspectCommand(jcommander));
    commands.put("install", new InstallCommand(jcommander));
    commands.put("modules", new PrintModulesCommand(jcommander));
    commands.put("patch", new PatchCommand(jcommander));
    commands.put("providers", new PrintProvidersCommand(jcommander));
    commands.put("rm", new RemoveTransformationCommand(jcommander));
    commands.put("rm-excludes", new RemoveExcludesCommand(jcommander));
    commands.put("rm-includes", new RemoveIncludesCommand(jcommander));
    commands.put("rm-chain", new RemoveChainCommand(jcommander));
    commands.put("rm-module", new RemoveModuleCommand(jcommander));
    commands.put("rm-plugin", new RemovePluginCommand(jcommander));
    commands.put("rm-provider", new RemoveProviderCommand(jcommander));
    commands.put("set-reader", new SetReaderCommand(jcommander));
    commands.put("set-writer", new SetWriterCommand(jcommander));
    commands.put("transformations", new PrintTransformationsCommand(jcommander));
    commands.put("plugins", new PrintPluginsCommand(jcommander));
    commands.put("--version", new VersionCommand());
    commands.put("--help", new HelpCommand(jcommander));
    Set<String> keys = commands.keySet();
    for (String key : keys) {
        if (!key.startsWith("--")) {
            jcommander.addCommand(key, commands.get(key));
        } else {
            jcommander.addCommand(key, commands.get(key), "-" + key.charAt(2));
        }
        JCommander aux = jcommander.getCommands().get(key);
        aux.setProgramName("walkmod " + key);
        aux.setAcceptUnknownOptions(false);
    }
    if (args == null || args.length == 0) {
        printHeader();
        new HelpCommand(jcommander).execute();
    } else {
        try {
            jcommander.parse(args);
        } catch (ParameterException e) {
            System.out.println(e.getMessage());
            System.out.println("Run walkmod --help to see the accepted parameters");
            return;
        }
        String command = jcommander.getParsedCommand();
        printHeader();
        Command commandObject = commands.get(command.substring("walkmod ".length(), command.length()));
        commandObject.execute();
        if (commandObject instanceof AsciiTableAware) {
            AsciiTableAware aux = (AsciiTableAware) commandObject;
            V2_AsciiTable table = aux.getTable();
            if (table != null) {
                V2_AsciiTableRenderer rend = new V2_AsciiTableRenderer();
                rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
                rend.setWidth(new AsciiTableWidth(50));
                RenderedTable rt = rend.render(table);
                System.out.println(rt);
            }
        }
    }
}
Also used : SetWriterCommand(org.walkmod.commands.SetWriterCommand) PatchCommand(org.walkmod.commands.PatchCommand) SetReaderCommand(org.walkmod.commands.SetReaderCommand) VersionCommand(org.walkmod.commands.VersionCommand) InitCommand(org.walkmod.commands.InitCommand) RemoveIncludesCommand(org.walkmod.commands.RemoveIncludesCommand) InspectCommand(org.walkmod.commands.InspectCommand) PrintChainsCommand(org.walkmod.commands.PrintChainsCommand) CheckCommand(org.walkmod.commands.CheckCommand) V2_AsciiTable(de.vandermeer.asciitable.v2.V2_AsciiTable) JCommander(com.beust.jcommander.JCommander) RemoveChainCommand(org.walkmod.commands.RemoveChainCommand) InstallCommand(org.walkmod.commands.InstallCommand) PrintModulesCommand(org.walkmod.commands.PrintModulesCommand) ParameterException(com.beust.jcommander.ParameterException) PrintProvidersCommand(org.walkmod.commands.PrintProvidersCommand) RemoveExcludesCommand(org.walkmod.commands.RemoveExcludesCommand) AddPluginCommand(org.walkmod.commands.AddPluginCommand) V2_AsciiTableRenderer(de.vandermeer.asciitable.v2.render.V2_AsciiTableRenderer) AddExcludesCommand(org.walkmod.commands.AddExcludesCommand) AddCfgProviderCommand(org.walkmod.commands.AddCfgProviderCommand) PrintTransformationsCommand(org.walkmod.commands.PrintTransformationsCommand) HelpCommand(org.walkmod.commands.HelpCommand) AddIncludesCommand(org.walkmod.commands.AddIncludesCommand) PrintPluginsCommand(org.walkmod.commands.PrintPluginsCommand) RenderedTable(de.vandermeer.asciitable.v2.RenderedTable) ApplyCommand(org.walkmod.commands.ApplyCommand) RemovePluginCommand(org.walkmod.commands.RemovePluginCommand) AsciiTableAware(org.walkmod.commands.AsciiTableAware) RemoveProviderCommand(org.walkmod.commands.RemoveProviderCommand) RemoveTransformationCommand(org.walkmod.commands.RemoveTransformationCommand) AddModuleCommand(org.walkmod.commands.AddModuleCommand) RemoveIncludesCommand(org.walkmod.commands.RemoveIncludesCommand) AddIncludesCommand(org.walkmod.commands.AddIncludesCommand) PrintProvidersCommand(org.walkmod.commands.PrintProvidersCommand) RemovePluginCommand(org.walkmod.commands.RemovePluginCommand) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) InspectCommand(org.walkmod.commands.InspectCommand) RemoveChainCommand(org.walkmod.commands.RemoveChainCommand) VersionCommand(org.walkmod.commands.VersionCommand) PrintPluginsCommand(org.walkmod.commands.PrintPluginsCommand) PrintModulesCommand(org.walkmod.commands.PrintModulesCommand) RemoveExcludesCommand(org.walkmod.commands.RemoveExcludesCommand) Command(org.walkmod.commands.Command) SetWriterCommand(org.walkmod.commands.SetWriterCommand) AddCfgProviderCommand(org.walkmod.commands.AddCfgProviderCommand) PrintChainsCommand(org.walkmod.commands.PrintChainsCommand) SetReaderCommand(org.walkmod.commands.SetReaderCommand) RemoveModuleCommand(org.walkmod.commands.RemoveModuleCommand) RemoveProviderCommand(org.walkmod.commands.RemoveProviderCommand) InstallCommand(org.walkmod.commands.InstallCommand) PatchCommand(org.walkmod.commands.PatchCommand) AddPluginCommand(org.walkmod.commands.AddPluginCommand) RemoveTransformationCommand(org.walkmod.commands.RemoveTransformationCommand) AddModuleCommand(org.walkmod.commands.AddModuleCommand) PrintTransformationsCommand(org.walkmod.commands.PrintTransformationsCommand) HelpCommand(org.walkmod.commands.HelpCommand) AddExcludesCommand(org.walkmod.commands.AddExcludesCommand) CheckCommand(org.walkmod.commands.CheckCommand) ApplyCommand(org.walkmod.commands.ApplyCommand) InitCommand(org.walkmod.commands.InitCommand) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) RemoveModuleCommand(org.walkmod.commands.RemoveModuleCommand)

Example 23 with AddTransformationCommand

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

the class XMLConfigurationProviderTest method testAddMultipleTransformationWithPath.

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

Example 24 with AddTransformationCommand

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

the class XMLConfigurationProviderTest method testAddExternalTransformation.

@Test
public void testAddExternalTransformation() 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("com.metricstream:metricstream:AddCurlyBraces", null, false, null, null, null, null, false);
        prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
        prov.load();
        Collection<PluginConfig> plugins = prov.getConfiguration().getPlugins();
        boolean containsMetricStream = false;
        Iterator<PluginConfig> it = plugins.iterator();
        while (it.hasNext() && !containsMetricStream) {
            PluginConfig next = it.next();
            containsMetricStream = next.getGroupId().equals("com.metricstream") && next.getArtifactId().equals("walkmod-metricstream-plugin");
        }
        Assert.assertTrue(containsMetricStream);
    } finally {
        xml.delete();
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) Test(org.junit.Test)

Example 25 with AddTransformationCommand

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

the class XMLConfigurationProviderTest method testAddConfigurationParameter.

@Test
public void testAddConfigurationParameter() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
    File aux = new File("src/test/resources/xmlparams");
    aux.mkdirs();
    File xml = new File(aux, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        prov.createConfig();
        TransformationConfig transfCfg = command.buildTransformationCfg();
        prov.addTransformationConfig("mychain", null, transfCfg, false, null, null);
        prov.addConfigurationParameter("testParam", "hello", "imports-cleaner", null, null, null, false);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("testParam") && output.contains("hello"));
    } finally {
        FileUtils.deleteDirectory(aux);
    }
}
Also used : TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) 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