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

com.atlassian.bamboo.specs.builders.task.CommandTask Maven / Gradle / Ivy

There is a newer version: 10.1.0
Show newest version
package com.atlassian.bamboo.specs.builders.task;

import com.atlassian.bamboo.specs.api.builders.task.Task;
import com.atlassian.bamboo.specs.model.task.CommandTaskProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

import static com.atlassian.bamboo.specs.api.validators.common.ImporterUtils.checkNotEmpty;

/**
 * Represents a task that executes a command.
 */
public class CommandTask extends Task {
    private String executable;
    @Nullable
    private String argument;
    @Nullable
    private String environmentVariables;
    @Nullable
    private String workingSubdirectory;


    /**
     * Sets label (not a path) of command to be executed. This label must be first
     * defined in the GUI on the Administration/Executables page.
     *
     * This field is mandatory
     */
    public CommandTask executable(@NotNull final String executable) {
        checkNotEmpty("executable", executable);
        this.executable = executable;
        return this;
    }

    /**
     * Sets command line argument to be passed when command is executed.
     */
    public CommandTask argument(@NotNull final String argument) {
        checkNotEmpty("argument", argument);
        this.argument = argument;
        return this;
    }

    /**
     * Sets environment variables to be set when command is executed.
     */
    public CommandTask environmentVariables(@NotNull final String environmentVariables) {
        checkNotEmpty("environment variables", environmentVariables);
        this.environmentVariables = environmentVariables;
        return this;
    }

    /**
     * Sets a directory the command should be executed in.
     */
    public CommandTask workingSubdirectory(@NotNull final String workingSubdirectory) {
        checkNotEmpty("working subdirectory", workingSubdirectory);
        this.workingSubdirectory = workingSubdirectory;
        return this;
    }

    @NotNull
    @Override
    protected CommandTaskProperties build() {
        return new CommandTaskProperties(description,
                taskEnabled,
                executable,
                argument,
                environmentVariables,
                workingSubdirectory,
                requirements,
                conditions);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof CommandTask)) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        CommandTask that = (CommandTask) o;
        return Objects.equals(executable, that.executable) &&
                Objects.equals(argument, that.argument) &&
                Objects.equals(environmentVariables, that.environmentVariables) &&
                Objects.equals(workingSubdirectory, that.workingSubdirectory);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), executable, argument, environmentVariables, workingSubdirectory);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy