List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:es.bsc.servicess.ide.actions.DeployAction.java
private void deployCoreElements(IJavaProject project, String coreElementsFolder) throws IOException { IFolder outFolder = project.getProject().getFolder("output"); // TODO: chage for different ce IFile war = outFolder.getFile(project.getProject().getName() + "_CoreElements.jar"); File srcFile = war.getLocation().toFile(); File ceDir = new File(coreElementsFolder); if (ceDir.isDirectory()) { FileUtils.copyFileToDirectory(srcFile, ceDir); }/*from www . j a v a 2 s .co m*/ }
From source file:com.athena.meerkat.controller.web.provisioning.AbstractProvisioningService.java
protected void copyAntScript(String cmdFileName, File jobDir) throws IOException { String cmdsPath = getCmdsPath(); FileUtils.copyFileToDirectory(new File(cmdsPath + cmdFileName), jobDir); }
From source file:de.tarent.maven.plugins.pkg.Utils.java
/** * Copies the <code>AuxFile</code> instances contained within the set. It * takes the <code>srcAuxFilesDir</code> and <code>auxFileDstDir</code> * arguments into account to specify the parent source and destination * directory of the files.//from w w w.ja v a 2s .com * * By default files are copied into directories. If the <code>rename</code> * property of the <code>AuxFile</code> instance is set however the file is * copied and renamed to the last part of the path. * * The return value is the amount of copied bytes. * * @param l * @param srcAuxFilesDir * @param dstDir * @param auxFiles * @param makeExecutable * @return * @throws MojoExecutionException */ public static long copyFiles(Log l, File srcDir, File dstDir, List<? extends AuxFile> auxFiles, String type, boolean makeExecutable) throws MojoExecutionException { long size = 0; Iterator<? extends AuxFile> ite = auxFiles.iterator(); while (ite.hasNext()) { AuxFile af = (AuxFile) ite.next(); File from = new File(srcDir, af.from); File to = new File(dstDir, af.to); l.info("copying " + type + ": " + from.toString()); l.info("destination: " + to.toString()); if (!from.exists()) { throw new MojoExecutionException("File to copy does not exist: " + from.toString()); } createParentDirs(to, type); try { if (from.isDirectory()) { to = new File(to, from.getName()); FileUtils.copyDirectory(from, to, FILTER); for (final Iterator<File> files = FileUtils.iterateFiles(from, FILTER, FILTER); files .hasNext();) { final File nextFile = files.next(); size += nextFile.length(); } } else if (af.isRename()) { FileUtils.copyFile(from, to); size += from.length(); if (makeExecutable) { makeExecutable(l, to.getAbsolutePath()); } } else { FileUtils.copyFileToDirectory(from, to); size += from.length(); if (makeExecutable) { makeExecutable(l, to.getAbsolutePath() + File.separator + from.getName()); } } } catch (IOException ioe) { throw new MojoExecutionException("IOException while copying " + type, ioe); } } return size; }
From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicProperties.java
/** * CHECKING FOR datastore.properties If the 'datastore.properties' do not exists into the * baseDir, try to use the configured one. If not found a shape file will be used (done by the * geoserver)./* w w w . j av a 2s .c om*/ * * @param baseDir * the directory of the layer * @return File (unchecked) datastore.properties if succes or null if some error occurred. */ protected static File checkDataStore(ImageMosaicConfiguration configuration, File configDir, File baseDir) { final File datastore = new File(baseDir, "datastore.properties"); if (datastore.exists()) { return datastore; } if (configuration.getDatastorePropertiesPath() == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("DataStoreProperties file not configured " + "nor found into destination dir. A shape file will be used."); } return null; } final File dsFile = Path.findLocation(configuration.getDatastorePropertiesPath(), configDir); if (dsFile == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to get the absolute path of the datastore properties file " + "(file: " + configuration.getDatastorePropertiesPath() + ") " + "(cfgdir: " + configDir + ")"); } } else { if (!dsFile.isDirectory()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Configuration DataStore file found: '" + dsFile.getAbsolutePath() + "'."); } try { FileUtils.copyFileToDirectory(dsFile, baseDir); return new File(baseDir, dsFile.getName()); } catch (IOException e) { if (LOGGER.isWarnEnabled()) LOGGER.warn(e.getMessage(), e); } } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn("DataStoreProperties file points to a directory! " + dsFile.getAbsolutePath() + "'. Skipping event"); } } } return null; }
From source file:com.cubeia.maven.plugin.firebase.FirebaseRunPlugin.java
private void copyProjectArtifactToDeploy(File firebaseDir) throws MojoFailureException, MojoExecutionException { File artifact = getProjectArtifactFile(); File target = ensureFirebaseDeployLib(firebaseDir); try {/*from w ww . java 2s . c o m*/ FileUtils.copyFileToDirectory(artifact, target); } catch (IOException e) { throw new MojoExecutionException("Failed to copy project artifact to deploy directory", e); } }
From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListFragment.java
public void backupFile(File file, File directory) { try {/*from w w w. j av a 2 s. co m*/ FileUtils.copyFileToDirectory(file, directory); } catch (FileNotFoundException f) { f.printStackTrace(); } catch (IOException e) { Toast.makeText(getActivity(), R.string.toast_backup_restore_exception, Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }
From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java
private void testSetup() throws IOException { // Setup//from w w w .j av a2 s. c om tempDir = folder.newFolder(TEMP_DIR_NAME); LOGGER.debug("Making directory: " + tempDir.getPath()); tempDir.mkdir(); File srcFile = new File( PROJECT_HOME + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE); FileUtils.copyFileToDirectory(srcFile, tempDir); }
From source file:edu.isi.wings.portal.controllers.RunController.java
public String publishRun(String runid) { HashMap<String, String> retmap = new HashMap<String, String>(); ExecutionMonitorAPI monitor = config.getDomainExecutionMonitor(); RuntimePlan plan = monitor.getRunDetails(runid); if (plan.getRuntimeInfo().getStatus() != Status.SUCCESS) { retmap.put("error", "Can only publish successfully completed runs"); } else {// w w w. j a va 2 s .co m try { Mapper opmm = new Mapper(); Publisher publisher = config.getPublisher(); String tstoreurl = publisher.getTstoreUrl(); String puburl = publisher.getUrl(); String upurl = publisher.getUploadServer().getUrl(); opmm.setPublishExportPrefix(puburl); String rname = runid.substring(runid.indexOf('#') + 1); String runurl = opmm.getRunUrl(rname); String tid = plan.getOriginalTemplateID(); String tmpname = tid.substring(tid.indexOf('#') + 1); String tmd5 = getTemplateMD5(plan.getOriginalTemplateID()); String tname = tmpname + "-" + tmd5; String turl = opmm.getTemplateUrl(tname); // Check if run already published if (graphExists(tstoreurl, runurl)) { retmap.put("url", runurl); retmap.put("error", "Run already published"); return json.toJson(retmap); } // Fetch expanded template (to get data binding ids) TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props); Template xtpl = tc.getTemplate(plan.getExpandedTemplateID()); HashMap<String, String> varBindings = new HashMap<String, String>(); for (Variable var : xtpl.getVariables()) { varBindings.put(var.getID(), var.getBinding().getID()); } // Create a temporary directory to upload/move File _tmpdir = File.createTempFile("temp", ""); File tempdir = new File(_tmpdir.getParent() + "/" + rname); FileUtils.deleteQuietly(tempdir); if (!_tmpdir.delete() || !tempdir.mkdirs()) throw new Exception("Cannot create temp directory"); File datadir = new File(tempdir.getAbsolutePath() + "/data"); File codedir = new File(tempdir.getAbsolutePath() + "/code"); File dcontdir = new File(tempdir.getAbsolutePath() + "/ont/data"); File acontdir = new File(tempdir.getAbsolutePath() + "/ont/components"); File wflowdir = new File(tempdir.getAbsolutePath() + "/ont/workflows"); File execsdir = new File(tempdir.getAbsolutePath() + "/ont/executions"); datadir.mkdirs(); codedir.mkdirs(); dcontdir.mkdirs(); acontdir.mkdirs(); wflowdir.mkdirs(); execsdir.mkdirs(); String tupurl = upurl + "/" + tempdir.getName(); String dataurl = tupurl + "/data"; String codeurl = tupurl + "/code"; String dconturl = tupurl + "/ont/data"; String aconturl = tupurl + "/ont/components"; String wflowurl = tupurl + "/ont/workflows"; String execsurl = tupurl + "/ont/executions"; Properties props = config.getProperties(); String dclib = props.getProperty("lib.domain.data.url"); String dcont = props.getProperty("ont.domain.data.url"); String aclib = props.getProperty("lib.concrete.url"); String acabs = props.getProperty("lib.abstract.url"); String wfpfx = props.getProperty("domain.workflows.dir.url"); String expfx = props.getProperty("domain.executions.dir.url"); String cdir = props.getProperty("lib.domain.code.storage"); String ddir = props.getProperty("lib.domain.data.storage"); // Get files to upload && modify "Locations" to point to uploaded urls HashSet<ExecutionFile> uploadFiles = new HashSet<ExecutionFile>(); HashSet<ExecutionCode> uploadCodes = new HashSet<ExecutionCode>(); for (ExecutionStep step : plan.getPlan().getAllExecutionSteps()) { for (ExecutionFile file : step.getInputFiles()) uploadFiles.add(file); for (ExecutionFile file : step.getOutputFiles()) uploadFiles.add(file); uploadCodes.add(step.getCodeBinding()); } for (ExecutionFile file : uploadFiles) { File copyfile = new File(file.getLocation()); // Only upload files below a threshold file size long maxsize = publisher.getUploadServer().getMaxUploadSize(); if (copyfile.length() > 0 && (maxsize == 0 || copyfile.length() < maxsize)) { // Copy over file to temp directory FileUtils.copyFileToDirectory(copyfile, datadir); // Change file path in plan to the web accessible one file.setLocation(file.getLocation().replace(ddir, dataurl)); } else { String bindingid = varBindings.get(file.getID()); file.setLocation(config.getServerUrl() + this.dataUrl + "/fetch?data_id=" + URLEncoder.encode(bindingid, "UTF-8")); } } for (ExecutionCode code : uploadCodes) { File copydir = null; if (code.getCodeDirectory() != null) { copydir = new File(code.getCodeDirectory()); // Change path in plan to the web accessible one code.setCodeDirectory(code.getCodeDirectory().replace(cdir, codeurl)); } else { File f = new File(code.getLocation()); copydir = f.getParentFile(); } // Copy over directory to temp directory FileUtils.copyDirectoryToDirectory(copydir, codedir); // Change path in plan to the web accessible one code.setLocation(code.getLocation().replace(cdir, codeurl)); } String dcontdata = IOUtils.toString(new URL(dcont)); dcontdata = dcontdata.replace(dcont, dconturl + "/ontology.owl"); FileUtils.write(new File(dcontdir.getAbsolutePath() + "/ontology.owl"), dcontdata); String dclibdata = IOUtils.toString(new URL(dclib)); dclibdata = dclibdata.replace(dcont, dconturl + "/ontology.owl"); dclibdata = dclibdata.replace(dclib, dconturl + "/library.owl"); dclibdata = dclibdata.replace(ddir, dataurl); FileUtils.write(new File(dcontdir.getAbsolutePath() + "/library.owl"), dclibdata); String aclibdata = IOUtils.toString(new URL(aclib)); aclibdata = aclibdata.replace(dcont, aconturl + "/ontology.owl"); aclibdata = aclibdata.replace(aclib, aconturl + "/library.owl"); aclibdata = aclibdata.replace(cdir, codeurl); FileUtils.write(new File(acontdir.getAbsolutePath() + "/library.owl"), aclibdata); String acabsdata = IOUtils.toString(new URL(acabs)); acabsdata = acabsdata.replace(dcont, dconturl + "/ontology.owl"); acabsdata = acabsdata.replace(aclib, aconturl + "/library.owl"); acabsdata = acabsdata.replace(acabs, aconturl + "/abstract.owl"); FileUtils.write(new File(acontdir.getAbsolutePath() + "/abstract.owl"), acabsdata); File planfile = new File(execsdir.getAbsolutePath() + "/" + plan.getPlan().getName() + ".owl"); String plandata = plan.getPlan().serialize(); plandata = plandata.replace("\"" + wfpfx, "\"" + wflowurl); plandata = plandata.replace("\"" + expfx, "\"" + execsurl); plandata = plandata.replace(dclib, dconturl + "/library.owl"); plandata = plandata.replace(dcont, dconturl + "/ontology.owl"); plandata = plandata.replace(aclib, aconturl + "/library.owl"); plandata = plandata.replace(acabs, aconturl + "/abstract.owl"); FileUtils.write(planfile, plandata); String rplanurl = execsurl + "/" + plan.getName() + ".owl"; File rplanfile = new File(execsdir.getAbsolutePath() + "/" + plan.getName() + ".owl"); String rplandata = IOUtils.toString(new URL(runid)); rplandata = rplandata.replace(wfpfx, wflowurl); rplandata = rplandata.replace(expfx, execsurl); rplandata = rplandata.replace(tmpname + ".owl", tname + ".owl"); rplandata = rplandata.replace("#" + tmpname + "\"", "#" + tname + "\""); rplandata = rplandata.replace(dclib, dconturl + "/library.owl"); rplandata = rplandata.replace(dcont, dconturl + "/ontology.owl"); rplandata = rplandata.replace(aclib, aconturl + "/library.owl"); rplandata = rplandata.replace(acabs, aconturl + "/abstract.owl"); FileUtils.write(rplanfile, rplandata); URL otplurl = new URL(plan.getOriginalTemplateID()); String otmplurl = wflowurl + "/" + otplurl.getRef() + ".owl"; File otplfile = new File(wflowdir.getAbsolutePath() + "/" + otplurl.getRef() + ".owl"); String otpldata = IOUtils.toString(otplurl); otpldata = otpldata.replace(wfpfx, wflowurl); otpldata = otpldata.replace(expfx, execsurl); otpldata = otpldata.replace(dclib, dconturl + "/library.owl"); otpldata = otpldata.replace(dcont, dconturl + "/ontology.owl"); otpldata = otpldata.replace(aclib, aconturl + "/library.owl"); otpldata = otpldata.replace(acabs, aconturl + "/abstract.owl"); FileUtils.write(otplfile, otpldata); URL xtplurl = new URL(plan.getExpandedTemplateID()); File xtplfile = new File(execsdir.getAbsolutePath() + "/" + xtplurl.getRef() + ".owl"); String xtpldata = IOUtils.toString(xtplurl); xtpldata = xtpldata.replace(wfpfx, wflowurl); xtpldata = xtpldata.replace(expfx, execsurl); xtpldata = xtpldata.replace(dclib, dconturl + "/library.owl"); xtpldata = xtpldata.replace(dcont, dconturl + "/ontology.owl"); xtpldata = xtpldata.replace(aclib, aconturl + "/library.owl"); xtpldata = xtpldata.replace(acabs, aconturl + "/abstract.owl"); FileUtils.write(xtplfile, xtpldata); // TODO: Change base url to an opmw.url + "/resource/WorkflowTemplate/ ?? uploadDirectory(publisher.getUploadServer(), tempdir); FileUtils.deleteQuietly(tempdir); // Convert results into prov and opmw File opmwfile = File.createTempFile("opmw-", ".owl"); File provfile = File.createTempFile("prov-", ".owl"); File tmplfile = File.createTempFile("tmpl-", ".owl"); String liburl = props.getProperty("lib.domain.execution.url"); runurl = opmm.transformWINGSResultsToOPMW(rplanurl, liburl, "RDF/XML", opmwfile.getAbsolutePath(), provfile.getAbsolutePath(), rname); turl = opmm.transformWINGSElaboratedTemplateToOPMW(otmplurl, "RDF/XML", tmplfile.getAbsolutePath(), tname); // Publish run opmw data publishFile(tstoreurl, runurl, opmwfile.getAbsolutePath()); // Publish provenance data to the default graph publishFile(tstoreurl, "default", provfile.getAbsolutePath()); // Publish template if it doesn't already exist if (!graphExists(tstoreurl, turl)) publishFile(tstoreurl, turl, tmplfile.getAbsolutePath()); opmwfile.delete(); provfile.delete(); tmplfile.delete(); retmap.put("url", runurl); } catch (Exception e) { e.printStackTrace(); retmap.put("error", e.getMessage()); } } return json.toJson(retmap); }
From source file:com.cubeia.maven.plugin.firebase.FirebaseRunPlugin.java
private void copyArtifactToDeploy(File firebaseDir, Artifact artifact) throws MojoFailureException, MojoExecutionException { if (artifact.getFile() == null) throw new MojoFailureException("Artifact '" + artifact + "' is not resolved"); File target = ensureFirebaseDeployLib(firebaseDir); try {//from w ww .j av a 2 s .c om FileUtils.copyFileToDirectory(artifact.getFile(), target); } catch (IOException e) { throw new MojoExecutionException("Failed to copy project artifact to deploy directory", e); } }
From source file:com.taobao.android.builder.tools.proguard.BundleProguarder.java
public static Result loadProguardFromCache(AppVariantContext appVariantContext, Input input) throws Exception { Result result = new Result(); String md5 = input.getMd5();/*from w w w . jav a2s .c om*/ result.key = input.getAwbBundles().get(0).getAwbBundle().getName() + "_" + md5; logger.info("bundle proguard for " + result.key + " with md5 key " + md5); File cacheDir = FileCacheCenter.queryFile(CACHE_TYPE, result.key, true, isRemoteCacheEnabled(appVariantContext)); result.cacheDir = cacheDir; if (null == cacheDir || !cacheDir.exists()) { logger.warn("bundle proguard for " + result.key + " miss cache " + cacheDir.getAbsolutePath()); return result; } logger.warn("bundle proguard for " + result.key + " hit cache "); File keepJson = new File(cacheDir, "keep.json"); File proguardCfg = new File(cacheDir, "proguard.cfg"); File usageCfg = new File(cacheDir, "usage.cfg"); Map<String, File> md5Map = input.getMd5Files(); if (input.getAwbBundles().get(0).getAwbBundle().isMainBundle()) { AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getMainDexFiles() .clear(); AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getInputDirs().clear(); for (File file : cacheDir.listFiles()) { if (file.getName().endsWith("jar") && ZipUtils.isZipFile(file)) { String jarMd5 = file.getName().replace(".jar", ""); File srcFile = md5Map.get(jarMd5); if (null != srcFile && srcFile.exists()) { String fileName = FileNameUtils.getUniqueJarName(srcFile); FileUtils.copyFile(file, new File(input.proguardOutputDir, fileName + ".jar")); AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()) .addMainDex(new BuildAtlasEnvTask.FileIdentity(fileName, new File(input.proguardOutputDir, fileName + ".jar"), false, false)); } else { FileUtils.copyFileToDirectory(file, input.proguardOutputDir); AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()) .addMainDex(new BuildAtlasEnvTask.FileIdentity(file.getName(), new File(input.proguardOutputDir, file.getName()), false, false)); } } } File awbProguardDir = input.printConfiguration.getParentFile(); //FileUtils.copyFileToDirectory(keepJson, awbProguardDir); if (proguardCfg.exists()) { FileUtils.copyFileToDirectory(proguardCfg, awbProguardDir); } if (usageCfg.exists()) { FileUtils.copyFileToDirectory(usageCfg, awbProguardDir); } result.success = true; return result; } else { if (!keepJson.exists()) { logger.error("bundle proguard for " + result.key + " missing keep.json "); FileUtils.deleteDirectory(cacheDir); return result; } Map<AwbTransform, List<File>> transformListMap = new HashMap<>(); for (AwbTransform awbTransform : input.getAwbBundles()) { File awbProguardDir = appVariantContext.getAwbProguardDir(awbTransform.getAwbBundle()); FileUtils.copyFileToDirectory(keepJson, awbProguardDir); if (proguardCfg.exists()) { FileUtils.copyFileToDirectory(proguardCfg, awbProguardDir); } if (usageCfg.exists()) { FileUtils.copyFileToDirectory(usageCfg, awbProguardDir); } List<File> inputFiles = new ArrayList<>(); transformListMap.put(awbTransform, inputFiles); List<File> files = new ArrayList<>(); files.addAll(awbTransform.getInputLibraries()); //configs.add(); if (null != awbTransform.getInputDir() && awbTransform.getInputDir().exists()) { files.add(awbTransform.getInputDir()); } for (File oldFile : files) { File file = new File(cacheDir, input.getFileMd5s().get(oldFile) + ".jar"); if (file.exists()) { if (ZipUtils.isZipFile(file)) { inputFiles.add(file); } } else { logger.error("miss proguard jar for :" + file.getAbsolutePath()); FileUtils.deleteDirectory(cacheDir); logger.error("delete cache Dir " + cacheDir.getAbsolutePath()); return result; } } } for (AwbTransform awbTransform : input.getAwbBundles()) { awbTransform.setInputFiles(transformListMap.get(awbTransform)); awbTransform.setInputDir(null); awbTransform.getInputLibraries().clear(); awbTransform.getAwbBundle().setKeepProguardFile(keepJson); } result.success = true; return result; } }