List of usage examples for java.io File pathSeparatorChar
char pathSeparatorChar
To view the source code for java.io File pathSeparatorChar.
Click Source Link
From source file:org.squidy.common.dynamiccode.DynamicCodeClassLoader.java
/** * Extracts a classpath string from a given class loader. Recognizes only URLClassLoader. *///from w w w.ja v a 2 s . co m private static String extractClasspath(ClassLoader cl) { StringBuffer buf = new StringBuffer(); while (cl != null) { if (LOG.isDebugEnabled()) { LOG.debug("Trying to extract classpath of class loader: " + cl.getClass().getName()); } if (cl instanceof URLClassLoader) { URL urls[] = ((URLClassLoader) cl).getURLs(); for (int i = 0; i < urls.length; i++) { if (buf.length() > 0) { buf.append(File.pathSeparatorChar); } String path = urls[i].getFile(); if (path.startsWith("/C:/") || path.startsWith("/c:/")) { path = path.substring(1, path.length()); path = path.replace('/', '\\'); path = path.replace("%20", " "); } buf.append(path); } } cl = cl.getParent(); } return buf.toString(); }
From source file:org.paxml.bean.excel.ReadExcelTag.java
protected Connection getConnection(File f) { try {/*from w w w.j a v a 2 s.co m*/ Class.forName(ODBC_DRIVER); } catch (Exception e) { throw new PaxmlRuntimeException(e); } try { return DriverManager .getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" + "Dbq=" + f.getAbsolutePath().replace("/", "" + File.pathSeparatorChar) + ";"); } catch (SQLException e) { throw new PaxmlRuntimeException("Cannot open excel file via odbc: " + f.getAbsolutePath(), e); } }
From source file:org.broadinstitute.gatk.tools.CatVariantsIntegrationTest.java
@Test() public void testCatVariantsGVCFIndexCreation() throws IOException { String cmdLine = String.format("java -cp \"%s\" %s -R %s -V %s -V %s -out %s", StringUtils.join(RuntimeUtils.getAbsoluteClassPaths(), File.pathSeparatorChar), CatVariants.class.getCanonicalName(), BaseTest.b37KGReference, CatVariantsVcf1, CatVariantsVcf2, BaseTest.createTempFile("CatVariantsGVCFIndexCreationTest", "." + GATKVCFUtils.GVCF_EXT)); ProcessController pc = ProcessController.getThreadLocal(); ProcessSettings ps = new ProcessSettings(Utils.escapeExpressions(cmdLine)); pc.execAndCheck(ps);//from www. j ava2s .c o m }
From source file:com.cfets.door.yarn.jboss.JBossClient.java
/** * Main run function for the client//from w w w . j a va 2 s . c om * * @return true if application completed successfully * @throws IOException * @throws YarnException */ public boolean run() throws IOException, YarnException { LOG.info("Running Client"); yarnClient.start(); YarnClusterMetrics clusterMetrics = yarnClient.getYarnClusterMetrics(); LOG.info("Got Cluster metric info from ASM" + ", numNodeManagers=" + clusterMetrics.getNumNodeManagers()); List<NodeReport> clusterNodeReports = yarnClient.getNodeReports(NodeState.RUNNING); LOG.info("Got Cluster node info from ASM"); for (NodeReport node : clusterNodeReports) { LOG.info("Got node report from ASM for" + ", nodeId=" + node.getNodeId() + ", nodeAddress" + node.getHttpAddress() + ", nodeRackName" + node.getRackName() + ", nodeNumContainers" + node.getNumContainers()); } QueueInfo queueInfo = yarnClient.getQueueInfo(this.amQueue); LOG.info("Queue info" + ", queueName=" + queueInfo.getQueueName() + ", queueCurrentCapacity=" + queueInfo.getCurrentCapacity() + ", queueMaxCapacity=" + queueInfo.getMaximumCapacity() + ", queueApplicationCount=" + queueInfo.getApplications().size() + ", queueChildQueueCount=" + queueInfo.getChildQueues().size()); List<QueueUserACLInfo> listAclInfo = yarnClient.getQueueAclsInfo(); for (QueueUserACLInfo aclInfo : listAclInfo) { for (QueueACL userAcl : aclInfo.getUserAcls()) { LOG.info("User ACL Info for Queue" + ", queueName=" + aclInfo.getQueueName() + ", userAcl=" + userAcl.name()); } } YarnClientApplication app = yarnClient.createApplication(); GetNewApplicationResponse appResponse = app.getNewApplicationResponse(); int maxMem = appResponse.getMaximumResourceCapability().getMemory(); LOG.info("Max mem capabililty of resources in this cluster " + maxMem); if (amMemory > maxMem) { LOG.info("AM memory specified above max threshold of cluster. Using max value." + ", specified=" + amMemory + ", max=" + maxMem); amMemory = maxMem; } ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext(); ApplicationId appId = appContext.getApplicationId(); appContext.setApplicationName(appName); ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class); Map<String, LocalResource> localResources = new HashMap<String, LocalResource>(); LOG.info("Copy App Master jar from local filesystem and add to local environment"); FileSystem fs = FileSystem.get(conf); Path src = new Path(appJar); String pathSuffix = appName + File.separator + appId.getId() + File.separator + JBossConstants.JBOSS_ON_YARN_APP; Path dst = new Path(fs.getHomeDirectory(), pathSuffix); jbossAppUri = dst.toUri().toString(); fs.copyFromLocalFile(false, true, src, dst); FileStatus destStatus = fs.getFileStatus(dst); LocalResource amJarRsrc = Records.newRecord(LocalResource.class); amJarRsrc.setType(LocalResourceType.FILE); amJarRsrc.setVisibility(LocalResourceVisibility.APPLICATION); amJarRsrc.setResource(ConverterUtils.getYarnUrlFromPath(dst)); amJarRsrc.setTimestamp(destStatus.getModificationTime()); amJarRsrc.setSize(destStatus.getLen()); localResources.put(JBossConstants.JBOSS_ON_YARN_APP, amJarRsrc); if (!log4jPropFile.isEmpty()) { Path log4jSrc = new Path(log4jPropFile); Path log4jDst = new Path(fs.getHomeDirectory(), "log4j.props"); fs.copyFromLocalFile(false, true, log4jSrc, log4jDst); FileStatus log4jFileStatus = fs.getFileStatus(log4jDst); LocalResource log4jRsrc = Records.newRecord(LocalResource.class); log4jRsrc.setType(LocalResourceType.FILE); log4jRsrc.setVisibility(LocalResourceVisibility.APPLICATION); log4jRsrc.setResource(ConverterUtils.getYarnUrlFromURI(log4jDst.toUri())); log4jRsrc.setTimestamp(log4jFileStatus.getModificationTime()); log4jRsrc.setSize(log4jFileStatus.getLen()); localResources.put("log4j.properties", log4jRsrc); } amContainer.setLocalResources(localResources); LOG.info("Set the environment for the application master"); Map<String, String> env = new HashMap<String, String>(); StringBuilder classPathEnv = new StringBuilder(Environment.CLASSPATH.$()).append(File.pathSeparatorChar) .append("./*"); for (String c : conf.getStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH, YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) { classPathEnv.append(File.pathSeparatorChar); classPathEnv.append(c.trim()); } classPathEnv.append(File.pathSeparatorChar).append("./log4j.properties"); if (conf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) { classPathEnv.append(':'); classPathEnv.append(System.getProperty("java.class.path")); } env.put("CLASSPATH", classPathEnv.toString()); amContainer.setEnvironment(env); Vector<CharSequence> vargs = new Vector<CharSequence>(30); LOG.info("Setting up app master command"); vargs.add(Environment.JAVA_HOME.$() + "/bin/java"); vargs.add("-Xmx" + amMemory + "m"); vargs.add(appMasterMainClass); vargs.add("--container_memory " + String.valueOf(containerMemory)); vargs.add("--num_containers " + String.valueOf(numContainers)); vargs.add("--priority " + String.valueOf(shellCmdPriority)); vargs.add("--admin_user " + adminUser); vargs.add("--admin_password " + adminPassword); vargs.add("--jar " + jbossAppUri); if (debugFlag) { vargs.add("--debug"); } vargs.add("1>" + JBossConstants.JBOSS_CONTAINER_LOG_DIR + "/JBossApplicationMaster.stdout"); vargs.add("2>" + JBossConstants.JBOSS_CONTAINER_LOG_DIR + "/JBossApplicationMaster.stderr"); StringBuilder command = new StringBuilder(); for (CharSequence str : vargs) { command.append(str).append(" "); } LOG.info("Completed setting up app master command " + command.toString()); List<String> commands = new ArrayList<String>(); commands.add(command.toString()); amContainer.setCommands(commands); Resource capability = Records.newRecord(Resource.class); capability.setMemory(amMemory); appContext.setResource(capability); appContext.setAMContainerSpec(amContainer); Priority pri = Records.newRecord(Priority.class); pri.setPriority(amPriority); appContext.setPriority(pri); appContext.setQueue(amQueue); LOG.info("Submitting the application to ASM"); yarnClient.submitApplication(appContext); return monitorApplication(appId); }
From source file:org.etosha.cumulusonyarn.CumulusRDFRunner.java
/** * Main run function for the client// w w w. j av a2 s.c om * * @return true if application completed successfully * @throws IOException * @throws YarnException */ public boolean run() throws IOException, YarnException { LOG.info("Running Client"); yarnClient.start(); YarnClusterMetrics clusterMetrics = yarnClient.getYarnClusterMetrics(); LOG.info("Got Cluster metric info from ASM" + ", numNodeManagers=" + clusterMetrics.getNumNodeManagers()); List<NodeReport> clusterNodeReports = yarnClient.getNodeReports(NodeState.RUNNING); LOG.info("Got Cluster node info from ASM"); for (NodeReport node : clusterNodeReports) { LOG.info("Got node report from ASM for" + ", nodeId=" + node.getNodeId() + ", nodeAddress" + node.getHttpAddress() + ", nodeRackName" + node.getRackName() + ", nodeNumContainers" + node.getNumContainers()); } QueueInfo queueInfo = yarnClient.getQueueInfo(this.amQueue); LOG.info("Queue info" + ", queueName=" + queueInfo.getQueueName() + ", queueCurrentCapacity=" + queueInfo.getCurrentCapacity() + ", queueMaxCapacity=" + queueInfo.getMaximumCapacity() + ", queueApplicationCount=" + queueInfo.getApplications().size() + ", queueChildQueueCount=" + queueInfo.getChildQueues().size()); List<QueueUserACLInfo> listAclInfo = yarnClient.getQueueAclsInfo(); for (QueueUserACLInfo aclInfo : listAclInfo) { for (QueueACL userAcl : aclInfo.getUserAcls()) { LOG.info("User ACL Info for Queue" + ", queueName=" + aclInfo.getQueueName() + ", userAcl=" + userAcl.name()); } } YarnClientApplication app = yarnClient.createApplication(); GetNewApplicationResponse appResponse = app.getNewApplicationResponse(); int maxMem = appResponse.getMaximumResourceCapability().getMemory(); LOG.info("Max mem capabililty of resources in this cluster " + maxMem); if (amMemory > maxMem) { LOG.info("AM memory specified above max threshold of cluster. Using max value." + ", specified=" + amMemory + ", max=" + maxMem); amMemory = maxMem; } ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext(); ApplicationId appId = appContext.getApplicationId(); appContext.setApplicationName(appName); ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class); Map<String, LocalResource> localResources = new HashMap<String, LocalResource>(); LOG.info("Copy App Master jar from local filesystem and add to local environment"); FileSystem fs = FileSystem.get(conf); Path src = new Path(appJar); String pathSuffix = appName + File.separator + appId.getId() + File.separator + CumulusConstants.JBOSS_ON_YARN_APP; Path dst = new Path(fs.getHomeDirectory(), pathSuffix); jbossAppUri = dst.toUri().toString(); fs.copyFromLocalFile(false, true, src, dst); FileStatus destStatus = fs.getFileStatus(dst); LocalResource amJarRsrc = Records.newRecord(LocalResource.class); amJarRsrc.setType(LocalResourceType.FILE); amJarRsrc.setVisibility(LocalResourceVisibility.APPLICATION); amJarRsrc.setResource(ConverterUtils.getYarnUrlFromPath(dst)); amJarRsrc.setTimestamp(destStatus.getModificationTime()); amJarRsrc.setSize(destStatus.getLen()); localResources.put(CumulusConstants.JBOSS_ON_YARN_APP, amJarRsrc); if (!log4jPropFile.isEmpty()) { Path log4jSrc = new Path(log4jPropFile); Path log4jDst = new Path(fs.getHomeDirectory(), "log4j.props"); fs.copyFromLocalFile(false, true, log4jSrc, log4jDst); FileStatus log4jFileStatus = fs.getFileStatus(log4jDst); LocalResource log4jRsrc = Records.newRecord(LocalResource.class); log4jRsrc.setType(LocalResourceType.FILE); log4jRsrc.setVisibility(LocalResourceVisibility.APPLICATION); log4jRsrc.setResource(ConverterUtils.getYarnUrlFromURI(log4jDst.toUri())); log4jRsrc.setTimestamp(log4jFileStatus.getModificationTime()); log4jRsrc.setSize(log4jFileStatus.getLen()); localResources.put("log4j.properties", log4jRsrc); } amContainer.setLocalResources(localResources); LOG.info("Set the environment for the application master"); Map<String, String> env = new HashMap<String, String>(); StringBuilder classPathEnv = new StringBuilder(Environment.CLASSPATH.$()).append(File.pathSeparatorChar) .append("./*"); for (String c : conf.getStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH, YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) { classPathEnv.append(File.pathSeparatorChar); classPathEnv.append(c.trim()); } classPathEnv.append(File.pathSeparatorChar).append("./log4j.properties"); if (conf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) { classPathEnv.append(':'); classPathEnv.append(System.getProperty("java.class.path")); } env.put("CLASSPATH", classPathEnv.toString()); amContainer.setEnvironment(env); Vector<CharSequence> vargs = new Vector<CharSequence>(30); LOG.info("Setting up app master command"); vargs.add(Environment.JAVA_HOME.$() + "/bin/java"); vargs.add("-Xmx" + amMemory + "m"); vargs.add(appMasterMainClass); vargs.add("--container_memory " + String.valueOf(containerMemory)); vargs.add("--num_containers " + String.valueOf(numContainers)); vargs.add("--priority " + String.valueOf(shellCmdPriority)); vargs.add("--admin_user " + adminUser); vargs.add("--admin_password " + adminPassword); vargs.add("--jar " + jbossAppUri); if (debugFlag) { vargs.add("--debug"); } vargs.add("1>" + CumulusConstants.JBOSS_CONTAINER_LOG_DIR + "/JBossApplicationMaster.stdout"); vargs.add("2>" + CumulusConstants.JBOSS_CONTAINER_LOG_DIR + "/JBossApplicationMaster.stderr"); StringBuilder command = new StringBuilder(); for (CharSequence str : vargs) { command.append(str).append(" "); } LOG.info("Completed setting up app master command " + command.toString()); List<String> commands = new ArrayList<String>(); commands.add(command.toString()); amContainer.setCommands(commands); Resource capability = Records.newRecord(Resource.class); capability.setMemory(amMemory); appContext.setResource(capability); appContext.setAMContainerSpec(amContainer); Priority pri = Records.newRecord(Priority.class); pri.setPriority(amPriority); appContext.setPriority(pri); appContext.setQueue(amQueue); LOG.info("Submitting the application to ASM"); yarnClient.submitApplication(appContext); return monitorApplication(appId); }
From source file:cn.edu.zjnu.acm.judge.core.Judger.java
private Path getNull(Path work) { return File.pathSeparatorChar == ';' ? work.resolve("NUL") : Paths.get("/dev/null"); }
From source file:org.broadinstitute.gatk.tools.CatVariantsIntegrationTest.java
@Test() public void testCatVariantsGVCFGzIndexCreation() throws IOException { String cmdLine = String.format("java -cp \"%s\" %s -R %s -V %s -V %s -out %s", StringUtils.join(RuntimeUtils.getAbsoluteClassPaths(), File.pathSeparatorChar), CatVariants.class.getCanonicalName(), BaseTest.b37KGReference, CatVariantsVcf1, CatVariantsVcf2, BaseTest.createTempFile("CatVariantsGVCFIndexCreationTest", "." + GATKVCFUtils.GVCF_GZ_EXT)); ProcessController pc = ProcessController.getThreadLocal(); ProcessSettings ps = new ProcessSettings(Utils.escapeExpressions(cmdLine)); pc.execAndCheck(ps);/*w w w. j ava 2 s. c o m*/ }
From source file:org.codehaus.mojo.aspectj.AbstractAjcCompiler.java
/** * Finds all artifacts in the weavemodule property, * and adds them to the ajc options.//from ww w.jav a2s . c o m * * @param arguments * @throws MojoExecutionException */ private void addModulesArgument(String argument, List arguments, Module[] modules, String aditionalpath, String role) throws MojoExecutionException { StringBuffer buf = new StringBuffer(); if (null != aditionalpath) { arguments.add(argument); buf.append(aditionalpath); } if (modules != null && modules.length > 0) { if (!arguments.contains(argument)) { arguments.add(argument); } for (int i = 0; i < modules.length; ++i) { Module module = modules[i]; String key = ArtifactUtils.versionlessKey(module.getGroupId(), module.getArtifactId()); Artifact artifact = (Artifact) project.getArtifactMap().get(key); if (artifact == null) { throw new MojoExecutionException("The artifact " + key + " referenced in aspectj plugin as " + role + ", is not found the project dependencies"); } if (buf.length() != 0) { buf.append(File.pathSeparatorChar); } buf.append(artifact.getFile().getPath()); } } if (buf.length() > 0) { String pathString = buf.toString(); arguments.add(pathString); getLog().debug("Adding " + argument + ": " + pathString); } }
From source file:uk.ac.diamond.scisoft.JythonCreator.java
private void initialiseInterpreter(IProgressMonitor monitor) throws Exception { /*// ww w . j a va2 s .c om * The layout of plugins can vary between where a built product and * a product run from Ellipse: * * 1) Built product * . this class in plugins/a.b.c * . flat hierarchy with jars and expanded bundles (with jars in a.b.c and a.b.c/jars) * 2) Ellipse run * . flagged by RUN_IN_ECLIPSE property * . source code can be in workspace/plugins or workspace_git (this class is in workspace_git/blah.git/a.b.c) * * Jython lives in diamond-jython.git in uk.ac.diamond.jython (after being moved from uk.ac.gda.libs) */ logger.debug("Initialising the Jython interpreter setup"); boolean isRunningInEclipse = Boolean.getBoolean(RUN_IN_ECLIPSE); // Horrible Hack warning: This code is copied from parts of Pydev to set up the interpreter and save it. { File pluginsDir = JythonPath.getPluginsDirectory(isRunningInEclipse); // plugins or git workspace directory if (pluginsDir == null) { logger.error("Failed to find plugins directory!"); return; } logger.debug("Plugins directory is {}", pluginsDir); // Set cache directory to something not in the installation directory IPreferenceStore pyStore = PydevPrefs.getPreferenceStore(); String cachePath = pyStore.getString(IInterpreterManager.JYTHON_CACHE_DIR); if (cachePath == null || cachePath.length() == 0) { final String workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); final File cacheDir = new File(workspace, ".jython_cachedir"); if (!cacheDir.exists()) cacheDir.mkdirs(); cachePath = cacheDir.getAbsolutePath(); pyStore.setValue(IInterpreterManager.JYTHON_CACHE_DIR, cacheDir.getAbsolutePath()); } System.setProperty("python.cachedir", cachePath); // check for the existence of this standard pydev script final File script = PydevPlugin.getScriptWithinPySrc("interpreterInfo.py"); if (!script.exists()) { logger.error("The file specified does not exist: {} ", script); throw new RuntimeException("The file specified does not exist: " + script); } logger.debug("Script path = {}", script.getAbsolutePath()); File java = JavaVmLocationFinder.findDefaultJavaExecutable(); logger.debug("Using java: {}", java); String javaPath; try { javaPath = java.getCanonicalPath(); } catch (IOException e) { logger.warn("Could not resolve default Java path so resorting to PATH", e); javaPath = "java"; } //If the interpreter directory comes back unset, we don't want to go any further. File interpreterDirectory = JythonPath.getInterpreterDirectory(isRunningInEclipse); if (interpreterDirectory == null) { logger.error("Interpreter directory not set. Cannot find interpreter."); return; } String executable = new File(interpreterDirectory, JythonPath.getJythonExecutableName()) .getAbsolutePath(); if (!(new File(executable)).exists()) { logger.error("Failed to find jython jar at all"); return; } logger.debug("executable path = {}", executable); String[] cmdarray = { javaPath, "-Xmx64m", // "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000", "-Dpython.cachedir.skip=true", // this works in Windows "-jar", executable, FileUtils.getFileAbsolutePath(script) }; File workingDir = new File(System.getProperty("java.io.tmpdir")); // logger.debug("Cache and working dirs are {} and {}", cachePath, workingDir); IPythonNature nature = null; String outputString = ""; try { Tuple<Process, String> outTuple = new SimpleRunner().run(cmdarray, workingDir, nature, monitor); outputString = IOUtils.toString(outTuple.o1.getInputStream()); } catch (IOException e1) { logger.error("Could not parse output from running interpreterInfo.py in Jython", e1); } catch (Exception e2) { logger.error("Something went wrong in running interpreterInfo.py in Jython", e2); } logger.debug("Output String is {}", outputString); // this is the main info object which contains the environment data InterpreterInfo info = null; try { // HACK Otherwise Pydev shows a dialog to the user. ModulesManagerWithBuild.IN_TESTS = true; info = InterpreterInfo.fromString(outputString, false); } catch (Exception e) { logger.error("InterpreterInfo.fromString(outTup.o1) has failed in pydev setup with exception"); logger.error("{}", e); } finally { ModulesManagerWithBuild.IN_TESTS = false; } if (info == null) { logger.error("pydev info is set to null"); return; } // the executable is the jar itself info.executableOrJar = executable; final String osName = System.getProperty("os.name"); final boolean isMacOSX = osName.contains("Mac OS X"); final String pathEnv = isMacOSX ? "DYLD_LIBRARY_PATH" : (osName.contains("Windows") ? "PATH" : "LD_LIBRARY_PATH"); logPaths("Library paths:", System.getenv(pathEnv)); logPaths("Class paths:", System.getProperty("java.library.path")); // set of python paths Set<String> pyPaths = new TreeSet<String>(); // we have to find the jars before we restore the compiled libs final List<File> jars = JavaVmLocationFinder.findDefaultJavaJars(); for (File jar : jars) { if (!pyPaths.add(jar.getAbsolutePath())) { logger.warn("File {} already there!", jar.getName()); } } Set<String> extraPlugins = new HashSet<String>(7); // Find all packages that contribute to loader factory Set<String> loaderPlugins = LoaderFactoryStartup.getPlugins(); if (loaderPlugins != null) { logger.debug("Extra plugins: {}", loaderPlugins); extraPlugins.addAll(loaderPlugins); } // We add the SWT plugins so that the plotting system works in Jython mode. // The class IRemotePlottingSystem ends up referencing color so SWT plugins are // required to expose IRemotePlottingSystem to the scripting layer. createSwtEntries(extraPlugins); //Get Jython paths for DAWN libs pyPaths.addAll(JythonPath.assembleJyPaths(pluginsDir, extraPlugins, isRunningInEclipse)); //Also need allPluginsDirs for later parts final List<File> allPluginDirs = JythonPath.findDirs(pluginsDir, extraPlugins, isRunningInEclipse); Set<String> removals = new HashSet<String>(); for (String s : info.libs) { String ls = s.toLowerCase(); for (String r : removedLibEndings) { if (ls.endsWith(r)) { removals.add(s); break; } } } info.libs.removeAll(removals); info.libs.addAll(pyPaths); // now set up the dynamic library environment File libraryDir = new File(pluginsDir.getParent(), "lib"); Set<String> paths = new LinkedHashSet<String>(); if (!isRunningInEclipse && libraryDir.exists()) { paths.add(libraryDir.getAbsolutePath()); } else { // check each plugin directory's for dynamic libraries String osarch = Platform.getOS() + "-" + Platform.getOSArch(); logger.debug("Using OS and ARCH: {}", osarch); for (File dir : allPluginDirs) { File d = new File(dir, "lib"); if (d.isDirectory()) { d = new File(d, osarch); if (d.isDirectory()) { if (paths.add(d.getAbsolutePath())) logger.debug("Adding library path: {}", d); } } } } // add from environment variables String ldPath = System.getenv(pathEnv); if (ldPath != null) { for (String p : ldPath.split(File.pathSeparator)) { paths.add(p); } } StringBuilder allPaths = new StringBuilder(); for (String p : paths) { allPaths.append(p); allPaths.append(File.pathSeparatorChar); } String libraryPath = allPaths.length() > 0 ? allPaths.substring(0, allPaths.length() - 1) : null; PyDevAdditionalInterpreterSettings settings = new PyDevAdditionalInterpreterSettings(); Collection<String> envVariables = settings.getAdditionalEnvVariables(); if (libraryPath == null) { logger.warn("{} not defined as no library paths were found!" + pathEnv); } else { logPaths("Setting " + pathEnv + " for dynamic libraries", libraryPath); envVariables.add(pathEnv + "=" + libraryPath); } if (isMacOSX) { // do we also add DYLD_VERSIONED_LIBRARY_PATH and DYLD_ROOT_PATH? String fbPathEnv = "DYLD_FALLBACK_LIBRARY_PATH"; String fbPath = System.getenv(fbPathEnv); if (fbPath == null) { logger.debug("{} not defined" + fbPathEnv); } else { logPaths("For Mac OS X, setting " + fbPathEnv + " for dynamic libraries", fbPath); envVariables.add(fbPathEnv + "=" + fbPath); } } String[] envVarsAlreadyIn = info.getEnvVariables(); if (envVarsAlreadyIn != null) { envVariables.addAll(Arrays.asList(envVarsAlreadyIn)); } // add custom loader extensions to work around Jython not being OSGI Set<String> loaderExts = LoaderFactoryStartup.getExtensions(); if (loaderExts != null) { String ev = "LOADER_FACTORY_EXTENSIONS="; for (String e : loaderExts) { ev += e + "|"; } envVariables.add(ev); } info.setEnvVariables(envVariables.toArray(new String[envVariables.size()])); // java, java.lang, etc should be found now info.restoreCompiledLibs(monitor); info.setName(INTERPRETER_NAME); logger.debug("Finalising the Jython interpreter manager"); final JythonInterpreterManager man = (JythonInterpreterManager) PydevPlugin .getJythonInterpreterManager(); HashSet<String> set = new HashSet<String>(); // Note, despite argument in PyDev being called interpreterNamesToRestore // in this context that name is the exe. // Pydev doesn't allow two different interpreters to be configured for the same // executable path so in some contexts the executable is the unique identifier (as it is here) set.add(executable); // Attempt to update existing Jython configuration IInterpreterInfo[] interpreterInfos = man.getInterpreterInfos(); IInterpreterInfo existingInfo = null; try { existingInfo = man.getInterpreterInfo(executable, monitor); } catch (MisconfigurationException e) { // MisconfigurationException thrown if executable not found } if (existingInfo != null && existingInfo.toString().equals(info.toString())) { logger.debug("Jython interpreter already exists with exact settings"); } else { // prune existing interpreters with same name Map<String, IInterpreterInfo> infoMap = new LinkedHashMap<String, IInterpreterInfo>(); for (IInterpreterInfo i : interpreterInfos) { infoMap.put(i.getName(), i); } if (existingInfo == null) { if (infoMap.containsKey(INTERPRETER_NAME)) { existingInfo = infoMap.get(INTERPRETER_NAME); logger.debug("Found interpreter of same name"); } } if (existingInfo == null) { logger.debug("Adding interpreter as an additional interpreter"); } else { logger.debug("Updating interpreter which was previously created"); } infoMap.put(INTERPRETER_NAME, info); try { IInterpreterInfo[] infos = new IInterpreterInfo[infoMap.size()]; int j = 0; for (String i : infoMap.keySet()) { infos[j++] = infoMap.get(i); } try { man.setInfos(infos, set, monitor); } catch (Throwable swallowed) { // Occurs with a clean workspace. } } catch (RuntimeException e) { logger.warn("Problem with restoring info"); } } logger.debug("Finished the Jython interpreter setup"); } }
From source file:org.beigesoft.uml.service.swing.CreatorDoclet.java
protected static void setOptions(RootDoc root) throws Exception { pathUmlProject = null;/*from w w w . jav a 2 s . c om*/ pathMavenProject = null; pathJavaDoc = null; for (String[] option : root.options()) { if (option[0].equals(OPTION_PATH_UML_PROJECT) && option.length == 2) { pathUmlProject = option[1].trim(); root.printNotice("Uml project path is " + pathUmlProject); } else if (option[0].equals("-d") && option.length == 2) { pathJavaDoc = option[1].trim(); root.printNotice("Javadoc path is " + pathJavaDoc); } else if (option[0].equals("-sourcepath") && option.length == 2) { String pathJavaSource = option[1].trim(); int firstSeparator = pathJavaSource.indexOf(File.pathSeparatorChar); if (firstSeparator != -1) { pathJavaSource = pathJavaSource.substring(0, firstSeparator).trim(); } root.printNotice("Firts java source path is " + pathJavaSource); int mvnSrcIdx = pathJavaSource.indexOf("/src/test/"); if (mvnSrcIdx == -1) { mvnSrcIdx = pathJavaSource.indexOf("/src/main/"); } if (mvnSrcIdx != -1) {//maven project pathMavenProject = pathJavaSource.substring(0, mvnSrcIdx) + File.separator + "src"; root.printNotice("Maven project path is " + pathMavenProject); } } if (pathUmlProject != null && pathMavenProject != null && pathJavaDoc != null) { break; } } if (pathJavaDoc == null) { root.printError("Can not find javadoc path!"); } if (pathUmlProject == null) { if (pathMavenProject != null) { pathUmlProject = pathMavenProject + File.separator + "uml"; root.printNotice("Uml project path is " + pathUmlProject); } else { root.printError( "Doclet UML project path option: [" + OPTION_PATH_UML_PROJECT + "] must be settled!"); } } if (pathUmlProject != null) { File file = new File(pathUmlProject); if (!file.isAbsolute()) { throw new Exception("Doclet UML project path option: [" + OPTION_PATH_UML_PROJECT + "] must be settled as absolute path " + "or nothing (assume path is [mvnproject]/src/uml)!"); } } }