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

org.infrastructurebuilder.util.DefaultVersionedProcessExecutionFactory Maven / Gradle / Ivy

There is a newer version: 0.17.3
Show newest version
/**
 * Copyright © 2019 admin ([email protected])
 *
 * 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 org.infrastructurebuilder.util;

import static java.util.Optional.ofNullable;

import java.io.PrintStream;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;

import org.infrastructurebuilder.util.execution.model.v1_0_0.ProcessExectionFactoryv1_0_0;

public class DefaultVersionedProcessExecutionFactory implements VersionedProcessExecutionFactory {

  private final Optional addl;
  private final Path                  scratchDir;

  public final static String DEFAULT_VERSION = "1.0.0";

  public DefaultVersionedProcessExecutionFactory(Path scratchDir, Optional addl) {
    this.scratchDir = Objects.requireNonNull(scratchDir);
    this.addl = Objects.requireNonNull(addl);
  }

  @Override
  public ProcessExecutionFactory getDefaultFactory(final Path workDirectory, final String id, final String executable) {
    return getFactoryForVersion(DEFAULT_VERSION, workDirectory, id, executable).get();
  }

  @Override
  public Optional getFactoryForVersion(final String version, final Path workDirectory,
      final String id, final String executable) {
    ProcessExecutionFactory f = null;
    switch (version) {
      case "1.1.0":
        break;
      case "1.0.0":
      default:
        f = createFactory_v1_0_0(workDirectory, id, executable);
        break;
    }
    return ofNullable(f);
  }

  @Override
  public Optional getAddl() {
    return addl;
  }

  @Override
  public Path getScratchDir() {
    return scratchDir;
  }

  private ProcessExecutionFactory createFactory_v1_0_0(final Path workDirectory, final String id,
      final String executable) {
    return new ProcessExectionFactoryv1_0_0(this, id, executable, workDirectory);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy