Java Code Examples for org.apache.commons.io.FileUtils#copyDirectory()
The following examples show how to use
org.apache.commons.io.FileUtils#copyDirectory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobEntryCopyFilesIT.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void copyFileFromSubDirectoryWithoutOverwrite() throws Exception { entry.setIncludeSubfolders( true ); entry.setoverwrite_files( false ); Path pathToSub = Files.createTempDirectory( source, "sub" ); Path pathToFile = Files.createTempFile( pathToSub, "file", "" ); FileUtils.copyDirectory( source.toFile(), destination.toFile() ); String path = destination.resolve( pathToSub.getFileName() ).resolve( pathToFile.getFileName() ).toString(); File file = new File( path ); long createTime = file.lastModified(); Result result = entry.execute( new Result(), 0 ); long copyTime = file.lastModified(); assertTrue( result.getResult() ); assertEquals( 0, result.getNrErrors() ); assertTrue( "File shouldn't be overwritten", createTime == copyTime ); }
Example 2
Source File: SimpleLocalCache.java From atlas with Apache License 2.0 | 6 votes |
@Override public boolean fetchFile(String type, String key, File localFile, boolean folder) throws FileCacheException { if (StringUtils.isEmpty(key)) { throw new FileCacheException("cache key is empty "); } File cacheFile = getLocalCacheFile(type, key); try { if (cacheFile.exists() && cacheFile.length() > 0) { if (cacheFile.isDirectory()) { FileUtils.copyDirectory(cacheFile, localFile); } else { FileUtils.copyFile(cacheFile, localFile); } } } catch (IOException e) { throw new FileCacheException(e.getMessage(), e); } return true; }
Example 3
Source File: GitPull.java From nano-framework with Apache License 2.0 | 6 votes |
public GitPull copy() throws IOException { if (enabled) { for (final File path : fullPath) { if (path.exists()) { if (confPath.exists() && StringUtils.equals(App.REPEAT_POLICY_CLEAN, app.getConfRepeatPolicy())) { cleanConf(); } FileUtils.copyDirectory(path, confPath); break; } } } return this; }
Example 4
Source File: KotlinSpringServerCodegenTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test(description = "test embedded enum array") public void embeddedEnumArrayTest() throws Exception { String baseModelPackage = "zz"; File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); //may be move to /build OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue______kotlinArrayEnumEmbedded.yaml"); KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, baseModelPackage + ".yyyy.model.xxxx"); ClientOptInput input = new ClientOptInput(); input.openAPI(openAPI); input.config(codegen); DefaultGenerator generator = new DefaultGenerator(); generator.opts(input).generate(); File resultSourcePath = new File(output, "src/main/kotlin"); File outputModel = Files.createTempDirectory("test").toFile().getCanonicalFile(); FileUtils.copyDirectory(new File(resultSourcePath, baseModelPackage), new File(outputModel, baseModelPackage)); //no exception ClassLoader cl = KotlinTestUtils.buildModule(Collections.singletonList(outputModel.getAbsolutePath()), Thread.currentThread().getContextClassLoader()); }
Example 5
Source File: DbCopyAction.java From olca-app with Mozilla Public License 2.0 | 6 votes |
private void doCopy(String newName) { boolean isActive = Database.isActive(config); try { if (isActive) { if (!Editors.closeAll()) return; Database.close(); ValidationView.clear(); } File fromFolder = DatabaseDir.getRootFolder(config.getName()); File toFolder = DatabaseDir.getRootFolder(newName); FileUtils.copyDirectory(fromFolder, toFolder); DerbyConfiguration newConf = new DerbyConfiguration(); newConf.setName(newName); Database.register(newConf); if (isActive) Database.activate(config); Navigator.refresh(); HistoryView.refresh(); CompareView.clear(); } catch (Exception e) { log.error("failed to copy database", e); } }
Example 6
Source File: CelosClientServerTest.java From celos with Apache License 2.0 | 6 votes |
@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(); 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); } }
Example 7
Source File: CelosClientServerTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = IOException.class) public void testRerunSlotFailsNoSlot() throws Exception { File src = new File(Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/client/wf-list").toURI()); FileUtils.copyDirectory(src, workflowsDir); WorkflowID workflowID = new WorkflowID("workflow-2"); celosClient.rerunSlot(workflowID, new ScheduledTime("2013-11-20T12:34Z")); }
Example 8
Source File: TestInstanceRepoCleaner.java From oodt with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { // get a temp directory path File tempDir = File.createTempFile("bogus", "txt").getParentFile(); FileUtils.copyDirectory(new File("./src/test/resources/testinstrepo"), new File( tempDir.getAbsolutePath() + "/" + "testinstrepo")); instRepoPath = tempDir.getAbsolutePath().endsWith("/") ? (tempDir .getAbsolutePath() + "testinstrepo") : (tempDir.getAbsolutePath() + "/" + "testinstrepo"); }
Example 9
Source File: SolrITInitializer.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Given a directory that will be used as the <code>coreRootDirectory</code> * for a jetty instance, Creates a core directory named * {@link #DEFAULT_TEST_CORENAME} using a trivial * <code>core.properties</code> if this file does not already exist. * * @see #writeCoreProperties(Path,String) * @see #CORE_PROPERTIES_FILENAME */ private static void seedCoreDir(String testFolder, String coreName, Path coreSourceConfig, Path coreDirectory) throws IOException { //Prepare alfresco solr core. Path confDir = coreDirectory.resolve("conf"); confDir.toFile().mkdirs(); if (Files.notExists(coreDirectory.resolve(CORE_PROPERTIES_FILENAME))) { Properties coreProperties = new Properties(); coreProperties.setProperty("name", coreName); writeCoreProperties(coreDirectory, coreProperties, testFolder); } // else nothing to do, DEFAULT_TEST_CORENAME already exists //Add alfresco solr configurations FileUtils.copyDirectory(coreSourceConfig.resolve("conf").toFile(), confDir.toFile()); }
Example 10
Source File: Indexer.java From tagme with Apache License 2.0 | 5 votes |
public static void makeIndex(Indexer indexer, String lang) throws IOException { //WORKING DIRECTORY File tmpBase = Dataset.getTmpDir(); File workingDir = new File(tmpBase, lang+"_"+indexer.getName()); workingDir.mkdirs(); FileUtils.cleanDirectory(workingDir); log.info("\tStart indexer "+indexer.getName()+"..."); indexer.makeIndex(lang, workingDir); log.info("\tBuilt index for "+indexer.getName()); if (! (indexer instanceof DatasetProcessor || indexer instanceof TextDatasetProcessor)){ log.info("\tCopying files for "+indexer.getName()+"..."); File realPlace = indexer.getIndexDir(lang); if (realPlace.exists()) FileUtils.cleanDirectory(realPlace); else realPlace.mkdirs(); FileUtils.copyDirectory(workingDir, realPlace); log.info("\tRemoving tmp files for "+indexer.getName()+"..."); } FileUtils.deleteDirectory(workingDir); log.info("\tProcess done for "+indexer.getName()+"!"); }
Example 11
Source File: TestLocalServerCreateDelete.java From rdf-delta with Apache License 2.0 | 5 votes |
private static void initialize() { Location loc = Location.create(DIR); FileOps.clearAll(DIR); // Copy in test setup. try { FileUtils.copyDirectory(new File(TestLocalServer.SERVER_DIR), new File(DIR)); } catch (IOException ex) { throw IOX.exception(ex); } DPS.resetSystem(); }
Example 12
Source File: BackupImport.java From openmeetings with Apache License 2.0 | 5 votes |
private void processProfiles(File baseDir) throws IOException { log.debug("Entered profiles folder"); for (File profile : baseDir.listFiles()) { Long id = getPrefixedId(PROFILES_PREFIX, profile, userMap); if (id != null) { FileUtils.copyDirectory(profile, getUploadProfilesUserDir(id)); } } }
Example 13
Source File: GitProjectRepoTest.java From writelatex-git-bridge with MIT License | 5 votes |
public static File makeTempRepoDir( TemporaryFolder tmpFolder, String name ) throws IOException { File tmp = tmpFolder.newFolder(name); Path rootdir = Paths.get( "src/test/resources/uk/ac/ic/wlgitbridge/" + "bridge/repo/GitProjectRepoTest/rootdir" ); FileUtils.copyDirectory(rootdir.toFile(), tmp); Files.renameAll(tmp, "DOTgit", ".git"); return tmp; }
Example 14
Source File: ProjectExplorerRefreshTest.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Test Refresh after modifying trace content while trace is opened. * * @throws IOException if an exception occurs */ @Test public void test16_02RefreshOpenedTraceContentModified() throws IOException { SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME); SWTBotTreeItem kernelTrace = SWTBotUtils.getTraceProjectItem(fBot, tracesFolder, TEST_FILE_KERNEL.getName()); kernelTrace.contextMenu().menu("Open").click(); SWTBotUtils.activateEditor(fBot, TEST_FILE_KERNEL.getName()); tracesFolder.contextMenu().menu("Open As Experiment...", "Generic Experiment").click(); SWTBotUtils.activateEditor(fBot, "Experiment"); SWTBotTreeItem project = SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME); SWTBotTreeItem experiment = SWTBotUtils.getTraceProjectItem(fBot, project, "Experiments", "Experiment"); FileUtils.copyDirectory(TEST_FILE_KERNEL_CLASH, FileUtils.getFile(fTracesFolder, TEST_FILE_KERNEL.getName()), false); // false -> last modified times are copied file time stamps assertTrue(kernelTrace.contextMenu().menuItems().contains("Delete Supplementary Files...")); assertTrue(experiment.contextMenu().menuItems().contains("Delete Supplementary Files...")); refresh(() -> tracesFolder.contextMenu().menu("Refresh").click()); SWTBotShell shell = fBot.shell("Trace Changed"); shell.bot().button("No").click(); assertTrue(kernelTrace.contextMenu().menuItems().contains("Delete Supplementary Files...")); assertTrue(experiment.contextMenu().menuItems().contains("Delete Supplementary Files...")); SWTBotUtils.activateEditor(fBot, TEST_FILE_KERNEL.getName()); SWTBotUtils.activateEditor(fBot, "Experiment"); FileUtils.copyDirectory(TEST_FILE_KERNEL, FileUtils.getFile(fTracesFolder, TEST_FILE_KERNEL.getName()), true); // true -> last modified times are original file time stamps assertTrue(kernelTrace.contextMenu().menuItems().contains("Delete Supplementary Files...")); refresh(() -> tracesFolder.contextMenu().menu("Refresh").click()); shell = fBot.shell("Trace Changed"); shell.bot().button("Yes").click(); SWTBotUtils.waitUntil(treeItem -> !treeItem.contextMenu().menuItems().contains("Delete Supplementary Files..."), kernelTrace, "Supplementary Files did not get deleted"); assertEquals(0, fBot.editors().size()); }
Example 15
Source File: TestHelper.java From butterfly with MIT License | 5 votes |
@BeforeMethod public void beforeMethod(Method method) throws URISyntaxException, IOException { transformedAppFolder = new File(appFolder.getParentFile(), String.format("test-app_%s_%s_%s", method.getDeclaringClass().getSimpleName(), method.getName(), System.currentTimeMillis())); FileUtils.copyDirectory(appFolder, transformedAppFolder); System.out.printf("Transformed app folder: %s\n", transformedAppFolder.getAbsolutePath()); transformationContext = Mockito.mock(TransformationContext.class); }
Example 16
Source File: WebJarControllerTest.java From wisdom with Apache License 2.0 | 4 votes |
@Test public void testEtagAndCacheControl() throws IOException, InterruptedException { ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); Crypto crypto = mock(Crypto.class); when(crypto.hexSHA1(anyString())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { try { String value = (String) invocation.getArguments()[0]; MessageDigest md; md = MessageDigest.getInstance(Hash.SHA1.toString()); md.update(value.getBytes("utf-8")); byte[] digest = md.digest(); return String.valueOf(Hex.encodeHex(digest)); } catch (Exception ex) { throw new RuntimeException(ex); } } }); root = new File("target/wisdom-test"); webjars.mkdirs(); // Copy autobahn FileUtils.copyDirectory(new File("target/test-classes/autobahnjs"), new File(webjars, "autobahnjs")); when(configuration.getBaseDir()).thenReturn(root); when(configuration.getWithDefault(CacheUtils.HTTP_CACHE_CONTROL_MAX_AGE, CacheUtils.HTTP_CACHE_CONTROL_DEFAULT)).thenReturn(CacheUtils .HTTP_CACHE_CONTROL_DEFAULT); when(configuration.getBooleanWithDefault(CacheUtils.HTTP_USE_ETAG, CacheUtils.HTTP_USE_ETAG_DEFAULT)).thenReturn(CacheUtils.HTTP_USE_ETAG_DEFAULT); final WebJarController controller = new WebJarController(crypto, configuration, "assets/libs"); assertThat(root).isNotNull(); // First attempt Action.ActionResult result = action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.serve(); } }).parameter("path", "autobahn.min.js").invoke(); assertThat(result.getResult().getStatusCode()).isEqualTo(200); assertThat(result.getResult().getHeaders().get("Cache-Control")).isEqualTo("max-age=3600"); assertThat(result.getResult().getHeaders().get("Etag")).isNotNull(); String lastModified = result.getResult().getHeaders().get("Last-Modified"); String etag = result.getResult().getHeaders().get("Etag"); // If-None-Match (ETAG check) result = action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.serve(); } }).parameter("path", "autobahn.min.js").header("If-None-Match", etag).invoke(); // Not modified. assertThat(result.getResult().getStatusCode()).isEqualTo(304); // If-Modified-Since (Date check) result = action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.serve(); } }).parameter("path", "autobahn.min.js").header("If-Modified-Since", lastModified).invoke(); // Not modified. assertThat(result.getResult().getStatusCode()).isEqualTo(304); }
Example 17
Source File: AbstractEmbeddedSolrServerTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
@BeforeClass public static void setUpHome() throws Exception { CONFIG_HOME = getFile("solrj/solr/shared").toPath().toAbsolutePath(); SOLR_HOME = createTempDir("solrHome"); FileUtils.copyDirectory(CONFIG_HOME.toFile(), SOLR_HOME.toFile()); }
Example 18
Source File: AnsibleFacadeImpl.java From zstack with Apache License 2.0 | 4 votes |
@Override public void deployModule(String modulePath, String playBookName) { File src = PathUtil.findFolderOnClassPath(modulePath, true); if (!src.isDirectory()) { throw new CloudRuntimeException(String.format("Cannot find ansible module[%s], it's either not existing or not a directory", modulePath)); } String moduleName = src.getName(); File root = new File(AnsibleConstant.ROOT_DIR); if (!root.exists()) { root.mkdirs(); } File filesRoot = new File(filesDir); if (!filesRoot.exists()) { filesRoot.mkdirs(); } try { if (!isNeedToDeploy(moduleName, src.getAbsolutePath())) { return; } String destModulePath = PathUtil.join(filesRoot.getAbsolutePath(), moduleName); File dest = new File(destModulePath); if (dest.exists()) { FileUtils.forceDelete(dest); FileUtils.forceMkdir(dest); } FileUtils.copyDirectory(src, dest); boolean isPlaybookLinked = false; for (File f : dest.listFiles()) { if (f.getName().equals(playBookName)) { String lnPath = PathUtil.join(AnsibleConstant.ROOT_DIR, playBookName); File lnFile = new File(lnPath); if (lnFile.exists()) { lnFile.delete(); } Files.createSymbolicLink(Paths.get(lnPath), Paths.get(f.getAbsolutePath())); isPlaybookLinked = true; } } // if playBookName=null, skip the deploy steps because the deploy is not independent if (playBookName != null && !isPlaybookLinked) { throw new IllegalArgumentException(String.format("cannot find playbook[%s] in module[%s], module files are%s", playBookName, modulePath, Arrays.asList(src.list()))); } logger.debug(String.format("successfully deployed ansible module[%s]", modulePath)); } catch (Exception e) { String err = String.format("Unable to deploy ansible module[%s] from %s", moduleName, modulePath); throw new CloudRuntimeException(err, e); } }
Example 19
Source File: GradleMicroProfileLRATest.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@Override public void setUp() throws Exception { super.setUp(); FileUtils.copyDirectory(new File("projects/gradle/microprofile-lra"), new File(getProjectPath())); importProject(); }
Example 20
Source File: GradleMicroProfileFaultToleranceTest.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@Override public void setUp() throws Exception { super.setUp(); FileUtils.copyDirectory(new File("projects/gradle/microprofile-fault-tolerance"), new File(getProjectPath())); importProject(); }