use of org.walkmod.conf.entities.impl.PluginConfigImpl in project walkmod-core by walkmod.
the class YAMLConfigurationProvider method load.
@Override
public void load() throws ConfigurationException {
File file = new File(fileName);
try {
JsonNode node = null;
if (file.exists() && file.length() > 0) {
node = mapper.readTree(file);
configuration.prepareInitializers();
if (node.has("plugins")) {
Iterator<JsonNode> it = node.get("plugins").iterator();
Collection<PluginConfig> pluginList = new LinkedList<PluginConfig>();
while (it.hasNext()) {
JsonNode current = it.next();
String pluginId = current.asText();
String[] split = pluginId.split(":");
if (split.length > 3) {
} else {
String groupId, artifactId, version;
groupId = split[0];
artifactId = split[1];
version = split[2];
PluginConfig plugin = new PluginConfigImpl();
plugin.setGroupId(groupId);
plugin.setArtifactId(artifactId);
plugin.setVersion(version);
pluginList.add(plugin);
}
}
configuration.setPlugins(pluginList);
}
if (node.has("modules")) {
Iterator<JsonNode> it = node.get("modules").iterator();
List<String> modules = new LinkedList<String>();
configuration.setModules(modules);
while (it.hasNext()) {
JsonNode current = it.next();
modules.add(current.asText());
}
configuration.setModules(modules);
}
if (node.has("merge-policies")) {
Iterator<JsonNode> it = node.get("merge-policies").iterator();
Collection<MergePolicyConfig> mergePolicies = new LinkedList<MergePolicyConfig>();
while (it.hasNext()) {
JsonNode next = it.next();
if (next.has("policy")) {
MergePolicyConfig mergeCfg = new MergePolicyConfigImpl();
mergeCfg.setName(next.get("name").asText());
mergeCfg.setDefaultObjectPolicy(next.get("default-object-policy").asText());
mergeCfg.setDefaultTypePolicy(next.get("default-type-policy").asText());
if (next.has("policy")) {
Iterator<JsonNode> it2 = next.get("policy").iterator();
Map<String, String> policies = new HashMap<String, String>();
while (it2.hasNext()) {
JsonNode nextPolicy = it2.next();
String objectType = nextPolicy.get("object-type").asText();
String policyType = nextPolicy.get("policy-type").asText();
policies.put(objectType, policyType);
}
mergeCfg.setPolicyEntries(policies);
}
mergePolicies.add(mergeCfg);
}
}
configuration.setMergePolicies(mergePolicies);
}
if (node.has("conf-providers")) {
Iterator<JsonNode> it = node.get("conf-providers").iterator();
Collection<ProviderConfig> provConfigs = new LinkedList<ProviderConfig>();
while (it.hasNext()) {
JsonNode next = it.next();
ProviderConfig provCfg = new ProviderConfigImpl();
provCfg.setType(next.get("type").asText());
provCfg.setParameters(converter.getParams(next));
provConfigs.add(provCfg);
}
configuration.setProviderConfigurations(provConfigs);
}
if (node.has("chains")) {
Iterator<JsonNode> it = node.get("chains").iterator();
Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
int i = 0;
while (it.hasNext()) {
ChainConfig chainCfg = new ChainConfigImpl();
JsonNode current = it.next();
if (current.has("name")) {
chainCfg.setName(current.get("name").asText());
} else {
chainCfg.setName("chain_" + i);
}
if (current.has("reader")) {
JsonNode reader = current.get("reader");
chainCfg.setReaderConfig(converter.getReader(reader));
} else {
addDefaultReaderConfig(chainCfg);
}
if (current.has("writer")) {
JsonNode writer = current.get("writer");
chainCfg.setWriterConfig(converter.getWriter(writer));
} else {
addDefaultWriterConfig(chainCfg);
}
if (current.has("walker")) {
chainCfg.setWalkerConfig(converter.getWalker(current));
} else {
addDefaultWalker(chainCfg);
if (current.has("transformations")) {
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
walkerCfg.setTransformations(converter.getTransformationCfgs(current));
}
}
chains.add(chainCfg);
}
configuration.setChainConfigs(chains);
} else if (node.has("transformations")) {
Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
ChainConfig chainCfg = new ChainConfigImpl();
chainCfg.setName("");
addDefaultReaderConfig(chainCfg);
addDefaultWalker(chainCfg);
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
walkerCfg.setTransformations(converter.getTransformationCfgs(node));
addDefaultWriterConfig(chainCfg);
chains.add(chainCfg);
configuration.setChainConfigs(chains);
}
}
} catch (JsonProcessingException e) {
throw new ConfigurationException("Error parsing the " + fileName + " configuration", e);
} catch (IOException e) {
throw new ConfigurationException("Error reading the " + fileName + " configuration", e);
}
configuration.preparePlugins();
}
use of org.walkmod.conf.entities.impl.PluginConfigImpl in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadPlugins.
private void loadPlugins() {
Element rootElement = document.getDocumentElement();
NodeList children = rootElement.getChildNodes();
int childSize = children.getLength();
for (int i = 0; i < childSize; i++) {
Node childNode = children.item(i);
if ("plugins".equals(childNode.getNodeName())) {
Element child = (Element) childNode;
Collection<PluginConfig> plugins = new LinkedList<PluginConfig>();
configuration.setPlugins(plugins);
NodeList pluginNodes = child.getChildNodes();
int pluginSize = pluginNodes.getLength();
for (int j = 0; j < pluginSize; j++) {
Node pluginNode = pluginNodes.item(j);
if ("plugin".equals(pluginNode.getNodeName())) {
Element pluginElement = (Element) pluginNode;
PluginConfig pc = new PluginConfigImpl();
String groupId = pluginElement.getAttribute("groupId");
String artifactId = pluginElement.getAttribute("artifactId");
String version = pluginElement.getAttribute("version");
if (groupId == null) {
throw new ConfigurationException("Invalid plugin definition. A groupId is necessary.");
}
if (artifactId == null) {
throw new ConfigurationException("Invalid plugin definition. A artifactId is necessary.");
}
if (version == null) {
throw new ConfigurationException("Invalid plugin definition. A version is necessary.");
}
pc.setGroupId(groupId);
pc.setArtifactId(artifactId);
pc.setVersion(version);
plugins.add(pc);
}
}
}
}
}
use of org.walkmod.conf.entities.impl.PluginConfigImpl in project walkmod-core by walkmod.
the class PrintPluginsCommand method execute.
public void execute() {
if (help) {
command.usage("init");
} else {
try {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options());
Configuration cfg = facade.getConfiguration();
Collection<PluginConfig> installedPlugins = null;
if (cfg != null) {
installedPlugins = cfg.getPlugins();
}
URL searchURL = new URL(MVN_SEARCH_URL);
InputStream is = null;
Map<String, Boolean> installedList = new LinkedHashMap<String, Boolean>();
Map<String, String> pluginsList = new LinkedHashMap<String, String>();
Map<String, String> pluginsURLs = new LinkedHashMap<String, String>();
try {
is = searchURL.openStream();
String content = readInputStreamAsString(is);
DefaultJSONParser parser = new DefaultJSONParser(content);
JSONObject object = parser.parseObject();
parser.close();
JSONArray artifactList = (object.getJSONObject("response")).getJSONArray("docs");
for (int i = 0; i < artifactList.size(); i++) {
JSONObject artifact = artifactList.getJSONObject(i);
String artifactId = artifact.getString("a");
if (artifactId.startsWith("walkmod-") && artifactId.endsWith("-plugin")) {
String groupId = artifact.getString("g");
if (!"org.walkmod.maven.plugins".equals(groupId)) {
String latestVersion = artifact.getString("latestVersion");
String pom = artifactId + "-" + latestVersion + ".pom";
String directory = groupId.replaceAll("\\.", "/");
URL artifactDetailsURL = new URL(ARTIFACT_DETAILS_URL + directory + "/" + artifactId + "/" + latestVersion + "/" + pom);
InputStream projectIs = null;
try {
projectIs = artifactDetailsURL.openStream();
} catch (Exception e) {
}
if (projectIs != null) {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(projectIs);
NodeList nList = doc.getElementsByTagName("description");
String description = "unavailable description";
if (nList.getLength() == 1) {
description = nList.item(0).getTextContent();
}
String id = "";
if (!groupId.equals("org.walkmod")) {
id = groupId + ":";
}
id += artifactId.substring("walkmod-".length(), artifactId.length() - "-plugin".length());
if (Character.isLowerCase(description.charAt(0))) {
description = Character.toUpperCase(description.charAt(0)) + description.substring(1, description.length());
}
if (!description.endsWith(".")) {
description = description + ".";
}
pluginsList.put(id, description);
nList = doc.getChildNodes().item(0).getChildNodes();
int max = nList.getLength();
String url = "unavailable url";
for (int j = 0; j < max; j++) {
String name = nList.item(j).getNodeName();
if (name.equals("url")) {
url = nList.item(j).getTextContent();
j = max;
}
}
pluginsURLs.put(id, url);
PluginConfig equivalentPluginCfg = new PluginConfigImpl();
equivalentPluginCfg.setGroupId(groupId);
equivalentPluginCfg.setArtifactId(artifactId);
boolean isInstalled = (installedPlugins != null && installedPlugins.contains(equivalentPluginCfg));
installedList.put(id, isInstalled);
} finally {
projectIs.close();
}
}
}
}
}
} finally {
is.close();
}
Set<String> keys = pluginsList.keySet();
List<String> sortedKeys = new LinkedList<String>(keys);
Collections.sort(sortedKeys);
at = new V2_AsciiTable();
at.addRule();
at.addRow("PLUGIN NAME (ID)", "RDY", "DESCRIPTION");
at.addStrongRule();
for (String key : sortedKeys) {
String installed = "";
if (installedList.get(key)) {
installed = "*";
}
at.addRow(key, installed, pluginsList.get(key) + "\n\nURL:" + pluginsURLs.get(key));
at.addRule();
}
} catch (Exception e) {
throw new WalkModException("Invalid plugins URL", e);
}
}
}
use of org.walkmod.conf.entities.impl.PluginConfigImpl 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.impl.PluginConfigImpl in project walkmod-core by walkmod.
the class InspectCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("inspect");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().offline(offline));
List<BeanDefinition> beans = facade.inspectPlugin(new PluginConfigImpl(pluginId.get(0)));
List<String> validTypesList = Arrays.asList("String", "JSONObject", "JSONArray");
if (beans != null) {
at = new V2_AsciiTable();
at.addRule();
at.addRow("TYPE NAME (ID)", "CATEGORY", "PROPERTIES", "DESCRIPTION");
at.addStrongRule();
for (BeanDefinition bean : beans) {
List<PropertyDefinition> properties = bean.getProperties();
if (properties == null || properties.isEmpty()) {
at.addRow(bean.getType(), bean.getCategory(), "", bean.getDescription());
} else {
int i = 0;
for (PropertyDefinition pd : properties) {
if (validTypesList.contains(pd.getType())) {
String label = pd.getName() + ":" + pd.getType();
if (pd.getDefaultValue() != null && pd.getDefaultValue().length() != 0) {
label = label + " (" + pd.getDefaultValue() + ")";
}
if (i == 0) {
at.addRow(bean.getType(), bean.getCategory(), label, bean.getDescription());
} else {
at.addRow("", "", label, "");
}
i++;
}
}
}
at.addRule();
}
}
}
}
Aggregations