Skip to content
Snippets Groups Projects
Commit 34c5dc7a authored by Maxim Shafirov's avatar Maxim Shafirov
Browse files

Writing to all files now includes ensuring parent directories do exist.

parent f91a993c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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)
}
Loading
Loading
@@ -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)
Loading
Loading
@@ -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++
}
 
Loading
Loading
@@ -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) {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment