diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-20 22:09:38 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-27 19:56:13 -0400 |
commit | bba2abe7ee38b8903822a07578c46466923d13ed (patch) | |
tree | a357fb8def6f58a9ea9a37411f3f5640dcb525fe /stage2/Lib.scala | |
parent | d2f8cade709b7d55a93e18592b6e38247d648ca9 (diff) | |
download | cbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.gz cbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.bz2 cbt-bba2abe7ee38b8903822a07578c46466923d13ed.zip |
start modularizing cbt into libraries
this extracts certain parts of cbt into stand-alone libraries, which can
be published to maven and used outside of cbt.
This also adds scalariform for these parts of the code.
This slows down cbt’s own build a lot because of the number of projects
involved! So we’ll follow this by a bunch of performance tweak commits.
Diffstat (limited to 'stage2/Lib.scala')
-rw-r--r-- | stage2/Lib.scala | 58 |
1 files changed, 2 insertions, 56 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index fd3346e..6488c1a 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -64,10 +64,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ c => c .getMethods - .filter{ m => - java.lang.reflect.Modifier.isPublic(m.getModifiers) - } - .filter( _.getParameterTypes.length == 0 ) + .filter( _.isPublic ) + .filter( _.parameterTypes.length == 0 ) .map(m => NameTransformer.decode(m.getName) -> m) .filterNot(_._1 contains "$") ).toMap @@ -262,34 +260,6 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ m } - def autoRelative( files: Seq[File], collector: PartialFunction[(File,String), String] = { case (_,r) => r }): Seq[(File, String)] = { - val map = files.sorted.flatMap{ base => - val b = base.getCanonicalFile.string - if( base.isDirectory ){ - base.listRecursive.map{ f => - f -> f.getCanonicalFile.string.stripPrefix(b).stripPrefix(File.separator) - } - } else { - Seq( base -> base.getName ) - } - }.collect{ - case v@(file, _) if collector.isDefinedAt(v) => file -> collector(v) - } - val relatives = map.unzip._2 - val duplicateFiles = (relatives diff relatives.distinct).distinct - assert( - duplicateFiles.isEmpty, - { - val rs = relatives.toSet - "Conflicting:\n\n" + - map.filter(rs contains _._2).groupBy(_._2).mapValues(_.map(_._1).sorted).toSeq.sortBy(_._1).map{ - case (name, files) => s"$name:\n" ++ files.mkString("\n") - }.mkString("\n\n") - } - ) - map - } - def createJar( jarFile: File, files: Seq[File], mainClass: Option[String] = None ): Option[File] = { deleteIfExists(jarFile.toPath) if( files.isEmpty ){ @@ -474,29 +444,5 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ ) findOuterMostModuleDirectory(directory.getParentFile) else directory } - def transformFiles( files: Seq[File], transform: String => String ): Seq[File] = { - transformFilesOrError( files, s => Right(transform(s)) )._1 - } - - def transformFilesOrError[T]( files: Seq[File], transform: String => Either[T,String] ): ( Seq[File], Seq[(File, T)] ) = { - val results = files.map{ file => - val string = file.readAsString - transform( string ).left.map( - file -> _ - ).right.map( - replaced => - if( string != replaced ) { - val tmpFile = file ++ ".cbt-tmp" - assert( !tmpFile.exists ) - write( tmpFile, replaced ) - move( tmpFile.toPath, file.toPath, StandardCopyOption.REPLACE_EXISTING ) - Some( file ) - } else None - ) - } - - ( results.map(_.right.toOption).flatten.flatten, results.map(_.left.toOption).flatten ) - } - def clearScreen = System.err.println( (27.toChar +: "[2J").mkString ) } |