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