List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:org.moe.cli.utils.NatJFileUtils.java
/** * Copies directory keeping symbolic links working * @param srcDir/*from w w w .j a v a 2 s .com*/ * @param destDir * @throws IOException */ public static void copyDirectoryWithSymbolicLinks(@NonNull File srcDir, @NonNull File destDir) throws IOException { if (!srcDir.isDirectory()) throw new IOException("Invalid framework file: " + srcDir + " is not a directory!"); File[] frameworkFiles = srcDir.listFiles(); for (File file : frameworkFiles) { try { boolean isSymlink = FileUtils.isSymlink(file); if (isSymlink) { Path target = Files.readSymbolicLink(file.toPath()); File newLink = new File(destDir, file.getName()); Files.createSymbolicLink(newLink.toPath(), target); } else { if (file.isDirectory()) { File nextDestDir = new File(destDir, file.getName()); copyDirectoryWithSymbolicLinks(file, nextDestDir); } else { FileUtils.copyFileToDirectory(file, destDir); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.mule.test.infrastructure.process.Controller.java
protected void deployDomain(String domain) { File domainFile = new File(domain); verify(domainFile.exists(), "Domain does not exist: %s", domain); try {// w w w . ja v a2 s.co m if (domainFile.isDirectory()) { FileUtils.copyDirectoryToDirectory(domainFile, this.domainsDir); } else { FileUtils.copyFileToDirectory(domainFile, this.domainsDir); } } catch (IOException e) { throw new MuleControllerException(String.format(DOMAIN_DEPLOY_ERROR, domain), e); } }
From source file:org.mule.test.infrastructure.process.Controller.java
protected void addLibrary(File jar) { verify(jar.exists(), "Jar file does not exist: %s", jar); verify("jar".equals(FilenameUtils.getExtension(jar.getAbsolutePath())), "Library [%s] don't have .jar extension.", jar); verify(jar.canRead(), "Cannot read jar file: %s", jar); verify(libsDir.canWrite(), "Cannot write on lib dir: %", libsDir); try {/*from ww w . j a v a 2 s .c o m*/ FileUtils.copyFileToDirectory(jar, libsDir); } catch (IOException e) { throw new MuleControllerException(String.format(ADD_LIBRARY_ERROR, jar, libsDir), e); } }
From source file:org.mule.test.infrastructure.process.Controller.java
public void deploy(String path) { File app = new File(path); verify(app.exists(), "File does not exists: %s", app); verify(app.canRead(), "Cannot read file: %s", app); try {// w ww. j a v a 2s. c om if (app.isFile()) { FileUtils.copyFileToDirectory(app, appsDir); } else { FileUtils.copyDirectoryToDirectory(app, appsDir); } } catch (IOException e) { throw new MuleControllerException("Could not deploy app [" + path + "] to [" + appsDir + "]", e); } }
From source file:org.n52.movingcode.runtime.codepackage.PlainPackage.java
@Override public void dumpPackage(String workspaceDirName, File targetDirectory) { // TODO Auto-generated method stub try {/*from w ww. j a va2 s . com*/ Collection<File> files = FileUtils.listFiles(plainWorkspace, null, false); for (File file : files) { if (file.isDirectory()) { FileUtils.copyDirectory(file, targetDirectory); } else { FileUtils.copyFileToDirectory(file, targetDirectory); } } } catch (IOException e) { LOGGER.error("Error! Could copy from " + plainWorkspace.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath()); } }
From source file:org.nanoko.coffee.mill.mojos.others.FinalArtifactProcessor.java
public void fileCreated(File file) throws ProcessorException { if (file.getName().endsWith(".js")) { try {//from w w w .j a va 2s . c om File output = new File(watchedProjectMojo.getLibDirectory(), subProjectMojo.project.getArtifactId() + ".js"); getLog().info("Copying " + file.getAbsolutePath() + " to " + output.getAbsolutePath()); FileUtils.copyFile(file, output); return; } catch (IOException e) { throw new ProcessorException("Can't copy " + file.getAbsolutePath() + " to " + watchedProjectMojo.getLibDirectory().getAbsolutePath(), e); } } if (file.getName().endsWith(".css")) { try { File output = new File(watchedProjectMojo.getWorkDirectory(), subProjectMojo.project.getArtifactId() + ".css"); getLog().info("Copying " + file.getAbsolutePath() + " to " + output.getAbsolutePath()); FileUtils.copyFileToDirectory(file, watchedProjectMojo.getWorkDirectory()); return; } catch (IOException e) { throw new ProcessorException("Can't copy " + file.getAbsolutePath() + " to " + watchedProjectMojo.getWorkDirectory().getAbsolutePath(), e); } } }
From source file:org.nanoko.coffee.mill.mojos.packaging.StylesheetsAggregatorMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { // Do we have css files ? System.out.println(getWorkDirectory().getAbsolutePath()); if (FileUtils.listFiles(getWorkDirectory(), new String[] { "css" }, true).size() == 0) { getLog().info("Skipping Stylessheets aggregation - no files"); return;//from w ww . j a va2 s .c o m } File output = new File(getWorkDirectory(), project.getBuild().getFinalName() + ".css"); Processor aggregator = new CSSAggregator(); Map<String, Object> options = new HashMap<String, Object>(); options.put("output", output); options.put("names", cssAggregation); options.put("extension", "css"); aggregator.configure(this, options); try { aggregator.processAll(); } catch (Processor.ProcessorException e) { throw new MojoExecutionException("Cannot aggregate CSS files", e); } if (output.isFile()) { try { FileUtils.copyFileToDirectory(output, getTarget()); // Do we already have a main JS artifact ? if (project.getArtifact().getFile() != null && project.getArtifact().getFile().exists()) { projectHelper.attachArtifact(project, "css", output); } else { project.getArtifact().setFile(output); } } catch (IOException e) { throw new MojoExecutionException("Cannot copy the aggregated file to the target folder", e); } } else { throw new MojoExecutionException( "Cannot copy the aggregated file to the target folder - the output file " + "does not exist"); } }