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

io.linguarobot.aws.cdk.maven.process.ProcessContext Maven / Gradle / Ivy

package io.linguarobot.aws.cdk.maven.process;

import com.google.common.collect.ImmutableMap;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.io.OutputStream;
import java.util.Map;
import java.util.Optional;

public class ProcessContext {

    public static final ProcessContext DEFAULT = ProcessContext.builder().build();

    private final File workingDirectory;
    private final Map environment;
    private final OutputStream output;

    private ProcessContext(@Nullable File workingDirectory,
                           @Nullable Map environment,
                           @Nullable OutputStream output) {
        this.workingDirectory = workingDirectory;
        this.environment = environment;
        this.output = output;
    }

    public Optional getWorkingDirectory() {
        return Optional.ofNullable(workingDirectory);
    }

    public Optional> getEnvironment() {
        return Optional.ofNullable(environment);
    }

    public Optional getOutput() {
        return Optional.ofNullable(output);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private File workingDirectory;
        private Map environment;
        private OutputStream output;

        private Builder() {
            this.environment = ImmutableMap.of();
            this.output = System.out;
        }

        public Builder withEnvironment(@Nonnull Map environment) {
            this.environment = ImmutableMap.copyOf(environment);
            return this;
        }

        public Builder withWorkingDirectory(@Nonnull File workingDirectory) {
            this.workingDirectory = workingDirectory;
            return this;
        }

        public Builder withOutput(@Nonnull OutputStream output) {
            this.output = output;
            return this;
        }

        public ProcessContext build() {
            return new ProcessContext(workingDirectory, environment, output);
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy