Skip to content
Newer
Older
100644 60 lines (57 sloc) 1.91 KB
a33223a @harrah legal cleanup
authored
1 /* sbt -- Simple Build Tool
2 * Copyright 2009 Mark Harrah
3 */
34fd967 @harrah General support for searching for the working directory to use for th…
authored
4 package xsbt.boot
5
33434bc @harrah Cut size of final jar by 300k.
authored
6 import Pre._
34fd967 @harrah General support for searching for the working directory to use for th…
authored
7 import java.io.File
8 import java.net.URI
b2077ce @harrah more 2.8 updates, launcher compiles and runs with 2.8
authored
9 import scala.collection.immutable.List
34fd967 @harrah General support for searching for the working directory to use for th…
authored
10
11 object Find { def apply(config: LaunchConfiguration, currentDirectory: File) = (new Find(config))(currentDirectory) }
988c22c @harrah support reason for retrieving jars in launcher
authored
12 class Find(config: LaunchConfiguration)
34fd967 @harrah General support for searching for the working directory to use for th…
authored
13 {
14 import config.boot.search
15 def apply(currentDirectory: File) =
16 {
17 val current = currentDirectory.getCanonicalFile
18 assert(current.isDirectory)
19
20 lazy val fromRoot = path(current, Nil).filter(hasProject).map(_.getCanonicalFile)
21 val found: Option[File] =
22 search.tpe match
23 {
24 case Search.RootFirst => fromRoot.headOption
25 case Search.Nearest => fromRoot.lastOption
26 case Search.Only =>
27 if(hasProject(current))
28 Some(current)
29 else
30 fromRoot match
31 {
32 case Nil => Some(current)
33 case head :: Nil => Some(head)
34 case xs =>
35 System.err.println("Search method is 'only' and multiple ancestor directories match:\n\t" + fromRoot.mkString("\n\t"))
36 System.exit(1)
37 None
38 }
39 case _ => Some(current)
40 }
dd4efec @harrah auto detect Scala version for non-cross-versioned launcher app
authored
41 val baseDirectory = orElse(found, current)
34fd967 @harrah General support for searching for the working directory to use for th…
authored
42 System.setProperty("user.dir", baseDirectory.getAbsolutePath)
54bc694 @harrah * cleaned up build
authored
43 (ResolvePaths(config, baseDirectory), baseDirectory)
34fd967 @harrah General support for searching for the working directory to use for th…
authored
44 }
54bc694 @harrah * cleaned up build
authored
45 private def hasProject(f: File) = f.isDirectory && search.paths.forall(p => ResolvePaths(f, p).exists)
46 private def path(f: File, acc: List[File]): List[File] = if(f eq null) acc else path(f.getParentFile, f :: acc)
47 }
48 object ResolvePaths
49 {
50 def apply(config: LaunchConfiguration, baseDirectory: File): LaunchConfiguration =
51 config.map(f => apply(baseDirectory, f))
52 def apply(baseDirectory: File, f: File): File =
79de239 @eed3si9n fix path resolution on Windows
eed3si9n authored
53 if (f.isAbsolute) f
54 else
55 {
56 assert(baseDirectory.isDirectory) // if base directory is not a directory, URI.resolve will not work properly
57 val uri = new URI(null, null, f.getPath, null)
58 new File(baseDirectory.toURI.resolve(uri))
59 }
34fd967 @harrah General support for searching for the working directory to use for th…
authored
60 }
Something went wrong with that request. Please try again.