Search in sources :

Example 6 with PluginConfig

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

the class RemovePluginCommand method build.

public List<PluginConfig> build() {
    List<PluginConfig> result = new LinkedList<PluginConfig>();
    for (String plugin : plugins) {
        PluginConfig pluginConfig = new PluginConfigImpl();
        String[] parts = plugin.split(":");
        boolean valid = parts.length <= 3;
        for (int i = 0; i < parts.length && valid; i++) {
            valid = !parts[i].trim().equals("");
        }
        if (valid) {
            if (parts.length == 1) {
                pluginConfig.setGroupId("org.walkmod");
                String artifactId = parts[0].trim();
                if (!artifactId.startsWith("walkmod-")) {
                    artifactId = "walkmod-" + artifactId;
                }
                if (!artifactId.endsWith("-plugin")) {
                    artifactId = artifactId + "-plugin";
                }
                pluginConfig.setArtifactId(artifactId);
                pluginConfig.setVersion("latest.integration");
            } else if (parts.length == 2) {
                pluginConfig.setGroupId(parts[0].trim());
                pluginConfig.setArtifactId(parts[1].trim());
                pluginConfig.setVersion("latest.integration");
            } else {
                pluginConfig.setGroupId(parts[0].trim());
                pluginConfig.setArtifactId(parts[1].trim());
                pluginConfig.setVersion(parts[2].trim());
            }
            result.add(pluginConfig);
        } else {
            throw new IllegalArgumentException("The plugin identifier is not well defined. The expected format is [groupId:artifactId:version]");
        }
    }
    return result;
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) LinkedList(java.util.LinkedList)

Example 7 with PluginConfig

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

the class AddPluginCommand method execute.

@Override
public void execute() throws Exception {
    if (help) {
        command.usage("add-plugin");
    } else {
        List<PluginConfig> list = build();
        for (PluginConfig pc : list) {
            WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().printErrors(printErrors));
            facade.addPluginConfig(pc, recursive);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) WalkModFacade(org.walkmod.WalkModFacade)

Example 8 with PluginConfig

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

the class XMLConfigurationProviderTest method testRemovePlugin.

@Test
public void testRemovePlugin() 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();
        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), false);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("imports-cleaner"));
        prov.removePluginConfig(pluginCfgs.get(0), false);
        output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(!output.contains("imports-cleaner"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
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 9 with PluginConfig

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

the class YAMLConfigurationProviderTest method testRemovePlugin.

@Test
public void testRemovePlugin() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("org.walkmod:javalang");
    File file = new File("src/test/resources/yaml/removePlugin.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    String input = "plugins:\n";
    input += "- \"org.walkmod:imports-cleaner:2.0\"";
    FileUtils.write(file, input);
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        PluginConfig pc = new PluginConfigImpl();
        pc.setGroupId("org.walkmod");
        pc.setArtifactId("imports-cleaner");
        provider.removePluginConfig(pc, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("imports-cleaner"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
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) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with PluginConfig

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

the class YAMLConfigurationProviderTest method testAddPlugin.

@Test
public void testAddPlugin() throws Exception {
    File file = new File("src/test/resources/yaml/addplugin.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);
        PluginConfig pluginCfg = new PluginConfigImpl();
        pluginCfg.setGroupId("org.walkmod");
        pluginCfg.setArtifactId("myplugin");
        pluginCfg.setVersion("1.0");
        provider.addPluginConfig(pluginCfg, false);
        String output = FileUtils.readFileToString(file);
        String desiredOutput = "plugins:\n";
        desiredOutput += "- \"org.walkmod:myplugin:1.0\"";
        Assert.assertEquals(desiredOutput, output);
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
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)

Aggregations

PluginConfig (org.walkmod.conf.entities.PluginConfig)22 LinkedList (java.util.LinkedList)10 Configuration (org.walkmod.conf.entities.Configuration)10 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)10 Test (org.junit.Test)9 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)9 File (java.io.File)8 ConfigurationException (org.walkmod.conf.ConfigurationException)4 ChainConfig (org.walkmod.conf.entities.ChainConfig)4 IOException (java.io.IOException)3 URL (java.net.URL)3 NodeList (org.w3c.dom.NodeList)3 WalkModFacade (org.walkmod.WalkModFacade)3 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)3 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 AddPluginCommand (org.walkmod.commands.AddPluginCommand)2 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)2 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)2 JSONArray (com.alibaba.fastjson.JSONArray)1