Skip to content

GapPatternPostProcessor should only rename .java files #20

@dwerle

Description

@dwerle

The GapPatternPostProcessor should check if files are actually .java files before renaming them (or more generally check if a match means that the file is to be renamed). The current processor will fail, for example, if both directories are empty and contain a .gitkeep file (will be renamed to .gitkeep.java).

for (Path processFile: filesToPostProcess) {
String oldClassName = processFile.getFileName().toString().replaceAll(".java", "");
String className = processFile.getFileName().toString().replaceAll(JAVAFILE_MATCHER_PATTERN,
replacementPattern);
Path targetPath = processFile.getParent().resolve(Paths.get(className + ".java"));
LOG.info(String.format("Renaming %s to %s", processFile.toString(), targetPath.toString()));
Files.move(processFile, targetPath, StandardCopyOption.REPLACE_EXISTING);
String content = new String(Files.readAllBytes(targetPath), charset);
content = content.replaceAll(String.format(searchPattern, oldClassName),
replacementPattern);
Files.write(targetPath, content.getBytes(charset));
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions