use of org.walkmod.WalkModFacade 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.WalkModFacade in project walkmod-core by walkmod.
the class PrintProvidersCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
jcommander.usage("modules");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options());
Configuration cfg = facade.getConfiguration();
if (cfg == null) {
log.error("Sorry, the current directory does not contain a walkmod configuration file or it is invalid.");
}
at = new V2_AsciiTable();
at.addRule();
at.addRow("CONFIGURATION PROVIDERS", "PARAMETERS");
at.addRule();
if (cfg != null) {
Collection<ProviderConfig> providers = cfg.getProviderConfigurations();
if (providers != null) {
for (ProviderConfig provider : providers) {
Map<String, Object> params = provider.getParameters();
if (params == null) {
at.addRow(provider.getType(), "");
} else {
Set<String> keys = params.keySet();
int i = 0;
for (String key : keys) {
if (i == 0) {
at.addRow(provider.getType(), params.get(key).toString());
} else {
at.addRow("", params.get(key).toString());
}
i++;
}
}
at.addRule();
}
}
}
at.addRule();
}
}
use of org.walkmod.WalkModFacade in project walkmod-core by walkmod.
the class RemoveIncludesCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
jcommander.usage("rm-includes");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().printErrors(printErrors));
facade.removeIncludesToChain(chain, includes, recursive, setToReader, setToWriter);
}
}
use of org.walkmod.WalkModFacade in project walkmod-core by walkmod.
the class RemoveModuleCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
jcommander.usage("rm-module");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().printErrors(printErrors));
facade.removeModules(modules);
}
}
use of org.walkmod.WalkModFacade in project walkmod-core by walkmod.
the class RemovePluginCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("rm-plugin");
} else {
List<PluginConfig> list = build();
for (PluginConfig pc : list) {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().printErrors(printErrors));
facade.removePluginConfig(pc, recursive);
}
}
}
Aggregations