FileUtils.copyFile(inputJar.getFile(), outputJar); new File(outputDir, FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir)); FileUtils.delete(outputFile); break; FileUtils.copyFile(inputFile, outputFile); FileUtils.deleteDirectoryContents(inputDir); inputDir.mkdirs(); Iterable<File> files = FileUtils.getAllFiles(inputDir); for (File inputFile : files) { File outputFile = new File(outputDir, FileUtils.relativePath(inputFile, inputDir)); FileUtils.copyFile(inputFile, outputFile);
@TaskAction public void preCompile() { // Create directory for output of annotation processor. FileUtils.mkdirs(annotationProcessorOutputFolder); }
private static void deleteDirectoryContents(@NonNull File directory) throws IOException { if (!directory.exists()) { FileUtils.mkdirs(directory); } else if (!directory.isDirectory()) { FileUtils.delete(directory); FileUtils.mkdirs(directory); } else { FileUtils.deleteDirectoryContents(directory); } }
String path = FileUtils.relativePossiblyNonExistingPath(input, folder); FileUtils.relativePossiblyNonExistingPath(input, folder)); switch(fileStatus.getValue()) { case ADDED: case CHANGED: if (excludeMatchers.stream().anyMatch(m -> m.matches(Paths.get(path)))) { FileUtils.mkdirs(strippedLib.getParentFile()); FileUtils.copyFile(input, strippedLib); } else { stripFile(input, strippedLib, abi); FileUtils.deleteIfExists(strippedLib); break; default: for (File input : FileUtils.getAllFiles(folder)) { if (input.isDirectory()) { continue; String path = FileUtils.relativePath(input, folder); File strippedLib = new File(output, path); FileUtils.mkdirs(strippedLib.getParentFile()); FileUtils.copyFile(input, strippedLib); } else { stripFile(input, strippedLib, abi); FileUtils.mkdirs(outFile.getParentFile());
deleteDirectoryContents(libBundleFolder); for (File jniFolder : getJniFolders()) { for (File lib : FileUtils.find(jniFolder, Pattern.compile("\\.so$"))) { File destLibFile = new File(libBundleFolder, FileUtils.relativePath(lib, jniFolder)); if (!destLibFile.getParentFile().exists()) { FileUtils.mkdirs(destLibFile.getParentFile()); FileUtils.copyFile(lib, destLibFile); deleteDirectoryContents(dexBundleFolder); for (File dexFolder : getDexFolders()) { for (File dexFile : FileUtils.find(dexFolder, Pattern.compile("\\.dex$"))) { File destDexFile = new File(dexBundleFolder, dexFile.getName()); FileUtils.copyFile(dexFile, destDexFile); for (File javaResFile : FileUtils.getAllFiles(javaResource)) { File destJavaResFile = new File( javaResBundleFolder, FileUtils.relativePath(javaResFile, javaResource)); if (!destJavaResFile.getParentFile().exists()) { FileUtils.mkdirs(destJavaResFile.getParentFile()); FileUtils.copyFile(javaResFile, destJavaResFile); ZipEntry zipEntry = entries.nextElement(); File destJavaResource = FileUtils.join(javaResBundleFolder, zipEntry.getName());
@NonNull public File getAtomMetadataFile() { return FileUtils.join( getExtractedFolder(), FD_INSTANTAPP_METADATA, FN_ATOM_METADATA); }
break; case REMOVED: FileUtils.delete(outputJar); break; && inputFile.getName() .endsWith(SdkConstants.DOT_CLASS)) { String relativePath = FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir); File out = new File(outputDir, relativePath); transformFile(inputFile, out, relativePath); String relativePath = FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir); File outputFile = new File(outputDir, relativePath); FileUtils.deleteIfExists(outputFile); break; for (File in : FileUtils.getAllFiles(inputDir)) { if (in.getName().endsWith(SdkConstants.DOT_CLASS)) { String relativePath = FileUtils.relativePossiblyNonExistingPath(in, inputDir); File out = new File(outputDir, relativePath); transformFile(in, out, relativePath);
/** * Return the expected output {@link File} for an input file located in the transform input * directory. The output file will have a similar relative path than the input file (to the * input dir) inside the output directory. * * @param inputDir the input directory containing the input file * @param inputFile the input file within the input directory * @param outputDir the output directory * @return the output file within the output directory with the right relative path. */ protected static File getOutputFile(File inputDir, File inputFile, File outputDir) { String relativePath = FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir); return new File(outputDir, relativePath); } }
private static void instrumentFilesIncremental( @NonNull Instrumenter instrumenter, @NonNull File inputDir, @NonNull File outputDir, @NonNull Map<File, Status> changedFiles) throws IOException { for (Map.Entry<File, Status> changedInput : changedFiles.entrySet()) { File inputFile = changedInput.getKey(); if (!inputFile.getName().endsWith(SdkConstants.DOT_CLASS)) { continue; } File outputFile = new File(outputDir, FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir)); switch (changedInput.getValue()) { case REMOVED: FileUtils.delete(outputFile); break; case ADDED: // fall through case CHANGED: instrumentFile(instrumenter, inputFile, outputFile); } } }
/** * Copies a file or a directory's contents to another file or directory, which can have a * different name. The target file/directory is replaced if it already exists. * * <p>The source file/directory must exist and must not reside in, contain, or be identical to * the target file/directory. */ private static void copyFileOrDirectory(@NonNull File from, @NonNull File to) throws IOException { Preconditions.checkArgument( from.exists(), "Source path " + from.getAbsolutePath() + " does not exists."); Preconditions.checkArgument(!FileUtils.isFileInDirectory(from, to)); Preconditions.checkArgument(!FileUtils.isFileInDirectory(to, from)); Preconditions.checkArgument(!from.getCanonicalFile().equals(to.getCanonicalFile())); if (from.isFile()) { Files.createParentDirs(to); FileUtils.copyFile(from, to); } else if (from.isDirectory()) { FileUtils.deletePath(to); FileUtils.copyDirectory(from, to); } }
/** * Makes a copy of the directory's content, in the specified location, while maintaining the * directory structure. So the entire directory tree from the source will be copied. * * @param from directory from which the content is copied * @param to destination directory, will be created if does not exist */ public static void copyDirectoryContentToDirectory( @NonNull final File from, @NonNull final File to) throws IOException { Preconditions.checkArgument(from.isDirectory(), "Source path is not a directory."); File[] children = from.listFiles(); if (children != null) { for (File f : children) { if (f.isDirectory()) { File destination = new File(to, relativePath(f, from)); Files.createParentDirs(destination); mkdirs(destination); copyDirectoryContentToDirectory(f, destination); } else if (f.isFile()) { File destination = new File(to, relativePath(f.getParentFile(), from)); Files.createParentDirs(destination); mkdirs(destination); copyFileToDirectory(f, destination); } } } }
private void mergeAll(@NonNull File outputDir, @NonNull String archivePath) throws IOException { File outputFile = new File(outputDir, archivePath); deleteIfExists(outputFile); mkdirs(outputFile.getParentFile()); List<File> allFiles = getAllFiles(archivePath); if (!allFiles.isEmpty()) { OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(outputFile)); // take each file in order and merge them. for (File file : allFiles) { Files.copy(file, os); } } finally { if (os != null) { os.close(); } } } }
FileUtils.deletePath(to); Files.createParentDirs(to); if (multiDex) { FileUtils.mkdirs(to);
/** * Clears the cache. * * @throws IOException failed to clear the cache */ public void clear() throws IOException { File[] files = directory.listFiles(); if (files == null) { return; } for (File f : files) { if (f.isFile()) { FileUtils.delete(f); } } } }
/** * Creates a new relative file. * * @param base the base directory * @param file the file, must not be the same as the base directory and must be located inside * {@code base} */ public RelativeFile(@NonNull File base, @NonNull File file) { Preconditions.checkArgument(!base.equals(file), "base.equals(file)"); this.base = base; this.file = file; String relativePath = FileUtils. relativePossiblyNonExistingPath(file, base); osIndependentRelativePath = FileUtils.toSystemIndependentPath(relativePath); }
private static void instrumentFilesFullRun( @NonNull Instrumenter instrumenter, @NonNull File inputDir, @NonNull File outputDir) throws IOException { FileUtils.cleanOutputDir(outputDir); Iterable<File> files = FileUtils.getAllFiles(inputDir); for (File inputFile : files) { if (!inputFile.getName().endsWith(SdkConstants.DOT_CLASS)) { continue; } File outputFile = new File(outputDir, FileUtils.relativePath(inputFile, inputDir)); instrumentFile(instrumenter, inputFile, outputFile); } }
String relativePath = FileUtils.relativePossiblyNonExistingPath( fileToProcess, directoryInput.getFile()); FileUtils.deleteDirectoryContents(outputFile);
private void stripFile(@NonNull File input, @NonNull File output, @Nullable Abi abi) throws IOException { FileUtils.mkdirs(output.getParentFile()); if (abi == null) { FileUtils.copyFile(input, output); return; } ProcessInfoBuilder builder = new ProcessInfoBuilder(); builder.setExecutable(stripExecutables.get(abi)); builder.addArgs("--strip-unneeded"); builder.addArgs("-o"); builder.addArgs(output.toString()); builder.addArgs(input.toString()); ILogger logger = new LoggerWrapper(project.getLogger()); ProcessResult result = new GradleProcessExecutor(project).execute( builder.createProcess(), new LoggedProcessOutputHandler(logger)); if (result.getExitValue() != 0) { logger.warning("Unable to strip library '%s', packaging it as is.", input.getAbsolutePath()); FileUtils.copyFile(input, output); } }
TransformManager.SCOPE_FULL_PROJECT, Format.DIRECTORY); FileUtils.mkdirs(outputDir); FileUtils.cleanOutputDir(outputDir); FileUtils.deletePath(perStreamDexFolder); FileUtils.deletePath(file); return null; }); TransformManager.CONTENT_DEX, TransformManager.SCOPE_FULL_PROJECT, Format.DIRECTORY); FileUtils.mkdirs(outputDir); FileUtils.cleanOutputDir(outputDir); FileUtils.mkdirs(outputDir);