Search in sources :

Example 6 with ConfigurationManager

use of org.walkmod.conf.ConfigurationManager in project walkmod-core by walkmod.

the class WalkModFacade method removeModules.

/**
 * Removes the module list from the configuration file
 *
 * @param modules
 *            Module names to remove
 * @throws Exception
 *             if the walkmod configuration file can't be read.
 */
public void removeModules(List<String> modules) throws Exception {
    long startTime = System.currentTimeMillis();
    Exception exception = null;
    if (!cfg.exists()) {
        init();
    }
    userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
    System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
    try {
        ConfigurationManager manager = new ConfigurationManager(cfg, false);
        ProjectConfigurationProvider cfgProvider = manager.getProjectConfigurationProvider();
        cfgProvider.removeModules(modules);
    } catch (Exception e) {
        exception = e;
    } finally {
        System.setProperty("user.dir", userDir);
        updateMsg(startTime, exception);
    }
}
Also used : ProjectConfigurationProvider(org.walkmod.conf.ProjectConfigurationProvider) File(java.io.File) ConfigurationManager(org.walkmod.conf.ConfigurationManager) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException)

Example 7 with ConfigurationManager

use of org.walkmod.conf.ConfigurationManager in project walkmod-core by walkmod.

the class WalkModFacade method removeTransformations.

/**
 * Remove a list of transformations for an specific chain. If it is recursive, this removal
 * action is applied into all the submodules.
 *
 * @param chain
 *            To remove the transformations. By default, it is the "default" chain.
 * @param transformations
 *            List of transformation names (type ids) to be removed.
 * @param recursive
 *            If the action is applied to all the submodules.
 * @throws Exception
 *             if the walkmod configuration file can't be read.
 */
public void removeTransformations(String chain, List<String> transformations, boolean recursive) throws Exception {
    long startTime = System.currentTimeMillis();
    Exception exception = null;
    if (transformations != null) {
        if (!cfg.exists()) {
            init();
        }
        userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
        System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
        try {
            ConfigurationManager manager = new ConfigurationManager(cfg, false);
            ProjectConfigurationProvider cfgProvider = manager.getProjectConfigurationProvider();
            cfgProvider.removeTransformations(chain, transformations, recursive);
        } catch (Exception e) {
            exception = e;
        } finally {
            System.setProperty("user.dir", userDir);
            updateMsg(startTime, exception);
        }
    }
}
Also used : ProjectConfigurationProvider(org.walkmod.conf.ProjectConfigurationProvider) File(java.io.File) ConfigurationManager(org.walkmod.conf.ConfigurationManager) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException)

Example 8 with ConfigurationManager

use of org.walkmod.conf.ConfigurationManager in project walkmod-core by walkmod.

the class WalkModFacade method install.

/**
 * Downloads the list of declared plugins in the configuration file using Ivy. Ignores the
 * ConfigurationProvided if passed in the constructor.
 *
 * @throws InvalidConfigurationException
 *             if the walkmod configuration is invalid and it is working in no verbose mode.
 */
public void install() throws InvalidConfigurationException {
    if (cfg.exists()) {
        if (options.isVerbose()) {
            log.info(cfg.getAbsoluteFile() + " [ok]");
        }
        // Uses Ivy always
        ConfigurationProvider cp = new IvyConfigurationProvider(options.isOffline(), options.isVerbose());
        if (options.isVerbose()) {
            log.info("** THE PLUGIN INSTALLATION STARTS **");
            System.out.print("----------------------------------------");
            System.out.println("----------------------------------------");
        }
        long startTime = System.currentTimeMillis();
        long endTime = startTime;
        DecimalFormat myFormatter = new DecimalFormat("###.###");
        DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.US);
        boolean error = false;
        try {
            userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
            System.setProperty("user.dir", options.getExecutionDirectory().getCanonicalPath());
            ConfigurationManager cfgManager = new ConfigurationManager(cfg, cp);
            Configuration cf = cfgManager.getConfiguration();
            List<String> modules = cf.getModules();
            if (modules != null && !modules.isEmpty()) {
                for (String module : modules) {
                    File aux = new File(module).getAbsoluteFile();
                    if (aux.isDirectory()) {
                        if (options.isVerbose()) {
                            log.info("** MODULE " + aux.getAbsoluteFile() + " [ok] **");
                        }
                        WalkModFacade facade = new WalkModFacade(OptionsBuilder.options(options).executionDirectory(aux).build());
                        facade.install();
                    } else {
                        log.error("The module " + aux.getAbsolutePath() + " is not an existing directory");
                    }
                }
            }
        } catch (Exception e) {
            System.setProperty("user.dir", userDir);
            if (options.isVerbose()) {
                error = true;
                endTime = System.currentTimeMillis();
                double time = 0;
                if (endTime > startTime) {
                    time = (double) (endTime - startTime) / (double) 1000;
                }
                String timeMsg = myFormatter.format(time);
                System.out.print("----------------------------------------");
                System.out.println("----------------------------------------");
                log.info("PLUGIN INSTALLATION FAILS");
                System.out.println();
                System.out.print("----------------------------------------");
                System.out.println("----------------------------------------");
                log.info("Total time: " + timeMsg + " seconds");
                log.info("Finished at: " + df.format(new Date()));
                log.info("Final memory: " + (Runtime.getRuntime().freeMemory()) / 1048576 + " M/ " + (Runtime.getRuntime().totalMemory() / 1048576) + " M");
                System.out.print("----------------------------------------");
                System.out.println("----------------------------------------");
                if (options.isPrintErrors()) {
                    log.error("Plugin installations fails", e);
                } else {
                    log.info("Plugin installations fails. Please, execute walkmod with -e to see the details");
                }
                if (options.isThrowException()) {
                    RuntimeException re = new RuntimeException();
                    re.setStackTrace(e.getStackTrace());
                    throw re;
                }
            } else {
                throw new InvalidConfigurationException(e);
            }
        }
        if (!error) {
            System.setProperty("user.dir", userDir);
            if (options.isVerbose()) {
                endTime = System.currentTimeMillis();
                double time = 0;
                if (endTime > startTime) {
                    time = (double) (endTime - startTime) / (double) 1000;
                }
                String timeMsg = myFormatter.format(time);
                System.out.print("----------------------------------------");
                System.out.println("----------------------------------------");
                System.out.println();
                log.info("PLUGIN INSTALLATION COMPLETE");
                System.out.print("----------------------------------------");
                System.out.println("----------------------------------------");
                log.info("Total time: " + timeMsg + " seconds");
                log.info("Finished at: " + df.format(new Date()));
                log.info("Final memory: " + (Runtime.getRuntime().freeMemory()) / 1048576 + " M/ " + (Runtime.getRuntime().totalMemory() / 1048576) + " M");
                System.out.print("----------------------------------------");
                System.out.println("----------------------------------------");
            }
        }
    } else {
        if (options.isVerbose()) {
            log.error(cfg.getAbsolutePath() + " does not exist. The root directory of your project must contain a walkmod.xml");
        } else {
            throw new WalkModException(cfg.getAbsolutePath() + " does not exist. The root directory of your project must contain a walkmod.xml");
        }
    }
}
Also used : WalkModException(org.walkmod.exceptions.WalkModException) Configuration(org.walkmod.conf.entities.Configuration) DynamicModulesConfigurationProvider(org.walkmod.conf.providers.DynamicModulesConfigurationProvider) ConfigurationProvider(org.walkmod.conf.ConfigurationProvider) ProjectConfigurationProvider(org.walkmod.conf.ProjectConfigurationProvider) DynamicConfigurationProvider(org.walkmod.conf.providers.DynamicConfigurationProvider) IvyConfigurationProvider(org.walkmod.conf.providers.IvyConfigurationProvider) DecimalFormat(java.text.DecimalFormat) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException) Date(java.util.Date) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) ConfigurationManager(org.walkmod.conf.ConfigurationManager) IvyConfigurationProvider(org.walkmod.conf.providers.IvyConfigurationProvider)

Example 9 with ConfigurationManager

use of org.walkmod.conf.ConfigurationManager in project walkmod-core by walkmod.

the class WalkModFacade method removeProviders.

/**
 * Removes the list of configuration providers from the config file.
 *
 * @param providers
 *            Name of the configuration providers to remove.
 * @param recursive
 *            If it necessary to remove the plugin from all the submodules.
 * @throws Exception
 *             If the walkmod configuration file can't be read.
 */
public void removeProviders(List<String> providers, boolean recursive) throws Exception {
    long startTime = System.currentTimeMillis();
    Exception exception = null;
    if (!cfg.exists()) {
        init();
    }
    userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
    System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
    try {
        ConfigurationManager manager = new ConfigurationManager(cfg, false);
        ProjectConfigurationProvider cfgProvider = manager.getProjectConfigurationProvider();
        cfgProvider.removeProviders(providers, recursive);
    } catch (Exception e) {
        exception = e;
    } finally {
        System.setProperty("user.dir", userDir);
        updateMsg(startTime, exception);
    }
}
Also used : ProjectConfigurationProvider(org.walkmod.conf.ProjectConfigurationProvider) File(java.io.File) ConfigurationManager(org.walkmod.conf.ConfigurationManager) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException)

Example 10 with ConfigurationManager

use of org.walkmod.conf.ConfigurationManager in project walkmod-core by walkmod.

the class WalkModFacade method addModules.

/**
 * Adds a module into the configuration file
 *
 * @param modules
 *            Modules to add
 * @throws Exception
 *             if the walkmod configuration file can't be read.
 */
public void addModules(List<String> modules) throws Exception {
    long startTime = System.currentTimeMillis();
    Exception exception = null;
    if (modules != null) {
        if (!cfg.exists()) {
            init();
        }
        userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
        System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
        try {
            ConfigurationManager manager = new ConfigurationManager(cfg, false);
            ProjectConfigurationProvider cfgProvider = manager.getProjectConfigurationProvider();
            cfgProvider.addModules(modules);
        } catch (Exception e) {
            exception = e;
        } finally {
            System.setProperty("user.dir", userDir);
            updateMsg(startTime, exception);
        }
    }
}
Also used : ProjectConfigurationProvider(org.walkmod.conf.ProjectConfigurationProvider) File(java.io.File) ConfigurationManager(org.walkmod.conf.ConfigurationManager) WalkModException(org.walkmod.exceptions.WalkModException) IOException(java.io.IOException) InvalidConfigurationException(org.walkmod.exceptions.InvalidConfigurationException)

Aggregations

ConfigurationManager (org.walkmod.conf.ConfigurationManager)23 IOException (java.io.IOException)21 File (java.io.File)20 InvalidConfigurationException (org.walkmod.exceptions.InvalidConfigurationException)20 WalkModException (org.walkmod.exceptions.WalkModException)20 ProjectConfigurationProvider (org.walkmod.conf.ProjectConfigurationProvider)12 Configuration (org.walkmod.conf.entities.Configuration)5 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)2 DynamicConfigurationProvider (org.walkmod.conf.providers.DynamicConfigurationProvider)2 DynamicModulesConfigurationProvider (org.walkmod.conf.providers.DynamicModulesConfigurationProvider)2 DateFormat (java.text.DateFormat)1 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 ConfigurationProvider (org.walkmod.conf.ConfigurationProvider)1 PluginConfig (org.walkmod.conf.entities.PluginConfig)1 IvyConfigurationProvider (org.walkmod.conf.providers.IvyConfigurationProvider)1