new File(outputDir, FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir));
/** * 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); } }
/** * Computes the relative of a file or directory with respect to a directory. * * @param file the file or directory, which must exist in the filesystem * @param dir the directory to compute the path relative to * @return the relative path from {@code dir} to {@code file}; if {@code file} is a directory * the path comes appended with the file separator (see documentation on {@code relativize} * on java's {@code URI} class) */ @NonNull public static String relativePath(@NonNull File file, @NonNull File dir) { checkArgument(file.isFile() || file.isDirectory(), "%s is not a file nor a directory.", file.getPath()); checkArgument(dir.isDirectory(), "%s is not a directory.", dir.getPath()); return relativePossiblyNonExistingPath(file, dir); }
public AndroidLibraryImpl( @NonNull AndroidDependency androidDependency, @NonNull Collection<File> localJarOverride) { this.address = androidDependency.getAddress().toString(); this.artifactFile = androidDependency.getArtifactFile(); this.folder = androidDependency.getExtractedFolder(); // compute relate jars folder jarsRootFolder = relativePossiblyNonExistingPath( androidDependency.getJarFile().getParentFile(), folder).intern(); // TODO Fix me once we are always extracting AARs during sync. localJarPath = Lists.newArrayListWithCapacity(localJarOverride.size()); for (File localJar : localJarOverride) { localJarPath.add(relativePossiblyNonExistingPath(localJar, folder).intern()); } }
/** * 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 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); } } }
private static void deleteOutputFile( @NonNull IncrementalVisitor.VisitorBuilder visitorBuilder, @NonNull File inputDir, @NonNull File inputFile, @NonNull File outputDir) { String inputPath = FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir); String outputPath = visitorBuilder.getMangledRelativeClassFilePath(inputPath); File outputFile = new File(outputDir, outputPath); if (outputFile.exists()) { try { FileUtils.delete(outputFile); } catch (IOException e) { // it's not a big deal if the file cannot be deleted, hopefully // no code is still referencing it, yet we should notify. LOGGER.warning("Cannot delete %1$s file.\nCause: %2$s", outputFile, Throwables.getStackTraceAsString(e)); } } }
String relativePath = FileUtils.relativePossiblyNonExistingPath( fileToProcess, directoryInput.getFile());
private static File getOutputStreamForFile( @NonNull TransformOutputProvider transformOutputProvider, @NonNull DirectoryInput input, @NonNull File file, @NonNull Slices slices) { String relativePackagePath = FileUtils.relativePossiblyNonExistingPath(file.getParentFile(), input.getFile()); Slice slice = slices.getSliceFor(new Slice.SlicedElement(relativePackagePath, file)); return transformOutputProvider.getContentLocation(slice.name, TransformManager.CONTENT_CLASS, Sets.immutableEnumSet(Scope.PROJECT, Scope.SUB_PROJECTS), Format.DIRECTORY); }
.relativePossiblyNonExistingPath(file.getParentFile(), inputDir); slices.addElement(packagePath, file);
String path = FileUtils.relativePossiblyNonExistingPath(input, folder); FileUtils.relativePossiblyNonExistingPath(input, folder)); switch(fileStatus.getValue()) { case ADDED:
&& 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); 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);
localTable.addColumn("Description", RepoPackage::getDisplayName, 30, 0); localTable.addColumn("Location", p -> FileUtils.relativePossiblyNonExistingPath( p.getLocation(), mRepoManager.getLocalPath()), 15, 15);