Example usage for org.apache.commons.configuration XMLPropertiesConfiguration XMLPropertiesConfiguration

List of usage examples for org.apache.commons.configuration XMLPropertiesConfiguration XMLPropertiesConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration XMLPropertiesConfiguration XMLPropertiesConfiguration.

Prototype

public XMLPropertiesConfiguration() 

Source Link

Document

Creates an empty XMLPropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().

Usage

From source file:org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.java

@Override
public void execute(CommandLineArgument[] args) {
    if (arguments[ARG_CFU_UPDATE_IDX].isEnabled()) {
        AddOnCollection aoc = getLatestVersionInfo();
        // Create some temporary options with the settings we need
        OptionsParamCheckForUpdates options = new OptionsParamCheckForUpdates();
        options.load(new XMLPropertiesConfiguration());
        options.setCheckOnStart(true);/*  ww  w .  j a  va  2 s  .  c  o  m*/
        options.setCheckAddonUpdates(true);
        options.setInstallAddonUpdates(true);
        checkForAddOnUpdates(aoc, options);
        while (downloadManager.getCurrentDownloadCount() > 0) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                // Ignore
            }
        }
        CommandLine.info(Constant.messages.getString("cfu.cmdline.updated"));
    }
    if (arguments[ARG_CFU_INSTALL_ALL_IDX].isEnabled()) {
        AddOnCollection aoc = getLatestVersionInfo();
        if (aoc == null) {
            CommandLine.error(Constant.messages.getString("cfu.cmdline.nocfu"));
        } else {
            AddOnDependencyChecker addOnDependencyChecker = new AddOnDependencyChecker(getLocalVersionInfo(),
                    aoc);
            AddOnDependencyChecker.AddOnChangesResult result;
            AddOnDependencyChecker.AddOnChangesResult allResults = null;
            Set<AddOn> allAddOns = new HashSet<>();

            for (AddOn ao : aoc.getAddOns()) {
                if (ao.getId().equals("coreLang") && (Constant.isDevBuild() || Constant.isDailyBuild())) {
                    // Ignore coreLang add-on if its not a full release
                    // this may well be missing strings that are now necessary
                    continue;
                }

                // Check to see if its already installed
                AddOn iao = getLocalVersionInfo().getAddOn(ao.getId());
                if (iao != null) {
                    if (!ao.isUpdateTo(iao)) {
                        continue;
                    }

                    result = addOnDependencyChecker.calculateUpdateChanges(ao);
                } else {
                    result = addOnDependencyChecker.calculateInstallChanges(ao);
                }

                if (result.getUninstalls().isEmpty()) {
                    allAddOns.addAll(result.getInstalls());
                    allAddOns.addAll(result.getNewVersions());
                    if (allResults == null) {
                        allResults = result;
                    } else {
                        allResults.addResults(result);
                    }
                }
            }

            if (allAddOns.isEmpty()) {
                // Nothing to do
                return;
            }

            for (AddOn addOn : allAddOns) {
                CommandLine.info(MessageFormat.format(Constant.messages.getString("cfu.cmdline.addonurl"),
                        addOn.getUrl()));
            }

            processAddOnChanges(null, allResults);

            while (downloadManager.getCurrentDownloadCount() > 0) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    // Ignore
                }
            }

            for (Downloader download : downloadManager.getProgress()) {
                if (download.isValidated()) {
                    CommandLine.info(MessageFormat.format(Constant.messages.getString("cfu.cmdline.addondown"),
                            download.getTargetFile().getAbsolutePath()));
                } else {
                    CommandLine.error(
                            MessageFormat.format(Constant.messages.getString("cfu.cmdline.addondown.failed"),
                                    download.getTargetFile().getName()));
                }
            }
            installNewExtensions();
        }
    }
    if (arguments[ARG_CFU_INSTALL_IDX].isEnabled()) {
        Vector<String> params = arguments[ARG_CFU_INSTALL_IDX].getArguments();
        if (params.size() == 1) {
            AddOnCollection aoc = getLatestVersionInfo();
            if (aoc == null) {
                CommandLine.error(Constant.messages.getString("cfu.cmdline.nocfu"));
            } else {
                String aoName = params.get(0);
                AddOn ao = aoc.getAddOn(aoName);
                if (ao == null) {
                    CommandLine.error(
                            MessageFormat.format(Constant.messages.getString("cfu.cmdline.noaddon"), aoName));
                    return;
                }
                AddOnDependencyChecker addOnDependencyChecker = new AddOnDependencyChecker(
                        getLocalVersionInfo(), aoc);
                AddOnDependencyChecker.AddOnChangesResult result;
                // Check to see if its already installed
                AddOn iao = getLocalVersionInfo().getAddOn(aoName);
                if (iao != null) {
                    if (!ao.isUpdateTo(iao)) {
                        CommandLine
                                .info(MessageFormat.format(Constant.messages.getString("cfu.cmdline.addoninst"),
                                        iao.getFile().getAbsolutePath()));
                        return;
                    }

                    result = addOnDependencyChecker.calculateUpdateChanges(ao);
                } else {
                    result = addOnDependencyChecker.calculateInstallChanges(ao);
                }

                if (!result.getUninstalls().isEmpty()) {
                    CommandLine.info(MessageFormat.format(
                            Constant.messages.getString("cfu.cmdline.addonurl.unintalls.required"),
                            result.getUninstalls()));
                    return;
                }

                Set<AddOn> allAddOns = new HashSet<>();
                allAddOns.addAll(result.getInstalls());
                allAddOns.addAll(result.getNewVersions());
                for (AddOn addOn : allAddOns) {
                    CommandLine.info(MessageFormat.format(Constant.messages.getString("cfu.cmdline.addonurl"),
                            addOn.getUrl()));
                }

                processAddOnChanges(null, result);

                while (downloadManager.getCurrentDownloadCount() > 0) {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        // Ignore
                    }
                }

                for (Downloader download : downloadManager.getProgress()) {
                    if (download.isValidated()) {
                        CommandLine
                                .info(MessageFormat.format(Constant.messages.getString("cfu.cmdline.addondown"),
                                        download.getTargetFile().getAbsolutePath()));
                    } else {
                        CommandLine.error(MessageFormat.format(
                                Constant.messages.getString("cfu.cmdline.addondown.failed"),
                                download.getTargetFile().getName()));
                    }
                }
                installNewExtensions();
            }
        }
    }
}