List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:org.eclipse.emf.mwe.utils.StandaloneSetup.java
protected void doRegisterResourceMapping(File file) { try {/* ww w . ja v a 2 s . c om*/ File f = file.getCanonicalFile(); if (f.getPath().endsWith(".jar")) { registerBundle(f); } else if (!scanFolder(f)) { File dotProject = findProjectFileForPossibleClassesFolder(f); if (dotProject != null) registerProject(dotProject); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.sonatype.nexus.test.booter.Jetty8NexusBooter.java
/** * Creates a NexusBooter instance, that pre-configures and adapts the Nexus bundle unzipped in passed in * {@code bundleBasedir} folder. Also, it sets Jetty's port to passed in {@code port}. Warning: the unzipped bundle * is modified after this constructor is executed, and WILL NOT BE ABLE TO BOOT anymore using the "standard way" * (cd-ing into it's /bin/jsw/... dir and using JSW scripts)! This is due to the fact that this booter moves some * JARs out of bundle to make them shared across boots. * //from ww w . j a v a 2s. c o m * @param bundleBasedir * @param port * @throws Exception */ public Jetty8NexusBooter(final File bundleBasedir, final int port) throws Exception { this.bundleBasedir = bundleBasedir.getCanonicalFile(); log.info("Bundle base directory: {}", bundleBasedir); this.sharedLibs = new File(bundleBasedir.getParentFile(), "shared"); log.info("Shared library directory: {}", sharedLibs); // modify the properties tamperJettyConfiguration(bundleBasedir, port); // shuffle bundle files tamperJarsForSharedClasspath(bundleBasedir); // -------------- // Setting system props, even if it might be redundant, just to be 100% positive // -------------- // set system property for bundleBasedir System.setProperty("bundleBasedir", bundleBasedir.getAbsolutePath()); // needed since NEXUS-4515 System.setProperty("jettyContext", "nexus.properties"); System.setProperty("jettyPlexusCompatibility", "true"); // Configure bootstrap logback configuration System.setProperty("logback.configurationFile", new File(bundleBasedir, "conf/logback.xml").getAbsolutePath()); // guice finalizer System.setProperty("guice.executor.class", "NONE"); // Note: in ITs we want to make Indexer perform blocking commits. // Since MavenIndexer 4.0, it performs async commits by default, meaning that no "helper" from Nexus // is able to tell and potentially block (see EventInspectorsUtil#waitForCalmPeriod() as example) execution // up to the moment when readers are refreshed (indexing operation IS done, but readers will not "see" the // change without reopening those). // By having this switch, we are switching Maven Indexer back into "blocking" mode as it was before 4.0. // The proper fix is to make all Indexer related ITs behave "properly" (with some heuristics?), and have some // sort of "try-wait-try-failAfterSomeRetries" the search operation itself. System.setProperty("mavenIndexerBlockingCommits", Boolean.TRUE.toString()); // Note: autorouting initialization prevented // Presence breaks many ITs, especially those that either listen for proxy requests (will be more coz of prefix file // and scrape discovery), or because remote proxy setup happens after nexus boot, and autorouting discovery makes proxies autoblock. // In either case, IT working with autorouting should explicitly enable it. // As "legacy" ITs are coming anyway from pre-WL era, they will have autorouting disabled ALWAYS // To write IT covering WL you'd use anyway the "new" IT infrastructure instead of this. System.setProperty(ConfigImpl.FEATURE_ACTIVE_KEY, Boolean.FALSE.toString()); // --------------- // create ClassWorld world = new ClassWorld(); // create shared loader sharedClassloader = buildSharedClassLoader(); }
From source file:nl.imvertor.common.file.AnyFile.java
/** * break a path down into individual elements and add to a list. * example : if a path is /a/b/c/d.txt, the breakdown will be [d.txt,c,b,a] * /*from w ww. j av a 2 s .c om*/ * taken from: http://www.devx.com/tips/Tip/13737 * * @param f input file * @return a List collection with the individual elements of the path in reverse order */ private List<String> getPathList(File f) { List<String> l = new ArrayList<String>(); File r; try { r = f.getCanonicalFile(); while (r != null) { l.add(r.getName()); r = r.getParentFile(); } } catch (IOException e) { e.printStackTrace(); l = null; } return l; }
From source file:org.apache.hadoop.hbase.util.CoprocessorClassLoader.java
private void init(Path path, String pathPrefix, Configuration conf) throws IOException { // Copy the jar to the local filesystem String parentDirStr = conf.get(LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + TMP_JARS_DIR; synchronized (parentDirLockSet) { if (!parentDirLockSet.contains(parentDirStr)) { Path parentDir = new Path(parentDirStr); FileSystem fs = FileSystem.getLocal(conf); fs.delete(parentDir, true); // it's ok if the dir doesn't exist now parentDirLockSet.add(parentDirStr); if (!fs.mkdirs(parentDir) && !fs.getFileStatus(parentDir).isDirectory()) { throw new RuntimeException("Failed to create local dir " + parentDirStr + ", CoprocessorClassLoader failed to init"); }//from w w w.jav a2s.co m } } FileSystem fs = path.getFileSystem(conf); File dst = new File(parentDirStr, "." + pathPrefix + "." + path.getName() + "." + System.currentTimeMillis() + ".jar"); fs.copyToLocalFile(path, new Path(dst.toString())); dst.deleteOnExit(); addURL(dst.getCanonicalFile().toURI().toURL()); JarFile jarFile = new JarFile(dst.toString()); try { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); Matcher m = libJarPattern.matcher(entry.getName()); if (m.matches()) { File file = new File(parentDirStr, "." + pathPrefix + "." + path.getName() + "." + System.currentTimeMillis() + "." + m.group(1)); IOUtils.copyBytes(jarFile.getInputStream(entry), new FileOutputStream(file), conf, true); file.deleteOnExit(); addURL(file.toURI().toURL()); } } } finally { jarFile.close(); } }
From source file:org.apache.servicemix.jbi.deployer.impl.AbstractInstaller.java
public void installBundle() throws Exception { InputStream is = null;/* www . ja va 2 s . c om*/ try { deployer.setJmxManaged(this); File artifact = new File(jbiArtifact.getCanonicalPath()); String bundleName = artifact.getName().substring(0, artifact.getName().length() - 4) + ".jar"; File osgi = new File(getGenerateDir(), bundleName); Transformer.transformToOSGiBundle(artifact, osgi); is = new BufferedInputStream(new FileInputStream(osgi)); bundle = getBundleContext().installBundle(artifact.getCanonicalFile().toURI().toString(), is); bundle.start(); } catch (Exception e) { if (is != null) { try { is.close(); } catch (IOException io) { LOGGER.info("Failed to close stream. " + io, io); } } throw e; } finally { deployer.setJmxManaged(null); } }
From source file:org.apache.jasper.compiler.JspRuntimeContext.java
/** * Method used to initialize SecurityManager data. *///from w ww .ja v a 2 s. co m private void initSecurity() { // Setup the PermissionCollection for this web app context // based on the permissions configured for the root of the // web app context directory, then add a file read permission // for that directory. Policy policy = Policy.getPolicy(); if (policy != null) { try { // Get the permissions for the web app context String docBase = context.getRealPath("/"); if (docBase == null) { docBase = options.getScratchDir().toString(); } String codeBase = docBase; if (!codeBase.endsWith(File.separator)) { codeBase = codeBase + File.separator; } File contextDir = new File(codeBase); URL url = contextDir.getCanonicalFile().toURL(); codeSource = new CodeSource(url, null); permissionCollection = policy.getPermissions(codeSource); // Create a file read permission for web app context directory if (!docBase.endsWith(File.separator)) { permissionCollection.add(new FilePermission(docBase, "read")); docBase = docBase + File.separator; } else { permissionCollection .add(new FilePermission(docBase.substring(0, docBase.length() - 1), "read")); } docBase = docBase + "-"; permissionCollection.add(new FilePermission(docBase, "read")); // Create a file read permission for web app tempdir (work) // directory String workDir = options.getScratchDir().toString(); if (!workDir.endsWith(File.separator)) { permissionCollection.add(new FilePermission(workDir, "read")); workDir = workDir + File.separator; } workDir = workDir + "-"; permissionCollection.add(new FilePermission(workDir, "read")); // Allow the JSP to access org.apache.jasper.runtime.HttpJspBase permissionCollection.add(new RuntimePermission("accessClassInPackage.org.apache.jasper.runtime")); if (parentClassLoader instanceof URLClassLoader) { URL[] urls = parentClassLoader.getURLs(); String jarUrl = null; String jndiUrl = null; for (int i = 0; i < urls.length; i++) { if (jndiUrl == null && urls[i].toString().startsWith("jndi:")) { jndiUrl = urls[i].toString() + "-"; } if (jarUrl == null && urls[i].toString().startsWith("jar:jndi:")) { jarUrl = urls[i].toString(); jarUrl = jarUrl.substring(0, jarUrl.length() - 2); jarUrl = jarUrl.substring(0, jarUrl.lastIndexOf('/')) + "/-"; } } if (jarUrl != null) { permissionCollection.add(new FilePermission(jarUrl, "read")); permissionCollection.add(new FilePermission(jarUrl.substring(4), "read")); } if (jndiUrl != null) permissionCollection.add(new FilePermission(jndiUrl, "read")); } } catch (Exception e) { context.log("Security Init for context failed", e); } } }
From source file:org.sonar.dotnet.tools.commons.visualstudio.VisualStudioProject.java
/** * Gets the source representation of a given file. * /* w w w .j a va 2 s .c o m*/ * @param file * the file to retrieve * @return the associated source file, or <code>null</code> if the file is not included in the assembly. */ public SourceFile getFile(File file) { File currentFile; try { currentFile = file.getCanonicalFile(); } catch (IOException e) { // File not found if (LOG.isDebugEnabled()) { LOG.debug("file not found " + file, e); } return null; } // We ensure the source files are loaded getSourceFiles(); return sourceFileMap.get(currentFile); }
From source file:com.naryx.tagfusion.expression.function.file.Zip.java
/** * Adding file to archive//from w w w . j av a 2s . c o m * * @param dir * @param result * @param recurse * @param filter */ private void getFiles(File dir, List<File> result, boolean recurse, FilenameFilter filter) { String[] files; if (filter == null) { files = dir.list(); } else { // FILTER files = dir.list(filter); } if (files != null) { File nextFile; for (int i = 0; i < files.length; i++) { nextFile = new File(dir.getPath() + File.separatorChar + files[i]); try { nextFile = nextFile.getCanonicalFile(); } catch (IOException ignore) { } if (!nextFile.isDirectory()) { result.add(nextFile); } else if (recurse) { // RECURSE getFiles(nextFile, result, recurse, filter); } } } }
From source file:org.geoserver.rest.catalog.DataStoreFileUploadTest.java
@Test public void testShapeFileUploadNotExisting() throws Exception { File file = new File("./target/notThere.tiff"); if (file.exists()) { assertTrue(file.delete());//from w ww. ja v a2 s .c o m } URL url = DataUtilities.fileToURL(file.getCanonicalFile()); String body = url.toExternalForm(); MockHttpServletResponse response = putAsServletResponse( ROOT_PATH + "/workspaces/gs/datastores/pds/external.shp", body, "text/plain"); assertEquals(400, response.getStatus()); }
From source file:com.adito.upgrade.CommandLineUpgrader.java
public CommandLineUpgrader(String[] args) throws Exception { File oldDir = new File(args[0]); if (!oldDir.exists() || !oldDir.isDirectory()) { System.err.println(oldDir.getAbsolutePath() + " does not exists or is not a directory"); System.exit(1);/* w w w .j a v a2s .c om*/ } File newDir = new File(args[1]); if (!newDir.exists() || !newDir.isDirectory()) { System.err.println(newDir.getAbsolutePath() + " does not exists or is not a directory"); System.exit(1); } if (oldDir.getCanonicalFile().equals(newDir.getCanonicalFile())) { System.err.println("Old and new installation directories are identical"); System.exit(1); } if (!new File(newDir, "install").exists()) { System.err.println("New installation does not appear to be 0.2.5+"); System.exit(1); } if (!new File(oldDir, "upgrade").exists()) { System.err.println("Old installation does not appear to be 0.1.15+"); System.exit(1); } File oldDbDir = new File(oldDir, "db"); File newDbDir = new File(newDir, "db"); upgrades = new ArrayList(); upgrades.add(new UserUpgrade(oldDbDir, newDbDir)); upgrades.add(new AuthSchemeUpgrade(oldDbDir, newDbDir)); upgrades.add(new TunnelsUpgrade(oldDbDir, newDbDir)); upgrades.add(new NetworkPlacesUpgrade(oldDbDir, newDbDir)); upgrades.add(new WebForwardsUpgrade(oldDbDir, newDbDir)); upgrades.add(new IPRestrictionsUpgrade(oldDbDir, newDbDir)); upgrades.add(new ApplicationShortcutsUpgrade(oldDbDir, newDbDir)); upgrades.add(new ReplacementsUpgrade(oldDbDir, newDbDir)); }