/** * {@inheritDoc} */ @Override public boolean isExpanded() { return getFileHandler().isDirectory(getFile()); }
/** * adds the location to the list, if the file exists. * * @param location path to add to the list * @param list where to append this path */ public void ifPresentAddPathToList(String location, List<String> list) { if (location == null || !this.getFileHandler().exists(location) || this.getFileHandler().isDirectory(location)) { throw new IllegalArgumentException("Invalid file path: " + location); } list.add(location); } }
/** * Write post Resources using with a StringBuilder * * @param path will be in the post resource * @param sb the StringBuilder we fill */ private void writePostResource(String path, StringBuilder sb) { if (getFileHandler().isDirectory(path)) { writeDirectoryPostResource(sb, path); } else if (path.toLowerCase().endsWith(".jar")) { writeJarPostResource(sb, path); } else { writeFilePostResource(sb, path); } }
/** * Write post Resources using with a StringBuilder * * @param path will be in the post resource * @param sb the StringBuilder we fill */ private void writePostResource(String path, StringBuilder sb) { if (getFileHandler().isDirectory(path)) { writeDirectoryPostResource(sb, path); } else if (path.toLowerCase().endsWith(".jar")) { writeJarPostResource(sb, path); } else { writeFilePostResource(sb, path); } }
/** * Write post Resources using with a PostResources xml element * * @param path will be in the post resource * @param postResourceEl the xml element we fill */ private void writePostResource(String path, Element postResourceEl) { if (getFileHandler().isDirectory(path)) { writeDirectoryPostResource(postResourceEl, path); } else if (path.toLowerCase().endsWith(".jar")) { writeJarPostResource(postResourceEl, path); } else { writeFilePostResource(postResourceEl, path); } }
/** * Write post Resources using with a PostResources xml element * * @param path will be in the post resource * @param postResourceEl the xml element we fill */ private void writePostResource(String path, Element postResourceEl) { if (getFileHandler().isDirectory(path)) { writeDirectoryPostResource(postResourceEl, path); } else if (path.toLowerCase().endsWith(".jar")) { writeJarPostResource(postResourceEl, path); } else { writeFilePostResource(postResourceEl, path); } }
/** * Resolves a file/directory path into a map of file paths which specifies each file of the * directory, or the file itself. * * @param files The map to put each resolved file in. * @param file The absolute file path to resolve. * @param relativePath The relative path of the file. */ private void resolveFile(Map<String, String> files, String file, String relativePath) { if (fileHandler.isDirectory(file)) { String[] children = fileHandler.getChildren(file); if (children != null && children.length != 0) { for (String child : children) { resolveFile(files, child, fileHandler.append(relativePath, fileHandler.getName(child))); } } } else { files.put(relativePath, file); } }
/** * Resolves a file/directory path into a map of file paths which specifies each file of the * directory, or the file itself. * * @param files The map to put each resolved file in. * @param file The absolute file path to resolve. * @param relativePath The relative path of the file. */ private void resolveFile(Map<String, String> files, String file, String relativePath) { if (fileHandler.isDirectory(file)) { String[] children = fileHandler.getChildren(file); if (children != null && children.length != 0) { for (String child : children) { resolveFile(files, child, fileHandler.append(relativePath, fileHandler.getName(child))); } } } else { files.put(relativePath, file); } }
/** * @param container the local installed container into which to perform deployment operations */ public AbstractLocalDeployer(LocalContainer container) { super(container); this.container = container; String configurationHome = container.getConfiguration().getHome(); if (configurationHome != null && !getFileHandler().isDirectory(configurationHome)) { throw new CargoException("The container configuration directory \"" + configurationHome + "\" does not exist. Please configure the container before " + "attempting to perform any local deployment. Read more on: " + "https://codehaus-cargo.github.io/cargo/Local+Configuration.html"); } }
if (getFileHandler().isDirectory(npnFolder))
if (getFileHandler().isDirectory(npnFolder))
/** * Verify that the home property has been set. */ private void verifyHome() { if (getHome() == null) { throw new ContainerException("You must set the mandatory [home] property"); } if (!getFileHandler().isDirectory(getHome())) { throw new ContainerException("[" + getHome() + "] is not a directory. It must point " + "to the container home directory."); } }
/** * Test the {@link FileHandler#isDirectory(java.lang.String)} method. * @throws Exception If anything goes wrong. */ public void testIsDirectory() throws Exception { this.fsManager.resolveFile("ram:///some/file").createFile(); assertFalse(this.fileHandler.isDirectory("ram:///some/file")); this.fsManager.resolveFile("ram:///some/path").createFolder(); assertTrue(this.fileHandler.isDirectory("ram:///some/path")); }
/** * Delete old profile. * @throws Exception if any error is raised during deleting of profile */ private void deleteOldProfile() throws Exception { getLogger().info("Deleting old profile.", this.getClass().getName()); // Delete profile in WebSphere wsContainer.runManageProfileCommand( "-delete", "-profileName", getPropertyValue(WebSpherePropertySet.PROFILE)); // Profile directory has to be deleted too. getLogger().debug("Deleting profile folder " + getHome(), this.getClass().getName()); getFileHandler().delete(getHome()); if (getFileHandler().isDirectory(getHome())) { throw new CargoException("Directory " + getHome() + " cannot be deleted"); } // Update profile informations in WebSphere wsContainer.runManageProfileCommand("-validateAndUpdateRegistry"); }
/** * read the specified file into a Document. * * @param sourceFile file to read * @return Document corresponding with sourceFile */ public Document loadXmlFromFile(String sourceFile) { if (!getFileHandler().exists(sourceFile)) { throw new CargoException("Cannot find file: " + sourceFile); } if (getFileHandler().isDirectory(sourceFile)) { throw new CargoException("The destination is a directory: " + sourceFile); } try (InputStream is = getFileHandler().getInputStream(sourceFile)) { return this.builder.parse(is); } catch (Exception e) { throw new CargoException("Cannot parse XML file " + sourceFile, e); } }
/** * Test file copy to a non-existing path.<br> * This has been raised by https://codehaus-cargo.atlassian.net/browse/CARGO-1004 */ public void testCopyToNonExistingPath() { String random = UUID.randomUUID().toString(); assertFalse("Subdirectory " + random + " already exists", this.fileHandler.isDirectory("target/" + random)); this.fileHandler.createFile("target/random.txt"); this.fileHandler.copyFile("target/random.txt", "target/" + random + "/random.txt", new FilterChain(), "UTF-8"); assertTrue("Subdirectory " + random + " does not exist after copy", this.fileHandler.isDirectory("target/" + random)); assertTrue("File in subdirectory " + random + " missing after copy", this.fileHandler.exists("target/" + random + "/random.txt")); }
/** * read the specified file into a Document. * * @param sourceFile file to read * @return Document corresponding with sourceFile */ public Document loadXmlFromFile(String sourceFile) { if (!getFileHandler().exists(sourceFile)) { throw new CargoException("Cannot find file: " + sourceFile); } if (getFileHandler().isDirectory(sourceFile)) { throw new CargoException("The destination is a directory: " + sourceFile); } try (InputStream is = getFileHandler().getInputStream(sourceFile)) { return this.builder.parse(is); } catch (Exception e) { throw new CargoException("Cannot parse XML file " + sourceFile, e); } }
this.getClass().getName()); if (!getFileHandler().isDirectory(deployableDir)) if (deployable.isExpanded()) if (getFileHandler().exists(target) && !getFileHandler().isDirectory(target)) if (getFileHandler().exists(target) && getFileHandler().isDirectory(target))
/** * Test the {@link FileHandler#createDirectory(java.lang.String, java.lang.String)} method. */ public void testCreateDirectory() { this.fileHandler.createDirectory("ram://test", "test"); assertTrue(this.fileHandler.exists("ram:///test/test")); assertTrue(this.fileHandler.isDirectory("ram:///test/test")); this.fileHandler.createDirectory("ram://test2/", "test"); assertTrue(this.fileHandler.exists("ram:///test2/test")); assertTrue(this.fileHandler.isDirectory("ram:///test2/test")); this.fileHandler.createDirectory("ram://test3", "/test"); assertTrue(this.fileHandler.exists("ram:///test3/test")); assertTrue(this.fileHandler.isDirectory("ram:///test3/test")); this.fileHandler.createDirectory(null, "ram://test4"); assertTrue(this.fileHandler.exists("ram:///test4")); assertTrue(this.fileHandler.isDirectory("ram:///test4")); this.fileHandler.createDirectory("ram://test5", null); assertTrue(this.fileHandler.exists("ram:///test5")); assertTrue(this.fileHandler.isDirectory("ram:///test5")); } }
/** * {@inheritDoc}. For TomEE this is the <code>apps</code> directory for EARs as well as EJBs * and the <code>webapps</code> directory for WARs. */ @Override public String getDeployableDir(Deployable deployable) { if (DeployableType.EAR.equals(deployable.getType()) || DeployableType.EJB.equals(deployable.getType())) { String apps = getContainer().getConfiguration().getPropertyValue( TomeePropertySet.APPS_DIRECTORY); String appsDirectory = getFileHandler().append(getContainer().getConfiguration().getHome(), apps); if (!getFileHandler().isDirectory(appsDirectory)) { appsDirectory = getFileHandler().createDirectory( getContainer().getConfiguration().getHome(), apps); } return appsDirectory; } else { return super.getDeployableDir(deployable); } } }