List of usage examples for org.apache.commons.io FileUtils copyDirectory
public static void copyDirectory(File srcDir, File destDir) throws IOException
From source file:net.buildstatic.mappacker.command.PackCommand.java
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) { try {/*w w w. ja va 2 s . co m*/ if (args.length > 1) { World world = Bukkit.getWorld(args[0]); if (world != null) { File tempDir = new File(System.getProperty("java.io.tmpdir")); File tempWorld = new File(tempDir, world.getWorldFolder().getName() + File.separator + world.getWorldFolder().getName()); FileUtils.copyDirectory(world.getWorldFolder(), tempWorld); File mapDat = new File(tempWorld, "map.dat"); if (!mapDat.exists() && !mapDat.createNewFile()) { FileUtils.deleteDirectory(tempWorld); sender.sendMessage( ChatColor.RED + "Error: Aborting... unable to create map.dat. Try again?"); return false; } YamlConfiguration configuration = YamlConfiguration.loadConfiguration(mapDat); StringBuilder creator = new StringBuilder(); for (int i = 1; i < args.length; i++) { creator.append(i == 1 || i + 1 == args.length ? "" : " "); creator.append(args[i]); } configuration.set("Creator", creator.toString()); configuration.save(mapDat); Arrays.stream(FILES_TO_REMOVE).forEach(fileName -> { File file = new File(tempWorld, fileName); if (file.isDirectory()) Arrays.stream(file.listFiles()).forEach(file1 -> file1.delete()); file.delete(); }); File zipped = new File(MapPacker.getInstance().getDataFolder(), tempWorld.getName() + ".zip"); if (zipped.exists() && !zipped.delete()) { sender.sendMessage(ChatColor.RED + "Error: Unable to delete old zip. Try again?"); FileUtils.deleteDirectory(tempWorld); return false; } ZipUtil.pack(new File(tempDir, world.getWorldFolder().getName()), zipped); if (zipped.exists()) sender.sendMessage(ChatColor.GREEN + "Success! The map is all ready to go @ " + zipped.getAbsolutePath() + "."); else sender.sendMessage(ChatColor.RED + "Error: File was not able to be zipped up. Try again?"); FileUtils.deleteDirectory(tempWorld); return true; } sender.sendMessage(ChatColor.RED + "Error: \"" + args[0] + "\" is not a valid world."); } else sender.sendMessage(ChatColor.RED + "Usage: /pack <world name> <creator>"); } catch (IOException ex) { ex.printStackTrace(); } return false; }
From source file:hudson.plugins.jobConfigHistory.ConfigInfoCollectorTest.java
/** * Test of collect method, of class ConfigInfoCollector. *///from www .j a v a2 s .co m @Test public void testCollectCreatedWithChangeEventBeforeCreated() throws Exception { FileUtils.copyDirectory(unpackResourceZip.getResource("config-history/jobs/Test1/2012-11-21_11-35-12"), unpackResourceZip.getResource("config-history/jobs/Test1/2012-11-21_11-28-12")); assertThatRootFolderHasYItemsOfTypeZ(1, "created"); }
From source file:at.ac.tuwien.infosys.repository.LocalComponentRepositoryTest.java
@Before public void setUp() throws Exception { repo = tempRepository.newFolder();/* www. java 2 s . c om*/ FileUtils.copyDirectory(new File("component-repository"), repo); // use mocked repository-location in repository class componentRepository.setRepository(repo.toPath()); String appURL = "file:" + repo.getAbsolutePath() + "/sample-app/0.0.1"; List<Resource> appBinaries = new ArrayList<Resource>(); appBinaries.add(new Resource("SampleClient.class", new URL(appURL + "/artifacts/SampleClient.class"))); List<Resource> appScripts = new ArrayList<Resource>(); appScripts.add(new Resource("install.sh", new URL(appURL + "/scripts/install.sh"))); appScripts.add(new Resource("restart.sh", new URL(appURL + "/scripts/restart.sh"))); appScripts.add(new Resource("run.sh", new URL(appURL + "/scripts/run.sh"))); appScripts.add(new Resource("stop.sh", new URL(appURL + "/scripts/stop.sh"))); appScripts.add(new Resource("uninstall.sh", new URL(appURL + "/scripts/uninstall.sh"))); expectedComponent = new Component("sample-app", new Version("0", "0", "1"), appBinaries, appScripts); }
From source file:net.monofraps.gradlebukkit.tasks.CopyPluginsTask.java
@TaskAction public void doWork() throws LifecycleExecutionException, IOException { final File bukkitTargetDir = new File(getProject().getBuildDir(), "bukkit"); final File bukkitPluginsDir = new File(bukkitTargetDir, "plugins"); if (!bukkitTargetDir.exists()) { if (!bukkitTargetDir.mkdir()) throw new LifecycleExecutionException( "Failed to create bukkit target directory " + bukkitTargetDir); }//ww w . j a v a 2 s. co m if (!bukkitPluginsDir.exists()) { if (!bukkitPluginsDir.mkdir()) throw new LifecycleExecutionException( "Failed to create bukkit plugin directory " + bukkitPluginsDir); } for (final Object fileObject : ((Bukkit) getProject().getExtensions().getByName("bukkit")) .getPluginsToCopy()) { final File plugin = getProject().file(fileObject); if (!plugin.exists()) { throw new LifecycleExecutionException( "Plugin copy failed: Plugin file " + plugin + " does not exist."); } final File target = new File(bukkitPluginsDir, plugin.getName()); if (target.exists()) continue; getLogger().lifecycle("Copying " + plugin + " to " + target); if (plugin.isDirectory()) { FileUtils.copyDirectory(plugin, target); } else { FileUtils.copyFile(plugin, target); } } }
From source file:de.uzk.hki.da.cb.CreateDCActionTests.java
@Before public void setUp() throws IOException { n.setWorkAreaRootPath(WORK_AREA_ROOT_PATH); FileUtils.copyDirectory(Path.makeFile(WORK_AREA_ROOT_PATH, UNDERSCORE + WorkArea.PIPS), Path.makeFile(WORK_AREA_ROOT_PATH, WorkArea.PIPS)); o.setPackage_type(CB_PACKAGETYPE_EAD); Map<String, String> dcMappings = new HashMap<String, String>(); dcMappings.put(CB_PACKAGETYPE_EAD, "src/main/xslt/dc/ead_to_dc.xsl"); action.setDcMappings(dcMappings);/*from ww w. j av a 2 s . co m*/ }
From source file:com.linkedin.pinot.filesystem.LocalPinotFS.java
@Override public boolean copy(URI srcUri, URI dstUri) throws IOException { File srcFile = new File(srcUri); File dstFile = new File(dstUri); if (dstFile.exists()) { FileUtils.deleteQuietly(dstFile); }//from w ww. jav a2 s .c om if (srcFile.isDirectory()) { // Throws Exception on failure FileUtils.copyDirectory(srcFile, dstFile); } else { // Will create parent directories, throws Exception on failure FileUtils.copyFile(srcFile, dstFile); } return true; }
From source file:com.ngdata.hbaseindexer.mr.TestUtils.java
private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir) throws IOException { LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs + ", outputShardDir: " + outputShardDir); // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit();/*from ww w . ja va 2s . c o m*/ FileUtils.copyDirectory(solrHomeDir, tmpDir); solrHomeDir = tmpDir; Path solrDataDir = new Path(outputShardDir, "data"); String dataDirStr = solrDataDir.toUri().toString(); SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null); LOG.info(String.format(Locale.ENGLISH, "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s", solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(), loader.getConfigDir(), dataDirStr, outputShardDir)); // TODO: This is fragile and should be well documented System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName()); System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS); System.setProperty("solr.hdfs.nrtcachingdirectory", "false"); System.setProperty("solr.hdfs.blockcache.enabled", "false"); System.setProperty("solr.autoCommit.maxTime", "600000"); System.setProperty("solr.autoSoftCommit.maxTime", "-1"); CoreContainer container = new CoreContainer(loader); container.load(); SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()), ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false); if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) { throw new UnsupportedOperationException( "Invalid configuration. Currently, the only DirectoryFactory supported is " + HdfsDirectoryFactory.class.getSimpleName()); } EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1"); return solr; }
From source file:com.hydroLibCreator.action.Creator.java
private void copyAudioFiles() { try {//from w w w . j av a2 s . c om FileUtils.copyDirectory(sourceDir, destinationDir); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.collective.celos.server.AutoScheduleTest.java
@Test public void testAutoSchedule() throws Exception { File src = new File(Thread.currentThread().getContextClassLoader() .getResource("com/collective/celos/client/wf-list").toURI()); FileUtils.copyDirectory(src, workflowsDir); Main.setupAutoschedule(port, 1);/*from w w w . ja va 2 s .c o m*/ Assert.assertTrue(autoScheduleWorked()); }
From source file:com.orange.ocara.model.export.docx.AuditDocxExporterTest.java
@Before public void setUp() throws Exception { templateDirectory = new File("src/main/assets/export/docx"); workingDirectory = testFolder.newFolder("working"); FileUtils.copyDirectory(templateDirectory, workingDirectory); audit = new Audit(); ruleSet = new RuleSet(); author = new Auditor(); site = new Site(); audit.setName(""); audit.setRuleSet(ruleSet);/*from w w w.j av a2 s . c o m*/ audit.setAuthor(author); audit.setSite(site); audit.setDate(Calendar.getInstance().getTime()); }