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:org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl.java
private Process _exec(Class<?> clazz, List<String> extraJvmOpts, String... args) throws IOException { String javaHome = System.getProperty("java.home"); String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; String classpath = getClasspath(); String className = clazz.getName(); ArrayList<String> argList = new ArrayList<String>(); argList.addAll(Arrays.asList(javaBin, "-Dproc=" + clazz.getSimpleName(), "-cp", classpath)); argList.addAll(extraJvmOpts);// ww w . j a va 2 s . c om for (Entry<String, String> sysProp : config.getSystemProperties().entrySet()) { argList.add(String.format("-D%s=%s", sysProp.getKey(), sysProp.getValue())); } // @formatter:off argList.addAll(Arrays.asList("-XX:+UseConcMarkSweepGC", "-XX:CMSInitiatingOccupancyFraction=75", "-Dapple.awt.UIElement=true", "-Djava.net.preferIPv4Stack=true", "-XX:+PerfDisableSharedMem", "-XX:+AlwaysPreTouch", Main.class.getName(), className)); // @formatter:on argList.addAll(Arrays.asList(args)); ProcessBuilder builder = new ProcessBuilder(argList); builder.environment().put("ACCUMULO_HOME", config.getDir().getAbsolutePath()); builder.environment().put("ACCUMULO_LOG_DIR", config.getLogDir().getAbsolutePath()); builder.environment().put("ACCUMULO_CLIENT_CONF_PATH", config.getClientConfFile().getAbsolutePath()); String ldLibraryPath = Joiner.on(File.pathSeparator).join(config.getNativeLibPaths()); builder.environment().put("LD_LIBRARY_PATH", ldLibraryPath); builder.environment().put("DYLD_LIBRARY_PATH", ldLibraryPath); // if we're running under accumulo.start, we forward these env vars String env = System.getenv("HADOOP_PREFIX"); if (env != null) builder.environment().put("HADOOP_PREFIX", env); env = System.getenv("ZOOKEEPER_HOME"); if (env != null) builder.environment().put("ZOOKEEPER_HOME", env); builder.environment().put("ACCUMULO_CONF_DIR", config.getConfDir().getAbsolutePath()); // hadoop-2.2 puts error messages in the logs if this is not set builder.environment().put("HADOOP_HOME", config.getDir().getAbsolutePath()); if (config.getHadoopConfDir() != null) builder.environment().put("HADOOP_CONF_DIR", config.getHadoopConfDir().getAbsolutePath()); Process process = builder.start(); LogWriter lw; lw = new LogWriter(process.getErrorStream(), new File(config.getLogDir(), clazz.getSimpleName() + "_" + process.hashCode() + ".err")); logWriters.add(lw); lw.start(); lw = new LogWriter(process.getInputStream(), new File(config.getLogDir(), clazz.getSimpleName() + "_" + process.hashCode() + ".out")); logWriters.add(lw); lw.start(); return process; }
From source file:com.sshtools.j2ssh.configuration.ConfigurationLoader.java
/** * * * @param filename//from w ww . j a v a 2 s .c o m * * @return * * @throws FileNotFoundException */ public static OutputStream saveFile(String filename) throws FileNotFoundException { // Look for the file in the config directory File f = new File(getConfigurationDirectory() + filename); if (f.exists()) { // Yes its there so create an outputstream to it return new FileOutputStream(f); } else { // Look for it absolute f = new File(filename); if (f.exists()) { return new FileOutputStream(filename); // yes so do absolute } else { // Determine whether the filename is absolute or not with a primitive check return new FileOutputStream((filename.indexOf(File.pathSeparator) >= 0) ? filename : (getConfigurationDirectory() + filename)); } } }
From source file:org.aspectj.testing.XMLBasedAjcTestCase.java
public SyntheticRepository createRepos(File cpentry) { ClassPath cp = new ClassPath(cpentry + File.pathSeparator + System.getProperty("java.class.path")); return SyntheticRepository.getInstance(cp); }
From source file:net.grinder.engine.agent.PropertyBuilder.java
/** * Rebase class path from relative path to absolute path. * * @param classPath class path/*from ww w . j a v a 2 s. c o m*/ * @return converted path. */ public String rebaseCustomClassPath(String classPath) { StringBuilder newClassPath = new StringBuilder(); boolean isFirst = true; for (String each : StringUtils.split(classPath, ";:")) { File file = new File(baseDirectory.getFile(), each); if (!isFirst) { newClassPath.append(File.pathSeparator); } isFirst = false; newClassPath.append(FilenameUtils.normalize(file.getAbsolutePath())); } return newClassPath.toString(); }
From source file:org.globus.workspace.testing.NimbusTestBase.java
/** * Helper for you to implement #getNimbusHome() (see 'basic' example). * * Determine the path to the "service/service/java/tests/suites" directory so * that paths can be conveniently (systematically) constructed to conf files. * * This can be rigged by setting the "nimbus.servicetestsuites.abspath" system property * if you find that necessary (to invoke from ant, for example). * * @return the "service/service/java/tests/suites" directory, never null * @throws Exception if the path can not be determined *//*from w w w .java 2 s. co m*/ public File determineSuitesPath() throws Exception { final Properties props = System.getProperties(); final String override = props.getProperty(FORCE_SUITES_DIR_PATH); if (override != null) { return new File(override); } final String token = "lib" + File.separator + "services" + File.separator; final String classpath = props.getProperty("java.class.path"); if (classpath == null) { throw new Exception("java.class.path property was deleted?"); } final String[] parts = classpath.split(File.pathSeparator); for (String part : parts) { final int idx = part.indexOf(token); if (idx > 0) { if (part.contains(token)) { final File candidate = candidate(part.substring(0, idx), "service/service/java/tests/suites/"); if (candidate != null && suitesSubdirsPresent(candidate)) { return candidate; } } } } // as a last resort, try analyzing cwd and all of its parent directories // to find repo topdir final File cwd = new File(props.getProperty("user.dir")); final String bail = "Adjust CWD or consider using the '" + FORCE_SUITES_DIR_PATH + "' property"; if (!okdir(cwd)) { throw new Exception(bail); } String apath = cwd.getAbsolutePath(); while (apath != null) { final File candidate = candidate(apath, "service/service/java/tests/suites/"); if (candidate != null && suitesSubdirsPresent(candidate)) { return candidate; } apath = new File(apath).getParent(); } throw new Exception(bail); }
From source file:net.cliseau.composer.javatarget.PointcutParseException.java
/** * Weave a given aspect into a given target program using AspectJ. * * @param aspectFile File containing the aspect to weave. * @param targetJARFile File to write the resulting JAR into. * @exception InstrumentationException Thrown when instrumenting the target program fails. *///from w ww .java 2 s . c o m private void weaveAspect(final File aspectFile, final File targetJARFile) throws IOException, InstrumentationException, InvalidConfigurationException { ArrayList<String> instrumentParams = new ArrayList<String>( Arrays.asList(aspectjConfig.getAspectJExecutable(), "-classpath", StringUtils.join(getAbsoluteInlinedDependencies(), File.pathSeparator), "-injars", aspectjConfig.getJavaProgramJAR(), "-outjar", targetJARFile.getPath(), "-source", aspectJSourceVersion)); if (verbose) instrumentParams.add("-showWeaveInfo"); instrumentParams.add(aspectFile.getPath()); String[] instrParamsArray = new String[instrumentParams.size()]; instrumentParams.toArray(instrParamsArray); // note: the "exec" below may throw an IOException if (CommandRunner.exec(instrParamsArray) != CommandRunner.NORMAL_TERMINATION) { throw new InstrumentationException("Could not instrument the target."); } }
From source file:org.apache.geronimo.mavenplugins.geronimo.server.StartServerMojo.java
private String prefixSystemPath(final String name, final File file) { assert name != null; assert file != null; String dirs = file.getPath(); String prop = System.getProperty(name, ""); if (prop.length() > 0) { dirs += File.pathSeparator; dirs += prop;// w w w . j av a2 s . c om } return dirs; }
From source file:net.grinder.engine.agent.PropertyBuilder.java
@SuppressWarnings("ResultOfMethodCallIgnored") private StringBuilder addPythonPathJvmArgument(StringBuilder jvmArguments) { jvmArguments.append(" -Dpython.path="); jvmArguments.append(new File(baseDirectory.getFile(), "lib").getAbsolutePath()); String pythonPath = System.getenv().get("PYTHONPATH"); if (pythonPath != null) { jvmArguments.append(File.pathSeparator).append(pythonPath); }/*ww w. j a v a 2 s. c om*/ String pythonHome = System.getenv().get("PYTHONHOME"); if (pythonHome != null) { jvmArguments.append(" -Dpython.home="); jvmArguments.append(pythonHome); } jvmArguments.append(" "); File jythonCache = new File(FileUtils.getTempDirectory(), "jython"); jythonCache.mkdirs(); jvmArguments.append(" -Dpython.cachedir=").append(jythonCache.getAbsolutePath()).append(" "); return jvmArguments; }
From source file:eu.stratosphere.nephele.taskmanager.TaskManager.java
/** * Constructs a new task manager, starts its IPC service and attempts to discover the job manager to * receive an initial configuration. All parameters are obtained from the * {@link GlobalConfiguration}, which must be loaded prior to instantiating the task manager. *//*from w ww .j a va2 s.co m*/ public TaskManager() throws Exception { LOG.info("TaskManager started as user " + UserGroupInformation.getCurrentUser().getShortUserName()); LOG.info("User system property: " + System.getProperty("user.name")); // IMPORTANT! At this point, the GlobalConfiguration must have been read! final InetSocketAddress jobManagerAddress; { LOG.info("Reading location of job manager from configuration"); final String address = GlobalConfiguration.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, null); final int port = GlobalConfiguration.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, ConfigConstants.DEFAULT_JOB_MANAGER_IPC_PORT); if (address == null) { throw new Exception("Job manager address not configured in the GlobalConfiguration."); } // Try to convert configured address to {@link InetAddress} try { final InetAddress tmpAddress = InetAddress.getByName(address); jobManagerAddress = new InetSocketAddress(tmpAddress, port); } catch (UnknownHostException e) { LOG.fatal("Could not resolve JobManager host name."); throw new Exception("Could not resolve JobManager host name: " + e.getMessage(), e); } LOG.info("Connecting to JobManager at: " + jobManagerAddress); } // Create RPC connection to the JobManager try { this.jobManager = RPC.getProxy(JobManagerProtocol.class, jobManagerAddress, NetUtils.getSocketFactory()); } catch (IOException e) { LOG.fatal("Could not connect to the JobManager: " + e.getMessage(), e); throw new Exception("Failed to initialize connection to JobManager: " + e.getMessage(), e); } int ipcPort = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_IPC_PORT_KEY, -1); int dataPort = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_DATA_PORT_KEY, -1); if (ipcPort == -1) { ipcPort = getAvailablePort(); } if (dataPort == -1) { dataPort = getAvailablePort(); } // Determine our own public facing address and start the server { final InetAddress taskManagerAddress; try { taskManagerAddress = getTaskManagerAddress(jobManagerAddress); } catch (Exception e) { throw new RuntimeException("The TaskManager failed to determine its own network address.", e); } this.localInstanceConnectionInfo = new InstanceConnectionInfo(taskManagerAddress, ipcPort, dataPort); LOG.info("TaskManager connection information:" + this.localInstanceConnectionInfo); // Start local RPC server try { this.taskManagerServer = RPC.getServer(this, taskManagerAddress.getHostAddress(), ipcPort, IPC_HANDLER_COUNT); this.taskManagerServer.start(); } catch (IOException e) { LOG.fatal("Failed to start TaskManager server. " + e.getMessage(), e); throw new Exception("Failed to start taskmanager server. " + e.getMessage(), e); } } // Try to create local stub of the global input split provider try { this.globalInputSplitProvider = RPC.getProxy(InputSplitProviderProtocol.class, jobManagerAddress, NetUtils.getSocketFactory()); } catch (IOException e) { LOG.fatal(e.getMessage(), e); throw new Exception("Failed to initialize connection to global input split provider: " + e.getMessage(), e); } // Try to create local stub for the lookup service try { this.lookupService = RPC.getProxy(ChannelLookupProtocol.class, jobManagerAddress, NetUtils.getSocketFactory()); } catch (IOException e) { LOG.fatal(e.getMessage(), e); throw new Exception("Failed to initialize channel lookup protocol. " + e.getMessage(), e); } // Try to create local stub for the accumulators try { this.accumulatorProtocolProxy = RPC.getProxy(AccumulatorProtocol.class, jobManagerAddress, NetUtils.getSocketFactory()); } catch (IOException e) { LOG.fatal("Failed to initialize accumulator protocol: " + e.getMessage(), e); throw new Exception("Failed to initialize accumulator protocol: " + e.getMessage(), e); } // Load profiler if it should be used if (GlobalConfiguration.getBoolean(ProfilingUtils.ENABLE_PROFILING_KEY, false)) { final String profilerClassName = GlobalConfiguration.getString(ProfilingUtils.TASKMANAGER_CLASSNAME_KEY, "eu.stratosphere.nephele.profiling.impl.TaskManagerProfilerImpl"); this.profiler = ProfilingUtils.loadTaskManagerProfiler(profilerClassName, jobManagerAddress.getAddress(), this.localInstanceConnectionInfo); if (this.profiler == null) { LOG.error("Cannot find class name for the profiler."); } else { LOG.info("Profiling of jobs is enabled."); } } else { this.profiler = null; LOG.info("Profiling of jobs is disabled."); } // Get the directory for storing temporary files final String[] tmpDirPaths = GlobalConfiguration .getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH) .split(",|" + File.pathSeparator); checkTempDirs(tmpDirPaths); final int pageSize = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETWORK_BUFFER_SIZE_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_NETWORK_BUFFER_SIZE); // Initialize network buffer pool int numBuffers = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETWORK_NUM_BUFFERS_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_NETWORK_NUM_BUFFERS); int bufferSize = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETWORK_BUFFER_SIZE_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_NETWORK_BUFFER_SIZE); int numInThreads = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETTY_NUM_IN_THREADS_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_NETTY_NUM_IN_THREADS); int numOutThreads = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETTY_NUM_OUT_THREADS_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_NETTY_NUM_OUT_THREADS); int lowWaterMark = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETTY_LOW_WATER_MARK, ConfigConstants.DEFAULT_TASK_MANAGER_NETTY_LOW_WATER_MARK); int highWaterMark = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_NETTY_HIGH_WATER_MARK, ConfigConstants.DEFAULT_TASK_MANAGER_NETTY_HIGH_WATER_MARK); // Initialize the channel manager try { this.channelManager = new ChannelManager(this.lookupService, this.localInstanceConnectionInfo, numBuffers, bufferSize, numInThreads, numOutThreads, lowWaterMark, highWaterMark); } catch (IOException ioe) { LOG.error(StringUtils.stringifyException(ioe)); throw new Exception("Failed to instantiate Byte-buffered channel manager. " + ioe.getMessage(), ioe); } { HardwareDescription resources = HardwareDescriptionFactory.extractFromSystem(); // Check whether the memory size has been explicitly configured. if so that overrides the default mechanism // of taking as much as is mentioned in the hardware description long memorySize = GlobalConfiguration.getInteger(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, -1); if (memorySize > 0) { // manually configured memory size. override the value in the hardware config resources = HardwareDescriptionFactory.construct(resources.getNumberOfCPUCores(), resources.getSizeOfPhysicalMemory(), memorySize * 1024L * 1024L); } this.hardwareDescription = resources; // Initialize the memory manager LOG.info("Initializing memory manager with " + (resources.getSizeOfFreeMemory() >>> 20) + " megabytes of memory. " + "Page size is " + pageSize + " bytes."); try { @SuppressWarnings("unused") final boolean lazyAllocation = GlobalConfiguration.getBoolean( ConfigConstants.TASK_MANAGER_MEMORY_LAZY_ALLOCATION_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_MEMORY_LAZY_ALLOCATION); this.memoryManager = new DefaultMemoryManager(resources.getSizeOfFreeMemory(), pageSize); } catch (Throwable t) { LOG.fatal("Unable to initialize memory manager with " + (resources.getSizeOfFreeMemory() >>> 20) + " megabytes of memory.", t); throw new Exception("Unable to initialize memory manager.", t); } } this.ioManager = new IOManager(tmpDirPaths); this.heartbeatThread = new Thread() { @Override public void run() { runHeartbeatLoop(); } }; this.heartbeatThread.setName("Heartbeat Thread"); this.heartbeatThread.start(); }
From source file:com.blackducksoftware.integration.hub.jenkins.maven.MavenBuildWrapper.java
private void setupAndAddMavenClasspathAction(final AbstractBuild<?, ?> build, final HubJenkinsLogger buildLogger) { try {/* w ww.ja va2 s. com*/ final MavenClasspathAction mavenClasspathAction = new MavenClasspathAction(); final BdMavenConfigurator mavenConfig = new BdMavenConfigurator(buildLogger); final String mavenVersion = getMavenVersion(build, mavenConfig, buildLogger); final StringBuilder mavenExtClasspath = new StringBuilder(); File dependencyRecorderJar = null; File buildInfo = null; File slf4jJar = null; File log4jJar = null; File slf4jJdkBindingJar = null; File gsonJar = null; final boolean maven3orLater = MavenUtil.maven3orLater(mavenVersion); boolean supportedVersion = false; try { if (maven3orLater) { if (mavenVersion.contains("3.0")) { supportedVersion = true; dependencyRecorderJar = mavenConfig.jarFile(Recorder_3_0_Loader.class); slf4jJar = mavenConfig.jarFile(org.slf4j.helpers.FormattingTuple.class); slf4jJdkBindingJar = mavenConfig.jarFile(org.slf4j.impl.JDK14LoggerAdapter.class); mavenClasspathAction.setIsRecorder30(true); } else if (mavenConfig.isMaven31OrLater(mavenVersion)) { supportedVersion = true; dependencyRecorderJar = mavenConfig.jarFile(Recorder_3_1_Loader.class); mavenClasspathAction.setIsRecorder31(true); } if (supportedVersion) { final String buildId = build.getId(); mavenClasspathAction.setBuildId(buildId); final FilePath workspace = build.getWorkspace(); if (workspace != null) { final String workingDirectory = workspace.getRemote(); mavenClasspathAction.setWorkingDirectory(workingDirectory); buildInfo = mavenConfig.jarFile(BuildInfo.class); log4jJar = mavenConfig.jarFile(Logger.class); gsonJar = mavenConfig.jarFile(Gson.class); } else { buildLogger.error("workspace: null"); build.setResult(Result.UNSTABLE); } } else { buildLogger.error("Unsupported version of Maven. Maven version: " + mavenVersion); build.setResult(Result.UNSTABLE); } } else { buildLogger.error("Unsupported version of Maven. Maven version: " + mavenVersion); build.setResult(Result.UNSTABLE); } } catch (final IllegalArgumentException e) { buildLogger.error("Failed to retrieve Maven information! " + e.toString(), e); build.setResult(Result.UNSTABLE); } catch (final IOException e) { buildLogger.error("Failed to retrieve Maven information! " + e.toString(), e); build.setResult(Result.UNSTABLE); } catch (final BDMavenRetrieverException e) { buildLogger.error("Failed to retrieve Maven information! " + e.toString(), e); build.setResult(Result.UNSTABLE); } if (supportedVersion) { // transport the necessary jars to slave final Node buildOn = build.getBuiltOn(); if (buildOn == null) { buildLogger.error("Node build on: null"); } else { FilePath remoteRootPath = new FilePath(buildOn.getRootPath(), "cache"); remoteRootPath = new FilePath(remoteRootPath, "hub-jenkins"); removeSnapshots(remoteRootPath); String pathSeparator = null; try { final VirtualChannel channel = buildOn.getChannel(); if (channel == null) { buildLogger.error("Channel build on: null"); } else { pathSeparator = channel.call(new GetPathSeparator()); } } catch (final IOException e) { buildLogger.error(e.toString(), e); } catch (final InterruptedException e) { buildLogger.error(e.toString(), e); } if (StringUtils.isEmpty(pathSeparator)) { pathSeparator = File.pathSeparator; } mavenClasspathAction.setSeparator(pathSeparator); if (dependencyRecorderJar != null) { appendClasspath(build, remoteRootPath, mavenExtClasspath, dependencyRecorderJar.getAbsolutePath(), buildLogger, pathSeparator); if (buildInfo != null) { appendClasspath(build, remoteRootPath, mavenExtClasspath, buildInfo.getAbsolutePath(), buildLogger, pathSeparator); } if (gsonJar != null) { appendClasspath(build, remoteRootPath, mavenExtClasspath, gsonJar.getAbsolutePath(), buildLogger, pathSeparator); } if (slf4jJar != null) { appendClasspath(build, remoteRootPath, mavenExtClasspath, slf4jJar.getAbsolutePath(), buildLogger, pathSeparator); } if (slf4jJdkBindingJar != null) { appendClasspath(build, remoteRootPath, mavenExtClasspath, slf4jJdkBindingJar.getAbsolutePath(), buildLogger, pathSeparator); } if (log4jJar != null) { appendClasspath(build, remoteRootPath, mavenExtClasspath, log4jJar.getAbsolutePath(), buildLogger, pathSeparator); } mavenClasspathAction.setMavenClasspathExtension(mavenExtClasspath.toString()); buildLogger.debug( "Hub Build Wrapper 'maven.ext.class.path' = " + mavenExtClasspath.toString()); build.addAction(mavenClasspathAction); return; } else { buildLogger.error("Dependency recorder Jar not found. Maven version: " + mavenVersion); } } } } catch (final Exception e) { buildLogger.error(e); } return; }