/** * Return the value for a given name from the System Properties or the Environmental Variables. * The former overrides the latter. * * @param name - the name of the System Property or Environmental Variable * @return the value of the variable or null if it was not found */ public static String getEnvOrProp(String name) { // System properties override env. variables String envVal = System.getenv(name); String sysPropVal = System.getProperty(name); if (sysPropVal != null) return sysPropVal; return envVal; }
public LocalFileSpy() { username = System.getenv("USER"); if (username == null) username = System.getenv("USERNAME"); if (username == null) username = "******"; // init path of the logfile String jlmDirPath = getJLMPropertiesDir(); if (jlmDirPath != null) filePath = jlmDirPath + "/progress.spy"; }
private String getEditor() { // if we have editor in the system properties, it should // override the env so we check that first String editor = System.getProperty("EDITOR"); if (org.apache.commons.lang3.StringUtils.isEmpty(editor)) { editor = System.getenv().get("EDITOR"); } if (org.apache.commons.lang3.StringUtils.isEmpty(editor)) { editor = System.getenv("VISUAL"); } if (org.apache.commons.lang3.StringUtils.isEmpty(editor)) { editor = "/bin/vi"; } return editor; }
@BeforeMethod protected void setUp(final Method testMethod) throws Exception { // setting hg executable String exec = System.getenv(HG_EXECUTABLE_PATH); if (exec != null) { myClientBinaryPath = new File(exec); } if (exec == null || !myClientBinaryPath.exists()) { final File pluginRoot = new File(PluginPathManager.getPluginHomePath(HgVcs.VCS_NAME)); myClientBinaryPath = new File(pluginRoot, "testData/bin"); } HgVcs.setTestHgExecutablePath(myClientBinaryPath.getPath()); myMainRepo = initRepositories(); myProjectDir = new File(myMainRepo.getDirFixture().getTempDirPath()); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { try { initProject(myProjectDir, testMethod.getName()); activateVCS(HgVcs.VCS_NAME); } catch (Exception e) { e.printStackTrace(); } } }); myChangeListManager = new HgTestChangeListManager(myProject); myTraceClient = true; doActionSilently(VcsConfiguration.StandardConfirmation.ADD); doActionSilently(VcsConfiguration.StandardConfirmation.REMOVE); }
private static File getHumanMediaTypeMappingsFile() throws RegistryException { String carbonHome = System.getProperty("carbon.home"); if (carbonHome == null) { carbonHome = System.getenv("CARBON_HOME"); } if (carbonHome != null) { File mediaTypesFile = new File( CarbonUtils.getEtcCarbonConfigDirPath(), HUMAN_READABLE_MEDIA_TYPE_MAPPINGS_FILE); if (!mediaTypesFile.exists()) { String msg = "Resource human readable media type mappings file (mime.mappings) file does " + "not exist in the path " + CarbonUtils.getEtcCarbonConfigDirPath(); log.error(msg); throw new RegistryException(msg); } return mediaTypesFile; } else { String msg = "carbon.home system property is not set. It is required to to derive " + "the path of the media type definitions file (mime.types)."; log.error(msg); throw new RegistryException(msg); } }
private void setSvnCredential(CIJob job) throws JDOMException, IOException { S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential"); try { String jenkinsTemplateDir = Utility.getJenkinsTemplateDir(); String credentialFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CREDENTIAL_XML; if (debugEnabled) { S_LOGGER.debug("credentialFilePath ... " + credentialFilePath); } File credentialFile = new File(credentialFilePath); SvnProcessor processor = new SvnProcessor(credentialFile); // DataInputStream in = new DataInputStream(new FileInputStream(credentialFile)); // while (in.available() != 0) { // System.out.println(in.readLine()); // } // in.close(); processor.changeNodeValue("credentials/entry//userName", job.getUserName()); processor.changeNodeValue("credentials/entry//password", job.getPassword()); processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName())); // jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setSvnCredential " + e.getLocalizedMessage()); } }
void setConfig(Configuration config) { log.debug("config: " + config); proxyHost = config.get(PARAM_PROXY_HOST); proxyPort = config.getInt(PARAM_PROXY_PORT, DEFAULT_PROXY_PORT); if (StringUtil.isNullString(proxyHost) || proxyPort <= 0) { String http_proxy = System.getenv("http_proxy"); if (!StringUtil.isNullString(http_proxy)) { try { HostPortParser hpp = new HostPortParser(http_proxy); proxyHost = hpp.getHost(); proxyPort = hpp.getPort(); } catch (HostPortParser.InvalidSpec e) { log.warning("Can't parse http_proxy environment var, ignoring: " + http_proxy + ": " + e); } } } if (StringUtil.isNullString(proxyHost) || proxyPort <= 0) { proxyHost = null; } else { log.info("Proxying through " + proxyHost + ":" + proxyPort); } userAgent = config.get(PARAM_USER_AGENT); if (StringUtil.isNullString(userAgent)) { userAgent = null; } else { log.debug("Setting User-Agent to " + userAgent); } }
static { dict = null; String wnhome = System.getenv("WNHOME"); String path = (new StringBuilder(String.valueOf(wnhome))) .append(File.separator) .append("dict") .toString(); System.out.println( (new StringBuilder("Path to dictionary:")).append(getWNLocation()).toString()); URL url = null; try { File f = new File( (new StringBuilder(String.valueOf(getWNLocation()))) .append(File.separator) .append("dict") .toString()); URI uri = f.toURI(); url = uri.toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } dict = new Dictionary(url); dict.open(); }
private static String expandEnvironment(Pattern pattern, String string) { if (string == null || pattern == null) { return string; } Matcher matcher = pattern.matcher(string); Map<String, String> envMap = null; while (matcher.find()) { // Retrieve environment variables if (envMap == null) { envMap = System.getenv(); } String envNameOnly = matcher.group(1); if (envMap.containsKey(envNameOnly)) { String envValue = envMap.get(envNameOnly); if (envValue != null) { String escapeStrings[] = {"\\", "$", "{", "}"}; for (String escapeString : escapeStrings) { envValue = envValue.replace(escapeString, "\\" + escapeString); } Pattern envNameClausePattern = Pattern.compile(Pattern.quote(matcher.group(0))); string = envNameClausePattern.matcher(string).replaceAll(envValue); } } } return string; }
public static String[] ginit(String[] args) { if (System.getenv("KONOHA_DEBUG") != null) { verboseDebug = true; verboseGc = true; verboseSugar = true; verboseCode = true; } CommandLineParser parser = new BasicParser(); CommandLine commandLine = null; try { commandLine = parser.parse(longOptions, args); } catch (ParseException e) { // TODO } if(commandLine.hasOption("verbose")) { verboseDebug = true; System.out.println("option vervose"); } if(commandLine.hasOption("verbose:gc")) { verboseGc = true; System.out.println("option vervose:gc"); } if(commandLine.hasOption("verbose:sugar")) { verboseSugar = true; System.out.println("option vervose:sugar"); } if(commandLine.hasOption("verbose:code")) { verboseCode = true; System.out.println("option vervose:code"); } if(commandLine.hasOption("interactive")) { interactiveFlag = true; System.out.println("option interactive"); } if(commandLine.hasOption("typecheck")) { compileonlyFlag = true; System.out.println("option typecheck"); } if(commandLine.hasOption("start-with")) { startupScript = commandLine.getOptionValue("start-with"); System.out.println("option start-with"); System.out.println(" with arg " + startupScript); } if(commandLine.hasOption("test")) { testScript = commandLine.getOptionValue("test"); System.out.println(" with arg " + testScript); } if(commandLine.hasOption("test-with")) { testScript = commandLine.getOptionValue("test"); System.out.println(" with arg " + testScript); } if(commandLine.hasOption("builtin-test")) { builtinTest = commandLine.getOptionValue("builtin-test"); System.out.println(" with arg " + builtinTest); } return commandLine.getArgs(); }
/* uses badsource and badsink */ public void bad() throws Throwable { String data; /* get environment variable ADD */ /* POTENTIAL FLAW: Read data from an environment variable */ data = System.getenv("ADD"); String root; if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) { /* running on Windows */ root = "C:\\uploads\\"; } else { /* running on non-Windows */ root = "/home/user/uploads/"; } if (data != null) { /* POTENTIAL FLAW: no validation of concatenated value */ File file = new File(root + data); FileInputStream streamFileInputSink = null; InputStreamReader readerInputStreamSink = null; BufferedReader readerBufferdSink = null; if (file.exists() && file.isFile()) { try { streamFileInputSink = new FileInputStream(file); readerInputStreamSink = new InputStreamReader(streamFileInputSink, "UTF-8"); readerBufferdSink = new BufferedReader(readerInputStreamSink); IO.writeLine(readerBufferdSink.readLine()); } catch (IOException exceptIO) { IO.logger.log(Level.WARNING, "Error with stream reading", exceptIO); } finally { /* Close stream reading objects */ try { if (readerBufferdSink != null) { readerBufferdSink.close(); } } catch (IOException exceptIO) { IO.logger.log(Level.WARNING, "Error closing BufferedReader", exceptIO); } try { if (readerInputStreamSink != null) { readerInputStreamSink.close(); } } catch (IOException exceptIO) { IO.logger.log(Level.WARNING, "Error closing InputStreamReader", exceptIO); } try { if (streamFileInputSink != null) { streamFileInputSink.close(); } } catch (IOException exceptIO) { IO.logger.log(Level.WARNING, "Error closing FileInputStream", exceptIO); } } } } }
// For war agent needs to be switched on private boolean listenForDiscoveryMcRequests(Configuration pConfig) { // Check for system props, system env and agent config boolean sysProp = System.getProperty("jolokia." + ConfigKey.DISCOVERY_ENABLED.getKeyValue()) != null; boolean env = System.getenv("JOLOKIA_DISCOVERY") != null; boolean config = pConfig.getAsBoolean(ConfigKey.DISCOVERY_ENABLED); return sysProp || env || config; }
/** Must be called from the Generator implementation */ void compileCode() throws Exception { System.out.println("Compiling code...\n"); Set<Map.Entry<String, String>> set = mCodeFiles.entrySet(); Iterator<Map.Entry<String, String>> itr = set.iterator(); while (itr.hasNext()) { Map.Entry<String, String> entry = itr.next(); File file = new File(entry.getKey()); String source = entry.getValue(); // dump file { FileOutputStream fos = new FileOutputStream(file); fos.write(source.getBytes()); fos.close(); } } itr = set.iterator(); while (itr.hasNext()) { Map.Entry<String, String> entry = itr.next(); File file = new File(entry.getKey()); if (!file.getName().endsWith(".h")) { // compile file, standard MoSync settings String mosyncdir = System.getenv("FULLPATH_MOSYNCDIR"); if (mosyncdir == null) mosyncdir = System.getenv("MOSYNCDIR"); String cmd = mosyncdir + "/bin/xgcc -g -S \"" + file.getAbsolutePath() + "\" -I" + mosyncdir + "/include"; if (exec(cmd, true, null) != 0) throw new Exception("Compilation failed: " + file.getName()); } } itr = set.iterator(); while (itr.hasNext()) { Map.Entry<String, String> entry = itr.next(); File file = new File(entry.getKey()); if (!file.delete()) throw new Exception("Could not delete file " + file.getName()); } }
public static String dataDirectory() { String OS = System.getProperty("os.name").toUpperCase(); if (OS.contains("WIN")) return System.getenv("APPDATA"); else if (OS.contains("MAC")) return System.getProperty("user.home") + "/Library/Application " + "Support"; else if (OS.contains("NUX")) return System.getProperty("user.home"); return System.getProperty("user.dir"); }
public static void addVMParameters( ParametersList parametersList, String mavenHome, MavenRunnerSettings runnerSettings) { parametersList.addParametersString(System.getenv(MAVEN_OPTS)); parametersList.addParametersString(runnerSettings.getVmOptions()); parametersList.addProperty("maven.home", mavenHome); }
/** * A constructor * * @param xmlRpcPort a xml RPC port * @param host a host * @param username a name of user (from URL) * @param port a port * @param command a command * @throws IOException if config file could not be loaded */ private SSHMain(final int xmlRpcPort, String host, String username, Integer port, String command) throws IOException { SSHConfig config = SSHConfig.load(); myHost = config.lookup(username, host, port); myXmlRpcClient = new GitSSHIdeaClient(xmlRpcPort, myHost.isBatchMode()); myHandlerNo = Integer.parseInt(System.getenv(GitSSHService.SSH_HANDLER_ENV)); myCommand = command; }
public static void startup(CTX konoha, String startup_script) { String[] buf = new String[256]; String path = System.getenv("KONOHA_SCRIPTPATH"); String local = ""; if (path == null) { path = System.getenv("KONOHA_HOME"); local = "/script"; } if (path == null) { path = System.getenv("HOME"); local = "/.konoha/script"; } //TODO snprintf(buf, sizeof(buf), "%s%s%s.k", path, local, startup_script); if (true /*TODO load(konoha, (const char*)buf)*/ ) { System.exit(1); } }
/** * Creates a github repository and pushes the files in the working folder into it (respecting * -with some restrictions- the .gitignore file) * * <p>If a repository already exists with the desired name, creates a new commit, maintaining * push/commit history. */ private void pushToGitHub() throws RuntimeException { // only GitHub implemented in this application IRepositoryManager rpm = new GitHubRepositoryManager(repositoryName); rpm.setUser(System.getenv("GH_USER")); rpm.setPass(System.getenv("GH_PASS")); try { // create a git repo on github or bitbucket... rpm.createRepository(); // add folder to track rpm.setLocalFolder(this.workingFolder); // push the files to the repo... rpm.push(); } catch (Exception e) { throw new RuntimeException(e); } }
public static String getAccountsFile() { final String path; if (Configuration.getCurrentOperatingSystem() == OperatingSystem.WINDOWS) { path = System.getenv("APPDATA") + File.separator + Configuration.NAME + "_Accounts.ini"; } else { path = Paths.getUnixHome() + File.separator + "." + Configuration.NAME_LOWERCASE + "acct"; } return path; }
/** sometimes call by sample application, at that time normally set some properties directly */ private Configure() { Properties p = new Properties(); Map args = new HashMap(); args.putAll(System.getenv()); args.putAll(System.getProperties()); p.putAll(args); this.property = p; reload(false); }
public String _env(String args[]) { verifyCommand(args, "${env;<name>}, get the environmet variable", null, 2, 2); try { return System.getenv(args[1]); } catch (Throwable t) { return null; } }
/** * Determines if the line numbers array should be added to the generated Groovy class. * * @return true if they should */ private boolean shouldAddLineNumbers() { try { // for now, we support this through a system property. return Boolean.valueOf(System.getenv("GROOVY_PAGE_ADD_LINE_NUMBERS")); } catch (Exception e) { // something wild happened return false; } }
private String bad_source() throws Throwable { String data; Logger log_bad = Logger.getLogger("local-logger"); /* get environment variable ADD */ data = System.getenv("ADD"); return data; }
public void bad() throws Throwable { String data; Logger log_bad = Logger.getLogger("local-logger"); /* get environment variable ADD */ data = System.getenv("ADD"); (new CWE36_Absolute_Path_Traversal__Environment_53b()).bad_sink(data); }
public static synchronized void init() { // 已经初始化,则直接返回 if (CommonConfigProvider.prop != null && CommonConfigProvider.prop.size() > 0) { return; } logger.info("init CommonConfigProvider.prop."); Properties properties = ConfigProperties.getProperties(); if (properties != null && properties.size() > 0) { CommonConfigProvider.prop = properties; logger.info("find properties from ConfigProperties"); } else { String configPath = System.getProperty(Constants.CONFIG_PATH); if (configPath == null) { logger.info("can't load config from:System.getProperty(Constants.CONFIG_PATH)"); configPath = System.getenv(Constants.CONFIG_PATH); logger.info("can't load config from:System.getenv(Constants.CONFIG_PATH)"); if (configPath == null) { logger.error( "config.path is null,now we use default config.if the environment is not dev,please check you startup param: -Dconfig.path=xxx"); configPath = DEFAULT_CONFIG_PATH; } } logger.info("config.path:{}", configPath); Properties configs = new Properties(); FileInputStream fileInputStream = null; InputStream inputStream = null; try { if (configPath.startsWith(FILE_PREFIX)) { configPath = configPath.substring(FILE_PREFIX.length()); fileInputStream = new FileInputStream(new File(configPath)); configs.load(fileInputStream); } else if (configPath.startsWith(CLASSPATH_PREFIX)) { configPath = configPath.substring(CLASSPATH_PREFIX.length()); inputStream = CommonConfigProvider.class.getResourceAsStream(configPath); configs.load(inputStream); } CommonConfigProvider.prop = configs; } catch (FileNotFoundException e) { logger.error("", e); } catch (IOException e) { logger.error("", e); } finally { IOUtils.closeQuietly(fileInputStream); IOUtils.closeQuietly(inputStream); } } logger.info( "CommonConfigProvider.prop ={},size:{}", CommonConfigProvider.prop, CommonConfigProvider.prop.size()); }
public void addEnvToIntent(Intent intent) { Map<String, String> envMap = System.getenv(); Set<Map.Entry<String, String>> envSet = envMap.entrySet(); Iterator<Map.Entry<String, String>> envIter = envSet.iterator(); int c = 0; while (envIter.hasNext()) { Map.Entry<String, String> entry = envIter.next(); intent.putExtra("env" + c, entry.getKey() + "=" + entry.getValue()); c++; } }
public class Context { private String targetIO = ""; private Object extraContext = ""; private int port = 0; private final String TMPFI = "/tmp/fi/"; private final String HADOOP_USERNAME = "******" + System.getenv("USER"); private final String HADOOP_STORAGE_DIR = TMPFI + HADOOP_USERNAME + "/"; // ******************************************** // rest // ******************************************** public Context() {} public Context(String s) { targetIO = new String(s); } public Context(int port) { this.port = port; } public int getPort() { return port; } public String getTargetIO() { return targetIO; } public void setExtraContext(Object extra) { this.extraContext = extra; } public Object getExtraContext() { return extraContext; } public String toString() { String tmp = targetIO; if (targetIO.contains("/tmp/" + HADOOP_USERNAME)) tmp = tmp.replaceFirst("/tmp/" + HADOOP_USERNAME, "/thh/"); if (targetIO.contains(HADOOP_STORAGE_DIR)) tmp = tmp.replaceFirst(HADOOP_STORAGE_DIR, "/rhh/"); return tmp; } public void setTargetIO(String f) { targetIO = new String(f); } }
public static void main(String args[]) throws InterruptedException, IOException { List<String> command = new ArrayList<String>(); command.add(System.getenv("windir") + "\\system32\\" + "tree.com"); command.add("/A"); ProcessBuilder builder = new ProcessBuilder(command); Map<String, String> environ = builder.environment(); builder.directory(new File(System.getenv("temp"))); System.out.println("Directory : " + System.getenv("temp")); final Process process = builder.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } System.out.println("Program terminated!"); }
// Try to find an URL for system props or config private String findAgentUrl(Configuration pConfig) { // System property has precedence String url = System.getProperty("jolokia." + ConfigKey.DISCOVERY_AGENT_URL.getKeyValue()); if (url == null) { url = System.getenv("JOLOKIA_DISCOVERY_AGENT_URL"); if (url == null) { url = pConfig.get(ConfigKey.DISCOVERY_AGENT_URL); } } return NetworkUtil.replaceExpression(url); }
public static void checkOCSSW() { String ocsswLocation = RuntimeContext.getConfig().getContextProperty(OCSSW_LOCATION_PROPERTY); // ocssw installed local if (ocsswLocation == null || ocsswLocation.trim().equals(SEADAS_OCSSW_LOCATION_LOCAL)) { String dirPath = RuntimeContext.getConfig() .getContextProperty(OCSSWROOT_PROPERTY, System.getenv(OCSSWROOT_ENVVAR)); if (dirPath == null) { dirPath = RuntimeContext.getConfig() .getContextProperty( SEADASHOME_PROPERTY, System.getProperty("user.home") + System.getProperty("file.separator") + "ocssw"); } if (dirPath != null) { // Check if ${ocssw.root}/run/scripts directory exists in the system. // Precondition to detect the existing installation: // the user needs to provide "seadas.ocssw.root" value in seadas.config // or set OCSSWROOT in the system env. ocsswRoot = dirPath; final File dir = new File( dirPath + System.getProperty("file.separator") + "run" + System.getProperty("file.separator") + "scripts"); if (dir.isDirectory()) { ocsswExist = true; return; } } } else { // ocssw installed in virtual box and needs be accessed through web services // need to access to two services: one for ocsswRoot, and the other for ocsswExist -this // doesn't work. Because ocsswrest package is not available to SeadasMain at this time // OCSSWClient ocsswClient = new OCSSWClient(); // WebTarget target = ocsswClient.getOcsswWebTarget(); // ocsswRoot = // target.path("ocssw").path("installDir").request(MediaType.TEXT_PLAIN).get(String.class); // ocsswExist = // target.path("ocssw").path("ocsswInfo").request(MediaType.APPLICATION_JSON).get(new // GenericType<HashMap<String, Boolean>>() {}).get("ocsswExists"); // Assumption: ocssw is already installed on the virtual box and the location is // ${remoteuser.home}/ocssw ocsswRoot = "${remoteuser.home}/ocssw"; ocsswExist = true; } }