add offline installtion

To utilize local preloaded repo, this will create lib/ directory with all artifacts required for sbt. This can be rsynced to the preloaded repo.
This commit is contained in:
Eugene Yokota 2017-03-06 22:34:59 -05:00
parent 479a28ac40
commit cea5d178d8
5 changed files with 97 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import scala.util.control.Exception.catching
import _root_.bintray.InternalBintrayKeys._
import _root_.bintray.{BintrayRepo, Bintray}
import NativePackagerHelper._
lazy val sbtVersionToRelease = sys.props.getOrElse("sbt.build.version", sys.env.getOrElse("sbt.build.version", {
sys.error("-Dsbt.build.version must be set")
@ -114,6 +115,19 @@ val root = (project in file(".")).
val rtExportJar = (packageBin in Compile in java9rtexport).value
Seq(launchJar -> "bin/sbt-launch.jar", rtExportJar -> "bin/java9-rt-export.jar")
},
mappings in Universal ++= {
val _ = (exportRepo in dist).value
directory((target in dist).value / "lib")
},
stage in Universal := {
val old = (stage in Universal).value
val sd = (stagingDirectory in Universal).value
val x = IO.read(sd / "bin" / "sbt-launch-lib.bash")
IO.write(sd / "bin" / "sbt-launch-lib.bash", x.replaceAllLiterally("declare init_sbt_version=", s"declare init_sbt_version=$sbtVersionToRelease"))
val y = IO.read(sd / "bin" / "sbt.bat")
IO.write(sd / "bin" / "sbt.bat", y.replaceAllLiterally("set INIT_SBT_VERSION=", s"set INIT_SBT_VERSION=$sbtVersionToRelease"))
old
},
// Misccelaneous publishing stuff...
projectID in Debian := moduleID.value,
@ -189,3 +203,49 @@ def publishToSettings =
def bintrayRelease(repo: BintrayRepo, pkg: String, version: String, log: Logger): Unit =
repo.release(pkg, version, log)
lazy val scala210 = "2.10.6"
lazy val scala212 = "2.12.1"
lazy val scala210Jline = "org.scala-lang" % "jline" % scala210
lazy val jansi = "org.fusesource.jansi" % "jansi" % "1.4"
lazy val scala212Jline = "jline" % "jline" % "2.14.1"
lazy val scala212Xml = "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6"
lazy val scala212Compiler = "org.scala-lang" % "scala-compiler" % scala212
lazy val sbtActual = "org.scala-sbt" % "sbt" % sbtVersionToRelease
def downloadUrl(uri: URI, out: File): Unit =
{
import dispatch.classic._
if(!out.exists) {
IO.touch(out)
val writer = new java.io.BufferedOutputStream(new java.io.FileOutputStream(out))
try Http(url(uri.toString) >>> writer)
finally writer.close()
}
}
lazy val dist = (project in file("dist"))
.enablePlugins(ExportRepoPlugin)
.settings(
name := "dist",
scalaVersion := scala210,
libraryDependencies ++= Seq(sbtActual, scala210Jline, jansi, scala212Compiler, scala212Jline, scala212Xml),
exportRepo := {
val old = exportRepo.value
sbtVersionToRelease match {
case v if v.startsWith("0.13.") =>
val outbase = exportRepoDirectory.value / "org.scala-sbt" / "compiler-interface" / v
val uribase = s"https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-interface/$v/"
downloadUrl(uri(uribase + "ivys/ivy.xml"), outbase / "ivys" / "ivy.xml")
downloadUrl(uri(uribase + "jars/compiler-interface.jar"), outbase / "jars" / "compiler-interface.jar")
downloadUrl(uri(uribase + "srcs/compiler-interface-sources.jar"), outbase / "srcs" / "compiler-interface-sources.jar")
case _ =>
}
old
},
exportRepoDirectory := target.value / "lib" / "local-preloaded",
conflictWarning := ConflictWarning.disable,
publish := (),
publishLocal := ()
)

View File

@ -1,2 +0,0 @@
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")

View File

@ -1,2 +1,4 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.4")
libraryDependencies += "net.databinder" %% "dispatch-http" % "0.8.10"
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
addSbtPlugin("com.eed3si9n" % "sbt-export-repo" % "0.1.0")

View File

@ -14,6 +14,7 @@ declare java_cmd=java
declare java_version
declare -r sbt_bin_dir="$(dirname "$(realpath "$0")")"
declare -r sbt_home="$(dirname "$sbt_bin_dir")"
declare init_sbt_version=
echoerr () {
echo 1>&2 "$@"
@ -156,6 +157,14 @@ process_args () {
vlog "[process_args] java_version = '$java_version'"
}
syncPreloaded() {
[[ -f "$HOME/.sbt/preloaded/org.scala-sbt/sbt/$init_sbt_version/jars/sbt.jar" ]] || {
command -v rsync >/dev/null 2>&1 && {
rsync -a --ignore-existing "$sbt_home/lib/local-preloaded/" "$HOME/.sbt/preloaded"
}
}
}
# Detect that we have java installed.
checkJava() {
local required_version="$1"
@ -200,6 +209,8 @@ copyRt() {
}
run() {
syncPreloaded
# no jar? download it.
[[ -f "$sbt_jar" ]] || acquire_sbt_jar "$sbt_version" || {
# still no jar? uh-oh.

View File

@ -81,6 +81,8 @@ call :checkjava
call :copyrt
call :sync_preloaded
call :run %SBT_ARGS%
if ERRORLEVEL 1 goto error
@ -91,15 +93,6 @@ goto end
"%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %*
goto :eof
:error
@endlocal
exit /B 1
:end
@endlocal
exit /B 0
:process
rem parses 1.7, 1.8, 9, etc out of java version "1.8.0_91"
"%_JAVACMD%" -Xmx512M -version 2> "%TEMP%.\out.txt"
@ -148,3 +141,25 @@ if /I "%JAVA_VERSION%" GEQ "9" (
set _JAVA_OPTS=!_JAVA_OPTS! -Dscala.ext.dirs="%java9_ext%"
)
exit /B 0
:sync_preloaded
set PRELOAD_SBT_JAR="%UserProfile%\.sbt\preloaded\org.scala-sbt\sbt\%INIT_SBT_VERSION%\jars\sbt.jar"
if /I "%JAVA_VERSION%" GEQ "8" (
where robocopy >nul 2>nul
if %ERRORLEVEL% equ 0 (
echo %PRELOAD_SBT_JAR%
if not exist %PRELOAD_SBT_JAR% (
echo 'about to robocopy'
robocopy "%SBT_HOME%\..\lib\local-preloaded\" "%UserProfile%\.sbt\preloaded"
)
)
)
exit /B 0
:error
@endlocal
exit /B 1
:end
@endlocal
exit /B 0