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();
}
}
}
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);
}
}
}
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);
}
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();
}
}
}
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();
}
}
}
Aggregations