当前位置: 首页>>代码示例>>Java>>正文


Java EnvironmentUtils类代码示例

本文整理汇总了Java中org.apache.commons.exec.environment.EnvironmentUtils的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentUtils类的具体用法?Java EnvironmentUtils怎么用?Java EnvironmentUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EnvironmentUtils类属于org.apache.commons.exec.environment包,在下文中一共展示了EnvironmentUtils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exec

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
void exec(String action, File dir, CommandLine cmdLine) {
    String label = action + ": " + cmdLine;
    try {
        DefaultExecutor executor = new DefaultExecutor();
        executor.setWorkingDirectory(dir);
        Map<String, String> environment = EnvironmentUtils.getProcEnvironment();
        environment.put("PATH", environment.get("PATH") + ":" + new File(frontendDirectory, "node").getAbsolutePath());
        int exitValue = executor.execute(cmdLine, environment);
        if (exitValue == 0) {
            getLog().info(label + ": OK");
        } else {
            throw new MojoExecutionException("EXEC FAILURE: " + label);
        }
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new IllegalStateException("EXEC FAILURE: " + label, e);
    }
}
 
开发者ID:spirylics,项目名称:web2app,代码行数:20,代码来源:Web2AppMojo.java

示例2: execAsync

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static void execAsync(String display, CommandLine commandline)
		throws ShellCommandException {
	log.debug("executing async command: " + commandline);
	DefaultExecutor exec = new DefaultExecutor();

	ExecuteResultHandler handler = new DefaultExecuteResultHandler();
	PumpStreamHandler streamHandler = new PumpStreamHandler(
			new PritingLogOutputStream());
	exec.setStreamHandler(streamHandler);
	try {
		if (display == null || display.isEmpty()) {
			exec.execute(commandline, handler);
		} else {
			Map env = EnvironmentUtils.getProcEnvironment();
			EnvironmentUtils.addVariableToEnvironment(env, "DISPLAY=:"
					+ display);

			exec.execute(commandline, env, handler);
		}
	} catch (Exception e) {
		throw new ShellCommandException(
				"An error occured while executing shell command: "
						+ commandline, e);
	}
}
 
开发者ID:cosysoft,项目名称:device,代码行数:27,代码来源:ShellCommand.java

示例3: launch

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
/**
 * Creates a process with an array of arguments. It seems to be the only
 * safe way to create a process with arguments containing spaces. The
 * implementation of {@link Runtime#exec(String, String[], File)} doesn't
 * appear to process single or double quotes when tokenizing a
 * command-line.
 * 
 * @see Runtime#exec(String[], String[], File)
 */
@Override
protected Process launch(CommandLine commandLine, @SuppressWarnings("rawtypes") Map environment,
		File workingDirectory) throws IOException {

	if (workingDirectory != null && !workingDirectory.exists()) {
		throw new IOException(workingDirectory + " doesn't exist.");
	}

	String[] envVars = EnvironmentUtils.toStrings(environment);
	String[] arguments = commandLine.getArguments();
	String[] command = new String[arguments.length + 1];
	
	command[0] = commandLine.getExecutable();
	System.arraycopy(arguments, 0, command, 1, arguments.length);

	return Runtime.getRuntime().exec(command, envVars, workingDirectory);
}
 
开发者ID:Zenika,项目名称:varnishtest-exec,代码行数:27,代码来源:VarnishtestExecutor.java

示例4: initialEnvironment

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
protected Map<String,String> initialEnvironment() throws ManagedProcessException {
	try {
		return EnvironmentUtils.getProcEnvironment();
	} catch (IOException e) {
		throw new ManagedProcessException("Retrieving default environment variables failed", e);
	}
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:8,代码来源:ManagedProcessBuilder.java

示例5: setupIPythonEnv

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
protected Map<String, String> setupIPythonEnv() throws IOException {
  Map<String, String> envs = EnvironmentUtils.getProcEnvironment();
  if (envs.containsKey("PYTHONPATH")) {
    if (additionalPythonPath != null) {
      envs.put("PYTHONPATH", additionalPythonPath + ":" + envs.get("PYTHONPATH"));
    }
  } else {
    envs.put("PYTHONPATH", additionalPythonPath);
  }
  LOGGER.info("PYTHONPATH:" + envs.get("PYTHONPATH"));
  return envs;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:13,代码来源:IPythonInterpreter.java

示例6: setupPySparkEnv

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
private Map setupPySparkEnv() throws IOException, InterpreterException {
  Map env = EnvironmentUtils.getProcEnvironment();

  // only set PYTHONPATH in local or yarn-client mode.
  // yarn-cluster will setup PYTHONPATH automatically.
  SparkConf conf = getSparkConf();
  if (!conf.get("spark.submit.deployMode", "client").equals("cluster")) {
    if (!env.containsKey("PYTHONPATH")) {
      env.put("PYTHONPATH", PythonUtils.sparkPythonPath());
    } else {
      env.put("PYTHONPATH", PythonUtils.sparkPythonPath());
    }
  }

  // get additional class paths when using SPARK_SUBMIT and not using YARN-CLIENT
  // also, add all packages to PYTHONPATH since there might be transitive dependencies
  if (SparkInterpreter.useSparkSubmit() &&
      !getSparkInterpreter().isYarnMode()) {

    String sparkSubmitJars = getSparkConf().get("spark.jars").replace(",", ":");

    if (!"".equals(sparkSubmitJars)) {
      env.put("PYTHONPATH", env.get("PYTHONPATH") + sparkSubmitJars);
    }
  }

  LOGGER.info("PYTHONPATH: " + env.get("PYTHONPATH"));

  // set PYSPARK_PYTHON
  if (getSparkConf().contains("spark.pyspark.python")) {
    env.put("PYSPARK_PYTHON", getSparkConf().get("spark.pyspark.python"));
  }
  return env;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:35,代码来源:PySparkInterpreter.java

示例7: open

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
/**
 * Start R repl
 * @throws IOException
 */
public void open() throws IOException, InterpreterException {
  createRScript();

  zeppelinR.put(hashCode(), this);

  CommandLine cmd = CommandLine.parse(rCmdPath);
  cmd.addArgument("--no-save");
  cmd.addArgument("--no-restore");
  cmd.addArgument("-f");
  cmd.addArgument(scriptPath);
  cmd.addArgument("--args");
  cmd.addArgument(Integer.toString(hashCode()));
  cmd.addArgument(Integer.toString(port));
  cmd.addArgument(libPath);
  cmd.addArgument(Integer.toString(sparkVersion.toNumber()));
  
  // dump out the R command to facilitate manually running it, e.g. for fault diagnosis purposes
  logger.debug(cmd.toString());

  executor = new DefaultExecutor();
  outputStream = new InterpreterOutputStream(logger);

  input = new PipedOutputStream();
  PipedInputStream in = new PipedInputStream(input);

  PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, outputStream, in);
  executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT));
  executor.setStreamHandler(streamHandler);
  Map env = EnvironmentUtils.getProcEnvironment();


  initialOutput = new InterpreterOutput(null);
  outputStream.setInterpreterOutput(initialOutput);
  executor.execute(cmd, env, this);
  rScriptRunning = true;

  // flush output
  eval("cat('')");
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:44,代码来源:ZeppelinR.java

示例8: getEnvironment

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
public Map<String, String> getEnvironment() {
    Map<String, String> env = Collections.emptyMap();
    try {
        env = EnvironmentUtils.getProcEnvironment();
    } catch (IOException e) {
        LOG.error("Unable to get environmental variables", e);
    }
    return env;
}
 
开发者ID:mesos,项目名称:logstash,代码行数:10,代码来源:NetworkUtils.java

示例9: createEnvironment

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
/**
 * Create an environment by merging the current environment and the supplied one.
 * If the supplied environment is null, null is returned.
 * @param environment
 * @return an execution environment
 */
private static Map<String, String> createEnvironment(Map<String, String> environment)
{
    Map<String, String> result = null;
    
    try
    {
        result = EnvironmentUtils.getProcEnvironment();
    }
    catch (IOException ex)
    {
        throw new ElasticsearchSetupException(
                "Cannot get the current process environment", ex);
    }

    if (environment != null)
    {
        result.putAll(environment);
    }

    // the elasticsearch start/plugin scripts print warnings if these environment variables are passed
    // and unsets these. And because the scripts would print a warning, we can't rely on the output :(
    result.remove("JAVA_TOOL_OPTIONS");
    result.remove("JAVA_OPTS");

    return result;
}
 
开发者ID:alexcojocaru,项目名称:elasticsearch-maven-plugin,代码行数:33,代码来源:ProcessUtil.java

示例10: extendEnvironmentWithNodeInPath

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
private static Map<String, String> extendEnvironmentWithNodeInPath(NodeManager node) throws IOException {
    Map<String, String> env = EnvironmentUtils.getProcEnvironment();
    if (env.containsKey("PATH")) {
        String path = env.get("PATH");
        env.put("PATH", node.getNodeExecutable().getParent() + File.pathSeparator + path);
    } else {
        env.put("PATH", node.getNodeExecutable().getParent());
    }
    return env;
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:11,代码来源:NPM.java

示例11: setupExecutors

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
@Before
public void setupExecutors() throws IOException {
    emptyEnvExecutor = new ShellExecutorHelper(new HashMap<String, String>());
    defaultEnvExecutor = new ShellExecutorHelper(EnvironmentUtils.getProcEnvironment());
}
 
开发者ID:Ericsson,项目名称:CodeCheckerEclipsePlugin,代码行数:6,代码来源:ShellExecutorHelperTest.java

示例12: exec

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
public Process exec(final CommandLine cmd, final Map env)
        throws IOException {
    String[] envVar = EnvironmentUtils.toStrings(env);
    return Runtime.getRuntime().exec(cmd.toStrings(), envVar);
}
 
开发者ID:deim0s,项目名称:XWBEx,代码行数:6,代码来源:CommandLauncherImpl.java

示例13: exec

import org.apache.commons.exec.environment.EnvironmentUtils; //导入依赖的package包/类
/**
 * Launches the given command in a new process, in the given working
 * directory
 * 
 * @param cmd
 *            the command line to execute as an array of strings
 * @param env
 *            the environment to set as an array of strings
 * @param workingDir
 *            the working directory where the command should run
 * @throws IOException
 *             probably forwarded from Runtime#exec
 */
public Process exec(final CommandLine cmd, final Map env,
		final File workingDir) throws IOException {

	String[] envVars = EnvironmentUtils.toStrings(env);

	return Runtime.getRuntime().exec(cmd.toStrings(),
               envVars, workingDir);
}
 
开发者ID:deim0s,项目名称:XWBEx,代码行数:22,代码来源:Java13CommandLauncher.java


注:本文中的org.apache.commons.exec.environment.EnvironmentUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。