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

br.com.objectos.shell.AbstractExecution Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016 Objectos, Fábrica de Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package br.com.objectos.shell;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import br.com.objectos.exec.Exec;
import br.com.objectos.exec.LineListener;
import br.com.objectos.exec.Result;

/**
 * @author [email protected] (Marcio Endo)
 */
abstract class AbstractExecution> {

  private final AbstractBuilder builder;
  private final Map substitutionMap = new HashMap<>();
  private LineListener lineListener = NoopLineListener.INSTANCE;

  public AbstractExecution(AbstractBuilder builder) {
    this.builder = builder;
  }

  public Result execute() throws IOException, InterruptedException {
    return new Exec()
        .command(command())
        .redirectInput(builder.inputStream(substitutionMap))
        .redirectOutput(lineListener)
        .execute();
  }

  public SELF redirectOutput(LineListener listener) {
    lineListener = listener;
    return self();
  }

  public SELF set(String variable, Object value) {
    substitutionMap.put(variable, value);
    return self();
  }

  abstract String[] command();

  abstract SELF self();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy