Search in sources :

Example 11 with WalkModFacade

use of org.walkmod.WalkModFacade in project walkmod-core by walkmod.

the class InitCommand method execute.

@Override
public void execute() throws Exception {
    if (help) {
        command.usage("init");
    } else {
        WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().configurationFormat(format));
        facade.init();
    }
}
Also used : WalkModFacade(org.walkmod.WalkModFacade)

Example 12 with WalkModFacade

use of org.walkmod.WalkModFacade 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();
            }
        }
    }
}
Also used : V2_AsciiTable(de.vandermeer.asciitable.v2.V2_AsciiTable) WalkModFacade(org.walkmod.WalkModFacade) BeanDefinition(org.walkmod.conf.entities.BeanDefinition) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) PropertyDefinition(org.walkmod.conf.entities.PropertyDefinition)

Example 13 with WalkModFacade

use of org.walkmod.WalkModFacade in project walkmod-core by walkmod.

the class InstallCommand method execute.

@Override
public void execute() throws Exception {
    if (help) {
        command.usage("install");
    } else {
        WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().printErrors(showException));
        facade.install();
    }
}
Also used : WalkModFacade(org.walkmod.WalkModFacade)

Example 14 with WalkModFacade

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

Example 15 with WalkModFacade

use of org.walkmod.WalkModFacade in project walkmod-core by walkmod.

the class RemoveTransformationCommand method execute.

@Override
public void execute() throws Exception {
    if (help) {
        jcommander.usage("rm");
    } else {
        WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().printErrors(printErrors));
        facade.removeTransformations(chain, types, recursive);
    }
}
Also used : 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