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

upgrade to Sjsonnet 0.4.9 (was 0.4.0) #3

Merged
merged 1 commit into from
Jan 26, 2024
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
6 changes: 3 additions & 3 deletions examples/default-task/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ repositories {
}

dependencies {
implementation("org.scala-lang:scala-library:2.13.10")
testImplementation("org.scalatest:scalatest_2.13:3.2.9")
testImplementation(platform("org.junit:junit-bom:5.7.2"))
implementation("org.scala-lang:scala-library:2.13.12")
testImplementation("org.scalatest:scalatest_2.13:3.2.17")
testImplementation(platform("org.junit:junit-bom:5.10.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

Expand Down
12 changes: 6 additions & 6 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
scala
`java-gradle-plugin`
`maven-publish`
id("com.gradle.plugin-publish") version "1.2.0"
id("com.gradle.plugin-publish") version "1.2.1"
}

group = "io.github.chklauser.sjsonnet"
Expand All @@ -13,16 +13,16 @@ repositories {
}

dependencies {
implementation("org.scala-lang:scala-library:2.13.10")
implementation("com.databricks:sjsonnet_2.13:0.4.0")
testImplementation("org.scalatest:scalatest_2.13:3.2.9")
testImplementation(platform("org.junit:junit-bom:5.7.2"))
implementation("org.scala-lang:scala-library:2.13.12")
implementation("com.databricks:sjsonnet_2.13:0.4.9")
testImplementation("org.scalatest:scalatest_2.13:3.2.17")
testImplementation(platform("org.junit:junit-bom:5.10.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
constraints {
implementation("org.apache.logging.log4j:log4j-core") {
version {
strictly("[2.17, 3[")
prefer("2.17.1")
prefer("2.22.1")
}
because("CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities")
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pluginManagement {
}

plugins {
id("org.ajoberstar.reckon.settings") version "0.18.0"
id("org.ajoberstar.reckon.settings") version "0.18.2"
}

extensions.configure<org.ajoberstar.reckon.gradle.ReckonExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import sjsonnet.{Expr, FileScope, Path, SjsonnetMain}
import java.util.concurrent.atomic.AtomicBoolean
import scala.collection.mutable
import internal.implicits._
import sjsonnet.DefaultParseCache
import sjsonnet.ParseCache

class SjsonnetPlugin extends Plugin[Project] {
private[this] var sourceSetRegistered = new AtomicBoolean(false)
Expand Down Expand Up @@ -84,6 +86,6 @@ class SjsonnetPlugin extends Plugin[Project] {
}

object SjsonnetPlugin {
val parseCache: ThreadLocal[mutable.HashMap[(Path, String), Parsed[(Expr, FileScope)]]] =
ThreadLocal.withInitial(() => SjsonnetMain.createParseCache())
val parseCache: ThreadLocal[ParseCache] =
ThreadLocal.withInitial(() => new DefaultParseCache())
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.gradle.api.provider.{MapProperty, Property}
import org.gradle.api.tasks.{CacheableTask, Input, InputFiles, OutputDirectory, PathSensitive, PathSensitivity, SkipWhenEmpty, TaskAction}
import org.gradle.api.{DefaultTask, GradleException}
import os.Path
import sjsonnet.Importer
import sjsonnet.ResolvedFile
import sjsonnet.{OsPath, SjsonnetMain}

import java.io.{BufferedOutputStream, File, FileOutputStream, OutputStreamWriter, StringWriter}
Expand Down Expand Up @@ -92,9 +94,9 @@ class SjsonnetTask extends DefaultTask() {
case value => throw new GradleException(s"Cannot translate $path=$value into a JSON value to pass to Jsonnet.")
}}

private def externalMap(source: java.util.Map[String, Any]): Map[String, ujson.Value] = {
private def externalMap(source: java.util.Map[String, Any]): Map[String, String] = {
import scala.jdk.CollectionConverters._
source.asScala.toMap.map(entry => (entry._1, javaToJson("", entry._2)))
source.asScala.toMap.map(entry => (entry._1, ujson.write(javaToJson("", entry._2))))
}

@TaskAction
Expand Down Expand Up @@ -155,23 +157,27 @@ class SjsonnetTask extends DefaultTask() {
val workingDirectory = sjsonnet.OsPath(os.Path(sourceFile, os.Path(sourceFile)))

val allowedImports = if(knownImports.nonEmpty) { Some(knownImports) } else { None }
val resolver = SjsonnetMain.resolveImport(searchRoot, allowedImports) _
val resolverWithLogging = (p:sjsonnet.Path,s: String) => {
val result = resolver(p,s)
if(getLogger.isDebugEnabled) {
getLogger.debug("jsonnet import working_directory={}, import={} ==> {}", Array(
p, s, result.map(_._1)
): _*)
val importer = SjsonnetMain.resolveImport(searchRoot, allowedImports)
val importerWithLogging = new Importer {
override def resolve(docBase: sjsonnet.Path, importName: String): Option[sjsonnet.Path] = {
val result = importer.resolve(docBase, importName)
if(getLogger.isDebugEnabled) {
getLogger.debug("jsonnet import working_directory={}, import={} ==> {}", Array(
docBase, importName, result
): _*)
}
result
}
result

override def read(path: sjsonnet.Path): Option[ResolvedFile] = importer.read(path)
}

new sjsonnet.Interpreter(
SjsonnetPlugin.parseCache.get(),
externalMap(externalVariables.get()),
externalMap(topLevelArguments.get()),
workingDirectory,
resolverWithLogging)
importerWithLogging,
SjsonnetPlugin.parseCache.get())
}

private def bufferedUtf8OutputStreamWriter(destinationFile: File) = {
Expand Down
Loading