public void resetEnvironment() { if (originalPath != null) { PROCESS_ENVIRONMENT.setEnvironmentVariable(pathVarName, originalPath); } for (Map.Entry<String, String> entry : originalEnvrionmentVars.entrySet()) { PROCESS_ENVIRONMENT.setEnvironmentVariable(entry.getKey(), entry.getValue()); } }
public void initialiseEnvironment() { String compilerPath = Joiner.on(File.pathSeparator).join(pathEntries); if (compilerPath.length() > 0) { originalPath = System.getenv(pathVarName); String path = compilerPath + File.pathSeparator + originalPath; System.out.println(String.format("Using path %s", path)); PROCESS_ENVIRONMENT.setEnvironmentVariable(pathVarName, path); } for (Map.Entry<String, String> entry : environmentVars.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); originalEnvrionmentVars.put(key, System.getenv(key)); System.out.println(String.format("Using environment key %s -> %s", key, value)); PROCESS_ENVIRONMENT.setEnvironmentVariable(key, value); } }
/** * Initialise the process environment so that this tool chain is visible to the default * discovery mechanism that the plugin uses (eg add the compiler to the PATH). */ public void initialiseEnvironment() { String compilerPath = Joiner.on(File.pathSeparator).join(pathEntries); if (compilerPath.length() > 0) { originalPath = System.getenv(pathVarName); String path = compilerPath + File.pathSeparator + originalPath; System.out.println(String.format("Using path %s", path)); PROCESS_ENVIRONMENT.setEnvironmentVariable(pathVarName, path); } }
private BuildResult doRun( final OutputListenerImpl outputListener, OutputListenerImpl errorListener, BuildListenerImpl listener) { // Capture the current state of things that we will change during execution InputStream originalStdIn = System.in; Properties originalSysProperties = new Properties(); originalSysProperties.putAll(System.getProperties()); File originalUserDir = new File(originalSysProperties.getProperty("user.dir")); Map<String, String> originalEnv = new HashMap<String, String>(System.getenv()); // Augment the environment for the execution System.setIn(getStdin()); processEnvironment.maybeSetProcessDir(getWorkingDir()); for (Map.Entry<String, String> entry : getEnvironmentVars().entrySet()) { processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue()); } Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties(); System.getProperties().putAll(implicitJvmSystemProperties); DefaultStartParameter parameter = new DefaultStartParameter(); parameter.setCurrentDir(getWorkingDir()); parameter.setShowStacktrace(ShowStacktrace.ALWAYS); CommandLineParser parser = new CommandLineParser(); DefaultCommandLineConverter converter = new DefaultCommandLineConverter(); converter.configure(parser); ParsedCommandLine parsedCommandLine = parser.parse(getAllArgs()); BuildLayoutParameters layout = converter.getLayoutConverter().convert(parsedCommandLine); Map<String, String> properties = new HashMap<String, String>(); new LayoutToPropertiesConverter().convert(layout, properties); converter.getSystemPropertiesConverter().convert(parsedCommandLine, properties); new PropertiesToStartParameterConverter().convert(properties, parameter); converter.convert(parsedCommandLine, parameter); DefaultGradleLauncherFactory factory = DeprecationLogger.whileDisabled( new Factory<DefaultGradleLauncherFactory>() { public DefaultGradleLauncherFactory create() { return (DefaultGradleLauncherFactory) GradleLauncher.getFactory(); } }); factory.addListener(listener); GradleLauncher gradleLauncher = factory.newInstance(parameter); gradleLauncher.addStandardOutputListener(outputListener); gradleLauncher.addStandardErrorListener(errorListener); try { return gradleLauncher.run(); } finally { // Restore the environment System.setProperties(originalSysProperties); processEnvironment.maybeSetProcessDir(originalUserDir); for (String envVar : getEnvironmentVars().keySet()) { String oldValue = originalEnv.get(envVar); if (oldValue != null) { processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue); } else { processEnvironment.maybeRemoveEnvironmentVariable(envVar); } } factory.removeListener(listener); System.setIn(originalStdIn); } }
public void resetEnvironment() { if (originalPath != null) { PROCESS_ENVIRONMENT.setEnvironmentVariable(pathVarName, originalPath); } }