aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-06-08 22:29:29 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-06-08 22:37:39 -0400
commitb103b922f8671e7f45cef0cbd876ebe26cb0a2fa (patch)
treef5ed98ca10fbd55b73b1c743c6faa6ccda8f664d
parentbf534fc64e54af905402833cace7687d73ba8817 (diff)
downloadcbt-b103b922f8671e7f45cef0cbd876ebe26cb0a2fa.tar.gz
cbt-b103b922f8671e7f45cef0cbd876ebe26cb0a2fa.tar.bz2
cbt-b103b922f8671e7f45cef0cbd876ebe26cb0a2fa.zip
Always create directory before trying to write file
-rw-r--r--nailgun_launcher/Stage0Lib.java8
-rw-r--r--stage1/Stage1Lib.scala6
-rw-r--r--stage2/Lib.scala4
-rw-r--r--stage2/PublishBuild.scala4
-rw-r--r--stage2/Scaffold.scala3
-rw-r--r--stage2/ToolsTasks.scala2
6 files changed, 17 insertions, 10 deletions
diff --git a/nailgun_launcher/Stage0Lib.java b/nailgun_launcher/Stage0Lib.java
index bd18748..ae09d78 100644
--- a/nailgun_launcher/Stage0Lib.java
+++ b/nailgun_launcher/Stage0Lib.java
@@ -46,6 +46,12 @@ public class Stage0Lib{
return join( pathSeparator, files );
}
+ public static File write(File file, String content, OpenOption... options) throws Exception{
+ file.getParentFile().mkdirs();
+ Files.write(file.toPath(), content.getBytes());
+ return file;
+ }
+
public static Boolean compile(
Boolean changed, Long start, String classpath, String target,
EarlyDependencies earlyDeps, List<File> sourceFiles, SecurityManager defaultSecurityManager
@@ -82,7 +88,7 @@ public class Stage0Lib{
System.setOut(System.err);
int exitCode = runMain( "com.typesafe.zinc.Main", zincArgs.toArray(new String[zincArgs.size()]), earlyDeps.zinc, defaultSecurityManager );
if( exitCode == 0 ){
- Files.write( statusFile.toPath(), "".getBytes());
+ write( statusFile, "" );
Files.setLastModifiedTime( statusFile.toPath(), FileTime.fromMillis(start) );
} else {
System.exit( exitCode );
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index d0d22d2..4376c17 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -54,6 +54,8 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
def blue(string: String) = scala.Console.BLUE++string++scala.Console.RESET
def green(string: String) = scala.Console.GREEN++string++scala.Console.RESET
+ def write(file: File, content: String, options: OpenOption*): File = Stage0Lib.write(file, content, options:_*)
+
def download(url: URL, target: File, sha1: Option[String]): Boolean = {
if( target.exists ){
logger.resolver(green("found ") ++ url.string)
@@ -231,7 +233,7 @@ ${files.sorted.mkString(" \\\n")}
if(code == ExitCode.Success){
// write version and when last compilation started so we can trigger
// recompile if cbt version changed or newer source files are seen
- Files.write(statusFile.toPath, "".getBytes)//cbtVersion.getBytes)
+ write(statusFile, "")//cbtVersion.getBytes)
Files.setLastModifiedTime(statusFile.toPath, FileTime.fromMillis(start) )
} else {
System.exit(code.integer) // FIXME: let's find a better solution for error handling. Maybe a monad after all.
@@ -284,7 +286,7 @@ ${files.sorted.mkString(" \\\n")}
} else {
val result = compute
val string = result.map(serialize).mkString("\n")
- Files.write(cacheFile.toPath, string.getBytes)
+ write(cacheFile, string)
result
}
}
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index ac7b45c..b76402a 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -241,6 +241,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
if( files.isEmpty ){
None
} else {
+ jarFile.getParentFile.mkdirs
logger.lib("Start packaging "++jarFile.string)
val manifest = new Manifest
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0")
@@ -360,8 +361,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
// FIXME: do not build this file name including scalaMajorVersion in multiple places
val path = jarTarget.toString ++ ( "/" ++ artifactId++ "_" ++ scalaMajorVersion ++ "-" ++ version ++ ".pom" )
val file = new File(path)
- Files.write(file.toPath, ("<?xml version='1.0' encoding='UTF-8'?>\n" ++ xml.toString).getBytes)
- file
+ write(file, "<?xml version='1.0' encoding='UTF-8'?>\n" ++ xml.toString)
}
def concurrently[T,R]( concurrencyEnabled: Boolean )( items: Seq[T] )( projection: T => R ): Seq[R] = {
diff --git a/stage2/PublishBuild.scala b/stage2/PublishBuild.scala
index 34c1d4f..2bf88bc 100644
--- a/stage2/PublishBuild.scala
+++ b/stage2/PublishBuild.scala
@@ -52,12 +52,12 @@ abstract class PublishBuild(context: Context) extends PackageBuild(context){
def publishUnsigned: Unit = {
lib.publishUnsigned(
- sourceFiles, pom +: `package`, publishUrl ++ releaseFolder, sonatypeCredentials
+ sourceFiles, `package` :+ pom, publishUrl ++ releaseFolder, sonatypeCredentials
)
}
def publishSigned: Unit = {
lib.publishSigned(
- sourceFiles, pom +: `package`, publishUrl ++ releaseFolder, sonatypeCredentials
+ sourceFiles, `package` :+ pom, publishUrl ++ releaseFolder, sonatypeCredentials
)
}
}
diff --git a/stage2/Scaffold.scala b/stage2/Scaffold.scala
index 1f3d515..78242fc 100644
--- a/stage2/Scaffold.scala
+++ b/stage2/Scaffold.scala
@@ -7,8 +7,7 @@ trait Scaffold{
private def createFile( projectDirectory: File, fileName: String, code: String ){
val outputFile = projectDirectory ++ ("/" ++ fileName)
- outputFile.getParentFile.mkdirs
- Files.write( ( outputFile ).toPath, code.getBytes, StandardOpenOption.CREATE_NEW )
+ Stage0Lib.write( outputFile, code, StandardOpenOption.CREATE_NEW )
import scala.Console._
println( GREEN ++ "Created " ++ fileName ++ RESET )
}
diff --git a/stage2/ToolsTasks.scala b/stage2/ToolsTasks.scala
index df33b5d..d388f12 100644
--- a/stage2/ToolsTasks.scala
+++ b/stage2/ToolsTasks.scala
@@ -137,7 +137,7 @@ ${assignments.mkString("\n")}
}
"""
val file = nailgun ++ ("/" ++ "EarlyDependencies.java")
- Files.write( file.toPath, code.getBytes )
+ lib.write( file, code )
println( Console.GREEN ++ "Wrote " ++ file.string ++ Console.RESET )
}
}