List of usage examples for org.apache.commons.io FileUtils copyDirectory
public static void copyDirectory(File srcDir, File destDir) throws IOException
From source file:de.uzk.hki.da.cb.PrepareSendToPresenterActionTests.java
/** * Sets the up./*from w w w . j a va 2 s .c om*/ * * @throws IOException Signals that an I/O exception has occurred. */ @Before public void setUp() throws IOException { n.setWorkAreaRootPath(new RelativePath(WORK_AREA_ROOT_PATH)); action.setWorkArea(new WorkArea(n, o)); action.setDistributedConversionAdapter(mock(DistributedConversionAdapter.class)); o.setIdentifier("identifier_1"); Node dipNode = new Node(); dipNode.setName("dipNode"); DAFile premis = new DAFile("rep_b", "premis.xml"); o.getLatestPackage().getFiles().add(premis); new File(WORK_AREA_ROOT_PATH + "/pips/institution").mkdirs(); new File(WORK_AREA_ROOT_PATH + "/pips/public").mkdirs(); FileUtils.copyDirectory(new File(WORK_AREA_ROOT_PATH + "/sources/1"), new File(WORK_AREA_ROOT_PATH + "/work/TEST/identifier_1")); FileUtils.copyDirectory(new File(WORK_AREA_ROOT_PATH + "/sources/2"), new File(WORK_AREA_ROOT_PATH + "/work/TEST/identifier_2")); }
From source file:com.ibm.team.build.internal.hjplugin.tests.RTCFacadeFactoryIT.java
public void testGetFacadeSwitch() throws IOException { if (Config.DEFAULT.isConfigured()) { RTCFacadeWrapper facade = null;//from w w w . j av a 2 s . co m try { facade = RTCFacadeFactory.getFacade(Config.DEFAULT.getToolkit(), null); // ask again for the same one, should get the same one back RTCFacadeWrapper facade2 = RTCFacadeFactory.getFacade(Config.DEFAULT.getToolkit(), null); if (facade != facade2) { Assert.fail("Cached toolkit was not reused " + facade + " second requested facade " + facade2); } } catch (Exception e) { Assert.fail("Toolkit not found at " + Config.DEFAULT.getToolkit()); } File srcDir = new File(Config.DEFAULT.getToolkit()); File destDir = null; try { // create a build toolkit copy destDir = Files.createTempDir(); FileUtils.copyDirectory(srcDir, destDir); try { // create a new facade with the build toolkit copy RTCFacadeWrapper facade3 = RTCFacadeFactory.getFacade(destDir.getAbsolutePath(), null); if (facade == facade3) { Assert.fail("Cached toolkit re-used for different toolkit path " + facade + " new toolkit facade " + facade3); } // get the new facade with the build toolkit copy and make sure it is the cached version RTCFacadeWrapper facade4 = RTCFacadeFactory.getFacade(destDir.getAbsolutePath(), null); if (facade3 != facade4) { Assert.fail( "Cached toolkit was not reused " + facade3 + " second requested facade " + facade4); } // get the new facade with the build toolkit copy with a trailing slash and make sure it is the cached version facade4 = RTCFacadeFactory.getFacade(destDir.getAbsolutePath() + File.separator, null); if (facade3 != facade4) { Assert.fail( "Cached toolkit was not reused " + facade3 + " second requested facade " + facade4); } } catch (Exception e) { Assert.fail("Failed swtiching to toolkit " + destDir); } } finally { if (destDir != null) { try { // delete the build toolkit copy FileUtils.deleteDirectory(destDir); } catch (Exception e) { // don't let the cleanup fail the build e.printStackTrace(System.out); } } } try { // ask for the original toolkit - it should still be cached since default size is 3 RTCFacadeWrapper facade2 = RTCFacadeFactory.getFacade(Config.DEFAULT.getToolkit(), null); if (facade != facade2) { Assert.fail("Cached toolkit was not reused " + facade + " second requested facade " + facade2); } } catch (Exception e) { Assert.fail("Toolkit not found at " + Config.DEFAULT.getToolkit()); } } }
From source file:com.sitewhere.configuration.ConfigurationMigrationSupport.java
/** * Detects whether using old configuration model and upgrades if necessary. * /*www.ja v a2 s. c o m*/ * @param global * @throws SiteWhereException */ public static void migrateProjectStructureIfNecessary(IGlobalConfigurationResolver global) throws SiteWhereException { File root = new File(global.getConfigurationRoot()); if (!root.exists()) { throw new SiteWhereException("Configuration root does not exist."); } File templateFolder = new File(root, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_TEMPLATE_FOLDER); if (!templateFolder.exists()) { if (!templateFolder.mkdir()) { throw new SiteWhereException("Unable to create template folder."); } for (String filename : OLD_TEMPLATE_FILENAMES) { File templateFile = new File(root, filename); if (templateFile.exists()) { migrateTemplateFile(root, templateFolder, filename); migrateResources(root, templateFolder); break; } } } // Migrate tenant configuration files to separate directories. File tenants = new File(root, FileSystemTenantConfigurationResolver.TENANTS_FOLDER); if (!tenants.exists()) { if (!tenants.mkdir()) { throw new SiteWhereException("Unable to create tenant resources folder."); } } Collection<File> oldConfigs = FileUtils.listFiles(root, FileFilterUtils.suffixFileFilter("-tenant.xml"), null); for (File oldConfig : oldConfigs) { int dash = oldConfig.getName().lastIndexOf('-'); String tenantName = oldConfig.getName().substring(0, dash); File tenantFolder = new File(tenants, tenantName); try { FileUtils.copyDirectory(templateFolder, tenantFolder); File tenantConfig = new File(tenantFolder, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_CONFIGURATION_FILE + "." + FileSystemTenantConfigurationResolver.TENANT_SUFFIX_ACTIVE); if (tenantConfig.exists()) { tenantConfig.delete(); } FileUtils.moveFile(oldConfig, tenantConfig); oldConfig.delete(); } catch (IOException e) { throw new SiteWhereException("Unable to copy template folder for tenant."); } } }
From source file:io.stallion.tools.ExportToHtml.java
@Override public void execute(ServeCommandOptions options) throws Exception { Log.info("EXECUTE EXPORT ACTION!!"); String exportFolder = Settings.instance().getTargetFolder() + "/export-" + DateUtils.formatNow("yyyy-MM-dd-HH-mm-ss"); File export = new File(exportFolder); if (!export.exists()) { export.mkdirs();/*from w w w .ja v a2s . co m*/ } FileUtils.copyDirectory(new File(Settings.instance().getTargetFolder() + "/assets"), new File(exportFolder + "/st-assets")); Set<String> assets = new HashSet<>(); Set<String> allUrlPaths = new HashSet<>(); for (SiteMapItem item : SiteMapController.instance().getAllItems()) { String uri = item.getPermalink(); Log.info("URI {0}", uri); if (!uri.contains("://")) { uri = "http://localhost" + uri; } URL url = new URL(uri); allUrlPaths.add(url.getPath()); } allUrlPaths.addAll(ExporterRegistry.instance().exportAll()); for (String path : allUrlPaths) { Log.info("Export page {0}", path); MockRequest request = new MockRequest(path, "GET"); MockResponse response = new MockResponse(); RequestHandler.instance().handleStallionRequest(request, response); response.getContent(); if (!path.contains(".")) { if (!path.endsWith("/")) { path += "/"; } path += "index.html"; } File file = new File(exportFolder + path); File folder = new File(file.getParent()); if (!folder.isDirectory()) { folder.mkdirs(); } String html = response.getContent(); html = html.replace(Settings.instance().getSiteUrl(), ""); FileUtils.write(file, html, UTF8); assets.addAll(findAssetsInHtml(response.getContent())); } for (String src : assets) { Log.info("Asset src: {0}", src); MockRequest request = new MockRequest(src, "GET"); MockResponse response = new MockResponse(); RequestHandler.instance().handleStallionRequest(request, response); int min = 300; if (response.getContent().length() < 300) { min = response.getContent().length(); } URL url = new URL("http://localhost" + src); File file = new File(exportFolder + url.getPath()); File folder = new File(file.getParent()); if (!folder.isDirectory()) { folder.mkdirs(); } if (url.getPath().endsWith(".js") || url.getPath().endsWith(".css")) { FileUtils.write(file, response.getContent(), UTF8); } else { //ByteArrayOutputStream bos = new ByteArrayOutputStream(); //response.getOutputStream() //bos.writeTo(response.getOutputStream()); //bos.close(); //FileUtils.writeByteArrayToFile(file, response.getContent().getBytes()); } } }
From source file:de.uzk.hki.da.cb.TarActionTests.java
@Before public void setUp() throws IOException { n.setWorkingResource("vm3"); n.setWorkAreaRootPath(new RelativePath(workAreaRootPath)); Package pkg = new Package(); pkg.setDelta(2);//from ww w . j a v a 2 s .co m o.getPackages().add(pkg); job.setRep_name(repName); action.setDistributedConversionAdapter(mock(DistributedConversionAdapter.class)); FileUtils.copyDirectory(new File(backupPackagePath), new File(packageForkPath)); }
From source file:com.mindquarry.desktop.workspace.conflict.ReplaceConflict.java
public void beforeUpdate() throws ClientException, IOException { File file = new File(status.getPath()); switch (action) { case UNKNOWN: // client did not set a conflict resolution log.error("AddConflict with no action set: " + status.getPath()); break;// w w w . j ava 2 s . com case RENAME: log.info("renaming " + file.getAbsolutePath() + " to " + newName); File source = new File(status.getPath()); File destination = new File(source.getParent(), newName); if (source.isDirectory()) { FileUtils.copyDirectory(source, destination); removeDotSVNDirectories(destination.getPath()); } else { FileUtils.copyFile(source, destination); } client.add(destination.getPath(), true, true); client.remove(new String[] { file.getPath() }, null, true); break; case REPLACE: log.info("replacing with new file/folder from server: " + status.getPath()); client.revert(file.getPath(), true); if (status.getRepositoryTextStatus() == StatusKind.replaced) { FileUtils.forceDelete(file); } break; } }
From source file:com.liferay.blade.cli.SamplesCommand.java
private void copySample(String sampleName) throws Exception { File workDir = _options.dir(); if (workDir == null) { workDir = _blade.getBase();/*from w w w. jav a 2 s . com*/ } File bladeRepo = new File(_blade.getCacheDir(), _BLADE_REPO_NAME); File liferayGradleSamples = new File(bladeRepo, "liferay-gradle"); for (File file : liferayGradleSamples.listFiles()) { String fileName = file.getName(); if (file.isDirectory() && fileName.equals(sampleName)) { File dest = new File(workDir, fileName); FileUtils.copyDirectory(file, dest); updateBuildGradle(dest); if (!Util.hasGradleWrapper(dest)) { addGradleWrapper(dest); } } } }
From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java
private void create(final File outputDirectory, final File resourcesDirectory) throws IOException, InterruptedException { FileUtils.copyDirectory(resourcesDirectory, new File(outputDirectory, "Resources")); FileUtils.writeLines(new File(outputDirectory, "manifest"), createManifest()); FileUtils.writeLines(new File(outputDirectory, "tiapp.xml"), createXml()); }
From source file:gobblin.scheduler.JobConfigFileMonitorTest.java
@BeforeClass public void setUp() throws Exception { this.jobConfigDir = Files .createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())) .toString();//from w ww. jav a2 s . com FileUtils.forceDeleteOnExit(new File(this.jobConfigDir)); FileUtils.copyDirectory(new File(JOB_CONFIG_FILE_DIR), new File(jobConfigDir)); Properties properties = new Properties(); try (Reader schedulerPropsReader = new FileReader("gobblin-test/resource/gobblin.test.properties")) { properties.load(schedulerPropsReader); } properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, jobConfigDir); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, jobConfigDir); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, "1000"); properties.setProperty(ConfigurationKeys.METRICS_ENABLED_KEY, "false"); SchedulerService quartzService = new SchedulerService(new Properties()); this.jobScheduler = new JobScheduler(properties, quartzService); this.serviceManager = new ServiceManager(Lists.newArrayList(quartzService, this.jobScheduler)); this.serviceManager.startAsync().awaitHealthy(10, TimeUnit.SECONDS); ; }
From source file:eu.artist.methodology.mpt.cheatsheet.Activator.java
public static void createDirs() throws IOException, URISyntaxException { final String STATE_LOCATION = Activator.getDefault().getStateLocation().toString(); System.out.println("Creating dirs in state location ..."); URL csURL = plugin.getBundle().getEntry("cheatsheets/"); //csURL = new URL("platform:/plugin/eu.artist.methodology.mpt.cheatsheet/cheatsheets/" + csMap.get(csId)); URL resolvedcsURL = FileLocator.toFileURL(csURL); URI resolvedcsURI = new URI(resolvedcsURL.getProtocol(), resolvedcsURL.getPath(), null); File csFile = new File(resolvedcsURI); FileUtils.copyDirectory(csFile, new File(STATE_LOCATION)); }