Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions checkstyle-tester/diff.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,15 @@ def postProcessCheckstyleReport(targetDir, repoName, repoPath) {
def checkstyleResultFile = new File(getOsSpecificPath("$targetDir", "checkstyle-result.xml"))
def oldPath = new File(getOsSpecificPath("src", "main", "java", "$repoName")).absolutePath
def newPath = getOsSpecificPath("$repoPath")
def tempFile = Files.createTempFile("temp", ".xml").toFile()

def content = checkstyleResultFile.text
content = content.replace(oldPath, newPath)
checkstyleResultFile.text = content
tempFile.withWriter { writer ->
checkstyleResultFile.eachLine { line ->
writer.writeLine(line.replace(oldPath, newPath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, ....

I started above discussion on this code.
Why we need such custom each line read write?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed because the original file.text loads the entire file into a single String, which causes OutOfMemoryError for large files, Error we saw earlier, i find eachLine/withWriter as the simplest streaming solution in Groovy that avoids loading the whole file into memory.

}
}
Files.copy(tempFile.toPath(), checkstyleResultFile.toPath(), REPLACE_EXISTING)
tempFile.delete()
}

def copyDir(source, destination) {
Expand Down