@Override public String toString() { return getPathString(); }
private static RelativePath stripFirstName(RelativePath relativePath) { String[] segments = relativePath.getSegments(); return new RelativePath(relativePath.isFile(), Arrays.copyOfRange(segments, 1, segments.length)); } }
@Override public String getDisplayName() { return path.toString(); }
/** * <p>Returns a copy of this path, with the last name replaced with the given name.</p> * * @param name The name. * @return The path. */ public RelativePath replaceLastName(String name) { String[] newSegments = new String[segments.length]; copySegments(newSegments, segments, segments.length - 1); newSegments[segments.length - 1] = internPathSegment(name); return new RelativePath(endsWithFile, newSegments); }
/** * Prepends the given names to the start of this path. * * @param segments The names to prepend * @return The new path. */ public RelativePath prepend(String... segments) { return new RelativePath(false, segments).append(this); }
private RelativePath(boolean endsWithFile, RelativePath parentPath, String... childSegments) { this.endsWithFile = endsWithFile; int targetOffsetForChildSegments; if (parentPath != null) { String[] sourceSegments = parentPath.getSegments(); segments = new String[sourceSegments.length + childSegments.length]; copySegments(segments, sourceSegments, sourceSegments.length); targetOffsetForChildSegments = sourceSegments.length; } else { segments = new String[childSegments.length]; targetOffsetForChildSegments = 0; } copyAndInternSegments(segments, targetOffsetForChildSegments, childSegments); }
@Override public void visitFile(FileVisitDetails fvd) { try { File outputFile = fvd.getRelativePath().getFile(outputDir); if (getLogger().isDebugEnabled()) getLogger().debug("Preprocessing " + fvd.getFile() + " -> " + outputFile); context.put(e.getKey(), e.getValue()); context.put("project", getProject()); context.put("package", DefaultGroovyMethods.join(fvd.getRelativePath().getParent().getSegments(), ".")); context.put("class", fvd.getRelativePath().getLastName().replaceFirst("\\.java$", "")); FileReader reader = new FileReader(fvd.getFile()); try { FileWriter writer = new FileWriter(outputFile); try { engine.evaluate(context, writer, fvd.getRelativePath().toString(), reader); } finally { writer.close();
/** * <p>Appends the given path to the end of this path. * * @param other The path to append * @return The new path */ public RelativePath append(RelativePath other) { return new RelativePath(other.endsWithFile, this, other.segments); }
public RelativePath getRelativePath() { if (relativePath == null) { RelativePath path = fileDetails.getRelativePath(); relativePath = specResolver.getDestPath().append(path.isFile(), path.getSegments()); } return relativePath; }
private File createFileInstance(RelativePath path) { return path.getFile(getTmpDir()); }
public RelativePath getDestPath() { RelativePath parentPath; if (parentResolver == null) { parentPath = new RelativePath(false); } else { parentPath = parentResolver.getDestPath(); } if (destDir == null) { return parentPath; } String path = PATH_NOTATION_PARSER.parseNotation(destDir); if (path.startsWith("/") || path.startsWith(File.separator)) { return RelativePath.parse(false, path); } return RelativePath.parse(false, parentPath, path); }
public File getBaseDir() { if (file == null || relativePath == null) { return null; } int relativeSegments = relativePath.getSegments().length; File parentFile = file; for (int i=0; i<relativeSegments; i++) { parentFile = parentFile.getParentFile(); } return parentFile; }
/** * Returns the parent of this path. * * @return The parent of this path, or null if this is the root path. */ public RelativePath getParent() { switch (segments.length) { case 0: return null; case 1: return EMPTY_ROOT; default: String[] parentSegments = new String[segments.length - 1]; copySegments(parentSegments, segments); return new RelativePath(false, parentSegments); } }
@Override public String getName() { return relativePath.getLastName(); }
public void execute(FileCopyDetails fileCopyDetails) { RelativePath path = fileCopyDetails.getRelativePath(); String newName = transformer.transform(path.getLastName()); if (newName != null) { path = path.replaceLastName(newName); fileCopyDetails.setRelativePath(path); } } }
/** * <p>Appends the given path to the end of this path. * * @param other The path to append * @return The new path */ public RelativePath plus(RelativePath other) { return append(other); }
/** * Appends the given names to the end of this path. * * @param segments The names to append. * @param endsWithFile when true, the new path refers to a file. * @return The new path. */ public RelativePath append(boolean endsWithFile, String... segments) { return new RelativePath(endsWithFile, this, segments); }
@Override public ProgramArguments augmentArguments(File inputDirectory, RelativePath inputRelativePath, ProgramArguments arguments) { ProgramArguments augmentedArguments = new ProgramArguments(arguments); augmentedArguments.add("OUTPUT_DIRECTORY", inputRelativePath.getFile(tempOutputDirectory).getParentFile().getAbsolutePath()); return augmentedArguments; }
@VisibleForTesting static NormalizedFileSnapshot getRelativeSnapshot(FileSnapshot fileSnapshot, StringInterner stringInterner) { String[] segments = fileSnapshot.getRelativePath().getSegments(); StringBuilder builder = new StringBuilder(); for (int i = 0, len = segments.length; i < len; i++) { if (i != 0) { builder.append('/'); } builder.append(segments[i]); } return getRelativeSnapshot(fileSnapshot, builder.toString(), stringInterner); }
@Override public String getName() { return relativePath.getLastName(); }