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

Update scalafmt-core to 3.7.13 #449

Closed
Closed
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.7.13
5b398b397a4cb9b419ec6100193cd79354c8f665
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.11"
version = "3.7.13"
runner.dialect = scala3Future
project.git = true
project.excludePaths = ["glob:**.sbt", "glob:**sbtgen.sc"]
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ trait Codecs {

implicit def decProjectNamingRule: Decoder[ProjectNamingRule] = deriveDecoder


//
implicit def decScalaProjectLayout: Decoder[ScalaProjectLayout] = semiauto.deriveEnumerationDecoder

Expand Down Expand Up @@ -66,7 +65,6 @@ trait Codecs {

implicit def encProjectNamingRule: Encoder[ProjectNamingRule] = deriveEncoder


//
implicit def encScalaProjectLayout: Encoder[ScalaProjectLayout] = semiauto.deriveEnumerationEncoder

Expand Down Expand Up @@ -106,6 +104,4 @@ trait Codecs {
implicit def encVersionOverlay: Encoder[VersionOverlay] = deriveEncoder
}

object Codecs extends Codecs {

}
object Codecs extends Codecs {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import scala.jdk.CollectionConverters.*
import scala.util.Try

object CommandlineIDLCompiler {
private val log: CompilerLog = CompilerLog.Default
private val log: CompilerLog = CompilerLog.Default
private val shutdown: Shutdown = ShutdownImpl

def main(args: Array[String]): Unit = {
val mf = IzArtifactMaterializer.currentArtifact
val izumiVersion = mf.version.toString
val mf = IzArtifactMaterializer.currentArtifact
val izumiVersion = mf.version.toString
val izumiInfoVersion = mf.justVersion

log.log(s"Izumi IDL Compiler $izumiInfoVersion")
Expand All @@ -37,7 +37,7 @@ object CommandlineIDLCompiler {
val results = Seq(
initDir(conf),
runCompilations(izumiVersion, conf),
runPublish(conf)
runPublish(conf),
)

if (!results.contains(true)) {
Expand All @@ -47,28 +47,32 @@ object CommandlineIDLCompiler {

private def runPublish(conf: IDLCArgs): Boolean = {
if (conf.publish && conf.languages.nonEmpty) {
conf.languages.foreach { lang =>
val manifest = toOptions(conf, Map.empty)(lang).manifest
publishLangArtifacts(conf, lang, manifest) match {
case Left(err) => throw err
case _ => ()
}
conf.languages.foreach {
lang =>
val manifest = toOptions(conf, Map.empty)(lang).manifest
publishLangArtifacts(conf, lang, manifest) match {
case Left(err) => throw err
case _ => ()
}
}
true
} else
false
}

def publishLangArtifacts(conf: IDLCArgs, langOpts: LanguageOpts, manifest: BuildManifest): Either[Throwable, Unit] = for {
credsFile <- Either.cond(langOpts.credentials.isDefined, langOpts.credentials.get,
new IllegalArgumentException(s"Can't publish ${langOpts.id} with empty credentials file. " +
credsFile <- Either.cond(
langOpts.credentials.isDefined,
langOpts.credentials.get,
new IllegalArgumentException(
s"Can't publish ${langOpts.id} with empty credentials file. " +
s"Use `--credentials` command line arg to set it"
)
),
)
lang <- Try(IDLLanguage.parse(langOpts.id)).toEither
creds <- new CredentialsReader(lang, credsFile).read(toJson(langOpts.overrides))
lang <- Try(IDLLanguage.parse(langOpts.id)).toEither
creds <- new CredentialsReader(lang, credsFile).read(toJson(langOpts.overrides))
target <- Try(conf.target.toAbsolutePath.resolve(langOpts.id)).toEither
res <- new ArtifactPublisher(target, lang, creds, manifest).publish()
res <- new ArtifactPublisher(target, lang, creds, manifest).publish()
} yield res

private def initDir(conf: IDLCArgs): Boolean = {
Expand Down Expand Up @@ -110,7 +114,7 @@ object CommandlineIDLCompiler {
log.log(toRun.niceList())
log.log("")

val path = conf.source.toAbsolutePath
val path = conf.source.toAbsolutePath
val target = conf.target.toAbsolutePath
target.toFile.mkdirs()

Expand Down Expand Up @@ -138,7 +142,7 @@ object CommandlineIDLCompiler {
}

private def runCompiler(target: Path, loaded: Timed[UnresolvedDomains], option: UntypedCompilerOptions): Unit = {
val langId = option.language.toString
val langId = option.language.toString
val itarget = option.target.getOrElse(target.resolve(langId))
log.log(s"Preparing typespace for $langId")
val toCompile = Timed {
Expand Down Expand Up @@ -203,12 +207,12 @@ object CommandlineIDLCompiler {
JsonObject.empty.asJson
}

val envJson = toJson(env)
val envJson = toJson(env)
val languageOverridesJson = toJson(lopt.overrides)
val globalOverridesJson = toJson(conf.overrides)
val patch = overlayJson.deepMerge(globalOverridesJson).deepMerge(envJson).deepMerge(languageOverridesJson)
val globalOverridesJson = toJson(conf.overrides)
val patch = overlayJson.deepMerge(globalOverridesJson).deepMerge(envJson).deepMerge(languageOverridesJson)

val reader = new ManifestReader(conf, log, shutdown, patch, lang, lopt.manifest)
val reader = new ManifestReader(conf, log, shutdown, patch, lang, lopt.manifest)
val manifest = reader.read()
manifest
}
Expand All @@ -217,24 +221,25 @@ object CommandlineIDLCompiler {
import io.circe.literal.*

for {
parsed <- parse(IzFiles.readString(path.toFile))
parsed <- parse(IzFiles.readString(path.toFile))
decoded <- parsed.as[VersionOverlay]
} yield {
val defQualifier = decoded.snapshotQualifiers.getOrElse(lang.toString.toLowerCase, "UNSET")
val timestamp = ZonedDateTime.now(ZoneId.of("UTC")).toEpochSecond
val qualifier = if (lang == IDLLanguage.Typescript) s"$defQualifier-$timestamp" else defQualifier
val version = ProjectVersion(decoded.version, decoded.release, qualifier)
val timestamp = ZonedDateTime.now(ZoneId.of("UTC")).toEpochSecond
val qualifier = if (lang == IDLLanguage.Typescript) s"$defQualifier-$timestamp" else defQualifier
val version = ProjectVersion(decoded.version, decoded.release, qualifier)
json"""{"common": {"version": $version}}"""
}
}

private def toJson(env: Map[String, String]) = {
val updatedEnv = env.map {
case (k, v) => io.circe.parser.parse(v) match {
case Right(b) if b.isBoolean => k -> b.asBoolean.get
case Right(s) if s.isString => k -> s.asString.get
case _ => k -> v
}
case (k, v) =>
io.circe.parser.parse(v) match {
case Right(b) if b.isBoolean => k -> b.asBoolean.get
case Right(s) if s.isString => k -> s.asString.get
case _ => k -> v
}
}
valToJson(ConfigFactory.parseMap(updatedEnv.asJava).root().unwrapped())
}
Expand All @@ -244,12 +249,10 @@ object CommandlineIDLCompiler {

(v: @unchecked) match {
case m: java.util.HashMap[?, ?] =>
m.asScala
.map {
case (k, value) =>
k.toString -> valToJson(value.asInstanceOf[AnyRef])
}
.asJson
m.asScala.map {
case (k, value) =>
k.toString -> valToJson(value.asInstanceOf[AnyRef])
}.asJson

case s: String =>
s.asJson
Expand All @@ -259,10 +262,9 @@ object CommandlineIDLCompiler {
}
}


private def getExt(lang: IDLLanguage, filter: List[String]): Seq[TranslatorExtension] = {
val descriptor = TypespaceCompilerBaseFacade.descriptor(lang)
val negative = filter.filter(_.startsWith("-")).map(_.substring(1)).map(ExtensionId).toSet
val negative = filter.filter(_.startsWith("-")).map(_.substring(1)).map(ExtensionId).toSet
descriptor.defaultExtensions.filterNot(e => negative.contains(e.id))
}
}
Expand All @@ -275,12 +277,11 @@ object VersionOverlay {
"0.0.1",
release = false,
Map(
IDLLanguage.Scala -> "SNAPSHOT",
IDLLanguage.Scala -> "SNAPSHOT",
IDLLanguage.Typescript -> "build.0",
IDLLanguage.Go -> "0",
IDLLanguage.CSharp -> "alpha",
)
.map { case (k, v) => k.toString.toLowerCase -> v }
IDLLanguage.Go -> "0",
IDLLanguage.CSharp -> "alpha",
).map { case (k, v) => k.toString.toLowerCase -> v },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ sealed trait Credentials {
def lang: IDLLanguage
}
class LangCredentials(override val lang: IDLLanguage) extends Credentials
case class ScalaCredentials(sbtRealm: String, sbtHost: String, sbtUser: String, sbtPassword: String,
sbtReleasesRepo: String, sbtSnapshotsRepo: String) extends LangCredentials(IDLLanguage.Scala)
case class ScalaCredentials(sbtRealm: String, sbtHost: String, sbtUser: String, sbtPassword: String, sbtReleasesRepo: String, sbtSnapshotsRepo: String)
extends LangCredentials(IDLLanguage.Scala)
case class TypescriptCredentials(npmRepo: String, npmUser: String, npmPassword: String, npmEmail: String) extends LangCredentials(IDLLanguage.Typescript)
case class GoCredentials(gitUser: String, gitEmail: String, gitRepoUrl: String, gitRepoName: String, gitPubKey: String) extends LangCredentials(IDLLanguage.Go)
case class CsharpCredentials(nugetRepo: String, nugetUser: String, nugetPassword: String) extends LangCredentials(IDLLanguage.CSharp)
case class ProtobufCredentials(gitUser: String, gitEmail: String, gitRepoUrl: String, gitRepoName: String, gitPubKey: String) extends LangCredentials(IDLLanguage.Protobuf)
case class ProtobufCredentials(gitUser: String, gitEmail: String, gitRepoUrl: String, gitRepoName: String, gitPubKey: String)
extends LangCredentials(IDLLanguage.Protobuf)

class CredentialsReader(lang: IDLLanguage, file: File) {
def read(overrides: Json): Either[Throwable, Credentials] = lang match {
case IDLLanguage.Scala => read[ScalaCredentials](file, overrides)
case IDLLanguage.Scala => read[ScalaCredentials](file, overrides)
case IDLLanguage.Typescript => read[TypescriptCredentials](file, overrides)
case IDLLanguage.Go => read[GoCredentials](file, overrides)
case IDLLanguage.CSharp => read[CsharpCredentials](file, overrides)
case IDLLanguage.Protobuf => read[ProtobufCredentials](file, overrides)
case IDLLanguage.Go => read[GoCredentials](file, overrides)
case IDLLanguage.CSharp => read[CsharpCredentials](file, overrides)
case IDLLanguage.Protobuf => read[ProtobufCredentials](file, overrides)
}

def read[T <: Credentials](file: File, overrides: Json)(implicit d: io.circe.Decoder[T]): Either[Throwable, Credentials] = for {
json <- parse(IzFiles.readString(file))
json <- parse(IzFiles.readString(file))
creds <- json.deepMerge(overrides).as[T]
} yield creds.asInstanceOf[Credentials]
}
Loading