/** * @param assembleDir directory to copy JAR files to */ private void copyJars(String assembleDir) { FileHandler fileHandler = new DefaultFileHandler(); File f = new File(assembleDir); File webInfLib = new File(f, "WEB-INF/lib"); fileHandler.mkdirs(webInfLib.getAbsolutePath()); for (File sourceFile : this.jarFiles) { fileHandler.copyFile(sourceFile.getAbsolutePath(), new File(webInfLib, sourceFile .getName()).getAbsolutePath()); } }
/** * @param assembleDir directory to copy JAR files to */ private void copyJars(String assembleDir) { FileHandler fileHandler = new DefaultFileHandler(); File f = new File(assembleDir); File webInfLib = new File(f, "WEB-INF/lib"); fileHandler.mkdirs(webInfLib.getAbsolutePath()); for (File sourceFile : this.jarFiles) { fileHandler.copyFile(sourceFile.getAbsolutePath(), new File(webInfLib, sourceFile .getName()).getAbsolutePath()); } }
getFileHandler().copyFile(from + "/" + path, to + "/" + path); if (spaceHotFix.exists()) getFileHandler().copyFile(spaceHotFix.getAbsolutePath(), to + "/servers/lib/54101.jar"); getFileHandler().copyFile(from + "/bin/jrun.exe", to + "/bin/jrun.exe"); getFileHandler().copyFile(from + "/bin/jrun", to + "/bin/jrun");
/** * {@inheritDoc} */ @Override protected void setupManager(LocalContainer container) { String from = ((InstalledLocalContainer) container).getHome(); String to = getHome(); getFileHandler().copyDirectory(from + "/server/webapps/manager", to + "/server/webapps/manager"); getFileHandler().copyFile(from + "/webapps/manager.xml", to + "/webapps/manager.xml"); }
/** * {@inheritDoc} */ @Override protected void setupManager(LocalContainer container) { String from = ((InstalledLocalContainer) container).getHome(); String to = getHome(); getFileHandler().copyDirectory(from + "/server/webapps/manager", to + "/server/webapps/manager"); getFileHandler().copyFile(from + "/webapps/manager.xml", to + "/webapps/manager.xml"); }
/** * {@inheritDoc} this does not deploy the manager, if the application is embedded. */ @Override protected void setupManager(LocalContainer container) { if (container instanceof EmbeddedLocalContainer) { // when running in the embedded mode, there's no need of any manager application. } else { String from = ((InstalledLocalContainer) container).getHome(); String to = getHome(); getFileHandler().copyDirectory(from + "/server/webapps/manager", to + "/server/webapps/manager"); getFileHandler().copyFile(from + "/conf/Catalina/localhost/manager.xml", to + "/conf/Catalina/localhost/manager.xml"); } }
getFileHandler().copyFile(closest, expected);
String tempFile = getFileHandler().append(getHome(), configurationXmlFile + ".temp"); getFileHandler().copyFile(customConfigurationXML, tempFile); getFileHandler().copyFile(defaultConfigurationXML, customConfigurationXML); getFileHandler().copyFile(tempFile, defaultConfigurationXML); getFileHandler().delete(tempFile);
/** * {@inheritDoc} this does not deploy the manager, if the application is embedded. */ @Override protected void setupManager(LocalContainer container) { if (container instanceof EmbeddedLocalContainer) { // when running in the embedded mode, there's no need of any manager application. } else { String from = ((InstalledLocalContainer) container).getHome(); String to = getHome(); getFileHandler().copyDirectory(from + "/server/webapps/manager", to + "/server/webapps/manager"); getFileHandler().copyFile(from + "/conf/Catalina/localhost/manager.xml", to + "/conf/Catalina/localhost/manager.xml"); } }
/** * Test non-existing XML attribute replacement */ public void testNonExistingXmlAttributeReplacement() { final String file = "target/jboss-standalone-nonexisting-xml-attribute.xml"; final String nonExistingAttribute = "nonexisting"; final String test = "nonexisting=\"test\""; this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true); XmlReplacement xmlReplacement = new XmlReplacement(file, "//server/socket-binding-group/socket-binding[@name='http']", nonExistingAttribute, XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test"); this.fileHandler.replaceInXmlFile(xmlReplacement); String read = this.fileHandler.readTextFile(file, "UTF-8"); assertTrue("File " + file + " does not contain: " + test, read.contains(test)); }
((InstalledLocalContainer) container).getHome(), "conf"); getFileHandler().copyFile(getFileHandler().append(sourceConf, "app-default.xml"), getFileHandler().append(confDir, "app-default.xml")); getFileHandler().copyFile(getFileHandler().append(sourceConf, "resin.conf"), getFileHandler().append(confDir, "resin.conf"));
((InstalledLocalContainer) container).getHome(), "conf"); getFileHandler().copyFile(getFileHandler().append(sourceConf, "app-default.xml"), getFileHandler().append(confDir, "app-default.xml")); getFileHandler().copyFile(getFileHandler().append(sourceConf, "resin.conf"), getFileHandler().append(confDir, "resin.conf"));
/** * Test valid XML replacement for replacing a neighbor */ public void testXmlNeighborReplacement() { final String file = "target/bindings-jboss-beans.xml"; final String old = "<property name=\"port\">@cargo.rmi.port@</property>"; final String permanent = "<property name=\"port\">@cargo.jboss.naming.port@</property>"; final String new1 = "<property name=\"port\">test1</property>"; this.fileHandler.copyFile("src/test/resources/bindings-jboss-beans.xml", file, true); String read = this.fileHandler.readTextFile(file, "UTF-8"); assertTrue("File " + file + " does not contain: " + old, read.contains(old)); assertTrue("File " + file + " does not contain: " + permanent, read.contains(permanent)); XmlReplacement xmlReplacement = new XmlReplacement(file, "//deployment/bean[@name='StandardBindings']/constructor/parameter/set/bean" + "/property[@name='serviceName' and text()='jboss:service=Naming']/.." + "/property[@name='bindingName' and text()='Port']/.." + "/property[@name='port']", null, XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test1"); this.fileHandler.replaceInXmlFile(xmlReplacement); read = this.fileHandler.readTextFile(file, "UTF-8"); assertFalse("File " + file + " still contains: " + old, read.contains(old)); assertTrue("File " + file + " does not contain: " + new1, read.contains(new1)); assertTrue("File " + file + " does not contain anymore: " + permanent, read.contains(permanent)); }
/** * 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")); }
/** * Test valid XML replacement */ public void testValidXmlReplacement() { final String file = "target/jboss-standalone-valid.xml"; final String old = "<socket-binding name=\"http\" port=\"@cargo.servlet.port@\"/>"; final String new1 = "<socket-binding name=\"http\" port=\"test1\"/>"; final String new2 = "<socket-binding name=\"http\" port=\"test1\">test2</socket-binding>"; this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true); String read = this.fileHandler.readTextFile(file, "UTF-8"); assertTrue("File " + file + " does not contain: " + old, read.contains(old)); XmlReplacement xmlReplacement = new XmlReplacement(file, "//server/socket-binding-group/socket-binding[@name='http']", "port", XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test1"); this.fileHandler.replaceInXmlFile(xmlReplacement); read = this.fileHandler.readTextFile(file, "UTF-8"); assertFalse("File " + file + " still contains: " + old, read.contains(old)); assertTrue("File " + file + " does not contain: " + new1, read.contains(new1)); xmlReplacement.setAttributeName(null); xmlReplacement.setValue("test2"); this.fileHandler.replaceInXmlFile(xmlReplacement); read = this.fileHandler.readTextFile(file, "UTF-8"); assertFalse("File " + file + " still contains: " + old, read.contains(old)); assertFalse("File " + file + " still contains: " + new1, read.contains(new1)); assertTrue("File " + file + " does not contain: " + new2, read.contains(new2)); }
/** * Test invalid XML XPath replacement */ public void testInvalidXmlXpathReplacement() { final String file = "target/jboss-standalone-invalid-xpath.xml"; final String nonExistingXpath = "//server/socket-binding-group/socket-binding[@name='nonexisting']"; this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true); XmlReplacement xmlReplacement = new XmlReplacement(file, nonExistingXpath, null, XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test"); try { this.fileHandler.replaceInXmlFile(xmlReplacement); fail(); } catch (CargoException e) { assertNotNull(e.getCause()); assertNotNull(e.getCause().getMessage()); assertTrue(e.getCause().getMessage().contains( "Node " + nonExistingXpath + " not found")); } }
/** * Test the {@link FileHandler#copyFile(java.lang.String, java.lang.String, boolean)} method. * @throws Exception If anything goes wrong. */ public void testCopyFileOverwrite() throws Exception { String source = "ram:///some/path/file.war"; String target = "ram:///other/path/newfile.war"; FileObject sourceObject = this.fsManager.resolveFile(source); sourceObject.createFile(); FileObject targetObject = this.fsManager.resolveFile(target); assertFalse(targetObject.exists()); this.fileHandler.copyFile(source, target, true); assertTrue(targetObject.exists()); }
/** * Test the {@link FileHandler#copyFile(java.lang.String, java.lang.String)} method. * @throws Exception If anything goes wrong. */ public void testCopyFile() throws Exception { String source = "ram:///some/path/file.war"; String target = "ram:///other/path/newfile.war"; FileObject sourceObject = this.fsManager.resolveFile(source); sourceObject.createFile(); FileObject targetObject = this.fsManager.resolveFile(target); assertFalse(targetObject.exists()); this.fileHandler.copyFile(source, target); assertTrue(targetObject.exists()); }
getFileHandler().copyFile(deployable.getFile(), target, true);
this.fileHandler.copyFile(getTestData().getTestDataFileFor("simple-war"), urlInternal + "/cargo-simple-war.war");