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.datasalt.pangool.solr.SolrRecordWriter.java
public SolrRecordWriter(int batchSize, boolean outputZipFile, int threadCount, int queueSize, String localSolrHome, String zipName, TupleDocumentConverter converter, TaskAttemptContext context) { this.localSolrHome = localSolrHome; this.zipName = zipName; conf = context.getConfiguration();/*from w ww . ja v a2 s .com*/ this.batchSize = batchSize; setLogLevel("org.apache.solr.core", "WARN"); setLogLevel("org.apache.solr.update", "WARN"); Logger.getLogger("org.apache.solr.core").setLevel(Level.WARN); Logger.getLogger("org.apache.solr.update").setLevel(Level.WARN); java.util.logging.Logger.getLogger("org.apache.solr.core").setLevel(java.util.logging.Level.WARNING); java.util.logging.Logger.getLogger("org.apache.solr.update").setLevel(java.util.logging.Level.WARNING); setLogLevel("org.apache.solr", "WARN"); Logger.getLogger("org.apache.solr").setLevel(Level.WARN); java.util.logging.Logger.getLogger("org.apache.solr").setLevel(java.util.logging.Level.WARNING); heartBeater = new HeartBeater(context); try { heartBeater.needHeartBeat(); /** The actual file in hdfs that holds the configuration. */ this.outputZipFile = outputZipFile; this.fs = FileSystem.get(conf); perm = new Path(FileOutputFormat.getOutputPath(context), getOutFileName(context, "part")); // Make a task unique name that contains the actual index output name to // make debugging simpler // Note: if using JVM reuse, the sequence number will not be reset for a // new task using the jvm Path temp = conf.getLocalPath("mapred.local.dir", "solr_" + conf.get("mapred.task.id") + '.' + sequence.incrementAndGet()); if (outputZipFile && !perm.getName().endsWith(".zip")) { perm = perm.suffix(".zip"); } fs.delete(temp, true); // delete old, if any fs.delete(perm, true); // delete old, if any local = fs.startLocalOutput(perm, temp); solrHome = findSolrConfig(conf); // } // Verify that the solr home has a conf and lib directory if (solrHome == null) { throw new IOException("Unable to find solr home setting"); } // Setup a solr instance that we can batch writes to LOG.info("SolrHome: " + solrHome.toUri()); String dataDir = new File(local.toString(), "data").getAbsoluteFile().toString(); // copy the schema to the conf dir File confDir = new File(local.toString(), "conf"); confDir.mkdirs(); File unpackedSolrHome = new File(solrHome.toString()); FileUtils.copyDirectory(new File(unpackedSolrHome, "conf"), confDir); Properties props = new Properties(); props.setProperty("solr.data.dir", dataDir); props.setProperty("solr.home", solrHome.toString()); SolrResourceLoader loader = new SolrResourceLoader(solrHome.toString(), null, props); LOG.info(String.format( "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to temporary directory %s, with permdir %s", solrHome, solrHome.toUri(), loader.getInstanceDir(), loader.getConfigDir(), dataDir, perm)); CoreContainer container = new CoreContainer(loader); CoreDescriptor descr = new CoreDescriptor(container, "core1", solrHome.toString()); descr.setDataDir(dataDir); descr.setCoreProperties(props); core = container.create(descr); container.register(core, false); solr = new EmbeddedSolrServer(container, "core1"); batchWriter = new BatchWriter(solr, batchSize, context.getTaskAttemptID().getTaskID(), threadCount, queueSize); this.converter = converter; } catch (Exception e) { e.printStackTrace(); LOG.error(e); throw new IllegalStateException(String.format("Failed to initialize record writer for %s, %s", context.getJobName(), conf.get("mapred.task.id")), e); } finally { heartBeater.cancelHeartBeat(); } }
From source file:com.pieframework.runtime.utils.azure.Cspack.java
private void stageRoleBinaries(Role role, File roleDir) { File roleBin = null;// w w w. j av a 2s. c o m if (role.getProps().get("type") != null) { roleBin = new File(roleDir.getPath() + File.separatorChar); roleBin.mkdir(); if (roleBin != null) { for (String key : role.getChildren().keySet()) { if (role.getChildren().get(key) instanceof Service) { Service s = (Service) role.getChildren().get(key); if (s.getProps().get("type") != null && s.getProps().get("type").equalsIgnoreCase("application")) { String query = s.getProps().get("package"); if (query != null) { String fQuery = s.getProps().get("package"); String nQuery = ResourceLoader.getResourceName(fQuery); String pQuery = ResourceLoader.getResourcePath(fQuery); Files bootstrap = (Files) s.getResources().get(nQuery); if (bootstrap != null) { List<File> flist = ResourceLoader.findPath(bootstrap.getLocalPath(), pQuery); if (flist.size() == 1 && flist.get(0).exists() && FilenameUtils.isExtension(flist.get(0).getPath(), "zip")) { try { Zipper.unzip(flist.get(0).getPath(), roleBin.getPath()); if (role.getProps().get("type").equals("WebRole")) { //Cleanup non-bin files for (File f : roleBin.listFiles()) { if (!f.getName().equalsIgnoreCase("bin")) { FileUtils.forceDelete(f); } } //Move contents of bin dir into the current directory File binDir = new File( roleBin.getPath() + File.separatorChar + "bin"); if (binDir.exists()) { for (File f : binDir.listFiles()) { if (f.isDirectory()) { FileUtils.copyDirectory(f, roleBin); } else { FileUtils.copyFileToDirectory(f, roleBin); } } FileUtils.forceDelete(binDir); } } } catch (ZipException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } } } } } }
From source file:com.redhat.jenkins.nodesharing.NodeSharingJenkinsRule.java
private GitClient createConfigRepo() throws URISyntaxException, IOException, InterruptedException { File orig = new File(getClass().getResource("dummy_config_repo").toURI()); Assert.assertTrue(orig.isDirectory()); File repo = File.createTempFile("jenkins.nodesharing", getClass().getSimpleName()); assert repo.delete(); assert repo.mkdir(); FileUtils.copyDirectory(orig, repo); StreamTaskListener listener = new StreamTaskListener(System.err, Charset.defaultCharset()); // To make it work with no gitconfig String name = "Pool Maintainer"; String mail = "pool.maintainer@acme.com"; EnvVars env = new EnvVars("GIT_AUTHOR_NAME", name, "GIT_AUTHOR_EMAIL", mail, "GIT_COMMITTER_NAME", name, "GIT_COMMITTER_EMAIL", mail); GitClient git = Git.with(listener, env).in(repo).using("git").getClient(); git.init();//from ww w. j a v a 2s. com git.add("*"); git.commit("Init"); return git; }
From source file:edu.isi.wings.portal.classes.domains.Domain.java
public static Domain importDomain(String domName, Config config, String importDomDir) { String domurl;//ww w . j a v a 2 s . c om try { domurl = FileUtils.readFileToString(new File(importDomDir + File.separator + "domain.url")); domurl = domurl.trim(); } catch (IOException e1) { e1.printStackTrace(); return null; } Domain fromdom = new Domain(domName, importDomDir, domurl, false); Properties props = config.getProperties(fromdom); DataCreationAPI dc = DataFactory.getCreationAPI(props); ComponentCreationAPI acc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI ccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props); ResourceAPI rc = ResourceFactory.getAPI(props); Domain todom = Domain.createDefaultDomain(domName, config.getUserDir(), config.getExportUserUrl()); props = config.getProperties(todom); DataCreationAPI todc = DataFactory.getCreationAPI(props); ComponentCreationAPI toacc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI toccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI totc = TemplateFactory.getCreationAPI(props); ResourceAPI torc = ResourceFactory.getAPI(props); // Copy from file-based apis to triple-store apis todc.copyFrom(dc); toacc.copyFrom(acc); toccc.copyFrom(ccc); totc.copyFrom(tc); if (rc != null && torc != null) torc.copyFrom(rc, ccc); // Copy legacy data/code directories to new data/code storage directory File srcDataDir = new File( fromdom.getDomainDirectory() + fsep + fromdom.getDataLibrary().getStorageDirectory()); File destDataDir = new File( todom.getDomainDirectory() + fsep + todom.getDataLibrary().getStorageDirectory()); File srcCodeDir = new File( fromdom.getDomainDirectory() + fsep + fromdom.getConcreteComponentLibrary().getStorageDirectory()); File destCodeDir = new File( todom.getDomainDirectory() + fsep + todom.getConcreteComponentLibrary().getStorageDirectory()); File srcBeamerDir = new File(fromdom.getDomainDirectory() + fsep + "beamer"); File destBeamerDir = new File(todom.getDomainDirectory() + fsep + "beamer"); try { if (srcDataDir.isDirectory()) FileUtils.copyDirectory(srcDataDir, destDataDir); if (srcCodeDir.isDirectory()) { FileUtils.copyDirectory(srcCodeDir, destCodeDir); // FIXME: Setting executable permissions on all files for now for (File f : FileUtils.listFiles(destCodeDir, null, true)) { f.setExecutable(true); } } if (srcBeamerDir.isDirectory()) FileUtils.copyDirectory(srcBeamerDir, destBeamerDir); } catch (IOException e) { e.printStackTrace(); } return todom; }
From source file:com.collective.celos.CelosClientServerTest.java
@Test public void testGetWorkflowStatusTransitionToRunningFailsWrongOozieService() throws Exception { File src = new File(Thread.currentThread().getContextClassLoader() .getResource("com/collective/celos/client/wf-list").toURI()); FileUtils.copyDirectory(src, workflowsDir); celosClient.iterateScheduler();/*from ww w . j ava 2s . c om*/ celosClient.iterateScheduler(); List<SlotState> slotStates = celosClient.getWorkflowStatus(new WorkflowID("workflow-1")).getSlotStates(); Assert.assertEquals(slotStates.size(), SLOTS_IN_CELOS_SERVER_SLIDING_WINDOW); for (SlotState slotState : slotStates) { Assert.assertEquals(slotState.getStatus(), SlotState.Status.READY); Assert.assertNull(slotState.getExternalID()); Assert.assertEquals(slotState.getRetryCount(), 0); } }
From source file:com.badlogicgames.packr.Packr.java
private void copyResources(File targetDir, List<String> resources) throws IOException { for (String resource : resources) { File file = new File(resource); if (!file.exists()) { System.out.println("resource '" + file.getAbsolutePath() + "' doesn't exist"); System.exit(-1);/* w w w. ja v a 2 s.c om*/ } if (file.isFile()) { FileUtils.copyFile(file, new File(targetDir, file.getName())); } if (file.isDirectory()) { File target = new File(targetDir, file.getName()); target.mkdirs(); FileUtils.copyDirectory(file, target); } } }
From source file:azkaban.execapp.event.LocalFlowWatcherTest.java
private ExecutableFlow prepareExecDir(File workingDir, File execDir, String flowName, int execId) throws IOException { FileUtils.copyDirectory(execDir, workingDir); File jsonFlowFile = new File(workingDir, flowName + ".flow"); @SuppressWarnings("unchecked") HashMap<String, Object> flowObj = (HashMap<String, Object>) JSONUtils.parseJSONFromFile(jsonFlowFile); Project project = new Project(1, "test"); Flow flow = Flow.flowFromObject(flowObj); ExecutableFlow execFlow = new ExecutableFlow(project, flow); execFlow.setExecutionId(execId);//from w w w . ja va 2s. c o m execFlow.setExecutionPath(workingDir.getPath()); return execFlow; }
From source file:de.crowdcode.movmvn.plugin.general.GeneralPlugin.java
private void moveFiles() { try {/*from www . j ava 2 s . c o m*/ context.logInfo("Move files..."); String projectSourceName = context.getProjectSourceName(); String projectTargetName = context.getProjectTargetName(); // Move files *.java from src -> src/main/java // Move files *.properties;*.txt;*.jpg -> src/main/resources // Move files *.java from test -> src/test/java // Move files *.properties;*.txt;*.jpg -> src/test/resources // Move files *.* from resources or resource -> src/main/resources // Move files from / to / but not .classpath, .project -> // src/main/resources // Move directory META-INF -> src/main/resources String[] extensionsJava = { "java" }; Iterator<File> fileIterator = FileUtils.iterateFiles(new File(projectSourceName + "/src"), extensionsJava, true); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); String nameResultAfterSrc = StringUtils.substringAfterLast(currentFile.getAbsolutePath(), "src\\"); nameResultAfterSrc = projectTargetName.concat("/src/main/java/").concat(nameResultAfterSrc); log.info("Target file: " + nameResultAfterSrc); File targetFile = new File(nameResultAfterSrc); FileUtils.copyFile(currentFile, targetFile, true); } // Check whether "resource" or "resources" exist? File directoryResources = new File(projectSourceName + "/resource"); File targetResourcesDir = new File(projectTargetName.concat("/src/main/resources")); if (directoryResources.exists()) { // Move the files FileUtils.copyDirectory(directoryResources, targetResourcesDir); } directoryResources = new File(projectSourceName + "/resources"); if (directoryResources.exists()) { // Move the files FileUtils.copyDirectory(directoryResources, targetResourcesDir); } // META-INF File directoryMetaInf = new File(projectSourceName + "/META-INF"); if (directoryMetaInf.exists()) { FileUtils.copyDirectoryToDirectory(directoryMetaInf, targetResourcesDir); } // Directory . *.txt, *.doc*, *.png, *.jpg -> src/main/docs File targetDocsDir = new File(projectTargetName.concat("/src/main/docs")); String[] extensionsRootDir = { "txt", "doc", "docx", "png", "jpg" }; fileIterator = FileUtils.iterateFiles(new File(projectSourceName), extensionsRootDir, false); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); FileUtils.copyFileToDirectory(currentFile, targetDocsDir); } // Directory . *.cmd, *.sh -> src/main/bin File targetBinDir = new File(projectTargetName.concat("/src/main/bin")); String[] extensionsRootBinDir = { "sh", "cmd", "properties" }; fileIterator = FileUtils.iterateFiles(new File(projectSourceName), extensionsRootBinDir, false); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); FileUtils.copyFileToDirectory(currentFile, targetBinDir); } } catch (IOException e) { log.info(e.getStackTrace().toString()); } }
From source file:ml.shifu.shifu.ShifuCLITest.java
@Test public void testRunEvalAll() throws Exception { File originModel = new File( "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json"); File tmpModel = new File("ModelConfig.json"); File originColumn = new File( "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json"); File tmpColumn = new File("ColumnConfig.json"); File modelsDir = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models"); File tmpModelsDir = new File("models"); FileUtils.copyFile(originModel, tmpModel); FileUtils.copyFile(originColumn, tmpColumn); FileUtils.copyDirectory(modelsDir, tmpModelsDir); // run evaluation set ShifuCLI.runEvalSet(false);//from w w w .j a va 2 s .c o m File evalScore = new File("evals/EvalA/EvalScore"); Assert.assertTrue(evalScore.exists()); FileUtils.deleteQuietly(tmpModel); FileUtils.deleteQuietly(tmpColumn); FileUtils.deleteQuietly(new File("evals/EvalA/EvalConfusionMatrix")); FileUtils.deleteQuietly(new File("evals/EvalB/EvalConfusionMatrix")); }
From source file:com.alibaba.jstorm.daemon.supervisor.SyncSupervisorEvent.java
/** * Don't need synchronize, due to EventManager will execute serially * /* w w w .j av a 2s.c o m*/ * @param conf * @param topologyId * @param masterCodeDir * @throws IOException * @throws TException */ private void downloadDistributeStormCode(Map conf, String topologyId, String masterCodeDir) throws IOException, TException { // STORM_LOCAL_DIR/supervisor/tmp/(UUID) String tmproot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString(); // STORM_LOCAL_DIR/supervisor/stormdist/topologyId String stormroot = StormConfig.supervisor_stormdist_root(conf, topologyId); JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true); // tmproot/stormjar.jar String localFileJarTmp = StormConfig.stormjar_path(tmproot); // extract dir from jar JStormUtils.extract_dir_from_jar(localFileJarTmp, StormConfig.RESOURCES_SUBDIR, tmproot); File srcDir = new File(tmproot); File destDir = new File(stormroot); try { FileUtils.moveDirectory(srcDir, destDir); } catch (FileExistsException e) { FileUtils.copyDirectory(srcDir, destDir); FileUtils.deleteQuietly(srcDir); } }