List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:com.github.scizeron.jidr.maven.plugin.JidrPackageApp.java
@Override public void execute() throws MojoExecutionException { InputStream input = null;/* w w w .java2 s .c om*/ FileOutputStream output = null; if ("pom".equals(this.project.getPackaging())) { getLog().info("Skip execute on " + this.project.getPackaging() + " project."); return; } final String outputDirname = this.project.getBuild().getDirectory() + File.separator + "distrib"; final String libOutputDir = outputDirname + File.separator + "lib"; final String appOutputDir = outputDirname + File.separator + "app"; final String confOutputDir = outputDirname + File.separator + "conf"; final String binOutputDir = outputDirname + File.separator + "bin"; try { new File(libOutputDir).mkdirs(); new File(appOutputDir).mkdirs(); new File(binOutputDir).mkdirs(); new File(confOutputDir).mkdirs(); File outputFile = new File(binOutputDir + File.separator + APP_SH_FILE); output = new FileOutputStream(outputFile); input = JidrPackageApp.class.getClassLoader().getResourceAsStream(APP_SH_FILE); final LineIterator lineIterator = IOUtils.lineIterator(input, Charsets.UTF_8); while (lineIterator.hasNext()) { output.write((lineIterator.nextLine() + "\n").getBytes()); } output.close(); getLog().info(String.format("Create \"%s\" in %s.", APP_SH_FILE, binOutputDir)); outputFile = new File(confOutputDir + File.separator + APP_CFG_FILE); output = new FileOutputStream(outputFile); output.write(new String("APP_ARTIFACT=" + project.getArtifactId() + "\n").getBytes()); output.write(new String("APP_PACKAGING=" + project.getPackaging() + "\n").getBytes()); output.write(new String("APP_VERSION=" + project.getVersion()).getBytes()); getLog().info(String.format("Create \"%s\" in %s.", APP_CFG_FILE, confOutputDir)); // si un repertoire src/main/bin est present dans le projet, le contenu // sera copie dans binOutputDir addExtraFiles(this.project.getBasedir().getAbsolutePath() + "/src/main/bin", binOutputDir); // si un repertoire src/main/conf est present dans le projet, le contenu // sera copie dans confOutputDir addExtraFiles(this.project.getBasedir().getAbsolutePath() + "/src/main/conf", confOutputDir); final String artifactFilename = this.project.getBuild().getFinalName() + "." + this.project.getPackaging(); FileUtils.copyFileToDirectory( new File(this.project.getBuild().getDirectory() + File.separator + artifactFilename), new File(appOutputDir)); getLog().info(String.format("Copy \"%s\" to %s.", artifactFilename, appOutputDir)); String distribFilename = this.project.getArtifactId() + "-" + this.project.getVersion() + "-" + classifier + "." + DISTRIB_TYPE; ZipFile distrib = new ZipFile( this.project.getBuild().getDirectory() + File.separator + distribFilename); ZipParameters zipParameters = new ZipParameters(); distrib.addFolder(new File(binOutputDir), zipParameters); distrib.addFolder(new File(appOutputDir), zipParameters); distrib.addFolder(new File(confOutputDir), zipParameters); getLog().info( String.format("Create \"%s\" to %s.", distribFilename, this.project.getBuild().getDirectory())); this.mavenProjectHelper.attachArtifact(this.project, DISTRIB_TYPE, classifier, distrib.getFile()); getLog().info(String.format("Attach \"%s\".", distribFilename)); } catch (Exception exception) { getLog().error(exception); } finally { try { if (output != null) { output.close(); } if (input != null) { input.close(); } } catch (IOException e) { getLog().error(e); } } }
From source file:dynamicrefactoring.domain.TestExport.java
/** * Comprueba que el proceso de exportacin de la refactorizacin dinmica * Rename Class a un directorio temporal "./temp" teniendo en cuenta que uno * de los ficheros .class requeridos no se encuentra en el repositorio. * /*from w w w .j a va 2 s . c om*/ * @throws XMLRefactoringReaderException * XMLRefactoringReaderException. * @throws IOException * IOException. */ @Test public void testExportFileNotExists() throws XMLRefactoringReaderException, IOException { final String refactoringName = "RenameClass.class"; final String definitionFolderName = new File(RENAME_CLASS_XML_FILE).getParentFile().getName(); final String ficheroOrigen = FilenameUtils.separatorsToSystem(RefactoringConstants.REFACTORING_CLASSES_DIR + "repository\\moon\\concreteaction\\" + refactoringName); try { // Copiamos uno de los ficheros .class que necesita la // refactorizacin al directorio // temporal y luego lo borramos para que posteriormente salte la // excepcin. FileUtils.copyFileToDirectory(new File(ficheroOrigen), new File(TEMP_DIR)); FileManager.deleteFile(ficheroOrigen); ExportImportUtilities.exportRefactoring(TEMP_DIR, RENAME_CLASS_XML_FILE, false); } catch (IOException e) { // Comprobamos que el directorio en el que se generara la // refactorizacin no existe al no // poderse completar la operacin. assertEquals(false, new File(TEMP_DIR + File.separatorChar + definitionFolderName).exists()); // Reponemos el fichero .class que habamos borrado para comprobar // que saltaba la // excepcin. FileManager.copyFile(new File(TEMP_DIR + File.separatorChar + refactoringName), new File(ficheroOrigen)); assertEquals(true, new File(ficheroOrigen).exists()); } }
From source file:com.linkedin.pinot.tools.backfill.BackfillSegmentUtils.java
/** * Downloads a segment from a table to a directory locally, and backs it up to given backup path * @param tableName/*from w w w . ja va2 s .c o m*/ * @param segmentName * @param downloadSegmentDir - download segment path * @param tableBackupDir - backup segments path * @return */ public boolean downloadSegment(String tableName, String segmentName, File downloadSegmentDir, File tableBackupDir) { boolean downloadSuccess = true; if (downloadSegmentDir.exists()) { try { FileUtils.deleteDirectory(downloadSegmentDir); } catch (IOException e) { LOGGER.warn("Failed to delete directory {}", downloadSegmentDir, e); } } downloadSegmentDir.mkdirs(); try { String urlString = String.format(DOWNLOAD_SEGMENT_ENDPOINT, _controllerHttpHost.toURI(), tableName, segmentName); URL url = new URL(urlString); InputStream inputStream = url.openConnection().getInputStream(); File segmentTar = new File(downloadSegmentDir, segmentName + TAR_SUFFIX); LOGGER.info("Downloading {} to {}", segmentName, segmentTar); OutputStream outputStream = new FileOutputStream(segmentTar); IOUtils.copyLarge(inputStream, outputStream); if (!segmentTar.exists()) { LOGGER.error("Download of {} unsuccessful", segmentName); return false; } LOGGER.info("Backing up segment {} to {}", segmentTar, tableBackupDir); FileUtils.copyFileToDirectory(segmentTar, tableBackupDir); LOGGER.info("Extracting segment {} to {}", segmentTar, downloadSegmentDir); TarGzCompressionUtils.unTar(segmentTar, downloadSegmentDir); File segmentDir = new File(downloadSegmentDir, segmentName); if (!segmentDir.exists()) { throw new RuntimeException("Unable to untar segment " + segmentName); } else { FileUtils.deleteQuietly(segmentTar); } } catch (Exception e) { LOGGER.error("Error in downloading segment {}", segmentName, e); downloadSuccess = false; } return downloadSuccess; }
From source file:com.opengamma.maven.scripts.ScriptableScriptGeneratorMojo.java
@SuppressWarnings("unchecked") @Override/*from www. j a va 2 s.com*/ public void execute() throws MojoExecutionException, MojoFailureException { boolean templateSet = !StringUtils.isBlank(_template); boolean templateMapSet = _baseClassTemplateMap != null && _baseClassTemplateMap.isEmpty(); if ((templateSet && templateMapSet) || (!templateSet && !templateMapSet)) { throw new MojoExecutionException("Exactly one of 'template' or 'baseClassTemplateMap' must be set"); } if (!_outputDir.exists()) { try { getLog().debug("Creating output directory " + _outputDir); if (!_outputDir.mkdirs()) { throw new MojoExecutionException( "Unable to create output directory " + _outputDir.getAbsolutePath()); } } catch (Exception e) { throw new MojoExecutionException("Error creating output directory " + _outputDir.getAbsolutePath()); } } List<String> classpathElementList; try { classpathElementList = _project.getCompileClasspathElements(); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error obtaining dependencies", e); } URL[] classpathUrls = ClasspathUtils.getClasspathURLs(classpathElementList); Set<String> annotationClasses = ClassNameAnnotationScanner.scan(classpathUrls, Scriptable.class.getName()); getLog().info("Generating " + annotationClasses.size() + " scripts"); ClassLoader classLoader = new URLClassLoader(classpathUrls, this.getClass().getClassLoader()); Map<Class<?>, Template> templateMap = resolveTemplateMap(classLoader); for (String className : annotationClasses) { Map<String, Object> templateData = new HashMap<String, Object>(); templateData.put("className", className); Template template = getTemplateForClass(className, classLoader, templateMap); if (template == null) { getLog().warn("No template for scriptable class " + className); continue; } ScriptsGenerator.generate(className, _outputDir, template, templateData); } if (_additionalScripts != null) { getLog().info("Copying " + _additionalScripts.length + " additional script(s)"); for (String script : _additionalScripts) { File scriptFile = new File(script); if (scriptFile.exists()) { if (!scriptFile.isFile()) { throw new MojoExecutionException( "Can only copy files, but additional script '" + scriptFile + "' is not a file"); } try { FileUtils.copyFileToDirectory(scriptFile, _outputDir); File copiedFile = new File(_outputDir, scriptFile.getName()); copiedFile.setReadable(true, false); copiedFile.setExecutable(true, false); } catch (IOException e) { throw new MojoExecutionException("Unable to copy additional script '" + scriptFile + "'", e); } } } } }
From source file:com.github.hadoop.maven.plugin.PackMojo.java
/** * Create the hadoop deploy artifacts//from www. j av a 2s . c om * * @throws IOException * @return File that contains the root of jar file to be packed. * @throws InvalidDependencyVersionException * @throws ArtifactNotFoundException * @throws ArtifactResolutionException */ private File createHadoopDeployArtifacts() throws IOException { FileUtils.deleteDirectory(outputDirectory); File rootDir = new File(outputDirectory.getAbsolutePath() + File.separator + "root"); FileUtils.forceMkdir(rootDir); File jarlibdir = new File(rootDir.getAbsolutePath() + File.separator + "lib"); FileUtils.forceMkdir(jarlibdir); File classesdir = new File(project.getBuild().getDirectory() + File.separator + "classes"); FileUtils.copyDirectory(classesdir, rootDir); Set<Artifact> filteredArtifacts = this.filterArtifacts(this.artifacts); getLog().info(""); getLog().info("Dependencies of this project independent of hadoop classpath " + filteredArtifacts); getLog().info(""); for (Artifact artifact : filteredArtifacts) { FileUtils.copyFileToDirectory(artifact.getFile(), jarlibdir); } return rootDir; }
From source file:com.photon.phresco.service.dependency.impl.DependencyUtils.java
public static void copyFilesTo(File[] files, File destPath) throws IOException { if (isDebugEnabled) { S_LOGGER.debug("Entering Method DependencyUtils.copyFilesTo(File[] files, File destPath)"); S_LOGGER.error(" copyFilesTo() Destination Filepath =" + destPath.getPath()); }/*from w w w . java 2s .co m*/ if (files == null || destPath == null) { return; //nothing to copy } for (File file : files) { if (file.isDirectory()) { FileUtils.copyDirectory(file, destPath); } else { FileUtils.copyFileToDirectory(file, destPath); } } }
From source file:eu.edisonproject.rest.FolderWatcherRunnable.java
private File executeClassification(File inputFolder) throws Exception { File txtFile = null;/*from w w w . ja v a 2 s.c o m*/ if (inputFolder.isFile()) { txtFile = inputFolder; inputFolder = inputFolder.getParentFile(); Thread.sleep(100); } boolean isProfile = false; String partent = inputFolder.getParentFile().getAbsolutePath(); if (partent.equals(jobProfileFolder.getAbsolutePath()) || partent.equals(courseProfileFolder.getAbsolutePath()) || partent.equals(cvProfileFolder.getAbsolutePath())) { isProfile = true; } if (!isProfile) { if (txtFile == null || txtFile.getName().endsWith(".txt")) { String[] args = new String[] { "-op", "c", "-i", inputFolder.getAbsolutePath(), "-o", inputFolder.getAbsolutePath(), "-c", baseCategoryFolder.getAbsolutePath(), "-p", propertiesFile.getAbsolutePath() }; BatchMain.main(args); boolean calcAvg = false; if (inputFolder.getAbsolutePath().equals(jobAverageFolder.getAbsolutePath()) || inputFolder.getAbsolutePath().equals(courseAverageFolder.getAbsolutePath()) || inputFolder.getAbsolutePath().equals(cvAverageFolder.getAbsolutePath())) { calcAvg = true; } convertMRResultToCSV(new File(inputFolder.getAbsolutePath() + File.separator + "part-r-00000"), inputFolder.getAbsolutePath() + File.separator + ECO2Controller.CSV_FILE_NAME, calcAvg); convertCSVJsonFile(inputFolder.getAbsolutePath() + File.separator + CSV_AVG_FILENAME, inputFolder.getAbsolutePath() + File.separator + JSON_AVG_FILENAME); if (inputFolder.getParentFile().getAbsolutePath() .equals(jobClassisifcationFolder.getAbsolutePath())) { for (File add : inputFolder.listFiles()) { if (add.getName().endsWith(".txt")) { FileUtils.copyFileToDirectory(add, jobAverageFolder); } } } if (inputFolder.getParentFile().getAbsolutePath() .equals(courseClassisifcationFolder.getAbsolutePath())) { for (File add : inputFolder.listFiles()) { if (add.getName().endsWith(".txt")) { FileUtils.copyFileToDirectory(add, ECO2Controller.courseAverageFolder); } } } if (inputFolder.getParentFile().getAbsolutePath() .equals(cvClassisifcationFolder.getAbsolutePath())) { for (File add : inputFolder.listFiles()) { if (add.getName().endsWith(".txt")) { FileUtils.copyFileToDirectory(add, cvAverageFolder); } } } return convertMRResultToJsonFile(inputFolder.getAbsolutePath() + File.separator + "part-r-00000"); } } else { File v1 = new File(inputFolder.getAbsolutePath() + File.separator + CSV_FILE_NAME); int count = 0; while (!v1.exists() || count < 10) { Thread.sleep(100); count++; } String[] args = new String[] { "-op", "p", "-v1", inputFolder.getAbsolutePath() + File.separator + CSV_FILE_NAME, "-v2", inputFolder.getAbsolutePath() + File.separator + "list.csv", "-o", inputFolder.getAbsolutePath(), "-p", propertiesFile.getAbsolutePath() }; BatchMain.main(args); } return null; }
From source file:com.planet57.gshell.internal.FileSystemAccessImpl.java
@Override public void copyToDirectory(final File source, final File target) throws IOException { checkNotNull(source);/* w w w . ja v a 2s .c o m*/ checkNotNull(target); log.debug("Copy file to directory: {} -> {}", source, target); FileUtils.copyFileToDirectory(source, target); }
From source file:de.extra.client.starter.ExtraClient.java
/** * Handle the input files based on parameters. - Create Backup and/or - * Delete file/* w ww. j av a2s . c o m*/ * * @param singleInputData * file */ void handleInputFile(final ISingleInputData singleInputData) { final String inputIdentifier = singleInputData.getInputIdentifier(); final File file = new File(inputIdentifier); if (parameters.shouldCreateBackup()) { final File backupDirectory = parameters.getBackupDirectory(); LOG.debug("copying {} to {}", new Object[] { file.getAbsolutePath(), backupDirectory.getAbsolutePath() }); try { FileUtils.copyFileToDirectory(file, backupDirectory); } catch (final IOException e) { LOG.error("Konnte Datei {} nicht nach {} kopieren ({}).", new Object[] { file.getAbsolutePath(), backupDirectory.getAbsolutePath(), e.getMessage() }); } } if (parameters.getDeleteInputFiles()) { LOG.debug("deleting {}", file.getAbsolutePath()); try { if (!file.delete()) { LOG.error("Datei {} konnte nicht gelscht werden.", file.getAbsolutePath()); } } catch (final Exception e) { LOG.error("Fehler beim Lschen der Datei {} ({}).", file.getAbsolutePath(), e.getMessage()); } } }
From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java
/** * Writes a resource (e.g. CSS file) to the destination directory. * @param resourceName The name of a resource (which the classloader can find). * @param destDir The destination directory. */// w w w .ja va 2 s . c om protected static void writeResource(final File resource, final File destDir) { try { LOGGER.log(Level.FINE, "Copying resource {0}", resource.getName()); FileUtils.copyFileToDirectory(resource, destDir); } catch (IOException ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage()); } }