Java 类com.intellij.util.EnvironmentUtil 实例源码

项目:intellij-ce-playground    文件:ProcessRunner.java   
/**
 * Creates process builder and setups it's commandLine, working directory, environment variables
 *
 * @param workingDir         Process working dir
 * @param executablePath     Path to executable file
 * @param arguments          Process commandLine  @return process builder
 */
public static GeneralCommandLine createAndSetupCmdLine(@Nullable final String workingDir,
                                                       @Nullable final Map<String, String> userDefinedEnv,
                                                       final boolean passParentEnv,
                                                       @NotNull final String executablePath,
                                                       @NotNull final String... arguments) {
  GeneralCommandLine cmdLine = new GeneralCommandLine();

  cmdLine.setExePath(toSystemDependentName(executablePath));

  if (workingDir != null) {
    cmdLine.setWorkDirectory(toSystemDependentName(workingDir));
  }

  cmdLine.addParameters(arguments);

  cmdLine.withParentEnvironmentType(passParentEnv ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE);
  cmdLine.withEnvironment(userDefinedEnv);
  //Inline parent env variables occurrences
  EnvironmentUtil.inlineParentOccurrences(cmdLine.getEnvironment());

  return cmdLine;
}
项目:intellij-ce-playground    文件:GitHandler.java   
/**
 * A constructor
 *
 * @param project   a project
 * @param directory a process directory
 * @param command   a command to execute (if empty string, the parameter is ignored)
 */
protected GitHandler(@NotNull Project project, @NotNull File directory, @NotNull GitCommand command) {
  myProject = project;
  myCommand = command;
  myAppSettings = GitVcsApplicationSettings.getInstance();
  myProjectSettings = GitVcsSettings.getInstance(myProject);
  myEnv = new HashMap<String, String>(EnvironmentUtil.getEnvironmentMap());
  myVcs = ObjectUtils.assertNotNull(GitVcs.getInstance(project));
  myWorkingDirectory = directory;
  myCommandLine = new GeneralCommandLine();
  if (myAppSettings != null) {
    myCommandLine.setExePath(myAppSettings.getPathToGit());
  }
  myCommandLine.setWorkDirectory(myWorkingDirectory);
  if (GitVersionSpecialty.CAN_OVERRIDE_GIT_CONFIG_FOR_COMMAND.existsIn(myVcs.getVersion())) {
    myCommandLine.addParameters("-c", "core.quotepath=false");
  }
  myCommandLine.addParameter(command.name());
  myStdoutSuppressed = true;
  mySilent = myCommand.lockingPolicy() == GitCommand.LockingPolicy.READ;
}
项目:intellij-ce-playground    文件:CvsOperation.java   
@NotNull
@Override
protected Map<String, String> compute() {
  Map<String, String> cvsEnv = new HashMap<String, String>();

  Map<String, String> knownToCvs = EnvironmentUtil.getEnvironmentMap();
  @SuppressWarnings("SpellCheckingInspection") String[] toCvs = {
    "CVSIGNORE", "CVSWRAPPERS", "CVSREAD", "CVSREADONLYFS", "CVSUMASK",
    "CVSROOT", "CVSEDITOR", "EDITOR", "VISUAL", "PATH", "HOME", "HOMEPATH", "HOMEDRIVE", "CVS_RSH", "CVS_SERVER",
    "CVS_PASSFILE", "CVS_CLIENT_PORT", "CVS_PROXY_PORT", "CVS_RCMD_PORT", "CVS_CLIENT_LOG",
    "CVS_SERVER_SLEEP", "CVS_IGNORE_REMOTE_ROOT", "CVS_LOCAL_BRANCH_NUM", "COMSPEC", "TMPDIR",
    "CVS_PID", "COMSPEC", "CVS_VERIFY_TEMPLATE", "CVS_NOBASES", "CVS_SIGN_COMMITS", "CVS_VERIFY_CHECKOUTS"
  };
  for (String name : toCvs) {
    String value = knownToCvs.get(name);
    if (value != null) {
      cvsEnv.put(name, value);
    }
  }

  return cvsEnv;
}
项目:intellij-ce-playground    文件:SshSettingsPanel.java   
private void updateSshTunnelDependentValues(@Nullable String tunnelSetting) {
  String svnSshVariableName = SshTunnelRuntimeModule.getSvnSshVariableName(
    !StringUtil.isEmpty(tunnelSetting) ? tunnelSetting : SshTunnelRuntimeModule.DEFAULT_SSH_TUNNEL_VALUE);
  String svnSshVariableValue = StringUtil.notNullize(EnvironmentUtil.getValue(svnSshVariableName));

  mySvnSshVariableLabel.setText(svnSshVariableName + ":");
  mySvnSshVariableField.setText(svnSshVariableValue);

  boolean isSvnSshVariableNameInTunnel = !StringUtil.isEmpty(svnSshVariableName);
  mySvnSshVariableLabel.setVisible(isSvnSshVariableNameInTunnel);
  mySvnSshVariableField.setVisible(isSvnSshVariableNameInTunnel);

  myExecutablePathTextField.getEmptyText().setText(SshTunnelRuntimeModule.getExecutablePath(tunnelSetting));

  setUpdateTunnelButtonEnabled(tunnelSetting);
}
项目:Intellij-Plugin    文件:GaugeUtil.java   
private static GaugeSettingsModel getSettingsFromPATH(GaugeSettingsModel model) throws GaugeNotFoundException {
    String path = EnvironmentUtil.getValue("PATH");
    LOG.info("PATH => " + path);
    if (!StringUtils.isEmpty(path)) {
        for (String entry : path.split(File.pathSeparator)) {
            File file = new File(entry, gaugeExecutable());
            if (isValidGaugeExec(file)) {
                LOG.info("executable path from `PATH`: " + file.getAbsolutePath());
                return new GaugeSettingsModel(file.getAbsolutePath(), model.getHomePath(), model.useIntelliJTestRunner());
            }
        }
    }
    String msg = "Could not find executable in `PATH`. Please make sure Gauge is installed." +
            "\nIf Gauge is installed then set the Gauge executable path in settings -> tools -> gauge.";
    throw new GaugeNotFoundException(msg);
}
项目:tools-idea    文件:ExternalCompiler.java   
@NotNull
public Process launchProcess(@NotNull final ModuleChunk chunk, @NotNull final String outputDir, @NotNull final CompileContext compileContext) throws IOException {
  final String[] commands = createStartupCommand(chunk, compileContext, outputDir);

  if (LOG.isDebugEnabled()) {
    @NonNls final StringBuilder buf = StringBuilderSpinAllocator.alloc();
    try {
      buf.append("\n===================================Environment:===========================\n");
      for (String pair : EnvironmentUtil.getEnvironment()) {
        buf.append("\t").append(pair).append("\n");
      }
      buf.append("=============================================================================\n");
      buf.append("Running compiler: ");
      for (final String command : commands) {
        buf.append(" ").append(command);
      }

      LOG.debug(buf.toString());
    }
    finally {
      StringBuilderSpinAllocator.dispose(buf);
    }
  }

  return Runtime.getRuntime().exec(commands);
}
项目:tools-idea    文件:GeneralCommandLine.java   
void setupEnvironment(final Map<String, String> environment) {
  environment.clear();

  if (myPassParentEnvironment) {
    environment.putAll(EnvironmentUtil.getEnvironmentMap());
  }

  if (!myEnvParams.isEmpty()) {
    if (SystemInfo.isWindows) {
      THashMap<String, String> envVars = new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
      envVars.putAll(environment);
      envVars.putAll(myEnvParams);
      environment.clear();
      environment.putAll(envVars);
    }
    else {
      environment.putAll(myEnvParams);
    }
  }
}
项目:tools-idea    文件:CvsOperation.java   
@NotNull
@Override
protected Map<String, String> compute() {
  Map<String, String> cvsEnv = new HashMap<String, String>();

  Map<String, String> knownToCvs = EnvironmentUtil.getEnvironmentMap();
  @SuppressWarnings("SpellCheckingInspection") String[] toCvs = {
    "CVSIGNORE", "CVSWRAPPERS", "CVSREAD", "CVSREADONLYFS", "CVSUMASK",
    "CVSROOT", "CVSEDITOR", "EDITOR", "VISUAL", "PATH", "HOME", "HOMEPATH", "HOMEDRIVE", "CVS_RSH", "CVS_SERVER",
    "CVS_PASSFILE", "CVS_CLIENT_PORT", "CVS_PROXY_PORT", "CVS_RCMD_PORT", "CVS_CLIENT_LOG",
    "CVS_SERVER_SLEEP", "CVS_IGNORE_REMOTE_ROOT", "CVS_LOCAL_BRANCH_NUM", "COMSPEC", "TMPDIR",
    "CVS_PID", "COMSPEC", "CVS_VERIFY_TEMPLATE", "CVS_NOBASES", "CVS_SIGN_COMMITS", "CVS_VERIFY_CHECKOUTS"
  };
  for (String name : toCvs) {
    String value = knownToCvs.get(name);
    if (value != null) {
      cvsEnv.put(name, value);
    }
  }

  return cvsEnv;
}
项目:consulo-javaee    文件:TomcatStartupPolicy.java   
private static void setupJavaPath(List<EnvironmentVariable> vars, String varName, String jrePath)
{
    if(jrePath != null)
    {
        vars.add(new EnvironmentVariable(varName, jrePath, true));
    }
    else
    {
        String envValue = EnvironmentUtil.getValue(varName);

        if(envValue != null)
        {
            vars.add(new EnvironmentVariable(varName, envValue, true));
        }
    }
}
项目:consulo    文件:ProgramParametersConfigurator.java   
public void configureConfiguration(SimpleProgramParameters parameters, CommonProgramRunConfigurationParameters configuration) {
  Project project = configuration.getProject();
  Module module = getModule(configuration);

  parameters.getProgramParametersList().addParametersString(expandPath(configuration.getProgramParameters(), module, project));

  parameters.setWorkingDirectory(getWorkingDir(configuration, project, module));

  Map<String, String> envs = new HashMap<>(configuration.getEnvs());
  EnvironmentUtil.inlineParentOccurrences(envs);
  for (Map.Entry<String, String> each : envs.entrySet()) {
    each.setValue(expandPath(each.getValue(), module, project));
  }

  parameters.setEnv(envs);
  parameters.setPassParentEnvs(configuration.isPassParentEnvs());
}
项目:consulo-java    文件:ExternalCompiler.java   
@Override
@NotNull
public Process launchProcess(@NotNull final ModuleChunk chunk, @NotNull final String outputDir, @NotNull final CompileContext compileContext) throws IOException
{
    final GeneralCommandLine commandLine = createStartupCommand(chunk, compileContext, outputDir);

    StringBuilder buf = new StringBuilder();
    buf.append("\n===================================Environment:===========================\n");
    for(String pair : EnvironmentUtil.getEnvironment())
    {
        buf.append("\t").append(pair).append("\n");
    }
    buf.append("=============================================================================\n");
    buf.append("Running compiler: ").append(commandLine);

    LOG.info(buf.toString());

    try
    {
        return commandLine.createProcess();
    }
    catch(ExecutionException e)
    {
        throw new IOException(e);
    }
}
项目:react-native-console    文件:RNPathUtilTest.java   
@Test
public void testLinuxPathEnv() {
    System.out.println("System PATH env:" + System.getenv("PATH"));
    System.out.println("System PATH env by IDEA:" + EnvironmentUtil.getValue("PATH"));
    System.out.println("JAVA_HOME:" + System.getenv("JAVA_HOME"));
    System.out.println("adb:" + RNPathUtil.getExecuteFullPathSingle("adb"));
}
项目:git-pair.idea    文件:GitRunner.java   
/**
 * Calculate git's path.
 *
 * @return path of the git executable, including the executable name.
 */
@Nullable
private String findGitExePath() {

    if (StringUtil.isNotEmpty(gitPathCache)) {
        return gitPathCache;
    }

    String path = EnvironmentUtil.getValue("PATH");
    if (StringUtil.isEmpty(path)) {
        return null;
    }

    String[] dirs;
    if (SystemInfo.isWindows) {
        dirs = path.split(";");
    } else {
        dirs = path.split(":");
    }

    for (String dir : dirs) {
        String filename;
        if (SystemInfo.isWindows) {
            filename = dir + "/git.exe";
        } else {
            filename = dir + "/git";
        }
        File file = new File(filename);
        if (file.exists() && file.isFile()) {
            gitPathCache = filename;
            return gitPathCache;
        }
    }

    return null;
}
项目:stylint-plugin    文件:NodeFinder.java   
@NotNull
private static List<File> listNodeInterpretersFromNvm(String exeFileName) {
    String nvmDirPath = EnvironmentUtil.getValue("NVM_DIR");
    if (StringUtil.isEmpty(nvmDirPath)) {
        return Collections.emptyList();
    }
    File nvmDir = new File(nvmDirPath);
    if (nvmDir.isDirectory() && nvmDir.isAbsolute()) {
        return listNodeInterpretersFromVersionDir(nvmDir, exeFileName);
    }
    return Collections.emptyList();
}
项目:intellij-ce-playground    文件:PathEnvironmentVariableUtil.java   
@NotNull
private static List<File> findExeFilesInPath(@NotNull String fileBaseName,
                                             boolean stopAfterFirstMatch,
                                             boolean logDetails,
                                             @Nullable FileFilter filter) {
  String systemPath = EnvironmentUtil.getValue(PATH_ENV_VAR_NAME);
  return doFindExeFilesInPath(systemPath, fileBaseName, stopAfterFirstMatch, logDetails, filter);
}
项目:intellij-ce-playground    文件:GeneralCommandLine.java   
/**
 * Returns an environment that will be passed to a child process.
 */
@NotNull
public Map<String, String> getParentEnvironment() {
  switch (myParentEnvironmentType) {
    case SYSTEM:
      return System.getenv();
    case CONSOLE:
      return EnvironmentUtil.getEnvironmentMap();
    default:
      return Collections.emptyMap();
  }
}
项目:intellij-ce-playground    文件:StartupUtil.java   
private static void fixProcessEnvironment(Logger log) {
  if (!Main.isCommandLine()) {
    System.setProperty("__idea.mac.env.lock", "unlocked");
  }
  boolean envReady = EnvironmentUtil.isEnvironmentReady();  // trigger environment loading
  if (!envReady) {
    log.info("initializing environment");
  }
}
项目:intellij-ce-playground    文件:SimpleProgramParameters.java   
public void setupEnvs(Map<String, String> envs, boolean passDefault) {
  if (!envs.isEmpty()) {
    final HashMap<String, String> map = new HashMap<String, String>(envs);
    EnvironmentUtil.inlineParentOccurrences(map);
    setEnv(map);
    setPassParentEnvs(passDefault);
  }
}
项目:intellij-ce-playground    文件:SshTunnelRuntimeModule.java   
@NotNull
public static String getSshTunnelValue(@Nullable String tunnelSetting) {
  tunnelSetting = !StringUtil.isEmpty(tunnelSetting) ? tunnelSetting : DEFAULT_SSH_TUNNEL_VALUE;
  String svnSshVariableName = getSvnSshVariableName(tunnelSetting);
  String svnSshVariableValue = EnvironmentUtil.getValue(svnSshVariableName);

  return !StringUtil.isEmpty(svnSshVariableValue)
         ? svnSshVariableValue
         : !StringUtil.isEmpty(svnSshVariableName) ? tunnelSetting.substring(1 + svnSshVariableName.length()) : tunnelSetting;
}
项目:vue-for-idea    文件:NodeFinder.java   
@NotNull
public static List<File> listNodeInterpretersFromNvm(String exeFileName) {
    String nvmDirPath = EnvironmentUtil.getValue(NVM_DIR);
    if (StringUtil.isEmpty(nvmDirPath)) {
        return Collections.emptyList();
    }
    File nvmDir = new File(nvmDirPath);
    if (nvmDir.isDirectory() && nvmDir.isAbsolute()) {
        return listNodeInterpretersFromVersionDir(nvmDir, exeFileName);
    }
    return Collections.emptyList();
}
项目:consulo-javaee    文件:TomcatStartupPolicy.java   
@Override
protected List<EnvironmentVariable> getEnvironmentVariables(TomcatLocalModel tomcatModel)
{
    try
    {
        ArrayList<EnvironmentVariable> vars = new ArrayList<>();
        vars.add(new EnvironmentVariable("CATALINA_HOME", tomcatModel.getHomeDirectory(), true));
        vars.add(new EnvironmentVariable("CATALINA_BASE", tomcatModel.getBaseDirectoryPath(), true));
        String tmpDir = EnvironmentUtil.getValue(CATALINA_TMPDIR_ENV_PROPERTY);
        if(tmpDir == null)
        {
            vars.add(new EnvironmentVariable(CATALINA_TMPDIR_ENV_PROPERTY, getCatalinaTempDirectory(tomcatModel), true));
        }
        String[] javaEnvVars = {
                JAVA_HOME_ENV_PROPERTY,
                JRE_HOME_ENV_PROPERTY
        };
        String jrePath = tomcatModel.getJrePath();
        for(String varName : javaEnvVars)
        {
            setupJavaPath(vars, varName, jrePath);
        }

        return vars;
    }
    catch(RuntimeConfigurationException e)
    {
        LOG.error(e);
        return null;
    }
}
项目:consulo-javaee    文件:TomcatUtil.java   
public static String getDefaultLocation()
{
    String result = EnvironmentUtil.getValue(TOMCAT_HOME_ENV_PROPERTY);
    if(result == null)
    {
        result = EnvironmentUtil.getValue(CATALINA_HOME_ENV_PROPERTY);
    }
    return result != null ? result.replace(File.separatorChar, '/') : "";
}
项目:consulo    文件:GeneralCommandLine.java   
/**
 * Returns an environment that will be inherited by a child process.
 * @see #getEffectiveEnvironment()
 */
@Nonnull
public Map<String, String> getParentEnvironment() {
  switch (myParentEnvironmentType) {
    case SYSTEM:
      return System.getenv();
    case CONSOLE:
      return EnvironmentUtil.getEnvironmentMap();
    default:
      return Collections.emptyMap();
  }
}
项目:consulo    文件:StartupUtil.java   
private static void fixProcessEnvironment(Logger log) {
  if (!Main.isCommandLine()) {
    System.setProperty("__idea.mac.env.lock", "unlocked");
  }
  boolean envReady = EnvironmentUtil.isEnvironmentReady();  // trigger environment loading
  if (!envReady) {
    log.info("initializing environment");
  }
}
项目:consulo    文件:SimpleProgramParameters.java   
/**
 * @deprecated Use {@link #setEnv(Map)} and {@link #setPassParentEnvs(boolean)} instead with already preprocessed variables.
 */
@Deprecated
public void setupEnvs(Map<String, String> envs, boolean passDefault) {
  if (!envs.isEmpty()) {
    envs = new HashMap<>(envs);
    EnvironmentUtil.inlineParentOccurrences(envs);
  }
  setEnv(envs);
  setPassParentEnvs(passDefault);
}
项目:intellij-ce-playground    文件:EditExternallyAction.java   
public void actionPerformed(AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  Options options = OptionsManager.getInstance().getOptions();
  String executablePath = options.getExternalEditorOptions().getExecutablePath();
  if (StringUtil.isEmpty(executablePath)) {
    Messages.showErrorDialog(project,
                             ImagesBundle.message("error.empty.external.editor.path"),
                             ImagesBundle.message("error.title.empty.external.editor.path"));
    OptionsConfigurabe.show(project);
  }
  else {
    if (files != null) {
      Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
      for (String varName : env.keySet()) {
        if (SystemInfo.isWindows) {
          executablePath = StringUtil.replace(executablePath, "%" + varName + "%", env.get(varName), true);
        }
        else {
          executablePath = StringUtil.replace(executablePath, "${" + varName + "}", env.get(varName), false);
        }
      }
      executablePath = FileUtil.toSystemDependentName(executablePath);
      File executable = new File(executablePath);
      GeneralCommandLine commandLine = new GeneralCommandLine();
      final String path = executable.exists() ? executable.getAbsolutePath() : executablePath;
      if (SystemInfo.isMac) {
        commandLine.setExePath(ExecUtil.getOpenCommandPath());
        commandLine.addParameter("-a");
        commandLine.addParameter(path);
      } else {
        commandLine.setExePath(path);
      }

      ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
      for (VirtualFile file : files) {
        if (file.isInLocalFileSystem() && typeManager.isImage(file)) {
          commandLine.addParameter(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());
        }
      }
      commandLine.setWorkDirectory(new File(executablePath).getParentFile());

      try {
        commandLine.createProcess();
      }
      catch (ExecutionException ex) {
        Messages.showErrorDialog(project, ex.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor"));
        OptionsConfigurabe.show(project);
      }
    }
  }
}
项目:tools-idea    文件:StartupUtil.java   
private static void fixProcessEnvironment(Logger log) {
  boolean envReady = EnvironmentUtil.isEnvironmentReady();  // trigger environment loading
  if (!envReady) {
    log.info("initializing environment");
  }
}
项目:tools-idea    文件:EditExternallyAction.java   
public void actionPerformed(AnActionEvent e) {
  Project project = e.getData(PlatformDataKeys.PROJECT);
  VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
  Options options = OptionsManager.getInstance().getOptions();
  String executablePath = options.getExternalEditorOptions().getExecutablePath();
  if (StringUtil.isEmpty(executablePath)) {
    Messages.showErrorDialog(project,
                             ImagesBundle.message("error.empty.external.editor.path"),
                             ImagesBundle.message("error.title.empty.external.editor.path"));
    OptionsConfigurabe.show(project);
  }
  else {
    if (files != null) {
      Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
      for (String varName : env.keySet()) {
        if (SystemInfo.isWindows) {
          executablePath = StringUtil.replace(executablePath, "%" + varName + "%", env.get(varName), true);
        }
        else {
          executablePath = StringUtil.replace(executablePath, "${" + varName + "}", env.get(varName), false);
        }
      }
      executablePath = FileUtil.toSystemDependentName(executablePath);
      File executable = new File(executablePath);
      GeneralCommandLine commandLine = new GeneralCommandLine();
      final String path = executable.exists() ? executable.getAbsolutePath() : executablePath;
      if (SystemInfo.isMac) {
        commandLine.setExePath(ExecUtil.getOpenCommandPath());
        commandLine.addParameter("-a");
        commandLine.addParameter(path);
      } else {
        commandLine.setExePath(path);
      }

      ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
      for (VirtualFile file : files) {
        if (file.isInLocalFileSystem() && typeManager.isImage(file)) {
          commandLine.addParameter(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());
        }
      }
      commandLine.setWorkDirectory(new File(executablePath).getParentFile());

      try {
        commandLine.createProcess();
      }
      catch (ExecutionException ex) {
        Messages.showErrorDialog(project, ex.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor"));
        OptionsConfigurabe.show(project);
      }
    }
  }
}