Search in sources :

Example 6 with PluginConfigImpl

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

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

Example 8 with PluginConfigImpl

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

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

the class AddPluginCommand method build.

public List<PluginConfig> build() {
    List<PluginConfig> result = new LinkedList<PluginConfig>();
    for (String plugin : plugins) {
        PluginConfig pluginConfig = new PluginConfigImpl(plugin);
        result.add(pluginConfig);
    }
    return result;
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) LinkedList(java.util.LinkedList)

Example 10 with PluginConfigImpl

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

the class PluginsConfigurationProvider method load.

@Override
public void load() throws ConfigurationException {
    Collection<PluginConfig> plugins = configuration.getPlugins();
    if (plugins == null) {
        plugins = new LinkedList<PluginConfig>();
        configuration.setPlugins(plugins);
    }
    Element rootElement = document.getDocumentElement();
    NodeList childNodes = rootElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        if ((childNode.getNodeType() == Node.ELEMENT_NODE) && "plugin".equals(childNode.getNodeName())) {
            Element paramElement = (Element) childNode;
            String groupId = paramElement.getAttribute("groupId");
            String artifactId = paramElement.getAttribute("artifactId");
            String version = paramElement.getAttribute("version");
            PluginConfig defaultPlugin = new PluginConfigImpl();
            defaultPlugin.setGroupId(groupId);
            defaultPlugin.setArtifactId(artifactId);
            defaultPlugin.setVersion(version);
            plugins.add(defaultPlugin);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl)

Aggregations

PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)11 PluginConfig (org.walkmod.conf.entities.PluginConfig)10 LinkedList (java.util.LinkedList)7 Configuration (org.walkmod.conf.entities.Configuration)5 File (java.io.File)4 Test (org.junit.Test)4 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)4 NodeList (org.w3c.dom.NodeList)3 ConfigurationException (org.walkmod.conf.ConfigurationException)3 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)2 IOException (java.io.IOException)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 WalkModFacade (org.walkmod.WalkModFacade)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InputStream (java.io.InputStream)1