Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmtc install on windows #285

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmta/src/main/resources/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"name":"[Lcaseapp.core.util.fansi.Category;"
},
{
"name":"[Ljava.io.File;"
},
{
"name":"[Ljava.lang.String;"
},
Expand Down Expand Up @@ -89,5 +92,9 @@
{
"name":"sun.security.provider.SHA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA2$SHA256",
"methods":[{"name":"<init>","parameterTypes":[] }]
}
]
4 changes: 2 additions & 2 deletions cmta/src/main/resources/resource-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"includes":[
{
"pattern":"\\Qnative/x86_64/libswoval-files0.dylib\\E"
},
},
{
"pattern":"\\Qreference.conf\\E"
}
]},
"bundles":[]
}
}
19 changes: 19 additions & 0 deletions cmtc/src/main/resources/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"name":"[Ljava.lang.String;"
},
{
"name":"[Ljava.nio.file.attribute.FileAttribute;"
},
{
"name":"[Lsun.security.pkcs.SignerInfo;"
},
Expand Down Expand Up @@ -115,6 +118,18 @@
"fields":[{"name":"thisX500Name"}],
"methods":[{"name":"<init>","parameterTypes":["sun.security.x509.X500Name"] }]
},
{
"name":"requests.Requester$",
"fields":[{"name":"0bitmap$1"}]
},
{
"name":"requests.Util$",
"fields":[{"name":"0bitmap$1"}]
},
{
"name":"requests.package$",
"fields":[{"name":"0bitmap$1"}]
},
{
"name":"sbt.internal.io.Retry$",
"fields":[{"name":"limit$lzy1"}]
Expand Down Expand Up @@ -225,6 +240,10 @@
"name":"sun.security.ssl.SSLContextImpl$DefaultSSLContext",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.SSLContextImpl$TLSContext",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand Down
41 changes: 17 additions & 24 deletions cmtc/src/main/scala/com/lunatech/cmt/client/command/Install.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import com.lunatech.cmt.Releasables.{*, given}

import sys.process.*
import scala.util.{Failure, Success, Try}
import java.io.File
import java.net.URL
import scala.util.Using

object Install:
Expand Down Expand Up @@ -124,27 +122,25 @@ object Install:
Right(())
}

private def getProjectTags(gitPrefix: String, githubProject: GithubProject): Try[Seq[String]] =
val cwd = file(".").getCanonicalFile
val uri = s"${gitPrefix}${githubProject.organisation}/${githubProject.project}.git"
val cmd = Seq("git", "-c", "versionsort.suffix=-", "ls-remote", "--tags", "--refs", "--sort", "v:refname", uri)
Try(Process(cmd, cwd).!!(ignoreProcessStdOutStdErr).split("\n").to(Seq).map(extractTag))

private def installFromGithubProject(
githubProject: GithubProject,
configuration: Configuration,
forceDelete: Boolean): Either[CmtError, String] = {
for {
_ <- checkPreExistingTargetFolder(githubProject.project, configuration, forceDelete)
installCompletionMessage <- {
val cwd = file(".").getCanonicalFile
val maybeTags = Try(
Process(
Seq(
"git",
"-c",
"versionsort.suffix=-",
"ls-remote",
"--tags",
"--refs",
"--sort",
"v:refname",
s"[email protected]:${githubProject.organisation}/${githubProject.project}.git"),
cwd).!!(ignoreProcessStdOutStdErr).split("\n").to(Seq).map(extractTag))
val maybeTags =
for {
tags <- getProjectTags("[email protected]:", githubProject).recoverWith(g_ =>
getProjectTags("https://github.com/", githubProject))
trimmedTags = tags.map(_.trim())
} yield trimmedTags
val tags: Seq[String] = maybeTags match {
case Success(s) => s
case Failure(_) => Seq.empty[String]
Expand Down Expand Up @@ -194,7 +190,8 @@ object Install:
private def getStudentAssetUrl(githubProject: GithubProject, tag: String): Either[CmtError, String] = {
val organisation = githubProject.organisation
val project = githubProject.project
Right(s"https://github.com/$organisation/$project/releases/download/$tag/$project-student.zip")
val url = s"https://github.com/${organisation}/${project}/releases/download/${tag}/${project}-student.zip"
Right(url)
}

private def downloadStudentAsset(
Expand All @@ -208,13 +205,9 @@ object Install:
}

private def downloadFile(fileUri: String, destination: ZipFile): Either[CmtError, Unit] =
Try((new URL(fileUri) #> new File(destination.value.getAbsolutePath)).!) match {
case Success(0) => Right(())
case Success(exitCode) =>
s"""Failed to download asset: ${fileUri}
|
|Command exit code = $exitCode
|""".stripMargin.toExecuteCommandErrorMessage.asLeft
val destinationPath = os.Path(Helpers.adaptToOSSeparatorChar(destination.value.getCanonicalPath()))
Try(os.write.over(destinationPath, requests.get.stream(fileUri), createFolders = true)) match {
case Success(()) => Right(())
case Failure(e) =>
s"""Failed to download asset: ${fileUri}
|
Expand Down
56 changes: 33 additions & 23 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@ import sbt._

object Version {
lazy val scalaVersion = "3.3.0"
lazy val scalaTest = "3.2.16"
lazy val scalaCheck = "3.2.14.0"
lazy val sbtio = "1.9.1"
lazy val typesafeConfig = "1.4.2"
lazy val caseapp = "2.1.0-M25"
lazy val cats = "2.10.0"
lazy val devDirs = "26"
lazy val github4s = "0.32.0"
lazy val http4s = "0.23.15"
lazy val circe = "0.14.5"
lazy val circeConfig = "0.8.0"
lazy val scalaTestVersion = "3.2.16"
lazy val scalaCheckVersion = "3.2.14.0"
lazy val sbtioVersion = "1.9.1"
lazy val typesafeConfigVersion = "1.4.2"
lazy val caseappVersion = "2.1.0-M25"
lazy val catsVersion = "2.10.0"
lazy val devDirsVersion = "26"
lazy val github4sVersion = "0.32.0"
lazy val http4sVersion = "0.23.15"
lazy val circeVersion = "0.14.5"
// lazy val circeConfig = "0.8.0"
lazy val LiHaoyiOsLibVersion = "0.9.1"
lazy val LiHaoyiRequestLibVersion = "0.8.0"
lazy val commonsCodecVersion = "1.16.0"

}

object Library {
lazy val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest % Test
lazy val scalaCheck = "org.scalatestplus" %% "scalacheck-1-16" % Version.scalaCheck % Test
lazy val sbtio = "org.scala-sbt" %% "io" % Version.sbtio
lazy val typesafeConfig = "com.typesafe" % "config" % Version.typesafeConfig
lazy val commonsCodec = "commons-codec" % "commons-codec" % "1.16.0"
lazy val caseapp = "com.github.alexarchambault" %% "case-app" % Version.caseapp
lazy val cats = "org.typelevel" %% "cats-core" % Version.cats
lazy val devDirs = ("dev.dirs" % "directories" % Version.devDirs).withJavadoc()

import Version._

lazy val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion % Test
lazy val scalaCheck = "org.scalatestplus" %% "scalacheck-1-16" % scalaCheckVersion % Test
lazy val sbtio = "org.scala-sbt" %% "io" % sbtioVersion
lazy val typesafeConfig = "com.typesafe" % "config" % typesafeConfigVersion
lazy val commonsCodec = "commons-codec" % "commons-codec" % commonsCodecVersion
lazy val caseapp = "com.github.alexarchambault" %% "case-app" % caseappVersion
lazy val cats = "org.typelevel" %% "cats-core" % catsVersion
lazy val devDirs = ("dev.dirs" % "directories" % devDirsVersion).withJavadoc()
lazy val requestLib = "com.lihaoyi" %% "requests" % LiHaoyiRequestLibVersion
lazy val osLib = "com.lihaoyi" %% "os-lib" % LiHaoyiOsLibVersion

lazy val http4s = Seq(
"org.http4s" %% "http4s-dsl",
"org.http4s" %% "http4s-blaze-server",
"org.http4s" %% "http4s-blaze-client",
"org.http4s" %% "http4s-circe").map(_ % Version.http4s)
"org.http4s" %% "http4s-circe").map(_ % http4sVersion)

lazy val circe = "io.circe" %% "circe-generic" % Version.circe
lazy val github4s = "com.47deg" %% "github4s" % Version.github4s
lazy val circe = "io.circe" %% "circe-generic" % circeVersion
lazy val github4s = "com.47deg" %% "github4s" % github4sVersion
}

object Dependencies {
Expand All @@ -52,6 +61,7 @@ object Dependencies {
github4s)).map(_.withSources())
lazy val cmtDependencies =
List(sbtio, typesafeConfig, scalaTest, scalaCheck, commonsCodec, caseapp, cats).map(_.withSources())
lazy val cmtcDependencies = (http4s ++ List(devDirs, circe, github4s, scalaTest, scalaCheck)).map(_.withSources())
lazy val cmtcDependencies =
(http4s ++ List(devDirs, circe, github4s, scalaTest, scalaCheck, osLib, requestLib)).map(_.withSources())
lazy val functionalTestDependencies = List(scalaTest, scalaCheck).map(_.withSources())
}