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.continuumsecurity.runner.StoryRunner.java
private void prepareReportsDir() throws IOException { FileUtils.deleteQuietly(new File(LATEST_REPORTS)); File viewDir = new File(LATEST_REPORTS + File.separator + "view"); FileUtils.copyDirectory(new File(RESOURCES_DIR), viewDir); }
From source file:com.photon.maven.plugins.android.standalonemojos.UnpackMojo.java
private File unpackClasses() throws MojoExecutionException { File outputDirectory = new File(project.getBuild().getDirectory(), "android-classes"); if (lazyLibraryUnpack && outputDirectory.exists()) getLog().info("skip library unpacking due to lazyLibraryUnpack policy"); else {/*from www.j av a 2 s. c o m*/ for (Artifact artifact : getRelevantCompileArtifacts()) { if (artifact.getFile().isDirectory()) { try { FileUtils.copyDirectory(artifact.getFile(), outputDirectory); } catch (IOException e) { throw new MojoExecutionException( "IOException while copying " + artifact.getFile().getAbsolutePath() + " into " + outputDirectory.getAbsolutePath(), e); } } else { try { JarHelper.unjar(new JarFile(artifact.getFile()), outputDirectory, new JarHelper.UnjarListener() { @Override public boolean include(JarEntry jarEntry) { return !jarEntry.getName().startsWith("META-INF") && jarEntry.getName().endsWith(".class"); } }); } catch (IOException e) { throw new MojoExecutionException( "IOException while unjarring " + artifact.getFile().getAbsolutePath() + " into " + outputDirectory.getAbsolutePath(), e); } } } } try { File sourceDirectory = new File(project.getBuild().getDirectory(), "classes"); if (!sourceDirectory.exists()) { sourceDirectory.mkdirs(); } FileUtils.copyDirectory(sourceDirectory, outputDirectory); } catch (IOException e) { throw new MojoExecutionException("IOException while copying " + sourceDirectory.getAbsolutePath() + " into " + outputDirectory.getAbsolutePath(), e); } return outputDirectory; }
From source file:net.sourceforge.floggy.maven.PersistenceMojo.java
/** * DOCUMENT ME!// w w w. j ava 2s .com * * @throws MojoExecutionException DOCUMENT ME! */ public void execute() throws MojoExecutionException { MavenLogWrapper.setLog(getLog()); LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "net.sourceforge.floggy.maven.MavenLogWrapper"); Weaver weaver = new Weaver(); try { List list = project.getCompileClasspathElements(); File temp = new File(project.getBuild().getDirectory(), String.valueOf(System.currentTimeMillis())); FileUtils.forceMkdir(temp); weaver.setOutputFile(temp); weaver.setInputFile(input); weaver.setClasspath((String[]) list.toArray(new String[list.size()])); if (configurationFile == null) { Configuration configuration = new Configuration(); configuration.setAddDefaultConstructor(addDefaultConstructor); configuration.setGenerateSource(generateSource); weaver.setConfiguration(configuration); } else { weaver.setConfigurationFile(configurationFile); } weaver.execute(); FileUtils.copyDirectory(temp, output); FileUtils.forceDelete(temp); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.FileCopier.java
/** * Copy the given source file or directory to the given destination, keeping the same creation date as the source. * * @param sourceFileOrDirectory the source file or directory * @param destinationFileOrDirectory the destination file or directory * @throws IOException if an IO error occurs during the copy */// w w w. j av a 2 s .c o m public static void copyFileOrDirectory(final File sourceFileOrDirectory, final File destinationFileOrDirectory) throws IOException { final File parentDirectory = destinationFileOrDirectory.getParentFile(); if (!parentDirectory.exists()) { boolean success = parentDirectory.mkdirs(); if (!success) { throw new IOException("Directory '" + parentDirectory + "' was not successfully created."); } } if (sourceFileOrDirectory.isDirectory()) { FileUtils.copyDirectory(sourceFileOrDirectory, destinationFileOrDirectory); } else { FileUtils.copyFile(sourceFileOrDirectory, destinationFileOrDirectory); } }
From source file:ipat_fx.FXMLDocumentController.java
@FXML private void saveOption(ActionEvent event) { FileChooser fc = new FileChooser(); File file = new File(contextPath + "Saves/"); if (!file.exists()) { file.mkdirs();/* ww w .java2 s . co m*/ } fc.setInitialDirectory(file); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); Date date = new Date(); fc.setInitialFileName("Ipat_" + dateFormat.format(date)); File dest = fc.showSaveDialog(null); File src = new File(dataPath); try { FileUtils.copyDirectory(src, dest); } catch (IOException ex) { Logger.getLogger(IPAT_FX.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.kdmanalytics.toif.report.internal.importWizard.ToifReportImportJob.java
/** * copy the toif data.// w w w .jav a 2 s .c om * * @param sourceFile * source * @param destinationFile * destination file * @throws IOException */ public void copy(File sourceFile, File destinationFile) throws IOException { FileUtils.copyDirectory(sourceFile, destinationFile); }
From source file:de.decidr.ui.controller.VaadinTenantThemeInstaller.java
/** * Installs the custom theme of the given tenant, if that tenant has a * custom theme. If a current or outdated version of the custom theme is * already installed, it will be overwritten. * // w ww. ja v a2 s. c o m * @param tenantId * @return whether a custom theme was successfully installed. Also returns * true if the custom theme was already installed and has been * overwritten. */ public static boolean installLocally(long tenantId) { TenantFacade tenantFacade = ModelFacades.getTenantFacade(); InputStream cssContents = null; InputStream logoFileContents = null; /* * The custom theme is created by copying the default theme and * replacing the logo and css files */ File template = null; File destination = null; /* * Target files to replace */ File cssFile = UIConventions.getCssFile(tenantId); File logoFile = UIConventions.getLogoFile(tenantId); try { cssContents = tenantFacade.getCurrentColorScheme(tenantId); logoFileContents = tenantFacade.getLogo(tenantId); /* * Create a copy of the default theme. */ template = UIConventions.getThemeDirectory(UIConventions.DEFAULT_THEME_NAME); destination = UIConventions.getThemeDirectory(UIConventions.getThemeName(tenantId)); if (!template.equals(destination)) { FileUtils.copyDirectory(template, destination); } /* * Replace CSS and logo */ replaceFile(cssFile, cssContents); replaceFile(logoFile, logoFileContents); } catch (IOException e) { logger.error("Cannot create custom tenant theme from template", e); try { /* * Undo creation of new directory if possible */ if (destination != null && destination.isDirectory()) { FileUtils.deleteDirectory(destination); } } catch (IOException undoException) { if (destination != null) { logger.error("Cannot undo creation of destination directory. We have a file corpse: " + destination.getAbsolutePath(), undoException); } } return false; } catch (TransactionException e) { DecidrUI.getCurrent().getMainWindow().addWindow(new TransactionErrorDialogComponent(e)); return false; } finally { IOUtils.closeQuietly(cssContents); IOUtils.closeQuietly(logoFileContents); } return true; }
From source file:net.mindengine.dashserver.compiler.GlobalAssetsFileWatcher.java
private void copyDirectoryAsset(File dir) throws IOException { String destFolder = compiledAssetsFolder.getAbsolutePath() + File.separator + dir.getName(); FileUtils.copyDirectory(dir, new File(destFolder)); Files.find(Paths.get(destFolder), 999, (p, bfa) -> bfa.isRegularFile()).forEach(file -> { String relativePath = new File(compiledAssetsFolder.getAbsolutePath()).toURI().relativize(file.toUri()) .getPath();/*from w ww . j a va2 s. c o m*/ try { addItemToAssets(relativePath.replace("\\", "/")); } catch (IOException e) { e.printStackTrace(); } }); }
From source file:com.compomics.pladipus.denovo.processsteps.DenovoGUIStep.java
@Override public boolean doAction() throws UnspecifiedPladipusException, PladipusProcessingException { LOGGER.info("Running " + this.getClass().getName()); File parameterFile = new File(parameters.get("id_params")); LOGGER.info("Updating parameters..."); try {//from ww w .j a v a 2s . com SearchParameters identificationParameters = SearchParameters.getIdentificationParameters(parameterFile); //fix the location SearchParameters.saveIdentificationParameters(identificationParameters, parameterFile); if (temp_deNovoGUI_output.exists()) { temp_deNovoGUI_output.delete(); } temp_deNovoGUI_output.mkdirs(); LOGGER.info("Starting searchGUI..."); //use this variable if you'd run following this classs File real_outputFolder = new File(parameters.get("output_folder")); parameters.put("output_folder", temp_deNovoGUI_output.getAbsolutePath()); new ProcessingEngine().startProcess(getJar(), constructArguments()); //storing intermediate results LOGGER.info("Storing results in " + real_outputFolder); FileUtils.copyDirectory(temp_deNovoGUI_output, real_outputFolder); //in case of future peptideShaker searches : parameters.put("identification_files", temp_deNovoGUI_output.getAbsolutePath()); } catch (IOException | ClassNotFoundException ioe) { UnspecifiedPladipusException ex = new UnspecifiedPladipusException("sumting went rong"); ex.addSuppressed(ioe); throw ex; } return true; }
From source file:com.thesett.elm.maven.BuildElmMojo.java
/** {@inheritDoc} */ public void execute(FrontendPluginFactory factory) throws FrontendException { if (shouldExecute()) { NodeExecutorConfig executorConfig = factory.getExecutorConfig(); File workingDirectory = executorConfig.getWorkingDirectory(); // Set up the working directory to be in an elm directory immediately beneath the working directory. String elmWorkingPath = workingDirectory.getPath() + "/" + ELM_DIR; File elmWorkingDir = null; try {//w w w.j a va2 s . co m elmWorkingDir = createDirIfNotExists(workingDirectory, elmWorkingPath); } catch (IOException e) { throw new FrontendException(e.getMessage(), e); } executorConfig = new WrappedExecutorConfig(executorConfig, elmWorkingDir); // Copy sources from the source dir to the working dir. try { FileUtils.copyDirectory(srcdir, elmWorkingDir); } catch (IOException e) { throw new FrontendException(e.getMessage(), e); } // Install dependencies and make it. ElmGithubInstallRunner elmGithubInstallRunner = new ElmGithubInstallRunner(executorConfig); ElmMakeRunner elmMakeRunner = new ElmMakeRunner(executorConfig); elmGithubInstallRunner.execute("", environmentVariables); String artifact = project.getArtifactId(); String outputDirName = project.getBuild().getOutputDirectory(); // Trim any leading or trailing path separators from the output path. String outDirectory = outPath.replaceAll("^/+", ""); outDirectory = outDirectory.replaceAll("/+$", ""); String outputFile = outputDirName + "/" + ("".equals(outDirectory) ? "" : outDirectory + "/") + artifact + ".js"; elmMakeRunner.execute(srcSpec + " --output " + outputFile, environmentVariables); } }