Search in sources :

Example 1 with WalkModFacade

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);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Configuration(org.walkmod.conf.entities.Configuration) Document(org.w3c.dom.Document) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) URL(java.net.URL) LinkedHashMap(java.util.LinkedHashMap) V2_AsciiTable(de.vandermeer.asciitable.v2.V2_AsciiTable) WalkModException(org.walkmod.exceptions.WalkModException) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) JSONArray(com.alibaba.fastjson.JSONArray) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) PluginConfig(org.walkmod.conf.entities.PluginConfig) JSONObject(com.alibaba.fastjson.JSONObject) DocumentBuilder(javax.xml.parsers.DocumentBuilder) WalkModFacade(org.walkmod.WalkModFacade) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 2 with WalkModFacade

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();
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) V2_AsciiTable(de.vandermeer.asciitable.v2.V2_AsciiTable) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) WalkModFacade(org.walkmod.WalkModFacade)

Example 3 with WalkModFacade

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);
    }
}
Also used : WalkModFacade(org.walkmod.WalkModFacade)

Example 4 with WalkModFacade

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);
    }
}
Also used : WalkModFacade(org.walkmod.WalkModFacade)

Example 5 with WalkModFacade

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);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) WalkModFacade(org.walkmod.WalkModFacade)

Aggregations

WalkModFacade (org.walkmod.WalkModFacade)25 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)6 Configuration (org.walkmod.conf.entities.Configuration)5 PluginConfig (org.walkmod.conf.entities.PluginConfig)3 ChainConfig (org.walkmod.conf.entities.ChainConfig)2 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)2 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1 BeanDefinition (org.walkmod.conf.entities.BeanDefinition)1