List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:uk.ac.tgac.rampart.stage.analyse.asm.analysers.QuastAsmAnalyser.java
@Override public List<ExecutionResult> execute(List<File> assemblies, File outputDir, String jobPrefix, ConanExecutorService ces)/*from ww w . j av a 2 s . c om*/ throws InterruptedException, ProcessExecutionException, ConanParameterException, IOException { if (outputDir.exists()) { FileUtils.deleteDirectory(outputDir); } outputDir.mkdirs(); // Create mapping between quast assembly name and actual file path this.assemblies = new HashMap<>(); for (File assembly : assemblies) { this.assemblies.put(assembly.getName().substring(0, assembly.getName().length() - 3), assembly.getCanonicalFile()); } // Add quast job id to list List<ExecutionResult> jobResults = new ArrayList<>(); File reference = args.getOrganism().getReference() != null ? args.getOrganism().getReference().getPath() : null; long estGenomeSize = reference != null ? 0 : args.getOrganism().getGenomeSize(); QuastV23 quastProcess = this.makeQuast(assemblies, outputDir, estGenomeSize, args.getOrganism().getPloidy() > 1, reference, args.getThreads(), false // Assume all sequences are not scaffolds... I don't like this options much in Quast. ); ExecutionResult result = ces.executeProcess(quastProcess, outputDir, jobPrefix, args.getThreads(), args.getMemory(), false); jobResults.add(result); return jobResults; }
From source file:android.databinding.compilationTest.SimpleCompilationTest.java
private ScopedException singleFileErrorTest(String resource, String targetFile, String expectedExtract, String errorMessage) throws IOException, URISyntaxException, InterruptedException { prepareProject();//from w w w . j a va 2 s . c om copyResourceTo(resource, targetFile); CompilationResult result = runGradle("assembleDebug"); assertNotEquals(0, result.resultCode); ScopedException scopedException = result.getBindingException(); assertNotNull(result.error, scopedException); ScopedErrorReport report = scopedException.getScopedErrorReport(); assertNotNull(report); assertEquals(1, report.getLocations().size()); Location loc = report.getLocations().get(0); if (expectedExtract != null) { String extract = extract(targetFile, loc); assertEquals(expectedExtract, extract); } final File errorFile = new File(report.getFilePath()); assertTrue(errorFile.exists()); assertEquals(new File(testFolder, targetFile).getCanonicalFile(), errorFile.getCanonicalFile()); if (errorMessage != null) { assertEquals(errorMessage, scopedException.getBareMessage()); } return scopedException; }
From source file:org.red5.server.war.MainServlet.java
/** * Main entry point for the Red5 Server as a war *//*from w ww .j a v a 2 s . co m*/ // Notification that the web application is ready to process requests public void contextInitialized(ServletContextEvent sce) { System.setProperty("red5.deployment.type", "war"); if (null != servletContext) { return; } servletContext = sce.getServletContext(); String prefix = servletContext.getRealPath("/"); long time = System.currentTimeMillis(); logger.info("RED5 Server (http://www.osflash.org/red5)"); logger.info("Loading red5 global context from: " + red5Config); logger.info("Path: " + prefix); try { // Detect root of Red5 configuration and set as system property String root; String classpath = System.getProperty("java.class.path"); File fp = new File(prefix + red5Config); fp = fp.getCanonicalFile(); if (!fp.isFile()) { // Given file does not exist, search it on the classpath String[] paths = classpath.split(System.getProperty("path.separator")); for (String element : paths) { fp = new File(element + "/" + red5Config); fp = fp.getCanonicalFile(); if (fp.isFile()) { break; } } } if (!fp.isFile()) { throw new Exception( "could not find configuration file " + red5Config + " on your classpath " + classpath); } root = fp.getAbsolutePath(); root = root.replace('\\', '/'); int idx = root.lastIndexOf('/'); root = root.substring(0, idx); // update classpath System.setProperty("java.class.path", classpath + File.pathSeparatorChar + root + File.pathSeparatorChar + root + "/classes"); logger.debug("New classpath: " + System.getProperty("java.class.path")); // set configuration root System.setProperty("red5.config_root", root); logger.info("Setting configuation root to " + root); // Setup system properties so they can be evaluated Properties props = new Properties(); props.load(new FileInputStream(root + "/red5.properties")); for (Object o : props.keySet()) { String key = (String) o; if (StringUtils.isNotBlank(key)) { System.setProperty(key, props.getProperty(key)); } } // Store root directory of Red5 idx = root.lastIndexOf('/'); root = root.substring(0, idx); if (System.getProperty("file.separator").equals("/")) { // Workaround for linux systems root = "/" + root; } System.setProperty("red5.root", root); logger.info("Setting Red5 root to " + root); Class contextClass = org.springframework.web.context.support.XmlWebApplicationContext.class; ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(contextClass); String[] strArray = servletContext.getInitParameter(ContextLoader.CONFIG_LOCATION_PARAM) .split("[,\\s]"); logger.info("Config location files: " + strArray.length); applicationContext.setConfigLocations(strArray); applicationContext.setServletContext(servletContext); applicationContext.refresh(); // set web application context as an attribute of the servlet // context so that it may be located via Springs // WebApplicationContextUtils servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); // register default // add the context to the parent factory.registerSingleton("default.context", applicationContext); } catch (Throwable e) { logger.error("", e); } long startupIn = System.currentTimeMillis() - time; logger.info("Startup done in: " + startupIn + " ms"); }
From source file:io.wcm.maven.plugins.i18n.TransformMojo.java
/** * Get the JSON file for source file.//from w ww. j a v a 2s . c om * @param sourceFile the source file * @param selectedOutputFormat Output format * @return File with name and path based on file parameter * @throws IOException */ private File getTargetFile(File sourceFile, OutputFormat selectedOutputFormat) throws IOException { File sourceDirectory = getSourceDirectory(); String relativePath = StringUtils.substringAfter(sourceFile.getAbsolutePath(), sourceDirectory.getAbsolutePath()); String relativeTargetPath = FileUtils.removeExtension(relativePath) + "." + selectedOutputFormat.getFileExtension(); File jsonFile = new File(getGeneratedResourcesFolder().getPath() + relativeTargetPath); jsonFile = jsonFile.getCanonicalFile(); File parentDirectory = jsonFile.getParentFile(); if (!parentDirectory.exists()) { parentDirectory.mkdirs(); } return jsonFile; }
From source file:org.apache.servicemix.jbi.deployer.impl.SharedLibraryInstaller.java
protected ClassLoader createClassLoader() { SharedLibraryDesc library = descriptor.getSharedLibrary(); // Make the current ClassLoader the parent ClassLoader parent = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle, getClass().getClassLoader()); boolean parentFirst = library.isParentFirstClassLoaderDelegation(); ClassPath cp = library.getSharedLibraryClassPath(); String[] classPathNames = cp.getPathElements(); List<URL> urls = new ArrayList<URL>(); for (String classPathName : classPathNames) { File f = new File(installRoot, classPathName); if (!f.exists()) { LOGGER.warn("Shared library classpath entry not found: '" + classPathName + "'"); }//from ww w .jav a 2 s. co m try { urls.add(f.getCanonicalFile().toURL()); } catch (IOException e) { throw new IllegalArgumentException( "Shared library classpath entry not found: '" + classPathName + "'"); } } return new MultiParentClassLoader(library.getIdentification().getName(), urls.toArray(new URL[urls.size()]), parent, !parentFirst, new String[0], new String[] { "java.", "javax." }); }
From source file:org.sonatype.nexus.proxy.storage.local.fs.DefaultFSLocalRepositoryStorageTest.java
@Test public void getFileFromBaseRelative() throws Exception { {/*from ww w. j a va 2 s. c om*/ final File fileFromBase = subject.getFileFromBase(repository, new ResourceStoreRequest("/foo/bar/../baz")); assertThat(fileFromBase.getCanonicalFile(), equalTo(new File(baseDir, "foo/baz"))); } { final File fileFromBase = subject.getFileFromBase(repository, new ResourceStoreRequest("/foo/bar/../bar/../../baz")); assertThat(fileFromBase.getCanonicalFile(), equalTo(new File(baseDir, "baz"))); } }
From source file:org.apache.torque.generator.configuration.DirectoryConfigurationProvider.java
private File getFile(String name, String directory, String description) throws ConfigurationException { File file = null; try {/*from ww w .j av a 2s . c o m*/ File configDir = new File(projectPaths.getConfigurationPath(), directory); file = new File(configDir, name); // use canonical file to resolve . and .. directories file = file.getCanonicalFile(); } catch (IOException e) { throw new ConfigurationException( "Canonical name for " + description + file + " could not be calculated", e); } return file; }
From source file:org.apache.catalina.startup.SetDocBaseRule.java
/** * Handle the beginning of an XML element. * * @param attributes The attributes of this element * * @exception Exception if a processing error occurs *///w ww. j av a 2 s . c om public void begin(Attributes attributes) throws Exception { Context child = (Context) digester.peek(0); Deployer parent = (Deployer) digester.peek(1); Host host = null; if (!(parent instanceof StandardHost)) { Method method = parent.getClass().getMethod("getHost", null); host = (Host) method.invoke(parent, null); } else { host = (Host) parent; } String appBase = host.getAppBase(); boolean unpackWARs = true; if (host instanceof StandardHost) { unpackWARs = ((StandardHost) host).isUnpackWARs(); } if (!unpackWARs && !("true".equals(attributes.getValue("unpackWAR")))) { return; } if ("false".equals(attributes.getValue("unpackWAR"))) { return; } File canonicalAppBase = new File(appBase); if (canonicalAppBase.isAbsolute()) { canonicalAppBase = canonicalAppBase.getCanonicalFile(); } else { canonicalAppBase = new File(System.getProperty("catalina.base"), appBase).getCanonicalFile(); } String docBase = child.getDocBase(); if (docBase == null) { // Trying to guess the docBase according to the path String path = child.getPath(); if (path == null) { return; } if (path.equals("")) { docBase = "ROOT"; } else { if (path.startsWith("/")) { docBase = path.substring(1); } else { docBase = path; } } } File file = new File(docBase); if (!file.isAbsolute()) { docBase = (new File(canonicalAppBase, docBase)).getPath(); } else { docBase = file.getCanonicalPath(); } if (docBase.toLowerCase().endsWith(".war")) { URL war = new URL("jar:" + (new File(docBase)).toURL() + "!/"); String contextPath = child.getPath(); if (contextPath.equals("")) { contextPath = "ROOT"; } docBase = ExpandWar.expand(host, war, contextPath); file = new File(docBase); docBase = file.getCanonicalPath(); } else { File docDir = new File(docBase); if (!docDir.exists()) { File warFile = new File(docBase + ".war"); if (warFile.exists()) { URL war = new URL("jar:" + warFile.toURL() + "!/"); docBase = ExpandWar.expand(host, war, child.getPath()); file = new File(docBase); docBase = file.getCanonicalPath(); } } } if (docBase.startsWith(canonicalAppBase.getPath())) { docBase = docBase.substring(canonicalAppBase.getPath().length()); docBase = docBase.replace(File.separatorChar, '/'); if (docBase.startsWith("/")) { docBase = docBase.substring(1); } } else { docBase = docBase.replace(File.separatorChar, '/'); } child.setDocBase(docBase); }
From source file:org.rhq.plugins.jbossas.script.ScriptFileFinder.java
protected void findScriptFiles(File scanDir, List<File> excludeDirs, List<File> scriptFiles) { if (!scanDir.isDirectory()) { return;/*from w w w . ja v a 2 s .co m*/ } File canonicalScanDir = null; try { canonicalScanDir = scanDir.getCanonicalFile(); } catch (IOException e) { // if we aren't allowed to reach the canonical path, skip this directory return; } // if we've seen this directory before (or it's explicitly excluded by the caller) skip this directory. // this protects against following cyclic symbolic links. if (excludeDirs.contains(canonicalScanDir)) { return; } // add to the directories we've seen excludeDirs.add(canonicalScanDir); scriptFiles.addAll(Arrays.asList(scanDir.listFiles(new ScriptFileFilter()))); File[] subDirs = scanDir.listFiles(new DirectoryFilter()); for (File subDir : subDirs) { findScriptFiles(subDir, excludeDirs, scriptFiles); // recurse } }
From source file:org.rhq.plugins.jbossas5.script.ScriptFileFinder.java
protected void findScriptFiles(File scanDir, List<File> excludeDirs, List<File> scriptFiles) { if (!scanDir.isDirectory()) { return;//from ww w . ja v a 2 s. c o m } File canonicalScanDir = null; try { canonicalScanDir = scanDir.getCanonicalFile(); } catch (IOException e) { // if we aren't allowed to reach the canonical path, skip this // directory return; } // if we've seen this directory before (or it's explicitly excluded by // the caller) skip this directory. // this protects against following cyclic symbolic links. if (excludeDirs.contains(canonicalScanDir)) { return; } // add to the directories we've seen excludeDirs.add(canonicalScanDir); scriptFiles.addAll(Arrays.asList(scanDir.listFiles(getScriptFileFilter(systemInfo)))); File[] subDirs = scanDir.listFiles(new DirectoryFilter()); for (File subDir : subDirs) { findScriptFiles(subDir, excludeDirs, scriptFiles); // recurse } }