From 5c9561eac8d3bc3eca28562d049cf0dd90d7d9ff Mon Sep 17 00:00:00 2001 From: Eric Loots Date: Wed, 23 Aug 2023 17:43:15 +0200 Subject: [PATCH 1/2] Fix 'cmtc install' on windows - Introduce Li Haoyi's 'requests' and 'os' libraries - Clean-up build dependencies file - Swap file download via scala process API to `requests/os` API - Add trimming of output of `git ls-remote` command --- .../lunatech/cmt/client/command/Install.scala | 41 ++++++-------- project/Dependencies.scala | 56 +++++++++++-------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/cmtc/src/main/scala/com/lunatech/cmt/client/command/Install.scala b/cmtc/src/main/scala/com/lunatech/cmt/client/command/Install.scala index 4d9f9f47..fb4a1ee3 100644 --- a/cmtc/src/main/scala/com/lunatech/cmt/client/command/Install.scala +++ b/cmtc/src/main/scala/com/lunatech/cmt/client/command/Install.scala @@ -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: @@ -124,6 +122,12 @@ 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, @@ -131,20 +135,12 @@ object Install: 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"git@github.com:${githubProject.organisation}/${githubProject.project}.git"), - cwd).!!(ignoreProcessStdOutStdErr).split("\n").to(Seq).map(extractTag)) + val maybeTags = + for { + tags <- getProjectTags("git@github.com:", 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] @@ -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( @@ -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} | diff --git a/project/Dependencies.scala b/project/Dependencies.scala index bc2bc35a..44030f67 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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 { @@ -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()) } From d3bfcc4e57afebb5c1024afe4e0feca32a3dc04e Mon Sep 17 00:00:00 2001 From: Eric Loots Date: Wed, 23 Aug 2023 17:56:49 +0200 Subject: [PATCH 2/2] Update native-image config files --- cmta/src/main/resources/reflect-config.json | 7 +++++++ cmta/src/main/resources/resource-config.json | 4 ++-- cmtc/src/main/resources/reflect-config.json | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cmta/src/main/resources/reflect-config.json b/cmta/src/main/resources/reflect-config.json index 924b2f89..3268dfa7 100644 --- a/cmta/src/main/resources/reflect-config.json +++ b/cmta/src/main/resources/reflect-config.json @@ -5,6 +5,9 @@ { "name":"[Lcaseapp.core.util.fansi.Category;" }, +{ + "name":"[Ljava.io.File;" +}, { "name":"[Ljava.lang.String;" }, @@ -89,5 +92,9 @@ { "name":"sun.security.provider.SHA", "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"sun.security.provider.SHA2$SHA256", + "methods":[{"name":"","parameterTypes":[] }] } ] diff --git a/cmta/src/main/resources/resource-config.json b/cmta/src/main/resources/resource-config.json index a5f8f572..3cdbaaa5 100644 --- a/cmta/src/main/resources/resource-config.json +++ b/cmta/src/main/resources/resource-config.json @@ -3,10 +3,10 @@ "includes":[ { "pattern":"\\Qnative/x86_64/libswoval-files0.dylib\\E" - }, + }, { "pattern":"\\Qreference.conf\\E" } ]}, "bundles":[] -} \ No newline at end of file +} diff --git a/cmtc/src/main/resources/reflect-config.json b/cmtc/src/main/resources/reflect-config.json index 6cc4fdad..7eeea2b8 100644 --- a/cmtc/src/main/resources/reflect-config.json +++ b/cmtc/src/main/resources/reflect-config.json @@ -5,6 +5,9 @@ { "name":"[Ljava.lang.String;" }, +{ + "name":"[Ljava.nio.file.attribute.FileAttribute;" +}, { "name":"[Lsun.security.pkcs.SignerInfo;" }, @@ -115,6 +118,18 @@ "fields":[{"name":"thisX500Name"}], "methods":[{"name":"","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"}] @@ -225,6 +240,10 @@ "name":"sun.security.ssl.SSLContextImpl$DefaultSSLContext", "methods":[{"name":"","parameterTypes":[] }] }, +{ + "name":"sun.security.ssl.SSLContextImpl$TLSContext", + "methods":[{"name":"","parameterTypes":[] }] +}, { "name":"sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory", "methods":[{"name":"","parameterTypes":[] }]