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 /stage1/resolver.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 'stage1/resolver.scala')
-rw-r--r-- | stage1/resolver.scala | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/stage1/resolver.scala b/stage1/resolver.scala index e3500b3..0f0acaa 100644 --- a/stage1/resolver.scala +++ b/stage1/resolver.scala @@ -77,26 +77,25 @@ trait DependencyImplementation extends Dependency{ ) } */ - - def runMain( className: String, args: Seq[String] ) = lib.runMain( className, args, classLoader ) - def flatClassLoader: Boolean = false - def mainClasses: Seq[Class[_]] = exportedClasspath.files.flatMap( lib.mainClasses( _, classLoader ) ) - - def runClass: Option[String] = lib.runClass( mainClasses ).map( _.getName ) + def runMain( className: String, args: Seq[String] ): ExitCode = lib.trapExitCode{ + lib.runMain( classLoader.loadClass( className ), args ) + } - def run( args: String* ): ExitCode = { - runClass.map( runMain( _, args ) ).getOrElse{ - // FIXME: this just doing nothing when class is not found has been repeatedly - // surprising. Let's try to make this more visible than just logging an error. - // Currently blocked on task `recursive` trying every subbuild and would error - // for all that don't have a run class. Maybe that's ok actually. - logger.task( "No main class found for " ++ show ) - ExitCode.Success - } + def runMain( args: Seq[String] ): ExitCode = lib.trapExitCode{ + mainMethod.getOrElse( + throw new RuntimeException( "No main class found in " + this ) + )( args ) } + def mainMethod = lib.pickOne( "Which one do you want to run?", mainMethods )( _.name ) + + def classes = exportedClasspath.files.flatMap( + lib.iterateClasses( _, classLoader, false ) + ) + def mainMethods = classes.flatMap( lib.discoverMain ) + def classLoader: ClassLoader = { if( flatClassLoader ){ new java.net.URLClassLoader(classpath.strings.map(f => new URL("file://" ++ f)).toArray) |