All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anrisoftware.sscontrol.scripts.unix.InstallPackagesLogger Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014-2015 Erwin Müller 
 *
 * This file is part of sscontrol-scripts-unix.
 *
 * sscontrol-scripts-unix is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * sscontrol-scripts-unix is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with sscontrol-scripts-unix. If not, see .
 */
package com.anrisoftware.sscontrol.scripts.unix;

import static com.anrisoftware.sscontrol.scripts.unix.InstallPackagesLogger._.command_null;
import static com.anrisoftware.sscontrol.scripts.unix.InstallPackagesLogger._.install_packages_done;
import static com.anrisoftware.sscontrol.scripts.unix.InstallPackagesLogger._.packages_null;
import static org.apache.commons.lang3.Validate.notNull;

import java.util.Map;

import javax.inject.Inject;

import com.anrisoftware.globalpom.exec.api.ProcessTask;
import com.anrisoftware.globalpom.exec.runcommands.RunCommands;
import com.anrisoftware.globalpom.exec.runcommands.RunCommandsArg;
import com.anrisoftware.globalpom.log.AbstractLogger;

/**
 * Logging for {@link InstallPackages}.
 *
 * @author Erwin Mueller, [email protected]
 * @since 1.0
 */
class InstallPackagesLogger extends AbstractLogger {

    private static final String SYSTEM_ARG = "system";
    private static final String PACKAGES_ARG = "packages";
    private static final String COMMAND_ARG = "command";

    enum _ {

        command_null("Install packages command argument '%s' must be set"),

        packages_null("Packages argument '%s' must be set"),

        install_packages_done("Installed packages {} for {}, {}.");

        private String name;

        private _(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    @Inject
    private RunCommandsArg runCommandsArg;

    /**
     * Sets the context of the logger to {@link InstallPackages}.
     */
    public InstallPackagesLogger() {
        super(InstallPackages.class);
    }

    void installPackagesDone(Object parent, RunCommands runCommands,
            ProcessTask task, Map args) {
        debug(install_packages_done, args, parent, task);
        if (runCommands != null) {
            runCommands.add(args.get(COMMAND_ARG), args);
        }
    }

    RunCommands runCommands(Map args, Object parent) {
        return runCommandsArg.runCommands(args, parent);
    }

    void checkArgs(Map args) {
        notNull(args.get(COMMAND_ARG), command_null.toString(), COMMAND_ARG);
        notNull(args.get(PACKAGES_ARG), packages_null.toString(), PACKAGES_ARG);
        notNull(args.get(SYSTEM_ARG), packages_null.toString(), SYSTEM_ARG);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy