/** * 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); } }
/** * {@inheritDoc} */ @Override public String getName() { if (getHome() != null && getFileHandler().exists(getFileHandler().append(getHome(), "start.jar"))) { return "Jetty " + getVersion(); } else { String className = this.getClass().getName(); int jettyStart = className.lastIndexOf(".Jetty") + 6; String version = className.substring(jettyStart, className.indexOf('x', jettyStart)); return "Jetty " + version + ".x"; } }
/** * {@inheritDoc} */ @Override public String getName() { if (getHome() != null && getFileHandler().exists(getFileHandler().append(getHome(), "start.jar"))) { return "Jetty " + getVersion(); } else { String className = this.getClass().getName(); int jettyStart = className.lastIndexOf(".Jetty") + 6; String version = className.substring(jettyStart, className.indexOf('x', jettyStart)); return "Jetty " + version + ".x"; } }
/** * Check if resource is deployed as module. * @param container WildFly installed local container. * @param jarFile JAR resource representing module. * @return true if module representing this dependency is already deployed */ public static boolean isModuleDeployed(InstalledLocalContainer container, String jarFile) { FileHandler fileHandler = container.getFileHandler(); String moduleArtifactName = getModuleArtifactName(jarFile, fileHandler); String folder = container.getHome() + "/modules/org/codehaus/cargo/classpath/" + moduleArtifactName + "/main"; if (fileHandler.exists(folder)) { return true; } return false; }
/** * Check if resource is deployed as module. * @param container WildFly installed local container. * @param jarFile JAR resource representing module. * @return true if module representing this dependency is already deployed */ public static boolean isModuleDeployed(InstalledLocalContainer container, String jarFile) { FileHandler fileHandler = container.getFileHandler(); String moduleArtifactName = getModuleArtifactName(jarFile, fileHandler); String folder = container.getHome() + "/modules/org/codehaus/cargo/classpath/" + moduleArtifactName + "/main"; if (fileHandler.exists(folder)) { return true; } return false; }
/** * @return true if the container has already been extracted, false otherwise */ public boolean isAlreadyExtracted() { boolean isExtracted = false; String timestampFile = getFileHandler().append(getExtractDir(), ".cargo"); if (getFileHandler().exists(timestampFile)) { isExtracted = true; } return isExtracted; }
/** * @return true if the container has already been downloaded, false otherwise */ public boolean isAlreadyDownloaded() { boolean isDownloaded = false; String targetFile = getFileHandler().append(getDownloadDir(), getSourceFileName()); if (getFileHandler().exists(targetFile)) { isDownloaded = true; } return isDownloaded; }
/** * Check if the directory exists. * * @param dir the directory name */ protected void checkDirExists(String dir) { String path = getFileHandler().append(getHome(), dir); boolean exists = getFileHandler().exists(path); if (!exists) { throw new ContainerException("Invalid existing configuration: directory [" + path + "] does not exist in JONAS_BASE"); } }
/** * Check if the directory exists. * * @param dir the directory name */ protected void checkDirExists(String dir) { String path = getFileHandler().append(getHome(), dir); boolean exists = getFileHandler().exists(path); if (!exists) { throw new ContainerException("Invalid existing configuration: directory [" + path + "] does not exist in JONAS_BASE"); } }
/** * Removes previously deployed artifact. * * @param deployable artifact to undeploy */ @Override public void undeploy(Deployable deployable) { if (deployable.getType() != DeployableType.WAR) { super.undeploy(deployable); return; } WAR war = (WAR) deployable; String fileName = getFileHandler().append(getDeployableDir(deployable), war.getContext() + ".war"); if (getFileHandler().exists(fileName)) { getLogger().info("Undeploying [" + fileName + "]...", this.getClass().getName()); getFileHandler().delete(fileName); } }
/** * Removes previously deployed artifact. * * @param deployable artifact to undeploy */ @Override public void undeploy(Deployable deployable) { if (deployable.getType() != DeployableType.WAR) { super.undeploy(deployable); return; } WAR war = (WAR) deployable; String fileName = getFileHandler().append(getDeployableDir(deployable), war.getContext() + ".war"); if (getFileHandler().exists(fileName)) { getLogger().info("Undeploying [" + fileName + "]...", this.getClass().getName()); getFileHandler().delete(fileName); } }
/** * 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); } }
/** * 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 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")); } }
/** * 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")); }
/** * {@inheritDoc} */ @Override protected void doConfigure(LocalContainer c) throws Exception { InstalledLocalContainer container = (InstalledLocalContainer) c; setupConfigurationDir(); // Copy initial configuration String initialConfiguration = getFileHandler().append(container.getHome(), "standalone"); getFileHandler().copyDirectory(initialConfiguration, getHome()); String configurationXmlFile = "configuration/" + getPropertyValue(JBossPropertySet.CONFIGURATION) + ".xml"; String configurationXML = getFileHandler().append(getHome(), configurationXmlFile); if (!getFileHandler().exists(configurationXML)) { throw new CargoException("Missing configuration XML file: " + configurationXML); } getLogger().info("Configuring JBoss using the [" + getPropertyValue(JBossPropertySet.CONFIGURATION) + "] server configuration", this.getClass().getName()); // Set user properties. createMgmtUsersProperties(); createApplicationUsersProperties(); createApplicationRolesProperties(); }
/** * {@inheritDoc} */ @Override protected void doConfigure(LocalContainer c) throws Exception { InstalledLocalContainer container = (InstalledLocalContainer) c; setupConfigurationDir(); // Copy initial configuration String initialConfiguration = getFileHandler().append(container.getHome(), "standalone"); getFileHandler().copyDirectory(initialConfiguration, getHome()); String configurationXmlFile = "configuration/" + getPropertyValue(JBossPropertySet.CONFIGURATION) + ".xml"; String configurationXML = getFileHandler().append(getHome(), configurationXmlFile); if (!getFileHandler().exists(configurationXML)) { throw new CargoException("Missing configuration XML file: " + configurationXML); } getLogger().info("Configuring JBoss using the [" + getPropertyValue(JBossPropertySet.CONFIGURATION) + "] server configuration", this.getClass().getName()); // Set user properties. createMgmtUsersProperties(); createApplicationUsersProperties(); createApplicationRolesProperties(); }
if (!getFileHandler().exists(varDirectory))
if (!getFileHandler().exists(varDirectory))