List of usage examples for org.apache.commons.io FileUtils copyDirectory
public static void copyDirectory(File srcDir, File destDir) throws IOException
From source file:com.alibaba.jstorm.schedule.FollowerRunnable.java
private void downloadCodeFromMaster(Assignment assignment, String topologyId) throws IOException, TException { try {//from w w w .j a v a 2 s . c o m String localRoot = StormConfig.masterStormdistRoot(data.getConf(), topologyId); String tmpDir = StormConfig.masterInbox(data.getConf()) + "/" + UUID.randomUUID().toString(); String masterCodeDir = assignment.getMasterCodeDir(); JStormServerUtils.downloadCodeFromMaster(data.getConf(), tmpDir, masterCodeDir, topologyId, false); File srcDir = new File(tmpDir); File destDir = new File(localRoot); try { FileUtils.moveDirectory(srcDir, destDir); } catch (FileExistsException e) { FileUtils.copyDirectory(srcDir, destDir); FileUtils.deleteQuietly(srcDir); } // Update downloadCode timeStamp StormConfig.write_nimbus_topology_timestamp(data.getConf(), topologyId, System.currentTimeMillis()); } catch (TException e) { // TODO Auto-generated catch block LOG.error(e + " downloadStormCode failed " + "topologyId:" + topologyId + "masterCodeDir:" + assignment.getMasterCodeDir()); throw e; } LOG.info("Finished downloading code for topology id " + topologyId + " from " + assignment.getMasterCodeDir()); }
From source file:com.collective.celos.CelosClientServerTest.java
@Test public void testGetWorkflowStatusTransitionToRunning() throws Exception { File src = new File(Thread.currentThread().getContextClassLoader() .getResource("com/collective/celos/client/wf-list").toURI()); FileUtils.copyDirectory(src, workflowsDir); celosClient.iterateScheduler();/*from w w w .j a v a 2 s.c o m*/ celosClient.iterateScheduler(); List<SlotState> slotStates = celosClient.getWorkflowStatus(new WorkflowID("workflow-2")).getSlotStates(); Assert.assertEquals(slotStates.size(), SLOTS_IN_CELOS_SERVER_SLIDING_WINDOW); List<SlotState> slotStatesOther = slotStates.subList(0, slotStates.size() - 1); SlotState slotStateLst = slotStates.get(slotStates.size() - 1); Assert.assertEquals(slotStateLst.getStatus(), SlotState.Status.RUNNING); Assert.assertNotNull(slotStateLst.getExternalID()); Assert.assertEquals(slotStateLst.getRetryCount(), 0); for (SlotState slotState : slotStatesOther) { Assert.assertEquals(slotState.getStatus(), SlotState.Status.READY); Assert.assertNull(slotState.getExternalID()); Assert.assertEquals(slotState.getRetryCount(), 0); } }
From source file:io.fabric8.jube.maven.BuildMojo.java
protected void createAssembly() throws MojoFailureException, MojoExecutionException { String extractBaseImageRef = "extractBaseImage"; String createZipRef = "createZip"; //String extractBaseImageRef = "internal/extractBaseImage.xml"; AssemblerConfigurationSource extractConfig = createAssemblyConfigurationSource(null, extractBaseImageRef); AssemblerConfigurationSource projectConfig = createAssemblyConfigurationSource(assemblyDescriptor, assemblyDescriptorRef);//from ww w . j a v a 2s . c o m AssemblerConfigurationSource zipConfig = createAssemblyConfigurationSource(null, createZipRef); Assembly assembly = null; File buildDir = new File(project.getBasedir(), "target/jube"); try { buildDir.mkdirs(); try { unpackBaseImage(buildDir, false); } catch (ArtifactResolutionException e) { unpackBaseImage(buildDir, true); } catch (ArtifactNotFoundException e) { unpackBaseImage(buildDir, true); } writeEnvironmentVariables(buildDir); writePorts(buildDir); assembly = extractAssembly(projectConfig); assembly.setId("docker"); if (exportDir.startsWith("/")) { exportDir = exportDir.substring(1); } assemblyArchiver.createArchive(assembly, exportDir, "dir", projectConfig, false); File assemblyDir = new File(project.getBasedir(), "target/" + JUBE_ASSEMBLY_DIR); FileUtils.copyDirectory(assemblyDir, buildDir); InstallHelper.chmodAllScripts(buildDir); Zips.createZipFile(LOG, buildDir, outputZipFile); getLog().info("Created image zip: " + outputZipFile); attachArtifactToBuild(); } catch (InvalidAssemblerConfigurationException e) { throw new MojoFailureException(assembly, "Assembly is incorrectly configured: " + assembly.getId(), "Assembly: " + assembly.getId() + " is not configured correctly: " + e.getMessage()); } catch (Exception e) { throw new MojoExecutionException("Failed to create assembly for image: " + e.getMessage(), e); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.AbstractPackagingMojo.java
/** * <p>//from w ww .java 2 s .c om * This saves a java.util.Properties to a file.<br /> * * It is possible to add a comment at the beginning of the file. * </p> * * @param outputFile, the File where to output the Properties * @param properties, the Properties to save * @param propertiesComment, the comment to add at the beginning of the file * @param success, the success message * @param failure, the failure message * @throws MojoExecutionException */ protected void savePropertiesToFile(File outputFile, Properties properties, String propertiesComment, String success, String failure) throws MojoExecutionException { OutputStream outputStream = null; try { outputFile.getParentFile().mkdirs(); outputStream = new FileOutputStream(outputFile); properties.store(outputStream, propertiesComment); if (filterProperties) { getLog().debug("Filtering properties files"); File tmpDir = new File(outputFile.getParentFile(), "tmp"); tmpDir.mkdir(); List<Resource> resources = new ArrayList<Resource>(); Resource r = new Resource(); r.setDirectory(outputFile.getParentFile().getAbsolutePath()); r.addInclude("*.properties"); r.setFiltering(true); resources.add(r); ArrayList<Object> filters = new ArrayList<Object>(); List<String> nonFilteredFileExtensions = new ArrayList<String>(); MavenResourcesExecution mre = new MavenResourcesExecution(resources, tmpDir, this.getProject(), this.sourceEncoding, filters, nonFilteredFileExtensions, session); mavenResourcesFiltering.filterResources(mre); FileUtils.copyDirectory(tmpDir, outputFile.getParentFile()); FileUtils.deleteDirectory(tmpDir); } getLog().info(success + " '" + outputFile + "'"); } catch (Exception e) { throw new MojoExecutionException(failure + " '" + outputFile + "'", e); } finally { try { outputStream.close(); } catch (Exception e) { } } }
From source file:com.enonic.cms.web.webdav.DavResourceImpl.java
@Override public void copy(final DavResource target, final boolean shallow) throws DavException { if (!exists()) { throw new DavException(DavServletResponse.SC_NOT_FOUND); }//from w ww . jav a2 s .c o m if (!target.getCollection().exists()) { throw new DavException(DavServletResponse.SC_CONFLICT); } final File targetFile = ((DavResourceImpl) target).file; try { if (isCollection()) { FileUtils.copyDirectory(this.file, targetFile); } else { FileUtils.copyFile(this.file, targetFile); } } catch (final IOException e) { throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e); } }
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void copyDirectory(@NonNull final GenericFile source, @NonNull final GenericFile target, final boolean useCommandLine) throws IOException { if (useCommandLine) { if (!source.exists()) { throw new FileNotFoundException("Source '" + source + "' does not exist"); }/*from ww w .j av a 2 s. c o m*/ if (!source.isDirectory()) { throw new IOException("Source '" + source + "' exists but is not a directory"); } if (source.getCanonicalPath().equals(target.getCanonicalPath())) { throw new IOException("Source '" + source + "' and destination '" + target + "' are the same"); } final boolean result = CommandLine.execute(new CommandCopyRecursively(source, target)); if (!result) { throw new IOException("Copying failed"); } } else { FileUtils.copyDirectory(source.toFile(), target.toFile()); } }
From source file:it.imtech.configuration.StartWizard.java
/** * Creates necessary folders in home user menu * @return /*w w w. ja v a2 s .c o m*/ */ private boolean checkAppDataFiles() { boolean result = false; try { File appdata = new File(Globals.USER_DIR); String currentpath = Globals.JRPATH + "appdata" + Utility.getSep(); File blank = new File(currentpath + "config" + Utility.getSep() + "blankpage.jpg"); File xmlconfnew = new File(currentpath + "config" + Utility.getSep() + "config.xml"); File logforj = new File(currentpath + "config" + Utility.getSep() + "log4j.xml"); File upllogforj = new File(currentpath + "config" + Utility.getSep() + "upllog4j.xml"); if (!appdata.exists()) { appdata.mkdir(); } File templates = new File(Globals.USER_DIR + "templates"); if (!templates.exists()) { templates.mkdir(); } File backupxml = new File(currentpath + "xml"); File remotexml = new File(Globals.USER_DIR + "xml"); FileUtils.copyDirectory(backupxml, remotexml); File config = new File(Globals.USER_DIR + "config"); if (!config.exists()) { config.mkdir(); } File undo = new File(Globals.USER_DIR + "undo"); if (!undo.exists()) { undo.mkdir(); } File certs = new File(Globals.USER_DIR + "certs"); if (!certs.exists()) { certs.mkdir(); } File uploads = new File(Globals.USER_DIR + "duplication"); if (!uploads.exists()) { uploads.mkdir(); } File xmlconfold = new File(Globals.USER_DIR + "config" + Utility.getSep() + "config.xml"); if (xmlconfold.exists()) { try { XMLConfiguration configureold = new XMLConfiguration(xmlconfold); XMLConfiguration configurenew = new XMLConfiguration(xmlconfnew); String versioneold = configureold.getString("version[@current]"); String versionenew = configurenew.getString("version[@current]"); String urlold = configureold.getString("configurl[@path]"); String urlnew = configurenew.getString("configurl[@path]"); if ((!versioneold.equals(versionenew)) || (!urlold.equals(urlnew))) { xmlconfold.delete(); FileUtils.copyFile(xmlconfnew, xmlconfold); } } catch (ConfigurationException ex) { result = false; } } else { FileUtils.copyFile(xmlconfnew, xmlconfold); } File logforjnew = new File(Globals.USER_DIR + "config" + Utility.getSep() + "log4j.xml"); FileUtils.copyFile(logforj, logforjnew); File upllogforjnew = new File(Globals.USER_DIR + "config" + Utility.getSep() + "upllog4j.xml"); FileUtils.copyFile(upllogforj, upllogforjnew); File blanknew = new File(Globals.USER_DIR + "config" + Utility.getSep() + "blankpage.jpg"); if (!blanknew.exists()) { FileUtils.copyFile(blank, blanknew); } result = true; } catch (IOException ex) { result = false; } return result; }
From source file:com.vasquez.FileSwitcher.java
private void doDataDir(int choice) { File sourceFile = null;// w w w .j av a 2 s.c o m File targetFile = null; if (choice == 0) { Logger.LogInfo("Backing up data directory if needed..."); sourceFile = new File(root.getAbsolutePath() + "\\data\\"); if (expansion) { targetFile = new File(root.getAbsolutePath() + "\\Expansion\\" + version + "\\data\\"); } else { targetFile = new File(root.getAbsolutePath() + "\\Classic\\" + version + "\\data\\"); } } else { Logger.LogInfo("Restoring data directory if needed..."); targetFile = new File(root.getAbsolutePath() + "\\data\\"); if (expansion) { sourceFile = new File(root.getAbsolutePath() + "\\Expansion\\" + version + "\\data\\"); } else { sourceFile = new File(root.getAbsolutePath() + "\\Classic\\" + version + "\\data\\"); } } try { if (sourceFile.exists() && sourceFile.isDirectory()) { if (targetFile.exists() && targetFile.isDirectory()) { FileUtils.deleteDirectory(targetFile); FileUtils.copyDirectory(sourceFile, targetFile); } else if (targetFile.exists() && !targetFile.isDirectory()) { targetFile.delete(); FileUtils.copyDirectory(sourceFile, targetFile); } else { FileUtils.copyDirectory(sourceFile, targetFile); } } else if (sourceFile.exists() && !sourceFile.isDirectory()) { Logger.LogWarning( "A 'data' of type file was detected. 'data' is supposed to be a folder. Deleting..."); sourceFile.delete(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.photon.phresco.service.dependency.impl.AbstractDependencyProcessor.java
protected void createSqlFolder(ProjectInfo info, File path) throws PhrescoException { String databaseType = ""; try {/* w w w.java2s . c o m*/ List<Database> databaseList = info.getTechnology().getDatabases(); String techId = info.getTechnology().getId(); if (databaseList == null || databaseList.size() == 0) { return; } File mysqlFolder = new File(path, sqlFolderPathMap.get(techId) + Constants.DB_MYSQL); File mysqlVersionFolder = getMysqlVersionFolder(mysqlFolder); for (Database db : databaseList) { databaseType = db.getName().toLowerCase(); List<String> versions = db.getVersions(); for (String version : versions) { String sqlPath = databaseType + File.separator + version.trim(); File sqlFolder = new File(path, sqlFolderPathMap.get(techId) + sqlPath); sqlFolder.mkdirs(); if (databaseType.equals(Constants.DB_MYSQL) && mysqlVersionFolder != null && !(mysqlVersionFolder.getPath().equals(sqlFolder.getPath()))) { FileUtils.copyDirectory(mysqlVersionFolder, sqlFolder); } else { File sqlFile = new File(sqlFolder, Constants.SITE_SQL); sqlFile.createNewFile(); } } } } catch (IOException e) { throw new PhrescoException(e); } }
From source file:com.technophobia.substeps.report.DefaultExecutionReportBuilder.java
public void copyResourcesRecursively(final URL originUrl, final File destination) throws IOException { final URLConnection urlConnection = originUrl.openConnection(); if (urlConnection instanceof JarURLConnection) { copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection); } else if (urlConnection instanceof FileURLConnection) { FileUtils.copyDirectory(new File(originUrl.getPath()), destination); } else {//from w w w . java 2 s .c o m throw new RuntimeException("URLConnection[" + urlConnection.getClass().getSimpleName() + "] is not a recognized/implemented connection type."); } }