diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-07 01:36:40 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-07 01:36:40 -0500 |
commit | e958dec0dbbcf7f7a28cd21641e76390fb3dba6a (patch) | |
tree | ec0933e230b0c3f222fceb82b3eec177d56ea979 /stage2/Lib.scala | |
parent | f0dc760df8757caea1d83b15142a3d0704488636 (diff) | |
download | cbt-e958dec0dbbcf7f7a28cd21641e76390fb3dba6a.tar.gz cbt-e958dec0dbbcf7f7a28cd21641e76390fb3dba6a.tar.bz2 cbt-e958dec0dbbcf7f7a28cd21641e76390fb3dba6a.zip |
cleanup: whitespace changes, separated more things into their own files, use ++ for strings everywhere. Added ++ method to File and URL and use it in many places
Diffstat (limited to 'stage2/Lib.scala')
-rw-r--r-- | stage2/Lib.scala | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 9971b55..6bb9c0b 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -37,9 +37,9 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ */ def loadRoot(context: Context, default: Context => Build = new Build(_)): Build = { context.logger.composition( context.logger.showInvocation("Build.loadRoot",context) ) - def findStartDir(cwd: String): String = { - val buildDir = realpath(cwd+"/build") - if(new File(buildDir).exists) findStartDir(buildDir) else cwd + def findStartDir(cwd: File): File = { + val buildDir = realpath( cwd ++ "/build" ) + if(buildDir.exists) findStartDir(buildDir) else cwd } val start = findStartDir(context.cwd) @@ -51,7 +51,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ if(useBasicBuildBuild) default( context ) else new cbt.BuildBuild( context.copy( cwd = start ) ) } catch { case e:ClassNotFoundException if e.getMessage == rootBuildClassName => - throw new Exception(s"no class $rootBuildClassName found in "+start) + throw new Exception(s"no class $rootBuildClassName found in " ++ start.string) } } @@ -68,13 +68,13 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } def srcJar(sources: Seq[File], artifactId: String, version: String, jarTarget: File): File = { - val file = new File(jarTarget+"/"+artifactId+"-"+version+"-sources.jar") + val file = jarTarget ++ ("/"++artifactId++"-"++version++"-sources.jar") lib.jarFile(file, sources) file } def jar(artifactId: String, version: String, compileTarget: File, jarTarget: File): File = { - val file = new File(jarTarget+"/"+artifactId+"-"+version+".jar") + val file = jarTarget ++ ("/"++artifactId++"-"++version++".jar") lib.jarFile(file, Seq(compileTarget)) file } @@ -102,7 +102,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ "scala.tools.nsc.ScalaDoc", Seq( // FIXME: can we use compiler dependency here? - "-cp", /*javacp+":"+*/ScalaDependencies(logger).classpath.string + ":" + dependenyClasspath.string, + "-cp", /*javacp++":"++*/ScalaDependencies(logger).classpath.string ++ ":" ++ dependenyClasspath.string, "-d", apiTarget.toString ) ++ compileArgs ++ sourceFiles.map(_.toString), new URLClassLoader( @@ -113,7 +113,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } } } - val docJar = new File(jarTarget+"/"+artifactId+"-"+version+"-javadoc.jar") + val docJar = jarTarget ++ ("/"++artifactId++"-"++version++"-javadoc.jar") lib.jarFile(docJar, Vector(apiTarget)) docJar } @@ -122,11 +122,11 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val loggers = logger.enabledLoggers.mkString(",") // FIXME: this is a hack to pass logger args on to the tests. // should probably have a more structured way - val loggerArg = if(loggers != "") Some("-Dlog="+loggers) else None + val loggerArg = if(loggers != "") Some("-Dlog="++loggers) else None logger.lib(s"invoke testDefault( $context )") val exitCode: ExitCode = loadDynamic( - context.copy( cwd = context.cwd+"/test/", args = loggerArg.toVector ++ context.args ), + context.copy( cwd = context.cwd ++ "/test", args = loggerArg.toVector ++ context.args ), new Build(_) with mixins.Test ).run logger.lib(s"return testDefault( $context )") @@ -135,9 +135,9 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ // task reflection helpers import ru._ - private lazy val anyRefMembers = ru.typeOf[AnyRef].members.toVector.map(taskName) - def taskNames(tpe: Type) = tpe.members.toVector.flatMap(lib.toTask).map(taskName).sorted - private def taskName(method: Symbol) = method.name.decodedName.toString + private lazy val anyRefMembers: Set[String] = ru.typeOf[AnyRef].members.toSet.map(taskName) + def taskNames(tpe: Type): Seq[String] = tpe.members.toVector.flatMap(lib.toTask).map(taskName).sorted + private def taskName(method: Symbol): String = method.name.decodedName.toString def toTask(symbol: Symbol): Option[MethodSymbol] = { Option(symbol) .filter(_.isPublic) @@ -161,10 +161,10 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ """ } else "" - ) + s"""Methods provided by CBT (but possibly overwritten) + ) ++ s"""Methods provided by CBT (but possibly overwritten) ${baseTasks.mkString(" ")}""" - ) + "\n" + ) ++ "\n" } } @@ -202,17 +202,13 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } } - // file system helpers - def basename(path: String) = path.stripSuffix("/").split("/").last - def basename(path: File) = path.toString.stripSuffix("/").split("/").last - def dirname(path: String) = realpath(path).stripSuffix("/").split("/").dropRight(1).mkString("/") - def realpath(name: String) = Paths.get(new File(name).getAbsolutePath).normalize.toString - def realpath(name: File) = new File(Paths.get(name.getAbsolutePath).normalize.toString) - def nameAndContents(file: File) = basename(file.toString) -> readAllBytes(Paths.get(file.toString)) + def basename(path: File): String = path.toString.stripSuffix("/").split("/").last + def dirname(path: File): File = new File(realpath(path).string.stripSuffix("/").split("/").dropRight(1).mkString("/")) + def nameAndContents(file: File) = basename(file) -> readAllBytes(Paths.get(file.toString)) def jarFile( jarFile: File, files: Seq[File] ): Unit = { - logger.lib("Start packaging "+jarFile) + logger.lib("Start packaging "++jarFile.string) val manifest = new Manifest manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0") val jar = new JarOutputStream(new FileOutputStream(jarFile.toString), manifest) @@ -227,7 +223,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val entry = new JarEntry( name ) entry.setTime(file.lastModified) jar.putNextEntry(entry) - jar.write( Files.readAllBytes( Paths.get(file.toString) ) ) + jar.write( readAllBytes( Paths.get(file.toString) ) ) jar.closeEntry name } @@ -235,11 +231,11 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val duplicateFiles = (names diff names.distinct).distinct assert( duplicateFiles.isEmpty, - s"Conflicting file names when trying to create $jarFile: "+duplicateFiles.mkString(", ") + s"Conflicting file names when trying to create $jarFile: "++duplicateFiles.mkString(", ") ) jar.close - logger.lib("Done packaging "+jarFile) + logger.lib("Done packaging " ++ jarFile.toString) } lazy val passphrase = @@ -255,9 +251,9 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ new ProcessBuilder( "gpg", "--batch", "--yes", "-a", "-b", "-s", "--passphrase", passphrase, file.toString ) .inheritIO.start.waitFor - if( 0 != statusCode ) throw new Exception("gpg exited with status code "+statusCode) + if( 0 != statusCode ) throw new Exception("gpg exited with status code " ++ statusCode.toString) - new File(file+".asc") + file ++ ".asc" } //def requiredForPom[T](name: String): T = throw new Exception(s"You need to override `def $name` in order to generate a valid pom.") @@ -324,9 +320,9 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } </dependencies> </project> - val path = new File(jarTarget+"/"+artifactId+"-"+version+".pom") - write.over(Path(path), "<?xml version='1.0' encoding='UTF-8'?>\n" + xml.toString) - path + val path = jarTarget.toString ++ ( "/" ++ artifactId ++ "-" ++ version ++ ".pom" ) + write.over(Path(path), "<?xml version='1.0' encoding='UTF-8'?>\n" ++ xml.toString) + new File(path) } def concurrently[T,R]( concurrencyEnabled: Boolean )( items: Seq[T] )( projection: T => R ): Seq[R] = { @@ -347,8 +343,8 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val files = (artifacts ++ artifacts.map(sign)).map(nameAndContents) lazy val checksums = files.flatMap{ case (name, content) => Seq( - name+".md5" -> md5(content).toArray.map(_.toByte), - name+".sha1" -> sha1(content).toArray.map(_.toByte) + name++".md5" -> md5(content).toArray.map(_.toByte), + name++".sha1" -> sha1(content).toArray.map(_.toByte) ) } val all = (files ++ checksums) @@ -363,16 +359,14 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL): Unit = { import java.net._ import java.io._ - logger.task("uploading "+fileName) - val url = new URL( - baseUrl + fileName - ) + logger.task("uploading "++fileName) + val url = baseUrl ++ fileName val httpCon = url.openConnection.asInstanceOf[HttpURLConnection] httpCon.setDoOutput(true) httpCon.setRequestMethod("PUT") val userPassword = read(Path(sonatypeLogin)).trim val encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes) - httpCon.setRequestProperty("Authorization", "Basic " + encoding) + httpCon.setRequestProperty("Authorization", "Basic " ++ encoding) httpCon.setRequestProperty("Content-Type", "application/binary") httpCon.getOutputStream.write( fileContents @@ -389,7 +383,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ files.map{ file => - if(file.isFile) new File( dirname(file.toString) ) + if(file.isFile) dirname(file) else file }.distinct.map{ file => val watchableFile = new WatchableFile(file) @@ -411,7 +405,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ .filterNot(_.kind == StandardWatchEventKind.OVERFLOW) .map(_.context.toString) .map(new File(_)) - changedFiles.foreach( f => logger.loop("Changed: "+f) ) + changedFiles.foreach( f => logger.loop( "Changed: " ++ f.toString ) ) changedFiles.collect(action) key.reset } |