Search in sources :

Example 16 with PluginConfig

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

Example 17 with PluginConfig

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

the class SpringConfigurationProvider method loadBeanFactory.

@Override
public void loadBeanFactory() throws ConfigurationException {
    GenericApplicationContext ctx = new GenericApplicationContext();
    ClassLoader currentClassLoader = configuration.getClassLoader();
    if (currentClassLoader != Thread.currentThread().getContextClassLoader()) {
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
        reader.setBeanClassLoader(currentClassLoader);
        reader.loadBeanDefinitions(new ClassPathResource(config, currentClassLoader));
        Collection<PluginConfig> plugins = configuration.getPlugins();
        if (plugins != null) {
            for (PluginConfig plugin : plugins) {
                String descriptorName = plugin.getArtifactId();
                if (!descriptorName.startsWith("walkmod-")) {
                    descriptorName = "walkmod-" + descriptorName;
                }
                if (!descriptorName.endsWith("-plugin")) {
                    descriptorName = descriptorName + "-plugin";
                }
                reader.loadBeanDefinitions(new ClassPathResource("META-INF/walkmod/" + descriptorName + ".xml", configuration.getClassLoader()));
                URL url = currentClassLoader.getResource("META-INF/walkmod2/" + descriptorName + ".xml");
                if (url != null) {
                    reader.loadBeanDefinitions(new ClassPathResource("META-INF/walkmod2/" + descriptorName + ".xml", configuration.getClassLoader()));
                }
            }
        }
        configuration.setBeanDefinitionRegistry(reader.getRegistry());
        ctx.refresh();
    }
    configuration.setBeanFactory(ctx);
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) URL(java.net.URL)

Example 18 with PluginConfig

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

the class PluginsConfigurationProviderTest method testNullOverwriting.

@Test
public void testNullOverwriting() {
    PluginsConfigurationProvider provider = new PluginsConfigurationProvider();
    Configuration conf = new ConfigurationImpl();
    provider.init(conf);
    provider.load();
    Collection<PluginConfig> plugins = conf.getPlugins();
    Assert.assertNotNull(plugins);
    Assert.assertEquals(1, plugins.size());
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 19 with PluginConfig

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

the class PluginsConfigurationProviderTest method testInvalidPlugins.

@Test
public void testInvalidPlugins() {
    IvyConfigurationProvider provider = new IvyConfigurationProvider();
    Configuration conf = new ConfigurationImpl();
    provider.init(conf);
    PluginConfig pc = new PluginConfigImpl();
    pc.setGroupId("foo");
    pc.setArtifactId("bar");
    pc.setVersion("10");
    conf.setPlugins(new LinkedList());
    conf.getPlugins().add(pc);
    Exception exception = null;
    try {
        provider.load();
    } catch (ConfigurationException e) {
        exception = e;
    }
    Assert.assertNotNull(exception);
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) ConfigurationException(org.walkmod.conf.ConfigurationException) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) ConfigurationException(org.walkmod.conf.ConfigurationException) Test(org.junit.Test)

Example 20 with PluginConfig

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

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