use of de.vandermeer.asciitable.v2.V2_AsciiTable 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 de.vandermeer.asciitable.v2.V2_AsciiTable 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 de.vandermeer.asciitable.v2.V2_AsciiTable 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();
}
}
}
}
use of de.vandermeer.asciitable.v2.V2_AsciiTable in project walkmod-core by walkmod.
the class PrintChainsCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("chains");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().configurationFile(configurationFile).build());
Configuration cfg = facade.getConfiguration();
at = new V2_AsciiTable();
at.addRule();
at.addRow("CHAIN", "READER PATH", "WRITER PATH", "TRANSFORMATIONS");
at.addStrongRule();
if (cfg == null) {
at.addRule();
log.error("Sorry, the current directory does not contain a walkmod configuration file or it is invalid.");
}
if (cfg != null) {
Collection<ChainConfig> chains = cfg.getChainConfigs();
if (chains != null) {
for (ChainConfig cc : chains) {
List<TransformationConfig> transformations = cc.getWalkerConfig().getTransformations();
int numTransformations = transformations.size();
int numReaderIncludesExcludes = 0;
int includesLength = 0;
String[] excludes = cc.getReaderConfig().getExcludes();
if (excludes != null) {
numReaderIncludesExcludes = excludes.length;
}
String[] includes = cc.getReaderConfig().getIncludes();
if (includes != null) {
includesLength = includes.length;
numReaderIncludesExcludes += includes.length;
}
int limit = numReaderIncludesExcludes + 1;
if (numTransformations > numReaderIncludesExcludes) {
limit = numTransformations;
}
int includesExcludesWriterLength = 0;
int includesWriterLength = 0;
String[] excludesWriter = cc.getWriterConfig().getExcludes();
if (excludesWriter != null) {
includesExcludesWriterLength += excludesWriter.length;
if (excludesWriter.length + 1 > limit) {
limit = excludesWriter.length + 1;
}
}
String[] includesWriter = cc.getWriterConfig().getIncludes();
if (includesWriter != null) {
includesExcludesWriterLength += includesWriter.length;
includesWriterLength = includesWriter.length;
if (includesWriter.length + 1 > limit) {
limit = includesWriter.length + 1;
}
}
for (int i = 0; i < limit; i++) {
TransformationConfig next = null;
String type = "";
if (i < numTransformations) {
next = transformations.get(i);
type = "- " + next.getType();
}
if (i == 0) {
at.addRow(cc.getName(), cc.getReaderConfig().getPath(), cc.getWriterConfig().getPath(), type);
} else {
String readerWildcard = "";
if (i - 1 < includesLength) {
readerWildcard = "> " + includes[i - 1];
} else {
if (i - 1 < numReaderIncludesExcludes) {
readerWildcard = "< " + excludes[i - 1 + includesLength];
}
}
String writerWildcard = "";
if (includesWriter != null && i - 1 < includesWriter.length) {
writerWildcard = "> " + includesWriter[i - 1];
} else if (i - 1 < includesExcludesWriterLength) {
writerWildcard = "< " + excludesWriter[i - 1 + includesWriterLength];
}
at.addRow("", readerWildcard, writerWildcard, type);
}
}
at.addRule();
}
}
}
}
}
use of de.vandermeer.asciitable.v2.V2_AsciiTable in project walkmod-core by walkmod.
the class AsciiTableWidth method getColumnWidths.
@Override
public int[] getColumnWidths(V2_AsciiTable table) {
int cols = table.getColumnCount();
int[] resultWidths = new int[cols];
// apply min width settings
System.arraycopy(minWidths, 0, resultWidths, 0, minWidths.length > cols ? cols : minWidths.length);
// iterate over all rows
for (V2_Row row : table.getTable()) {
if (row instanceof ContentRow) {
ContentRow crow = (ContentRow) row;
Object[] cells = crow.getColumns();
// iterate over all cells in the row
for (int i = 0; i < cells.length; i++) {
String[] lines = ArrayTransformations.PROCESS_CONTENT(cells[i]);
if (lines != null) {
// measuring the width of each line within a cell
for (String line : lines) {
int lineWidth = line.length() + 2 * crow.getPadding()[i];
if (lineWidth > maxWidth) {
lineWidth = maxWidth;
}
if (lineWidth > resultWidths[i]) {
int maxWidth = (maxWidths.length > i) ? maxWidths[i] : 0;
if (maxWidth < 1 || lineWidth < maxWidth) {
resultWidths[i] = lineWidth;
} else {
resultWidths[i] = maxWidth;
}
}
}
}
}
}
}
return resultWidths;
}
Aggregations