Search in sources :

Example 6 with ProviderConfig

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

the class YAMLConfigurationProviderTest method testRemoveProvider.

@Test
public void testRemoveProvider() throws Exception {
    AddCfgProviderCommand command = new AddCfgProviderCommand("maven", null);
    File file = new File("src/test/resources/yaml/addcfgproviders.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);
        ProviderConfig provCfg = command.build();
        provider.addProviderConfig(provCfg, false);
        List<String> providers = new LinkedList<String>();
        providers.add("maven");
        provider.removeProviders(providers, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("maven"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) AddCfgProviderCommand(org.walkmod.commands.AddCfgProviderCommand) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with ProviderConfig

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

the class DefaultConfigurationAdapter method prepare.

@Override
public void prepare() {
    Collection<ProviderConfig> providers = config.getProviderConfigurations();
    if (providers != null) {
        for (ProviderConfig pc : providers) {
            Object aux = config.getBean(pc.getType(), pc.getParameters());
            if (aux instanceof ConfigurationProvider) {
                ConfigurationProvider cp = ((ConfigurationProvider) aux);
                cp.init(config);
                cp.load();
            }
        }
    }
    Collection<MergePolicyConfig> mergePolicies = config.getMergePolicies();
    if (mergePolicies != null) {
        Map<String, MergeEngine> mergeEngines = new HashMap<String, MergeEngine>();
        config.setMergeEngines(mergeEngines);
        for (MergePolicyConfig mpc : mergePolicies) {
            MergeEngine me = new MergeEngine();
            mergeEngines.put(mpc.getName(), me);
            String dopTypeLabel = mpc.getDefaultObjectPolicy();
            Object dop = null;
            Object top = null;
            if (dopTypeLabel != null) {
                dop = config.getBean(dopTypeLabel, null);
            }
            if (dop != null && dop instanceof MergePolicy<?>) {
                me.setDefaultObjectMergePolicy((MergePolicy) dop);
            }
            String topTypeLabel = mpc.getDefaultTypePolicy();
            if (topTypeLabel != null) {
                top = config.getBean(topTypeLabel, null);
            }
            if ((top != null) && top instanceof MergePolicy<?>) {
                me.setDefaultTypeMergePolicy((MergePolicy) top);
            }
            Map<String, String> policyEntries = mpc.getPolicyEntries();
            Class<?> oType = null;
            Object pType = null;
            Map<Class<?>, MergePolicy> resolvedEntries = new HashMap<Class<?>, MergePolicy>();
            if (policyEntries != null && !policyEntries.isEmpty()) {
                for (Map.Entry<String, String> entry : policyEntries.entrySet()) {
                    try {
                        oType = config.getClassLoader().loadClass(entry.getKey());
                    } catch (ClassNotFoundException e) {
                        throw new WalkModException("Invalid policy entry for " + entry.getKey());
                    }
                    pType = config.getBean(entry.getValue(), null);
                    if (pType instanceof MergePolicy) {
                        resolvedEntries.put(oType, (MergePolicy) pType);
                    }
                }
            }
            me.setPolicyConfiguration(resolvedEntries);
        }
    }
}
Also used : MergePolicyConfig(org.walkmod.conf.entities.MergePolicyConfig) WalkModException(org.walkmod.exceptions.WalkModException) HashMap(java.util.HashMap) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) ConfigurationProvider(org.walkmod.conf.ConfigurationProvider) MergeEngine(org.walkmod.merger.MergeEngine) MergePolicy(org.walkmod.merger.MergePolicy) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with ProviderConfig

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

the class ConfigurationImpl method preparePlugins.

@Override
public void preparePlugins() {
    Collection<PluginConfig> pluginCfg = getPlugins();
    HashSet<String> plugins = new HashSet<String>();
    HashSet<String> previousPlugins = new HashSet<String>();
    if (pluginCfg == null || pluginCfg.isEmpty()) {
        pluginCfg = new LinkedList<PluginConfig>();
    } else {
        for (PluginConfig pc : pluginCfg) {
            previousPlugins.add(pc.getGroupId() + ":" + pc.getArtifactId());
        }
    }
    Collection<ChainConfig> chains = getChainConfigs();
    if (chains != null) {
        Iterator<ChainConfig> it = chains.iterator();
        while (it.hasNext()) {
            ChainConfig cc = it.next();
            composeName(cc.getReaderConfig().getType(), plugins);
            composeName(cc.getWalkerConfig().getParserConfig().getType(), plugins);
            List<TransformationConfig> trans = cc.getWalkerConfig().getTransformations();
            if (trans != null) {
                for (TransformationConfig transformation : trans) {
                    String type = transformation.getType();
                    if (!type.equals("script") && !type.equals("template")) {
                        composeName(type, plugins);
                    }
                }
            }
            composeName(cc.getWriterConfig().getType(), plugins);
        }
    }
    Collection<ProviderConfig> providers = getProviderConfigurations();
    if (providers != null) {
        for (ProviderConfig provider : providers) {
            String type = provider.getType();
            composeName(type, plugins);
        }
    }
    Collection<InitializerConfig> initializers = getInitializers();
    if (initializers != null) {
        for (InitializerConfig initializer : initializers) {
            plugins.add(initializer.getPluginGroupId() + ":walkmod-" + initializer.getPluginArtifactId() + "-plugin");
        }
    }
    for (String id : plugins) {
        if (!previousPlugins.contains(id)) {
            String[] parts = id.split(":");
            PluginConfig cfg = new PluginConfigImpl();
            cfg.setGroupId(parts[0].trim());
            cfg.setArtifactId(parts[1].trim());
            cfg.setVersion("latest.integration");
            pluginCfg.add(cfg);
        }
    }
    setPlugins(pluginCfg);
}
Also used : ProviderConfig(org.walkmod.conf.entities.ProviderConfig) InitializerConfig(org.walkmod.conf.entities.InitializerConfig) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ChainConfig(org.walkmod.conf.entities.ChainConfig) PluginConfig(org.walkmod.conf.entities.PluginConfig) HashSet(java.util.HashSet)

Example 9 with ProviderConfig

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

the class XMLConfigurationProviderTest method testRemoveProviders.

@Test
public void testRemoveProviders() throws Exception {
    AddCfgProviderCommand command = new AddCfgProviderCommand("maven", null);
    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();
        ProviderConfig provCfg = command.build();
        prov.addProviderConfig(provCfg, false);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("maven"));
        List<String> providers = new LinkedList<String>();
        providers.add("maven");
        prov.removeProviders(providers, false);
        output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(!output.contains("maven"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : AddCfgProviderCommand(org.walkmod.commands.AddCfgProviderCommand) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with ProviderConfig

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

the class XMLConfigurationProviderTest method testConfigProvidersConfig.

@Test
public void testConfigProvidersConfig() throws Exception {
    AddCfgProviderCommand command = new AddCfgProviderCommand("maven", null);
    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();
        ProviderConfig provCfg = command.build();
        prov.addProviderConfig(provCfg, false);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("maven"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : AddCfgProviderCommand(org.walkmod.commands.AddCfgProviderCommand) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) File(java.io.File) Test(org.junit.Test)

Aggregations

ProviderConfig (org.walkmod.conf.entities.ProviderConfig)13 File (java.io.File)7 Test (org.junit.Test)7 AddCfgProviderCommand (org.walkmod.commands.AddCfgProviderCommand)6 Configuration (org.walkmod.conf.entities.Configuration)5 LinkedList (java.util.LinkedList)4 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)4 ChainConfig (org.walkmod.conf.entities.ChainConfig)3 PluginConfig (org.walkmod.conf.entities.PluginConfig)3 ProviderConfigImpl (org.walkmod.conf.entities.impl.ProviderConfigImpl)3 HashMap (java.util.HashMap)2 MergePolicyConfig (org.walkmod.conf.entities.MergePolicyConfig)2 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1