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; }
@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); }
private static RelativePath stripFirstName(RelativePath relativePath) { String[] segments = relativePath.getSegments(); return new RelativePath(relativePath.isFile(), Arrays.copyOfRange(segments, 1, segments.length)); } }
private boolean shouldBeIgnored(RelativePath relativePath) { if (ignoreMatchers.isEmpty()) { return false; } for (PathMatcher ignoreSpec : ignoreMatchers) { if (ignoreSpec.matches(relativePath.getSegments(), 0)) { return true; } } return false; }
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); }
public RelativePath getRelativePath() { if (relativePath == null) { RelativePath path = fileDetails.getRelativePath(); relativePath = specResolver.getDestPath().append(path.isFile(), path.getSegments()); } return relativePath; }
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());