List of usage examples for org.apache.commons.vfs FileObject resolveFile
public FileObject resolveFile(String path) throws FileSystemException;
From source file:org.jclouds.vfs.provider.blobstore.test.BlobStoreProviderTestCase.java
private void writeFile(FileObject base, String name, String value) throws FileSystemException, IOException { FileObject file = base.resolveFile(name); FileContent content = file.getContent(); CharStreams.write(value, CharStreams .newWriterSupplier(Utils.newOutputStreamSupplier(content.getOutputStream()), Charsets.UTF_8)); content.close();//w w w.j av a 2s . c o m }
From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java
/** * Does a 'cp' command./*from w ww .ja va 2 s .c o m*/ */ private void cp(final String[] cmd) throws Exception { if (cmd.length < 3) { throw new Exception("USAGE: cp <src> <dest>"); } FileObject src = remoteMgr.resolveFile(remoteCwd, cmd[1]); FileObject dest = remoteMgr.resolveFile(remoteCwd, cmd[2]); if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } dest.copyFrom(src, Selectors.SELECT_ALL); }
From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java
/** * Does a 'get' command./*from w w w .ja v a 2s .c om*/ */ private void get(final String[] cmd) throws Exception { if (cmd.length < 3) { throw new Exception("USAGE: get <src> <dest>"); } FileObject src = remoteMgr.resolveFile(remoteCwd, cmd[1]); FileObject dest = mgr.resolveFile(cwd, cmd[2]); if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } dest.copyFrom(src, Selectors.SELECT_ALL); }
From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java
/** * Does a 'put' command./*from ww w .j a v a2s . c o m*/ */ private void put(final String[] cmd) throws Exception { if (cmd.length < 3) { throw new Exception("USAGE: put <src> <dest>"); } FileObject src = mgr.resolveFile(cwd, cmd[2]); FileObject dest = remoteMgr.resolveFile(remoteCwd, cmd[1]); if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } dest.copyFrom(src, Selectors.SELECT_ALL); }
From source file:org.josso.tooling.gshell.install.installer.JBossInstaller.java
protected void configureServerXml() throws InstallException { // -------------------------------------------------------------------- // Configure server.xml // -------------------------------------------------------------------- // We will use xupdate to alter catalina configuration : server.xml FileObject serverXml = null;// w w w .j ava 2 s. com try { String jbossWeb = "jbossweb.sar"; // jboss 5 by default if (getPlatformVersion().startsWith("4.2")) jbossWeb = "jboss-web.deployer"; else if (getPlatformVersion().startsWith("4.0")) jbossWeb = "jbossweb-tomcat55.sar"; else if (getPlatformVersion().startsWith("3.2")) jbossWeb = "jbossweb-tomcat50.sar"; FileObject targetJBossWebDir = targetDeployDir.resolveFile(jbossWeb); serverXml = targetJBossWebDir.resolveFile("server.xml"); // Get a DOM document of the server.xml : Node serverXmlDom = readContentAsDom(serverXml); boolean modified = false; // Perfomr specific configurations if (configureRealm(serverXmlDom)) modified = true; if (configureValve(serverXmlDom)) modified = true; if (modified) { // Backup Container configuration. If we cannot perform a backup, do nothing if (!backupFile(serverXml, targetJBossWebDir)) { getPrinter().printActionWarnStatus("Configure", targetJBossWebDir.getName().getFriendlyURI() + "/server.xml", "Must be done manually (Follow setup guide)"); return; } // Write modifications to file writeContentFromDom(serverXmlDom, serverXml); getPrinter().printActionOkStatus("Save", serverXml.getName().getBaseName(), serverXml.getName().getFriendlyURI()); } } catch (Exception e) { log.error(e.getMessage(), e); getPrinter().printErrStatus("Cannot configure container : ", e.getMessage()); getPrinter().printActionWarnStatus("Configure", targetConfDir.getName().getFriendlyURI() + "/server.xml", "Must be done manually (Follow setup guide)"); } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean backupFile(FileObject src, FileObject targetDir) { try {//from ww w . j a va 2 s . com int attempt = 1; FileObject bkp = targetDir.resolveFile(src.getName().getBaseName() + ".bkp." + attempt); while (bkp.exists() && attempt < 99) { attempt++; bkp = targetDir.resolveFile(src.getName().getBaseName() + ".bkp." + attempt); } if (bkp.exists()) { getPrinter().printActionErrStatus("Backup", src.getName().getBaseName(), "Too many backups already"); return false; } bkp.copyFrom(src, Selectors.SELECT_SELF); getPrinter().printActionOkStatus("Backup", src.getName().getBaseName(), bkp.getName().getFriendlyURI()); return true; } catch (IOException e) { getPrinter().printActionErrStatus("Backup", src.getName().getBaseName(), e.getMessage()); return false; } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean installFile(String fileName, FileObject srcDir, FileObject destDir, boolean replace) throws IOException { try {/*from w w w. j av a 2 s .c o m*/ FileObject srcFile = srcDir.resolveFile(fileName); return installFile(srcFile, destDir, srcFile.getName().getBaseName(), replace); } finally { printer.flush(); } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean installFile(FileObject srcFile, FileObject destDir, String newName, boolean replace) throws IOException { try {/*from w w w. ja v a 2 s . c o m*/ String fname = srcFile.getName().getBaseName(); if (srcFile == null || !srcFile.exists()) { printInstallErrStatus(fname, "Source file not found " + fname); throw new IOException("Source file not found " + fname); } // Validates src and dest files if (destDir == null || !destDir.exists()) { printInstallErrStatus(fname, "Target directory not found " + destDir.getURL()); throw new IOException("Target directory not found " + destDir.getURL()); } FileObject destFile = destDir.resolveFile(newName); boolean exists = destFile.exists(); if (!replace && exists) { printInstallWarnStatus(fname, "Not replaced (see --replace option)"); if (fname.equals("josso-agent-config.xml")) { agentConfigFileInstalled = false; } return false; } FileUtil.copyContent(srcFile, destFile); printInstallOkStatus(fname, (exists ? "Replaced " : "Created ") + destFile.getName().getFriendlyURI()); return true; } finally { printer.flush(); } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
/** * @param srcFolder// w w w. ja v a 2 s . c o m * @param destDir * @param replace * @throws java.io.IOException */ protected void installFolder(FileObject srcFolder, FileObject destDir, String newName, boolean replace) throws IOException { // Check destination folder if (!destDir.exists()) { printInstallErrStatus(srcFolder.getName().getBaseName(), "Target directory not found " + destDir.getName().getBaseName()); throw new IOException("Target directory not found " + destDir.getName().getBaseName()); } // This is the new folder we're creating in destination. FileObject newFolder = destDir.resolveFile(newName); boolean exists = newFolder.exists(); if (!replace && exists) { printInstallWarnStatus(newFolder.getName().getBaseName(), "Not replaced (see --replace option)"); return; } if (exists) { // remove all descendents (removes old jars and other files when upgrading josso gateway) newFolder.delete(Selectors.EXCLUDE_SELF); } newFolder.copyFrom(srcFolder, Selectors.SELECT_ALL); // Copy ALL descendats printInstallOkStatus(srcFolder.getName().getBaseName(), (exists ? "Replaced " : "Created ") + newFolder.getName().getFriendlyURI()); }
From source file:org.josso.tooling.gshell.install.installer.WasceInstaller.java
@Override public void performAdditionalTasks(FileObject libsDir) throws InstallException { try {//from ww w. j a v a 2 s. com // undeploy wasce tomcat6 module if exists FileObject tomcatModule = targetDir.resolveFile("repository/org/apache/geronimo/configs/tomcat6"); if (tomcatModule.exists()) { getPrinter().printMsg("Undeploying tomcat6 module"); int status = undeploy("tomcat6"); if (status == 0) { getPrinter().printOkStatus("Undeploy tomcat6 module", "Successful"); } else { getPrinter().printErrStatus("Undeploy tomcat6 module", "Error"); throw new InstallException("Error undeploying tomcat6 module!!!"); } } // undeploy old josso wasce agent if exists FileObject jossoWasceAgentModule = targetDir.resolveFile("repository/org/josso/josso-wasce-agent"); if (jossoWasceAgentModule.exists()) { getPrinter().printMsg("Undeploying old josso wasce agent"); int status = undeploy("josso-wasce-agent"); if (status == 0) { getPrinter().printOkStatus("Undeploy josso wasce agent", "Successful"); } else { getPrinter().printErrStatus("Undeploy josso wasce agent", "Error"); throw new InstallException("Error undeploying josso wasce agent!!!"); } } // install jars to wasce repository try { getPrinter().printMsg("Installing new jars to WASCE repository"); FileObject wasceRepo = targetDir.resolveFile("repository"); FileObject wasceRepoFolder = libsDir.resolveFile("repository"); wasceRepo.copyFrom(wasceRepoFolder, Selectors.SELECT_ALL); getPrinter().printOkStatus("Install new jars", "Successful"); } catch (FileSystemException e) { getPrinter().printErrStatus("Install new jars", "Error"); throw new InstallException("Error copying jars to wasce repository!!!"); } // deploy josso wasce agent getPrinter().printMsg("Deploying josso wasce agent"); FileObject jossoWasceCarFile = null; FileObject[] agentBins = libsDir.getChildren(); for (int i = 0; i < agentBins.length; i++) { FileObject agentBin = agentBins[i]; if (agentBin.getName().getBaseName().startsWith("josso-wasce")) { jossoWasceCarFile = agentBin; break; } } if (jossoWasceCarFile == null) { throw new InstallException("Josso wasce agent car file doesn't exist!!!"); } int status = installPlugin(jossoWasceCarFile); if (status == 0) { getPrinter().printOkStatus("Install josso wasce agent", "Successful"); } else { getPrinter().printErrStatus("Install josso wasce agent", "Error"); throw new InstallException("Error installing josso wasce agent!!!"); } // start stopped services getPrinter().printMsg("Starting tomcat related services"); status = startTomcatRelatedServices(); if (status == 0) { getPrinter().printOkStatus("Start tomcat related services", "Successful"); } else { getPrinter().printErrStatus("Start tomcat related services", "Error"); throw new InstallException("Error starting tomcat related services!!!"); } } catch (IOException e) { throw new InstallException(e.getMessage(), e); } }