Skip to content

Commit 700f7ae

Browse files
author
Antonio Cunei
committed
Reorganized Adapter
1 parent 0b072ab commit 700f7ae

File tree

4 files changed

+147
-145
lines changed

4 files changed

+147
-145
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package sbt.dbuild.hack {
2+
object DbuildHack {
3+
val Load = sbt.Load
4+
}
5+
}
6+
7+
package com.typesafe.dbuild.adapter {
8+
import java.io.File
9+
10+
object LoggingInterface {
11+
val Level = sbt.Level
12+
type Logger = sbt.Logger
13+
type LogEvent = sbt.LogEvent
14+
val ControlEvent = sbt.ControlEvent
15+
val StackTrace = sbt.StackTrace
16+
type BasicLogger = sbt.BasicLogger
17+
}
18+
19+
import LoggingInterface.Level._
20+
trait StreamLoggerAdapter {
21+
def log(level: Value, message: => String): Unit
22+
def log(label: String, message: String): Unit
23+
def err(s: => String): Unit = log(Error, s)
24+
def out(s: => String): Unit = log(Info.toString, s)
25+
}
26+
27+
object Adapter {
28+
val IO = sbt.IO
29+
val Path = sbt.Path
30+
type RichFile = sbt.RichFile
31+
type FileFilter = sbt.FileFilter
32+
def toFF = sbt.FileFilter.globFilter _
33+
val DirectoryFilter = sbt.DirectoryFilter
34+
type ExactFilter = sbt.ExactFilter
35+
type NameFilter = sbt.NameFilter
36+
type FileRepository = sbt.FileRepository
37+
type Logger = sbt.Logger
38+
import Path._
39+
def allPaths(f:File) = sbt.PathFinder(f).***
40+
val syntax = new {}
41+
val syntaxio = syntax
42+
type ModuleID = sbt.ModuleID
43+
type Artifact = sbt.Artifact
44+
type ProjectResolver = sbt.ProjectResolver
45+
type ScalaInstance = sbt.ScalaInstance
46+
val ScalaInstance = sbt.ScalaInstance
47+
val Load = sbt.dbuild.hack.DbuildHack.Load
48+
val applyCross: (String, Option[String => String]) => String =
49+
sbt.CrossVersion.applyCross
50+
def defaultID(base: File, prefix: String = "default") =
51+
sbt.Build.defaultID(base, prefix)
52+
def scalaInstance(libraryJar: File, compilerJar: File, launcher: xsbti.Launcher, extraJars: File*): ScalaInstance =
53+
ScalaInstance(libraryJar, compilerJar, launcher, extraJars:_*)
54+
}
55+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package sbt.dbuild.hack {
2+
object DbuildHack {
3+
val Load = sbt.internal.Load
4+
val applyCross: (String, Option[String => String]) => String =
5+
sbt.librarymanagement.CrossVersion.applyCross
6+
val defaultID: (java.io.File,String) => String =
7+
sbt.internal.BuildDef.defaultID
8+
}
9+
}
10+
package com.typesafe.dbuild.adapter {
11+
import java.io.File
12+
13+
object LoggingInterface {
14+
val Level = sbt.util.Level
15+
type Logger = sbt.util.Logger
16+
type LogEvent = sbt.util.LogEvent
17+
val ControlEvent = sbt.util.ControlEvent
18+
val StackTrace = sbt.internal.util.StackTrace
19+
type BasicLogger = sbt.internal.util.BasicLogger
20+
}
21+
22+
trait StreamLoggerAdapter
23+
24+
object Adapter {
25+
val IO = sbt.io.IO
26+
val Path = sbt.io.Path
27+
type RichFile = sbt.io.RichFile
28+
type FileFilter = sbt.io.FileFilter
29+
def toFF = sbt.io.FileFilter.globFilter _
30+
val DirectoryFilter = sbt.io.DirectoryFilter
31+
type ExactFilter = sbt.io.ExactFilter
32+
type NameFilter = sbt.io.NameFilter
33+
type FileRepository = sbt.librarymanagement.FileRepository
34+
type Logger = sbt.util.Logger
35+
def allPaths(f:File) = sbt.io.PathFinder(f).allPaths
36+
val syntaxio = sbt.io.syntax
37+
val syntax = sbt.syntax
38+
type ModuleID = sbt.librarymanagement.ModuleID
39+
type Artifact = sbt.librarymanagement.Artifact
40+
type ProjectResolver = sbt.internal.librarymanagement.ProjectResolver
41+
type ScalaInstance = sbt.internal.inc.ScalaInstance
42+
val ScalaInstance = sbt.internal.inc.ScalaInstance
43+
val Load = sbt.dbuild.hack.DbuildHack.Load
44+
val applyCross = sbt.dbuild.hack.DbuildHack.applyCross
45+
def defaultID(base: File, prefix: String = "default") =
46+
sbt.dbuild.hack.DbuildHack.defaultID(base, prefix)
47+
48+
// these bits are inappropriately copied from zinc v1.0.0-X1, where they
49+
// are private now, and exactly from:
50+
// internal/zinc-classpath/src/main/scala/sbt/internal/inc/ScalaInstance.scala
51+
private val VersionPrefix = "version "
52+
private def fastActualVersion(scalaLoader: ClassLoader): String =
53+
{
54+
val stream = scalaLoader.getResourceAsStream("compiler.properties")
55+
try {
56+
val props = new java.util.Properties
57+
props.load(stream)
58+
props.getProperty("version.number")
59+
} finally stream.close()
60+
}
61+
import java.net.{ URL, URLClassLoader }
62+
private def scalaLoader(launcher: xsbti.Launcher): Seq[File] => ClassLoader = jars =>
63+
new URLClassLoader(jars.map(_.toURI.toURL).toArray[URL], launcher.topLoader)
64+
private def actualVersion(scalaLoader: ClassLoader)(label: String) =
65+
try fastActualVersion(scalaLoader)
66+
catch { case e: Exception => slowActualVersion(scalaLoader)(label) }
67+
private def slowActualVersion(scalaLoader: ClassLoader)(label: String) =
68+
{
69+
val v = try { Class.forName("scala.tools.nsc.Properties", true, scalaLoader).getMethod("versionString").invoke(null).toString }
70+
catch { case cause: Exception => throw new sbt.internal.inc.InvalidScalaInstance("Scala instance doesn't exist or is invalid: " + label, cause) }
71+
if (v.startsWith(VersionPrefix)) v.substring(VersionPrefix.length) else v
72+
}
73+
//
74+
// The code below was deprecated and has been removed from ScalaInstance in zinc 1.0.x,
75+
// however it may work for us.
76+
//
77+
// TODO: use one of the currently supported variants of ScalaInstance.apply()
78+
//
79+
def scalaInstance(libraryJar: File, compilerJar: File, launcher: xsbti.Launcher, extraJars: File*): ScalaInstance = {
80+
val classLoader = scalaLoader(launcher)
81+
val loader = classLoader(libraryJar :: compilerJar :: extraJars.toList)
82+
val version = actualVersion(loader)(" (library jar " + libraryJar.getAbsolutePath + ")")
83+
new ScalaInstance(VersionPrefix, loader, libraryJar, compilerJar, extraJars.toArray, None)
84+
}
85+
}
86+
}

build.sbt

Lines changed: 4 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -58,159 +58,20 @@ lazy val adapter = (
5858
dependsOnRemote(zincIf211:_*)
5959
settings(sourceGenerators in Compile += task {
6060
val dir = (sourceManaged in Compile).value
61-
val fileName = "Adapter.scala"
61+
val fileName = "Default.scala"
6262
val file = dir / fileName
6363
val sv = scalaVersion.value
6464
val v = sbtVersion.value
6565
if(!dir.isDirectory) dir.mkdirs()
6666
IO.write(file, (
67-
if (v.startsWith("1.0")) """
68-
package sbt.dbuild.hack {
69-
object DbuildHack {
70-
val Load = sbt.internal.Load
71-
val applyCross: (String, Option[String => String]) => String =
72-
sbt.librarymanagement.CrossVersion.applyCross
73-
val defaultID: (java.io.File,String) => String =
74-
sbt.internal.BuildDef.defaultID
75-
}
76-
}
77-
package com.typesafe.dbuild.adapter {
78-
import java.io.File
79-
80-
object LoggingInterface {
81-
val Level = sbt.util.Level
82-
type Logger = sbt.util.Logger
83-
type LogEvent = sbt.util.LogEvent
84-
val ControlEvent = sbt.util.ControlEvent
85-
val StackTrace = sbt.internal.util.StackTrace
86-
type BasicLogger = sbt.internal.util.BasicLogger
87-
}
88-
89-
trait StreamLoggerAdapter
90-
91-
object Adapter {
92-
val IO = sbt.io.IO
93-
val Path = sbt.io.Path
94-
type RichFile = sbt.io.RichFile
95-
type FileFilter = sbt.io.FileFilter
96-
def toFF = sbt.io.FileFilter.globFilter _
97-
val DirectoryFilter = sbt.io.DirectoryFilter
98-
type ExactFilter = sbt.io.ExactFilter
99-
type NameFilter = sbt.io.NameFilter
100-
type FileRepository = sbt.librarymanagement.FileRepository
101-
type Logger = sbt.util.Logger
102-
def allPaths(f:File) = sbt.io.PathFinder(f).allPaths
103-
val syntaxio = sbt.io.syntax
104-
val syntax = sbt.syntax
105-
type ModuleID = sbt.librarymanagement.ModuleID
106-
type Artifact = sbt.librarymanagement.Artifact
107-
type ProjectResolver = sbt.internal.librarymanagement.ProjectResolver
108-
type ScalaInstance = sbt.internal.inc.ScalaInstance
109-
val ScalaInstance = sbt.internal.inc.ScalaInstance
110-
val Load = sbt.dbuild.hack.DbuildHack.Load
111-
val applyCross = sbt.dbuild.hack.DbuildHack.applyCross
112-
def defaultID(base: File, prefix: String = "default") =
113-
sbt.dbuild.hack.DbuildHack.defaultID(base, prefix)
114-
115-
// these bits are inappropriately copied from zinc v1.0.0-X1, where they
116-
// are private now, and exactly from:
117-
// internal/zinc-classpath/src/main/scala/sbt/internal/inc/ScalaInstance.scala
118-
private val VersionPrefix = "version "
119-
private def fastActualVersion(scalaLoader: ClassLoader): String =
120-
{
121-
val stream = scalaLoader.getResourceAsStream("compiler.properties")
122-
try {
123-
val props = new java.util.Properties
124-
props.load(stream)
125-
props.getProperty("version.number")
126-
} finally stream.close()
127-
}
128-
import java.net.{ URL, URLClassLoader }
129-
private def scalaLoader(launcher: xsbti.Launcher): Seq[File] => ClassLoader = jars =>
130-
new URLClassLoader(jars.map(_.toURI.toURL).toArray[URL], launcher.topLoader)
131-
private def actualVersion(scalaLoader: ClassLoader)(label: String) =
132-
try fastActualVersion(scalaLoader)
133-
catch { case e: Exception => slowActualVersion(scalaLoader)(label) }
134-
private def slowActualVersion(scalaLoader: ClassLoader)(label: String) =
135-
{
136-
val v = try { Class.forName("scala.tools.nsc.Properties", true, scalaLoader).getMethod("versionString").invoke(null).toString }
137-
catch { case cause: Exception => throw new sbt.internal.inc.InvalidScalaInstance("Scala instance doesn't exist or is invalid: " + label, cause) }
138-
if (v.startsWith(VersionPrefix)) v.substring(VersionPrefix.length) else v
139-
}
140-
//
141-
// The code below was deprecated and has been removed from ScalaInstance in zinc 1.0.x,
142-
// however it may work for us.
143-
//
144-
// TODO: use one of the currently supported variants of ScalaInstance.apply()
145-
//
146-
def scalaInstance(libraryJar: File, compilerJar: File, launcher: xsbti.Launcher, extraJars: File*): ScalaInstance = {
147-
val classLoader = scalaLoader(launcher)
148-
val loader = classLoader(libraryJar :: compilerJar :: extraJars.toList)
149-
val version = actualVersion(loader)(" (library jar " + libraryJar.getAbsolutePath + ")")
150-
new ScalaInstance(VersionPrefix, loader, libraryJar, compilerJar, extraJars.toArray, None)
151-
}
152-
}
153-
""" else """
154-
package sbt.dbuild.hack {
155-
object DbuildHack {
156-
val Load = sbt.Load
157-
}
158-
}
159-
package com.typesafe.dbuild.adapter {
160-
import java.io.File
161-
162-
object LoggingInterface {
163-
val Level = sbt.Level
164-
type Logger = sbt.Logger
165-
type LogEvent = sbt.LogEvent
166-
val ControlEvent = sbt.ControlEvent
167-
val StackTrace = sbt.StackTrace
168-
type BasicLogger = sbt.BasicLogger
169-
}
170-
171-
import LoggingInterface.Level._
172-
trait StreamLoggerAdapter {
173-
def log(level: Value, message: => String): Unit
174-
def log(label: String, message: String): Unit
175-
def err(s: => String): Unit = log(Error, s)
176-
def out(s: => String): Unit = log(Info.toString, s)
177-
}
178-
179-
object Adapter {
180-
val IO = sbt.IO
181-
val Path = sbt.Path
182-
type RichFile = sbt.RichFile
183-
type FileFilter = sbt.FileFilter
184-
def toFF = sbt.FileFilter.globFilter _
185-
val DirectoryFilter = sbt.DirectoryFilter
186-
type ExactFilter = sbt.ExactFilter
187-
type NameFilter = sbt.NameFilter
188-
type FileRepository = sbt.FileRepository
189-
type Logger = sbt.Logger
190-
import Path._
191-
def allPaths(f:File) = sbt.PathFinder(f).***
192-
val syntax = new {}
193-
val syntaxio = syntax
194-
type ModuleID = sbt.ModuleID
195-
type Artifact = sbt.Artifact
196-
type ProjectResolver = sbt.ProjectResolver
197-
type ScalaInstance = sbt.ScalaInstance
198-
val ScalaInstance = sbt.ScalaInstance
199-
val Load = sbt.dbuild.hack.DbuildHack.Load
200-
val applyCross: (String, Option[String => String]) => String =
201-
sbt.CrossVersion.applyCross
202-
def defaultID(base: File, prefix: String = "default") =
203-
sbt.Build.defaultID(base, prefix)
204-
def scalaInstance(libraryJar: File, compilerJar: File, launcher: xsbti.Launcher, extraJars: File*): ScalaInstance =
205-
ScalaInstance(libraryJar, compilerJar, launcher, extraJars:_*)
206-
}
207-
""")+("""
67+
"""
68+
package com.typesafe.dbuild.adapter
20869
object Defaults {
20970
val version = "%s"
21071
val org = "%s"
21172
val hash = "%s"
21273
}
213-
}""" format (version.value, organization.value, scala.sys.process.Process("git log --pretty=format:%H -n 1").lines.head))
74+
""" format (version.value, organization.value, scala.sys.process.Process("git log --pretty=format:%H -n 1").lines.head))
21475

21576
)
21677
Seq(file)

project/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sbt.version=1.0.0-M4
2-
#sbt.version=0.13.8
1+
#sbt.version=1.0.0-M4
2+
sbt.version=0.13.8

0 commit comments

Comments
 (0)