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

org.snapscript.common.command.CommandBuilder Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.common.command;

import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Callable;

public class CommandBuilder {
   
   private final String directory;
   private final boolean redirect;
   private final boolean wait;
   
   public CommandBuilder() {
      this(".");
   }
   
   public CommandBuilder(String directory) {
      this(directory, true);
   }
   
   public CommandBuilder(String directory, boolean redirect) {
      this(directory, redirect, false);
   }
   
   public CommandBuilder(String directory, boolean redirect, boolean wait) {
      this.directory = directory;
      this.redirect = redirect;
      this.wait = wait;
   }

   public Callable create(String source) throws Exception {
      return create(source, directory);
   }
   
   public Callable create(String source, String directory) throws Exception {
      return create(source, directory, Collections.EMPTY_MAP);
   }
   
   public Callable create(String source, Map context) throws Exception {
      return create(source, directory, context);
   }
   
   public Callable create(String source, String directory, Map context) throws Exception {
      File path = new File(directory);
      Environment environment = new MapEnvironment(context);
      Command command = new ProcessCommand(source, path, redirect, wait);
      
      return new CommandOperation(command, environment);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy