Skip to content

Commit

Permalink
Writing to all files now includes ensuring parent directories do exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
shafirov committed Sep 23, 2016
1 parent f91a993 commit 34c5dc7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/groovy/KWP.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,6 @@ class KWP implements Plugin<Project> {
void installKwp(File targetDir, boolean force) {
def file = new File(targetDir, "kwp.js")
if (!file.exists() || force) {
targetDir.mkdirs()
writeSafely(file) { buf ->
buf.append(loaderText)
}
Expand All @@ -35,8 34,6 @@ class KWP implements Plugin<Project> {
def sources = new LinkedHashSet<String>()
collectDependencies(project, sources, dependencies)

targetDir.mkdirs()

writeSafely(new File(targetDir, "__modules.txt")) { buf ->
dependencies.each {jar ->
def m = unzipSafely(jar, targetDir)
Expand Down Expand Up @@ -79,12 76,12 @@ class KWP implements Plugin<Project> {
if (zipEntry.isDirectory()) continue

if (zipEntry.name.endsWith(".meta.js") || zipEntry.name.endsWith('.js.map')) {
new File(targetFolder, zipEntry.name).text = zip.getInputStream(zipEntry).text
writeSafely(new File(targetFolder, zipEntry.name), zip.getInputStream(zipEntry).text)
targets
}
else if (zipEntry.name.endsWith(".js")) {
targetFile = new File(targetFolder, zipEntry.name)
targetFile.text = zip.getInputStream(zipEntry).text
writeSafely(targetFile, zip.getInputStream(zipEntry).text)
targets
}

Expand All @@ -106,11 103,17 @@ class KWP implements Plugin<Project> {
return str
}

void writeSafely(File file, String contents) {
if (!file.exists() || file.text != contents) {
file.getParentFile().mkdirs()
file.text = contents
}
}

void writeSafely(File file, Closure<StringBuilder> builder) {
def buffer = new StringBuilder()
builder(buffer)
def contents = buffer.toString()
if (!file.exists() || file.text != contents) file.text = contents
writeSafely(file, buffer.toString())
}

String normalizedAbsolutePath(File file) {
Expand Down

0 comments on commit 34c5dc7

Please sign in to comment.