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

com.anrisoftware.globalpom.exec.runcommands.RunCommands Maven / Gradle / Ivy

/*
 * Copyright 2014-2015 Erwin Müller 
 *
 * This file is part of globalpomutils-exec.
 *
 * globalpomutils-exec is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * globalpomutils-exec 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 General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with globalpomutils-exec. If not, see .
 */
package com.anrisoftware.globalpom.exec.runcommands;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.google.inject.assistedinject.Assisted;

/**
 * Saves the run commands.
 *
 * @author Erwin Mueller, [email protected]
 * @since 2.3
 */
public class RunCommands {

    private final Object parent;

    private final List commands;

    private final String name;

    @Inject
    private RunCommandsLogger log;

    /**
     * @see RunCommandsFactory#create(String, Object)
     */
    @Inject
    RunCommands(@Assisted String name, @Assisted Object parent) {
        this.name = name;
        this.parent = parent;
        this.commands = new ArrayList();
    }

    public void add(Object command, Object args) {
        commands.add(command);
        log.commandAdded(command, args, name, parent);
    }

    public List getCommands() {
        return Collections.unmodifiableList(commands);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).append("name", name).toString();
    }
}