Skip to content

Commit

Permalink
Format whole project
Browse files Browse the repository at this point in the history
  • Loading branch information
kxbmap committed Oct 18, 2021
1 parent 3e6e32a commit 45a4f15
Show file tree
Hide file tree
Showing 47 changed files with 210 additions and 177 deletions.
13 changes: 7 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ name := "sbt-jooq"
publish / skip := true

ThisBuild / scalacOptions ++= Seq(
"-release", "8",
"-release",
"8",
"-deprecation",
"-unchecked",
"-feature",
Expand All @@ -17,7 +18,7 @@ lazy val core = project
.settings(
name := "sbt-jooq-core",
buildInfoKeys := Seq[BuildInfoKey](
"defaultJooqVersion" -> jooqVersion,
"defaultJooqVersion" -> jooqVersion
),
buildInfoPackage := "sbtjooq",
)
Expand Down Expand Up @@ -53,7 +54,7 @@ lazy val codegenTool = project
crossPaths := false,
autoScalaLibrary := false,
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % logbackVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion
),
Compile / javacOptions ++= Seq("--release", "8"),
)
Expand All @@ -66,7 +67,7 @@ lazy val checker = project
scripted := scripted.dependsOn(core / publishLocal).evaluated,
addSbtPlugin("org.wartremover" % "sbt-wartremover" % sbtWartRemoverVersion),
buildInfoKeys := Seq[BuildInfoKey](
"defaultJooqWartsVersion" -> jooqWartsVersion,
"defaultJooqWartsVersion" -> jooqWartsVersion
),
buildInfoPackage := "sbtjooq.checker",
)
Expand All @@ -84,11 +85,11 @@ lazy val docs = project
"H2_VERSION" -> h2Version,
),
scalacOptions ++= Seq(
"-Wconf:cat=unused-nowarn:s",
"-Wconf:cat=unused-nowarn:s"
),
libraryDependencies += sbtDependency.value,
libraryDependencySchemes ++= Seq(
"org.scala-lang.modules" %% "scala-xml" % "always",
"org.scala-lang.modules" %% "scala-xml" % "always"
),
)

Expand Down
8 changes: 3 additions & 5 deletions checker/src/main/scala/sbtjooq/checker/CheckerLevel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ object CheckerLevel {

}

final class CheckerLevels private(
val sqlDialect: CheckerLevel,
val plainSQL: CheckerLevel) {
final class CheckerLevels private (val sqlDialect: CheckerLevel, val plainSQL: CheckerLevel) {

def withSQLDialect(level: CheckerLevel): CheckerLevels =
new CheckerLevels(level, plainSQL)
Expand All @@ -31,7 +29,7 @@ final class CheckerLevels private(

private def collect(level: CheckerLevel): Seq[Wart] = Seq(
if (sqlDialect == level) Seq(JooqWarts.SQLDialect) else Nil,
if (plainSQL == level) Seq(JooqWarts.PlainSQL) else Nil
if (plainSQL == level) Seq(JooqWarts.PlainSQL) else Nil,
).flatten

override def toString: String = s"CheckerLevels(sqlDialect = $sqlDialect, plainSQL = $plainSQL)"
Expand All @@ -41,7 +39,7 @@ object CheckerLevels {

def default: CheckerLevels = new CheckerLevels(
sqlDialect = CheckerLevel.Error,
plainSQL = CheckerLevel.Error
plainSQL = CheckerLevel.Error,
)

}
14 changes: 8 additions & 6 deletions checker/src/main/scala/sbtjooq/checker/JooqCheckerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object JooqCheckerPlugin extends AutoPlugin {

override def globalSettings: Seq[Setting[_]] = Seq(
jooqCheckerLevels := CheckerLevels.default,
jooqCheckerJooqWartsVersion := BuildInfo.defaultJooqWartsVersion
jooqCheckerJooqWartsVersion := BuildInfo.defaultJooqWartsVersion,
)

override def projectConfigurations: Seq[Configuration] = Seq(JooqChecker)
Expand All @@ -31,17 +31,19 @@ object JooqCheckerPlugin extends AutoPlugin {

private def jooqCheckerDefaultSettings: Seq[Setting[_]] = Seq(
libraryDependencies +=
("com.github.kxbmap" %% "jooq-warts" % jooqCheckerJooqWartsVersion.value % JooqChecker).intransitive(),
("com.github.kxbmap" %% "jooq-warts" % jooqCheckerJooqWartsVersion.value % JooqChecker).intransitive()
) ++
JooqPlugin.jooqDependencies(JooqChecker) ++
inConfig(JooqChecker)(Seq(
managedClasspath := Classpaths.managedJars(JooqChecker, classpathTypes.value, update.value)
))
inConfig(JooqChecker)(
Seq(
managedClasspath := Classpaths.managedJars(JooqChecker, classpathTypes.value, update.value)
)
)

lazy val jooqCheckerSettings: Seq[Setting[_]] = Seq(
wartremoverClasspaths ++= (JooqChecker / managedClasspath).value.files.map(_.toURI.toString),
wartremoverErrors := wartremoverErrors.value.filterNot(JooqWarts.all) ++ jooqCheckerLevels.value.errors,
wartremoverWarnings := wartremoverWarnings.value.filterNot(JooqWarts.all) ++ jooqCheckerLevels.value.warnings
wartremoverWarnings := wartremoverWarnings.value.filterNot(JooqWarts.all) ++ jooqCheckerLevels.value.warnings,
)

}
2 changes: 1 addition & 1 deletion codegen-tool/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</root>
</configuration>
3 changes: 0 additions & 3 deletions codegen/src/main/scala/sbtjooq/codegen/CodegenConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ object CodegenConfig {
Sequence(toSeq ++ other.toSeq)
}


def empty: CodegenConfig = Sequence(Seq.empty)

def fromURI(uri: URI): Single =
Expand All @@ -50,7 +49,6 @@ object CodegenConfig {

def fromURIString(uri: String): Single = fromURI(sbt.uri(uri))


implicit def fileToCodegenConfig(file: File): Single = FromFile(file)

implicit def xmlElemToCodegenConfig(xml: Elem): Single = FromXML(xml)
Expand All @@ -63,7 +61,6 @@ object CodegenConfig {
implicit def nodeBufferToCodegenConfig(buffer: NodeBuffer): Sequence =
Sequence(buffer.map(FromXML))


implicit val appendCodegenConfigToCodegenConfig: Append.Values[CodegenConfig, CodegenConfig] = _ ++ _

implicit def appendSingleToCodegenConfig[A](implicit ev: A => Single): Append.Value[CodegenConfig, A] = _ + _
Expand Down
61 changes: 35 additions & 26 deletions codegen/src/main/scala/sbtjooq/codegen/JooqCodegenPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ object JooqCodegenPlugin extends AutoPlugin {
inConfig(JooqCodegen)(
Defaults.configSettings ++
Seq(
jooqModules := Seq("jooq-codegen"),
jooqModules := Seq("jooq-codegen")
) ++
inTask(run)(Seq(
mainClass := Some(Codegen.mainClass),
fork := Codegen.needsFork(autoJooqLibrary.value, jooqVersion.value, javaHome.value),
javaOptions ++= Codegen.javaOptions(autoJooqLibrary.value, jooqVersion.value, javaHome.value),
))
inTask(run)(
Seq(
mainClass := Some(Codegen.mainClass),
fork := Codegen.needsFork(autoJooqLibrary.value, jooqVersion.value, javaHome.value),
javaOptions ++= Codegen.javaOptions(autoJooqLibrary.value, jooqVersion.value, javaHome.value),
)
)
) ++
JooqPlugin.jooqDependencies(JooqCodegen) ++
Seq(
Expand Down Expand Up @@ -112,7 +114,7 @@ object JooqCodegenPlugin extends AutoPlugin {
(managedSourceDirectories.value :+ jooqSource.value).distinct
},
jooqCodegenVariables ++= Map(
"RESOURCE_DIRECTORY" -> (JooqCodegen / resourceDirectory).value,
"RESOURCE_DIRECTORY" -> (JooqCodegen / resourceDirectory).value
),
jooqCodegenConfigTransformer := ConfigTransformer(
jooqSource.value,
Expand All @@ -126,35 +128,39 @@ object JooqCodegenPlugin extends AutoPlugin {
jooqCodegenGeneratedSources := generatedSourcesTask.value,
)


private def codegenTask: Initialize[Task[Seq[File]]] = Def.task {
if ((jooqCodegen / skip).value)
jooqCodegenGeneratedSources.value
else
Def.taskDyn(Def.sequential(
warnIfConfigIsEmpty,
runCodegen(jooqCodegenTransformedConfigFiles.value),
)).value
Def.taskDyn(
Def.sequential(
warnIfConfigIsEmpty,
runCodegen(jooqCodegenTransformedConfigFiles.value),
)
).value
}

private def codegenIfAbsentTask: Initialize[Task[Seq[File]]] = Def.task {
if ((jooqCodegenIfAbsent / skip).value)
jooqCodegenGeneratedSources.value
else
Def.taskDyn(Def.sequential(
warnIfConfigIsEmpty,
runCodegen(jooqCodegenGeneratedSourcesFinders.value.collect {
case (config, finder) if finder.get().isEmpty => config
}),
)).value
Def.taskDyn(
Def.sequential(
warnIfConfigIsEmpty,
runCodegen(jooqCodegenGeneratedSourcesFinders.value.collect {
case (config, finder) if finder.get().isEmpty => config
}),
)
).value
}

private def runCodegen(configs: Seq[File]): Initialize[Task[Seq[File]]] =
if (configs.isEmpty) jooqCodegenGeneratedSources
else Def.sequential(
(JooqCodegen / run).toTask(configs.mkString(" ", " ", "")),
jooqCodegenGeneratedSources,
)
else
Def.sequential(
(JooqCodegen / run).toTask(configs.mkString(" ", " ", "")),
jooqCodegenGeneratedSources,
)

private lazy val warnIfConfigIsEmpty: Initialize[Task[Unit]] = Def.task {
if (jooqCodegenConfig.value.isEmpty) {
Expand All @@ -164,7 +170,8 @@ object JooqCodegenPlugin extends AutoPlugin {
|To turn off this warning,
|- `set $conf / jooqCodegenConfig := <your configuration>` or
|- `set $conf / jooqCodegen / skip := true`
|""".stripMargin)
|""".stripMargin
)
}
}

Expand Down Expand Up @@ -218,9 +225,11 @@ object JooqCodegenPlugin extends AutoPlugin {

private def generatedSourcesFindersTask: Initialize[Task[Seq[(File, PathFinder)]]] = Def.task {
jooqCodegenGeneratorTargets.value.map {
case (conf, target) => conf -> target.descendantsExcept(
(jooqCodegenGeneratedSources / includeFilter).value,
(jooqCodegenGeneratedSources / excludeFilter).value)
case (conf, target) =>
conf -> target.descendantsExcept(
(jooqCodegenGeneratedSources / includeFilter).value,
(jooqCodegenGeneratedSources / excludeFilter).value,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import sbt._
import sbt.Def.Classpath
import sbt.io.Using

class ClasspathLoader(classpath: Classpath)
extends URLClassLoader(classpath.files.map(_.asURL).toArray, null)
class ClasspathLoader(classpath: Classpath) extends URLClassLoader(classpath.files.map(_.asURL).toArray, null)

object ClasspathLoader {
val using: Using[Classpath, ClasspathLoader] = Using.resource(new ClasspathLoader(_))
Expand Down
16 changes: 10 additions & 6 deletions codegen/src/main/scala/sbtjooq/codegen/internal/Codegen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ object Codegen {
else
Nil


private def codegenToolDependencies: Seq[ModuleID] =
Seq("com.github.kxbmap" % "sbt-jooq-codegen-tool" % BuildInfo.sbtJooqVersion)

Expand All @@ -51,7 +50,8 @@ object Codegen {
"javax.activation" % "activation" % BuildInfo.javaxActivationVersion,
"javax.xml.bind" % "jaxb-api" % BuildInfo.jaxbApiVersion,
"com.sun.xml.bind" % "jaxb-core" % BuildInfo.jaxbCoreVersion,
"com.sun.xml.bind" % "jaxb-impl" % BuildInfo.jaxbImplVersion)
"com.sun.xml.bind" % "jaxb-impl" % BuildInfo.jaxbImplVersion,
)
else
Nil

Expand All @@ -66,9 +66,11 @@ object Codegen {
codegenJooqVersion: JooqVersion,
codegenJavaVersion: JavaVersion,
): Seq[ModuleID] =
if (!javaVersion.isJavaEEModulesBundled
if (
!javaVersion.isJavaEEModulesBundled
&& !codegenJooqVersion.generatedAnnotationDisabledByDefault
&& (codegenJooqVersion, codegenJavaVersion).useJavaxAnnotationByDefault)
&& (codegenJooqVersion, codegenJavaVersion).useJavaxAnnotationByDefault
)
Seq("javax.annotation" % "javax.annotation-api" % BuildInfo.javaxAnnotationApiVersion)
else
Nil
Expand All @@ -78,10 +80,12 @@ object Codegen {
codegenJooqVersion: JooqVersion,
codegenJavaVersion: JavaVersion,
): Seq[String] =
if (javaVersion.isJigsawEnabled
if (
javaVersion.isJigsawEnabled
&& javaVersion.isJavaEEModulesBundled
&& !codegenJooqVersion.generatedAnnotationDisabledByDefault
&& (codegenJooqVersion, codegenJavaVersion).useJavaxAnnotationByDefault)
&& (codegenJooqVersion, codegenJavaVersion).useJavaxAnnotationByDefault
)
Seq("--add-modules", "java.xml.ws.annotation")
else
Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ object ConfigTransformer {
def appendGeneratorTargetDirectory(target: File): Node => Node = {
def append(node: Node, child: Node): Node =
(node, child) match {
case (e@Elem(p, l, a, s, xs@_*), x) if x.isAtom && e.text.trim.isEmpty =>
case (e @ Elem(p, l, a, s, xs @ _*), x) if x.isAtom && e.text.trim.isEmpty =>
Elem(p, l, a, s, false, xs :+ x: _*)
case (Elem(p, l, a, s, xs@_*), c@Elem(_, _, _, _, cc@_*)) =>
case (Elem(p, l, a, s, xs @ _*), c @ Elem(_, _, _, _, cc @ _*)) =>
xs.span(_.label != c.label) match {
case (ls, Seq(t, rs@_*)) =>
case (ls, Seq(t, rs @ _*)) =>
Elem(p, l, a, s, false, ls ++ cc.foldLeft(t)(append) ++ rs: _*)
case _ =>
Elem(p, l, a, s, false, xs :+ c: _*)
Expand All @@ -34,14 +34,13 @@ object ConfigTransformer {
def replaceConfigVariables(vars: Map[String, Any], expand: Any => NodeSeq): Node => Node = {
def go(parents: List[Node]): Node => NodeSeq = {
def path = parents.reverseMap(_.label).mkString("/", "/", "")
def replace(t: String): NodeSeq = {
def replace(t: String): NodeSeq =
t.span(_ != '$') match {
case (_, "") => Text(t)
case (l, r) if r.startsWith("$$") => Text(l + "$") +: replace(r.drop(2))
case (l, r) if r.startsWith("${") => Text(l) +: value(r.drop(2))
case (_, r) => sys.error("Expected '$$' or '${' but " + r)
}
}
def value(t: String): NodeSeq =
t.span(_ != '}') match {
case (_, "") => sys.error(s"Missing closing brace `}` at '$path'")
Expand All @@ -50,13 +49,13 @@ object ConfigTransformer {
expand(v) ++ replace(r.drop(1))
}
locally {
case e@Elem(p, l, a, s, xs@_*) => Elem(p, l, a, s, xs.isEmpty, xs.flatMap(go(e :: parents)): _*)
case e @ Elem(p, l, a, s, xs @ _*) => Elem(p, l, a, s, xs.isEmpty, xs.flatMap(go(e :: parents)): _*)
case Text(text) => replace(text)
case node => node
}
}
locally {
case e@Elem(p, l, a, s, xs@_*) => Elem(p, l, a, s, xs.isEmpty, xs.flatMap(go(e :: Nil)): _*)
case e @ Elem(p, l, a, s, xs @ _*) => Elem(p, l, a, s, xs.isEmpty, xs.flatMap(go(e :: Nil)): _*)
case node => node
}
}
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/main/scala/sbtjooq/codegen/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ package object internal {
def parse(javaHome: File): Either[String, JavaVersion] = {
val releaseFile = javaHome / "release"
val versionLine = """JAVA_VERSION="(.+)"""".r
try
try {
IO.readLines(releaseFile)
.collectFirst {
case versionLine(v) => companion(v)
}
.toRight(s"No JAVA_VERSION line in $releaseFile")
catch {
} catch {
case e: FileNotFoundException => Left(e.getMessage)
}
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/sbt-test/it-flyway-sbt/managed/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ lazy val migration = project
flywayUrl := "jdbc:h2:./test",
flywaySchemas := Seq("PUBLIC"),
flywayLocations := Seq("classpath:db/migration"),
libraryDependencies += "com.h2database" % "h2" % sys.props("scripted.h2.version") % Runtime
libraryDependencies += "com.h2database" % "h2" % sys.props("scripted.h2.version") % Runtime,
)
5 changes: 4 additions & 1 deletion codegen/src/sbt-test/it-flyway-sbt/managed/jooq-codegen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<inputSchema>PUBLIC</inputSchema>
<includes>.*</includes>
<excludes>flyway_schema_history</excludes>
<schemaVersionProvider>SELECT :schema_name || '_' || MAX("installed_rank") || '_' || SUM("checksum") FROM "flyway_schema_history"</schemaVersionProvider>
<schemaVersionProvider>
SELECT :schema_name || '_' || MAX("installed_rank") || '_' || SUM("checksum")
FROM "flyway_schema_history"
</schemaVersionProvider>
</database>
<target>
<packageName>com.example.db</packageName>
Expand Down
Loading

0 comments on commit 45a4f15

Please sign in to comment.