List of usage examples for org.apache.commons.io FileUtils moveFile
public static void moveFile(File srcFile, File destFile) throws IOException
From source file:jp.primecloud.auto.process.lb.PuppetLoadBalancerProcess.java
protected void backupManifest(File manifestFile) { if (!manifestFile.exists()) { return;/*from w w w . j ava 2 s. c om*/ } // ?? File backupDir = new File(manifestDir, "backup"); File backupFile = new File(backupDir, manifestFile.getName()); try { if (!backupDir.exists()) { backupDir.mkdir(); } if (backupFile.exists()) { FileUtils.forceDelete(backupFile); } FileUtils.moveFile(manifestFile, backupFile); } catch (IOException e) { // ?? log.warn(e.getMessage()); } }
From source file:ddf.test.itests.platform.TestConfiguration.java
/** * Tests that when system properties file is missing, export fails * * @throws Exception/*from ww w.j a v a 2 s . c o m*/ */ @Test public void testExportFailureWithoutSystemPropertiesFile() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.moveFile(SYSTEM_PROPERTIES.toFile(), SYSTEM_PROPERTIES_COPY.toFile()); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Warning should have been returned when exporting to %s.", getDefaultExportDirectory()), response, containsString("Path [etc" + FILE_SEPARATOR + "system.properties] does not exist or cannot be read; therefore, it will not be included in the export.")); }
From source file:kr.co.leem.system.FileSystemUtils.java
/** * ? ??.//from w w w.j a v a 2s . com * * @param srcFile ? ? . * @param destFile ?? ? . * @see FileUtils#moveFile(File, File) */ public static void moveFile(final String srcFile, final String destFile) { processIO(new IOCallback<Object>() { public Object doInProcessIO() throws IOException, NullPointerException { FileUtils.moveFile(new File(srcFile), new File(destFile)); return null; } }); }
From source file:com.thoughtworks.cruise.ConfigureCruiseBy.java
@com.thoughtworks.gauge.Step("Moving password file to tmp") public void movingPasswordFileToTmp() throws Exception { String path = passwordFilePath(); String tmpPath = tmpPath(path); FileUtils.deleteQuietly(new File(tmpPath)); FileUtils.moveFile(new File(path), new File(tmpPath)); }
From source file:com.thoughtworks.cruise.ConfigureCruiseBy.java
public void restoreThePasswordFile() throws Exception { String path = passwordFilePath(); FileUtils.moveFile(new File(tmpPath(path)), new File(path)); }
From source file:jp.primecloud.auto.process.puppet.PuppetNodesProcess.java
protected void backupManifest(Long instanceNo) { Instance instance = instanceDao.read(instanceNo); File manifestFile = new File(manifestDir, instance.getFqdn() + ".base_coordinate.pp"); if (!manifestFile.exists()) { return;/*from w w w. j ava 2 s .c o m*/ } // ?? File backupDir = new File(manifestDir, "backup"); File backupFile = new File(backupDir, manifestFile.getName()); try { if (!backupDir.exists()) { backupDir.mkdir(); } if (backupFile.exists()) { FileUtils.forceDelete(backupFile); } FileUtils.moveFile(manifestFile, backupFile); } catch (IOException e) { // ?? log.warn(e.getMessage()); } }
From source file:com.edgenius.wiki.service.impl.ThemeServiceImpl.java
public void installTheme(File themeFile) throws ThemeInvalidException, ThemeInvalidVersionException { try {//from w w w . j av a 2 s. c o m String name = explodeTheme(themeFile, true); //put install file to resource directory, replace old one if existing. File installFile = new File(themeResourcesRoot.getFile(), name + INSTALL_EXT_NAME); if (installFile.exists()) { installFile.delete(); } FileUtils.moveFile(themeFile, installFile); } catch (ThemeInvalidException e) { log.error("Unable to install theme.", e); throw e; } catch (IOException e) { log.error("Unable to install theme.", e); throw new ThemeInvalidException(e); } }
From source file:interfazGrafica.frmMoverRFC.java
private void BotonLigarCURPRFCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonLigarCURPRFCActionPerformed String curp = ""; curp = txtCapturaCurp.getText();//w ww . j a v a2 s .c om String ct = ""; String nombre_archivo = ""; String sigExp = ""; String qconsultaCURP = ""; RFCescaneado NombreArchivo = new RFCescaneado(); nombre_archivo = NombreArchivo.obtenerArchivosExp().nombre; //nombreArchivo.setText(Nombre_Archivo); System.out.println("Nombre del archivo obtenido de obtenerArchivosExp" + nombre_archivo); qconsultaCURP = "select ct from curp_rfc where curp ='" + curp + "'"; System.out.println("" + qconsultaCURP); Configuracion bd = new Configuracion(); bd.conectarBD(); try { bd.statement = bd.connection.createStatement(); System.out.println("cree el statement:"); bd.resultSet = bd.statement.executeQuery(qconsultaCURP); if (bd.resultSet.next()) { ct = bd.resultSet.getString("ct"); System.out.println("Ct correspondiente de la bd al curp :" + ct); } bd.cerrarConexion(); } catch (SQLException ex) { System.out.println("Entre al catch"); } doc = this.RenombrarArchivo(ct, nombre_archivo, curp); File origen = new File("C:\\escaneos\\Local\\CarpetaRFC\\" + doc.nuevoNombre); File dest = new File(doc.rutades + doc.nuevoNombre); File tempo = new File("C:\\escaneos\\Local\\Temporal\\"/*+doc.nuevoNombre*/); //File local = new File () try { FileUtils.moveFile(origen, dest); } catch (IOException ex) { JOptionPane.showMessageDialog(botonAnt, "Ya existe un RFC ligado a ese CURP favor de revisar que sea correcto"); Logger.getLogger(frmMoverRFC.class.getName()).log(Level.SEVERE, null, ex); } if (tempo.listFiles().length > 1) { System.out.println("Existen documentos en temporal "); File directorio = new File("C:\\escaneos\\Local\\Temporal\\"); File[] ficheros = directorio.listFiles(); System.out.println("Borre el archivo temporal" + ficheros.toString()); ficheros[0].delete(); System.out.println("Borrar: " + ficheros[0]); } expe.obtenerArchivoRemoto(); expe.copiarACarpetaTemporal(expe.toString()); expe.moverACarpetaLocal(expe.toString()); txtCapturaCurp.setText(""); mostrarPDF(); }
From source file:ddf.test.itests.platform.TestConfiguration.java
/** * Tests that when system properties file is missing, export fails * * @throws Exception/*from w ww .j a v a2 s . com*/ */ @Test public void testExportFailureWithoutUsersPropertiesFile() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.moveFile(USERS_PROPERTIES.toFile(), USERS_PROPERTIES_COPY.toFile()); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Warning should have been returned when exporting to %s.", getDefaultExportDirectory()), response, containsString("Path [etc" + FILE_SEPARATOR + "users.properties] does not exist or cannot be read; therefore, it will not be included in the export.")); }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.smartdeployment.main.SmartDeploymentService.java
private String enrich_CAMF_CSAR_Process(String csarTmp, String serviceName) { String extractedFolder = csarTmp + ".extracted"; String toscaFile = extractedFolder + "/Definitions/Application.tosca"; String scriptDir = extractedFolder + "/Scripts/"; try {/* w w w . j a v a 2s. c om*/ // extract CSAR CSARParser.extractCsar(new File(csarTmp), extractedFolder); // enrich with QUELLE for String toscaXML = FileUtils.readFileToString(new File(toscaFile)); EngineLogger.logger.debug("Read tosca string done. 100 first characters: {}", toscaXML); EngineLogger.logger.debug("Now trying to enrich with QUELLE...."); //enrichCAMFToscaWithQuelle(toscaXML, serviceName, new String[]{EnrichFunctions.QuelleCloudServiceRecommendation.toString(), EnrichFunctions.SalsaInfoCompletion.toString()}); SmartDeploymentService sds = new SmartDeploymentService(); String result = sds.enrichCAMFToscaWithQuelle(toscaXML, serviceName, new String[] { EnrichFunctions.QuelleCloudServiceRecommendation.toString() }); EngineLogger.logger.debug("After enrich with QUELLE, the result is: {}", result); // write back to right place FileUtils.writeStringToFile(new File(toscaFile), result); // read software requirement in TOSCA for each node, put in a map + artifact // a map between node ID and full requirement in Tag Map<String, String> allRequirements = new HashMap<>(); TDefinitions def = ToscaXmlProcess.readToscaFile(toscaFile); for (TNodeTemplate node : ToscaStructureQuery.getNodeTemplateList(def)) { EngineLogger.logger.debug("Checking node: {}", node.getId()); String policiesStr = new String(); if (node.getPolicies() != null) { EngineLogger.logger.debug("Found policies of node: " + node.getId() + "/" + node.getName()); List<TPolicy> policies = node.getPolicies().getPolicy(); for (TPolicy p : policies) { if (p.getPolicyType().getLocalPart().equals("Requirement") && p.getPolicyType().getPrefix().equals("SmartDeployment")) { if (p.getName().startsWith("CONSTRAINT")) { // TODO: parse SYBL policies } else { policiesStr += p.getName().trim(); if (!p.getName().trim().endsWith(";")) { policiesStr += ";"; EngineLogger.logger.debug("polociesStr = {}", policiesStr); } } } } } EngineLogger.logger.debug("Collected policies for node {} is : {}", node.getId(), policiesStr); allRequirements.put(node.getId(), policiesStr); } EngineLogger.logger.debug("In total, we got following requirements: " + allRequirements.toString()); // Load dependency graph knowledge base String dependencyDataFile = SmartDeploymentService.class.getResource("/data/salsa.dependencygraph.xml") .getFile(); SalsaStackDependenciesGraph depGraph = SalsaStackDependenciesGraph .fromXML(FileUtils.readFileToString(new File(dependencyDataFile))); // ENRICH SCRIPT // extract all the requirement, put into the hashmap for (Map.Entry<String, String> entry : allRequirements.entrySet()) { EngineLogger.logger.debug("Analyzing node: {}. Full policies string is: *** {} ***", entry.getKey(), entry.getValue()); // extract CARL Strings CharStream stream = new ANTLRInputStream(entry.getValue()); CARLLexer lexer = new CARLLexer(stream); CommonTokenStream tokens = new CommonTokenStream(lexer); CARLParser parser = new CARLParser(tokens); RequirementsContext requirementsContext = parser.requirements(); ParseTreeWalker walker = new ParseTreeWalker(); // create standard walker CARLProgramListener extractor = new CARLProgramListener(parser); walker.walk(extractor, requirementsContext); // initiate walk of tree with listener org.eclipse.camf.carl.model.Requirements requirements = extractor.getRequirements(); HashMap<String, String> allReqsOfNode = new HashMap<>(); ArrayList<String> checkList = new ArrayList<>(); // os=Ubuntu; os:ver=12.04; sw=jre:1.7 ==> os=Ubuntu, // here flat all the requirement of the node for (IRequirement req : requirements.getRequirements()) { EngineLogger.logger.debug("Irequirement: " + req.toString()); if (req.getCategory().equals(RequirementCategory.SOFTWARE)) { SoftwareRequirement swr = (SoftwareRequirement) req; allReqsOfNode.put("sw", removeQuote(swr.getName())); allReqsOfNode.put(removeQuote(swr.getName()) + ":ver", swr.getVersion().getVersion()); checkList.add(swr.getName()); } else { if (req.getCategory().equals(RequirementCategory.OPERATING_SYSTEM)) { // the system part is generated by quelle OSRequirement osReq = (OSRequirement) req; if (osReq.getName() != null) { allReqsOfNode.put("os", removeQuote(osReq.getName())); } if (osReq.getVersion() != null) { allReqsOfNode.put("os:ver", osReq.getVersion().getVersion()); } } } } // find all the deploymet script of all "sw" requirements LinkedList<String> listOfScripts = new LinkedList<>(); EngineLogger.logger.debug("The node {} will be enriched based-on the requirements: {}", entry.getKey(), checkList.toString()); for (String swReq : checkList) { EngineLogger.logger.debug("Searching deployment script for software req: {}", swReq); SalsaStackDependenciesGraph theNode = depGraph.findNodeByName(swReq); EngineLogger.logger.debug("Node found: {}", theNode.getName()); EngineLogger.logger.debug("All requirements: {}", allReqsOfNode.toString()); LinkedList<String> tmp = theNode.searchDeploymentScriptTemplate(allReqsOfNode); if (tmp != null) { listOfScripts.addAll(tmp); } } EngineLogger.logger.debug(listOfScripts.toString()); // create a script to solve all dependencies first String nodeID = entry.getKey(); String theDependencyScript = "#!/bin/bash \n\n######## Generated by the Decision Module to solve the software dependencies ######## \n\n"; for (String appendScript : listOfScripts) { String theAppend = SmartDeploymentService.class.getResource("/scriptRepo/" + appendScript) .getFile(); String stringToAppend = FileUtils.readFileToString(new File(theAppend)); theDependencyScript += stringToAppend + "\n"; } theDependencyScript += "######## End of generated script ########"; String tmpScriptFile = scriptDir + "/" + nodeID + ".salsatmp"; // read original script, remove the #!/bin/bash if having String originalScriptFile = null; TNodeTemplate node = ToscaStructureQuery.getNodetemplateById(nodeID, def); EngineLogger.logger.debug("Getting artifact template of node: {}", node.getId()); for (TDeploymentArtifact art : node.getDeploymentArtifacts().getDeploymentArtifact()) { EngineLogger.logger.debug("Checking art.Name: {}, type: {}", art.getName(), art.getArtifactType().getLocalPart()); if (art.getArtifactType().getLocalPart().equals("ScriptArtifactPropertiesType")) { String artTemplateID = art.getArtifactRef().getLocalPart(); TArtifactTemplate artTemplate = ToscaStructureQuery.getArtifactTemplateById(artTemplateID, def); if (artTemplate != null) { originalScriptFile = artTemplate.getArtifactReferences().getArtifactReference().get(0) .getReference(); originalScriptFile = extractedFolder + "/" + originalScriptFile; } } } if (originalScriptFile != null) { String originalScript = FileUtils.readFileToString(new File(originalScriptFile)); originalScript = originalScript.replace("#!/bin/bash", ""); originalScript = originalScript.replace("#!/bin/sh", ""); theDependencyScript += originalScript; FileUtils.writeStringToFile(new File(tmpScriptFile), theDependencyScript); EngineLogger.logger.debug("originalScript: {}, moveto: {}", originalScriptFile, originalScriptFile + ".original"); FileUtils.moveFile(FileUtils.getFile(originalScriptFile), FileUtils.getFile(originalScriptFile + ".original")); FileUtils.moveFile(FileUtils.getFile(tmpScriptFile), FileUtils.getFile(originalScriptFile)); } else { // TODO: there is no original script, just add new template, add tmpScript into that } } // end for each node in allRequirements analysis // repack the CSAR FileUtils.deleteQuietly(FileUtils.getFile(csarTmp)); File directory = new File(extractedFolder); File[] fList = directory.listFiles(); //CSARParser.buildCSAR(fList, csarTmp); String builtCSAR = SalsaConfiguration.getToscaTemplateStorage() + "/" + serviceName + ".csar"; CSARParser.buildCSAR(extractedFolder, builtCSAR); } catch (IOException ex) { EngineLogger.logger.error("Error when enriching CSAR: " + csarTmp, ex); return "Error"; } catch (JAXBException ex) { EngineLogger.logger.error("Cannot parse the Tosca definition in CSAR file: " + toscaFile, ex); return "Error"; } // return the link to the CSAR String csarURLReturn = SalsaConfiguration.getSalsaCenterEndpoint() + "/rest/smart/CAMFTosca/enrich/CSAR/" + serviceName; EngineLogger.logger.info("Enrich CSAR done. URL to download is: {}", csarURLReturn); return csarURLReturn; }