java.lang.System.getenv()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(382)

本文整理了Java中java.lang.System.getenv()方法的一些代码示例,展示了System.getenv()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.getenv()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:getenv

System.getenv介绍

[英]Returns an unmodifiable map of all environment variables to their values.
[中]

代码示例

代码示例来源:origin: apache/incubator-dubbo

@Override
public Object getInternalProperty(String key) {
  return System.getenv(key);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Object getInternalProperty(String key) {
  return System.getenv(key);
}

代码示例来源:origin: jenkinsci/jenkins

public BuildIDs call() throws IOException {
  job = System.getenv("JOB_NAME");
  number = System.getenv("BUILD_NUMBER");
  id = System.getenv("BUILD_ID");
  return this;
}

代码示例来源:origin: jenkinsci/jenkins

public String[] call() throws IOException {
    return new String[] {
      System.getenv("JOB_NAME"),
      System.getenv("BUILD_NUMBER")
    };
  }
}

代码示例来源:origin: ctripcorp/apollo

private String getProperty(String name) {
 String value = null;
 value = System.getProperty(name);
 if (value == null) {
  value = System.getenv(name);
 }
 return value;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  @Nullable
  public String resolvePlaceholder(String placeholderName) {
    try {
      String propVal = System.getProperty(placeholderName);
      if (propVal == null) {
        // Fall back to searching the system environment.
        propVal = System.getenv(placeholderName);
      }
      return propVal;
    }
    catch (Throwable ex) {
      System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" +
          this.text + "] as system property: " + ex);
      return null;
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

public String[] getEnv() {
  Map<String,String> envs = System.getenv();
  String[] envp = new String[envs.size()];
  
  int i = 0;
  for (Map.Entry<String,String> e : envs.entrySet()) {
    envp[i++] = e.getKey()+'+'+e.getValue();
  }
  return envp;
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * System environment -> System properties
 *
 * @param key key
 * @return value
 */
public static String getSystemProperty(String key) {
  String value = System.getenv(key);
  if (StringUtils.isEmpty(value)) {
    value = System.getProperty(key);
  }
  return value;
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * System environment -> System properties
 *
 * @param key key
 * @return value
 */
public static String getSystemProperty(String key) {
  String value = System.getenv(key);
  if (StringUtils.isEmpty(value)) {
    value = System.getProperty(key);
  }
  return value;
}

代码示例来源:origin: netty/netty

private static File locateHostsFile() {
  File hostsFile;
  if (PlatformDependent.isWindows()) {
    hostsFile = new File(System.getenv("SystemRoot") + WINDOWS_HOSTS_FILE_RELATIVE_PATH);
    if (!hostsFile.exists()) {
      hostsFile = new File(WINDOWS_DEFAULT_SYSTEM_ROOT + WINDOWS_HOSTS_FILE_RELATIVE_PATH);
    }
  } else {
    hostsFile = new File(X_PLATFORMS_HOSTS_FILE_PATH);
  }
  return hostsFile;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  @Nullable
  protected String getSystemAttribute(String attributeName) {
    try {
      return System.getenv(attributeName);
    }
    catch (AccessControlException ex) {
      if (logger.isInfoEnabled()) {
        logger.info("Caught AccessControlException when accessing system environment variable '" +
            attributeName + "'; its value will be returned [null]. Reason: " + ex.getMessage());
      }
      return null;
    }
  }
};

代码示例来源:origin: jenkinsci/jenkins

@Override
public boolean canWork() {
  try {
    exe = System.getenv("WINSW_EXECUTABLE");
    if (exe==null)
      return false;   // not under winsw
    return exec("status") ==0;
  } catch (InterruptedException | IOException e) {
    LOGGER.log(FINE, getClass()+" unsuitable", e);
    return false;
  }
}

代码示例来源:origin: apache/incubator-dubbo

public static Properties getProperties() {
  if (PROPERTIES == null) {
    synchronized (ConfigUtils.class) {
      if (PROPERTIES == null) {
        String path = System.getProperty(Constants.DUBBO_PROPERTIES_KEY);
        if (path == null || path.length() == 0) {
          path = System.getenv(Constants.DUBBO_PROPERTIES_KEY);
          if (path == null || path.length() == 0) {
            path = Constants.DEFAULT_DUBBO_PROPERTIES;
          }
        }
        PROPERTIES = ConfigUtils.loadProperties(path, false, true);
      }
    }
  }
  return PROPERTIES;
}

代码示例来源:origin: apache/incubator-dubbo

public static Properties getProperties() {
  if (PROPERTIES == null) {
    synchronized (ConfigUtils.class) {
      if (PROPERTIES == null) {
        String path = System.getProperty(Constants.DUBBO_PROPERTIES_KEY);
        if (path == null || path.length() == 0) {
          path = System.getenv(Constants.DUBBO_PROPERTIES_KEY);
          if (path == null || path.length() == 0) {
            path = Constants.DEFAULT_DUBBO_PROPERTIES;
          }
        }
        PROPERTIES = ConfigUtils.loadProperties(path, false, true);
      }
    }
  }
  return PROPERTIES;
}

代码示例来源:origin: jenkinsci/jenkins

private static final File getBaseDir() {
  File baseDir;
  
  String baseEnv = System.getenv("BASE");
  if (baseEnv != null) {
    baseDir = new File(baseEnv);
  } else {
    LOGGER.log(Level.WARNING, "Could not find environment variable 'BASE' for Jenkins base directory. Falling back to JENKINS_HOME");
    baseDir = Jenkins.getInstance().getRootDir();
  }
  return baseDir;
}

代码示例来源:origin: libgdx/libgdx

@Override
public Preferences getPreferences (String name) {
  File libraryPath = new File(System.getenv("HOME"), "Library");
  File finalPath = new File(libraryPath, name + ".plist");
  @SuppressWarnings("unchecked")
  NSMutableDictionary<NSString, NSObject> nsDictionary = (NSMutableDictionary<NSString, NSObject>)NSMutableDictionary
    .read(finalPath);
  // if it fails to get an existing dictionary, create a new one.
  if (nsDictionary == null) {
    nsDictionary = new NSMutableDictionary<NSString, NSObject>();
    nsDictionary.write(finalPath, false);
  }
  return new IOSPreferences(nsDictionary, finalPath.getAbsolutePath());
}

代码示例来源:origin: libgdx/libgdx

@Override
public Preferences getPreferences (String name) {
  File libraryPath = new File(System.getenv("HOME"), "Library");
  File finalPath = new File(libraryPath, name + ".plist");
  String path = libraryPath + "/" + name + ".plist";
  NSMutableDictionary<String, Object> nsDictionary = NSMutableDictionary.dictionaryWithContentsOfFile(path);
  // if it fails to get an existing dictionary, create a new one.
  if (nsDictionary == null) {
    nsDictionary = (NSMutableDictionary<String, Object>)NSMutableDictionary.alloc().init();
    nsDictionary.writeToFileAtomically(path, false);
  }
  return new IOSPreferences(nsDictionary, finalPath.getAbsolutePath());
}

代码示例来源:origin: libgdx/libgdx

@Override
public Preferences getPreferences (String name) {
  File libraryPath = new File(System.getenv("HOME"), "Library");
  File finalPath = new File(libraryPath, name + ".plist");
  String path = libraryPath + "/" + name + ".plist";
  NSMutableDictionary<String, Object> nsDictionary = NSMutableDictionary.dictionaryWithContentsOfFile(path);
  // if it fails to get an existing dictionary, create a new one.
  if (nsDictionary == null) {
    nsDictionary = (NSMutableDictionary<String, Object>)NSMutableDictionary.alloc().init();
    nsDictionary.writeToFileAtomically(path, false);
  }
  return new IOSPreferences(nsDictionary, finalPath.getAbsolutePath());
}

代码示例来源:origin: jenkinsci/jenkins

private static EnvVars initMaster() {
    EnvVars vars = new EnvVars(System.getenv());
    vars.platform = Platform.current();
    if(Main.isUnitTest || Main.isDevelopmentMode)
      // if unit test is launched with maven debug switch,
      // we need to prevent forked Maven processes from seeing it, or else
      // they'll hang
      vars.remove("MAVEN_OPTS");
    return vars;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testReplaceFromEnv() {
  Map<String,String> env = System.getenv();
  if (env.containsKey("PATH")) {
    String text = "${PATH}";
    assertEquals(env.get("PATH"), SystemPropertyUtils.resolvePlaceholders(text));
  }
}

相关文章