List of usage examples for java.io File pathSeparator
String pathSeparator
To view the source code for java.io File pathSeparator.
Click Source Link
From source file:com.asakusafw.compiler.bootstrap.AllBatchCompilerDriver.java
private static List<File> extractEmbedResources(String path) { if (path == null) { return Collections.emptyList(); }/* w w w . j a v a2 s . c o m*/ List<File> results = new ArrayList<>(); for (String s : path.split(File.pathSeparator)) { results.add(new File(s)); } return results; }
From source file:org.apache.hadoop.yarn.applications.unmanagedamlauncher.UnmanagedAMLauncher.java
public void launchAM(ApplicationAttemptId attemptId) throws IOException, YarnException { Credentials credentials = new Credentials(); Token<AMRMTokenIdentifier> token = rmClient.getAMRMToken(attemptId.getApplicationId()); // Service will be empty but that's okay, we are just passing down only // AMRMToken down to the real AM which eventually sets the correct // service-address. credentials.addToken(token.getService(), token); File tokenFile = File.createTempFile("unmanagedAMRMToken", "", new File(System.getProperty("user.dir"))); try {/* w w w. java2 s. c o m*/ FileUtil.chmod(tokenFile.getAbsolutePath(), "600"); } catch (InterruptedException ex) { throw new RuntimeException(ex); } tokenFile.deleteOnExit(); DataOutputStream os = new DataOutputStream(new FileOutputStream(tokenFile, true)); credentials.writeTokenStorageToStream(os); os.close(); Map<String, String> env = System.getenv(); ArrayList<String> envAMList = new ArrayList<String>(); boolean setClasspath = false; for (Map.Entry<String, String> entry : env.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.equals("CLASSPATH")) { setClasspath = true; if (classpath != null) { value = value + File.pathSeparator + classpath; } } envAMList.add(key + "=" + value); } if (!setClasspath && classpath != null) { envAMList.add("CLASSPATH=" + classpath); } ContainerId containerId = ContainerId.newContainerId(attemptId, 0); String hostname = InetAddress.getLocalHost().getHostName(); envAMList.add(Environment.CONTAINER_ID.name() + "=" + containerId); envAMList.add(Environment.NM_HOST.name() + "=" + hostname); envAMList.add(Environment.NM_HTTP_PORT.name() + "=0"); envAMList.add(Environment.NM_PORT.name() + "=0"); envAMList.add(Environment.LOCAL_DIRS.name() + "= /tmp"); envAMList.add(ApplicationConstants.APP_SUBMIT_TIME_ENV + "=" + System.currentTimeMillis()); envAMList.add(ApplicationConstants.CONTAINER_TOKEN_FILE_ENV_NAME + "=" + tokenFile.getAbsolutePath()); String[] envAM = new String[envAMList.size()]; Process amProc = Runtime.getRuntime().exec(amCmd, envAMList.toArray(envAM)); final BufferedReader errReader = new BufferedReader( new InputStreamReader(amProc.getErrorStream(), Charset.forName("UTF-8"))); final BufferedReader inReader = new BufferedReader( new InputStreamReader(amProc.getInputStream(), Charset.forName("UTF-8"))); // read error and input streams as this would free up the buffers // free the error stream buffer Thread errThread = new Thread() { @Override public void run() { try { String line = errReader.readLine(); while ((line != null) && !isInterrupted()) { System.err.println(line); line = errReader.readLine(); } } catch (IOException ioe) { LOG.warn("Error reading the error stream", ioe); } } }; Thread outThread = new Thread() { @Override public void run() { try { String line = inReader.readLine(); while ((line != null) && !isInterrupted()) { System.out.println(line); line = inReader.readLine(); } } catch (IOException ioe) { LOG.warn("Error reading the out stream", ioe); } } }; try { errThread.start(); outThread.start(); } catch (IllegalStateException ise) { } // wait for the process to finish and check the exit code try { int exitCode = amProc.waitFor(); LOG.info("AM process exited with value: " + exitCode); } catch (InterruptedException e) { e.printStackTrace(); } finally { amCompleted = true; } try { // make sure that the error thread exits // on Windows these threads sometimes get stuck and hang the execution // timeout and join later after destroying the process. errThread.join(); outThread.join(); errReader.close(); inReader.close(); } catch (InterruptedException ie) { LOG.info("ShellExecutor: Interrupted while reading the error/out stream", ie); } catch (IOException ioe) { LOG.warn("Error while closing the error/out stream", ioe); } amProc.destroy(); }
From source file:org.apache.flink.client.FlinkYarnSessionCli.java
/** * Creates a new Yarn Client.//from w w w. j av a 2 s . c o m * @param cmd the command line to parse options from * @return an instance of the client or null if there was an error */ public AbstractFlinkYarnClient createFlinkYarnClient(CommandLine cmd) { AbstractFlinkYarnClient flinkYarnClient = getFlinkYarnClient(); if (flinkYarnClient == null) { return null; } if (!cmd.hasOption(CONTAINER.getOpt())) { // number of containers is required option! LOG.error("Missing required argument " + CONTAINER.getOpt()); printUsage(); return null; } flinkYarnClient.setTaskManagerCount(Integer.valueOf(cmd.getOptionValue(CONTAINER.getOpt()))); // Jar Path Path localJarPath; if (cmd.hasOption(FLINK_JAR.getOpt())) { String userPath = cmd.getOptionValue(FLINK_JAR.getOpt()); if (!userPath.startsWith("file://")) { userPath = "file://" + userPath; } localJarPath = new Path(userPath); } else { LOG.info("No path for the flink jar passed. Using the location of " + flinkYarnClient.getClass() + " to locate the jar"); localJarPath = new Path("file://" + flinkYarnClient.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); } flinkYarnClient.setLocalJarPath(localJarPath); // Conf Path String confDirPath = CliFrontend.getConfigurationDirectoryFromEnv(); GlobalConfiguration.loadConfiguration(confDirPath); Configuration flinkConfiguration = GlobalConfiguration.getConfiguration(); flinkYarnClient.setFlinkConfigurationObject(flinkConfiguration); flinkYarnClient.setConfigurationDirectory(confDirPath); File confFile = new File(confDirPath + File.separator + CONFIG_FILE_NAME); if (!confFile.exists()) { LOG.error("Unable to locate configuration file in " + confFile); return null; } Path confPath = new Path(confFile.getAbsolutePath()); flinkYarnClient.setConfigurationFilePath(confPath); List<File> shipFiles = new ArrayList<>(); // path to directory to ship if (cmd.hasOption(SHIP_PATH.getOpt())) { String shipPath = cmd.getOptionValue(SHIP_PATH.getOpt()); File shipDir = new File(shipPath); if (shipDir.isDirectory()) { shipFiles = new ArrayList<>(Arrays.asList(shipDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return !(name.equals(".") || name.equals("..")); } }))); } else { LOG.warn("Ship directory is not a directory. Ignoring it."); } } //check if there is a logback or log4j file if (confDirPath.length() > 0) { File logback = new File(confDirPath + File.pathSeparator + CONFIG_FILE_LOGBACK_NAME); if (logback.exists()) { shipFiles.add(logback); flinkYarnClient.setFlinkLoggingConfigurationPath(new Path(logback.toURI())); } File log4j = new File(confDirPath + File.pathSeparator + CONFIG_FILE_LOG4J_NAME); if (log4j.exists()) { shipFiles.add(log4j); if (flinkYarnClient.getFlinkLoggingConfigurationPath() != null) { // this means there is already a logback configuration file --> fail LOG.warn("The configuration directory ('" + confDirPath + "') contains both LOG4J and " + "Logback configuration files. Please delete or rename one of them."); } // else flinkYarnClient.setFlinkLoggingConfigurationPath(new Path(log4j.toURI())); } } flinkYarnClient.setShipFiles(shipFiles); // queue if (cmd.hasOption(QUEUE.getOpt())) { flinkYarnClient.setQueue(cmd.getOptionValue(QUEUE.getOpt())); } // JobManager Memory if (cmd.hasOption(JM_MEMORY.getOpt())) { int jmMemory = Integer.valueOf(cmd.getOptionValue(JM_MEMORY.getOpt())); flinkYarnClient.setJobManagerMemory(jmMemory); } // Task Managers memory if (cmd.hasOption(TM_MEMORY.getOpt())) { int tmMemory = Integer.valueOf(cmd.getOptionValue(TM_MEMORY.getOpt())); flinkYarnClient.setTaskManagerMemory(tmMemory); } if (cmd.hasOption(SLOTS.getOpt())) { int slots = Integer.valueOf(cmd.getOptionValue(SLOTS.getOpt())); flinkYarnClient.setTaskManagerSlots(slots); } String[] dynamicProperties = null; if (cmd.hasOption(DYNAMIC_PROPERTIES.getOpt())) { dynamicProperties = cmd.getOptionValues(DYNAMIC_PROPERTIES.getOpt()); } String dynamicPropertiesEncoded = StringUtils.join(dynamicProperties, CliFrontend.YARN_DYNAMIC_PROPERTIES_SEPARATOR); flinkYarnClient.setDynamicPropertiesEncoded(dynamicPropertiesEncoded); if (cmd.hasOption(DETACHED.getOpt())) { this.detachedMode = true; flinkYarnClient.setDetachedMode(detachedMode); } if (cmd.hasOption(NAME.getOpt())) { flinkYarnClient.setName(cmd.getOptionValue(NAME.getOpt())); } else { // set the default application name, if none is specified if (defaultApplicationName != null) { flinkYarnClient.setName(defaultApplicationName); } } return flinkYarnClient; }
From source file:com.googlecode.jeeunit.tomcat6.EmbeddedTomcat6Container.java
private URI buildWar() throws IOException { ScatteredArchive sar;/*from w w w . j a v a2s. c o m*/ File webResourceDir = getWebResourceDir(); if (webResourceDir.exists() && webResourceDir.isDirectory()) { sar = new ScatteredArchive("jeeunit-autodeploy", Type.WAR, webResourceDir); } else { sar = new ScatteredArchive("jeeunit-autodeploy", Type.WAR); } String classpath = System.getProperty("java.class.path"); String[] pathElems = classpath.split(File.pathSeparator); for (String pathElem : pathElems) { File file = new File(pathElem); if (file.exists() && classpathFilter.accept(file)) { sar.addClassPath(file); } } for (File metadata : metadataFiles) { if (metadata.exists()) { sar.addMetadata(metadata); } } URI warUri = sar.toURI(); File war = new File(warUri); FileUtils.copyFile(war, new File(webappsDir, "jeeunit.war")); return warUri; }
From source file:com.asakusafw.compiler.bootstrap.AllBatchCompilerDriver.java
private static List<URL> extractPluginPath(String path) { if (path == null) { return Collections.emptyList(); }/*from www . ja v a 2 s .c o m*/ List<URL> results = new ArrayList<>(); for (String s : path.split(File.pathSeparator)) { if (s.trim().isEmpty()) { continue; } try { File file = new File(s); if (file.exists() == false) { throw new FileNotFoundException(file.getAbsolutePath()); } URL url = file.toURI().toURL(); results.add(url); } catch (IOException e) { LOG.warn(MessageFormat.format(Messages.getString("AllBatchCompilerDriver.warnFailedToLoadPlugin"), //$NON-NLS-1$ s), e); } } return results; }
From source file:com.fides.GrinderPropertiesConfigure.java
private void setClassPath() { // Print the list of plugin dependencies logger.debug("------------------PROJECT DEPENDENCIES----------------------"); Artifact a = null;/* w w w . ja va 2s . com*/ Collection artifacts = pluginArtifacts; StringBuffer pluginDependencies = new StringBuffer(); String grinderJar = null; for (Iterator i = artifacts.iterator(); i.hasNext();) { a = (Artifact) i.next(); logger.debug("------------------------------------------------------------"); if (a.getArtifactId().equals("grinder") == false && (!a.getArtifactId().contains("jython") || (a.getArtifactId().contains("jython") && a.getVersion().equals(getJythonVersion())))) { logger.debug("GroupId: {} ArtifactId: {} Version: {} ", new Object[] { a.getGroupId(), a.getArtifactId(), a.getVersion() }); try { grinderJar = MavenUtilities.getPluginAbsolutePath(a.getGroupId(), a.getArtifactId(), a.getVersion()); grinderJar = MavenUtilities.normalizePath(grinderJar); pluginDependencies.append(grinderJar); if (i.hasNext()) { pluginDependencies.append(File.pathSeparator); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } } } // include all COMPILE scoped dependencies if configured for such if (includeDependencies) { for (Artifact artifact : (Set<Artifact>) this.project.getDependencyArtifacts()) { if ("jar".equals(artifact.getType()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && (!Artifact.SCOPE_TEST.equals(artifact.getScope()))) { logger.debug("Adding dependency: {} to the classpath", ArtifactUtils.versionlessKey(artifact)); try { grinderJar = MavenUtilities.getPluginAbsolutePath(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); grinderJar = MavenUtilities.normalizePath(grinderJar); pluginDependencies.append(grinderJar); pluginDependencies.append(File.pathSeparator); } catch (Exception ex) { ex.printStackTrace(); } } } } propertiesPlugin.setProperty("grinder.jvm.classpath", pluginDependencies.toString()); logger.debug("--- Classpath Now configured"); }
From source file:org.lab41.graphlab.twill.GraphLabRunnable.java
/** * GraphLab requires all the hadoop path globs to be expanded. * @return the classpath./*w w w .j a v a 2s . c o m*/ * * @throws IOException * @throws InterruptedException * @throws ExecutionException */ private String getHadoopClassPath() throws IOException, InterruptedException, ExecutionException { List<String> args = Lists.newArrayList(); String hadoopCommonHome = System.getenv("HADOOP_COMMON_HOME"); if (hadoopCommonHome == null) { args.add("hadoop"); } else { args.add(hadoopCommonHome + "/bin/hadoop"); } args.add("classpath"); ProcessBuilder processBuilder = new ProcessBuilder(args); Map<String, String> env = processBuilder.environment(); // Inside a yarn application, HADOOP_CONF_DIR points at a path specific to the node manager and is not // intended to be used by other programs. env.remove("HADOOP_CONF_DIR"); String hadoopClientConfDir = env.get("HADOOP_CLIENT_CONF_DIR"); if (hadoopClientConfDir != null) { env.put("HADOOP_CONF_DIR", hadoopClientConfDir); } Process process = processBuilder.start(); StringWriter writer = new StringWriter(); IOUtils.copy(process.getInputStream(), writer, Charsets.US_ASCII); ExecutorService executor = Executors.newFixedThreadPool(2); try { Future<Void> errFuture = executor.submit(logInputStream(process.getErrorStream())); process.waitFor(); errFuture.get(); } finally { executor.shutdown(); } String classPath = writer.toString(); // Sometimes the classpath includes globs. List<String> classPathList = Lists.newArrayList(); for (String pattern : classPath.split(File.pathSeparator)) { LOG.debug("classpath pattern: " + pattern); File file = new File(pattern); File dir = file.getParentFile(); if (dir == null) { // We must be a top-level path, so just carry it through to the classpath. classPathList.add(file.toString()); } else { String[] children = dir.list(new WildcardFileFilter(file.getName())); if (children != null) { for (String path : children) { String f = new File(dir, path).toString(); LOG.debug("discovered jar: " + f); classPathList.add(f); } } } } return Joiner.on(File.pathSeparator).join(classPathList); }
From source file:org.eclipse.edt.ide.deployment.services.internal.testserver.ConfigServlet.java
/** * Parses the value for a list of DD names, which are in the order they should be processed. * /*from w w w. j ava2 s . c om*/ * @return true if the ordering of DD names has changed. */ public boolean parseOrderedDDs(String ddFiles) { server.log("Parsing DD file order argument: " + ddFiles, LogLevel.INFO); List<String> oldNames = orderedDDNames; orderedDDNames = new ArrayList<String>(); StringTokenizer tok = new StringTokenizer(ddFiles, File.pathSeparator); while (tok.hasMoreTokens()) { orderedDDNames.add(tok.nextToken()); } int size = orderedDDNames.size(); if (size == oldNames.size()) { for (int i = 0; i < size; i++) { if (!oldNames.get(i).equals(orderedDDNames.get(i))) { return true; } } return false; } return true; }
From source file:org.eclipse.dirigible.ide.jgit.utils.GitFileUtils.java
public static String[] getValidProjectFolders(File gitDirectory) throws IOException { List<String> valid = new ArrayList<String>(); String[] all = gitDirectory.list(); for (String name : all) { if (name.equals(DOT_GIT)) { continue; }/*from w w w . j a va 2 s . c o m*/ File file = new File(gitDirectory.getCanonicalPath() + File.pathSeparator + name); if (file.isDirectory()) { valid.add(name); } } return valid.toArray(new String[] {}); }
From source file:org.jboss.web.tomcat.service.WebCtxLoader.java
/** * Set the appropriate context attribute for our class path. This * is required only because Jasper depends on it. *//*from w ww.jav a2s. c o m*/ private void setClassPath() { // Validate our current state information if (!(webContainer instanceof Context)) return; ServletContext servletContext = ((Context) webContainer).getServletContext(); if (servletContext == null) return; try { Method method = webContainer.getClass().getMethod("getCompilerClasspath", (Class[]) null); Object baseClasspath = method.invoke(webContainer, (Object[]) null); if (baseClasspath != null) { servletContext.setAttribute(Globals.CLASS_PATH_ATTR, baseClasspath.toString()); return; } } catch (Exception e) { // Ignore e.printStackTrace(); } StringBuffer classpath = new StringBuffer(); // Assemble the class path information from our repositories for (int i = 0; i < repositories.size(); i++) { String repository = repositories.get(i).toString(); if (repository.startsWith("file://")) repository = repository.substring(7); else if (repository.startsWith("file:")) repository = repository.substring(5); else if (repository.startsWith("jndi:")) repository = servletContext.getRealPath(repository.substring(5)); else continue; if (repository == null) continue; if (i > 0) classpath.append(File.pathSeparator); classpath.append(repository); } // Store the assembled class path as a servlet context attribute servletContext.setAttribute(Globals.CLASS_PATH_ATTR, classpath.toString()); }