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

moved plugin dependencies #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ name := "jooq-sbt-plugin"

crossScalaVersions := Seq("2.9.3", "2.10.6", "2.11.7")

libraryDependencies += "com.floreysoft" % "jmte" % "3.2.0"
val jooqVersion = "3.8.4"

libraryDependencies ++= Seq(
"com.floreysoft" % "jmte" % "3.2.0",
"org.jooq" % "jooq" % jooqVersion,
"org.jooq" % "jooq-meta" % jooqVersion,
"org.jooq" % "jooq-codegen" % jooqVersion,
"org.slf4j" % "slf4j-api" % "1.7.2",
"org.slf4j" % "slf4j-log4j12" % "1.7.2",
"org.slf4j" % "jul-to-slf4j" % "1.7.2",
"log4j" % "log4j" % "1.2.17"
)
37 changes: 12 additions & 25 deletions src/main/scala/sean8223/JOOQPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object JOOQPlugin extends Plugin {

// setting keys

val jooqOptions = SettingKey[Seq[Tuple2[String, String]]]("jooq-options", "JOOQ options.")
val jooqOptions = SettingKey[Seq[(String, String)]]("jooq-options", "JOOQ options.")

val jooqVersion = SettingKey[String]("jooq-version", "JOOQ version.")

Expand Down Expand Up @@ -88,53 +88,40 @@ object JOOQPlugin extends Plugin {
}
},

libraryDependencies <++= (scalaVersion, jooqVersion) apply {
(sv, jv) => {
Seq("org.jooq" % "jooq" % jv % JOOQ.name,
"org.jooq" % "jooq" % jv, // also add this to the project's compile configuration
"org.jooq" % "jooq-meta" % jv % JOOQ.name,
"org.jooq" % "jooq-codegen" % jv % JOOQ.name,
"org.slf4j" % "slf4j-api" % "1.7.2" % JOOQ.name,
"org.slf4j" % "slf4j-log4j12" % "1.7.2" % JOOQ.name,
"org.slf4j" % "jul-to-slf4j" % "1.7.2" % JOOQ.name,
"log4j" % "log4j" % "1.2.17" % JOOQ.name)
}
},

ivyConfigurations += JOOQ

)

private def getOrGenerateJooqConfig(log:Logger, outputDirectory:File, options:Seq[Tuple2[String,String]], jooqConfigFile:Option[File], templateValues:Option[()=>Map[String, AnyRef]]) : File = {

(jooqConfigFile, templateValues) match {
case (Some(template), Some(values)) => {
case (Some(template), Some(values)) =>
val engine = new Engine
val renderedConfig = File.createTempFile("jooq-config", ".xml")
renderedConfig.deleteOnExit
renderedConfig.deleteOnExit()
val writer = new PrintWriter(renderedConfig)
val substitutions = JavaConversions.mapAsJavaMap(values.apply())
writer.write(engine.transform(IO.read(template), substitutions))
writer.close()
renderedConfig
}

case _ => jooqConfigFile.getOrElse(generateJooqConfig(log, outputDirectory, options))
}
}

private def generateJooqConfig(log:Logger, outputDirectory:File, options:Seq[Tuple2[String,String]]) : File = {
private def generateJooqConfig(log:Logger, outputDirectory:File, options:Seq[(String, String)]) : File = {
val tmp = File.createTempFile("jooq-config", ".xml")
tmp.deleteOnExit
tmp.deleteOnExit()
val fw = new FileWriter(tmp)
try {
val replaced = Seq("generator.target.directory" -> outputDirectory.getAbsolutePath) ++ options.filter { kv => kv._1 != "generator.target.directory" }
val xml = replaced.foldLeft(<configuration/>) {
(xml, kv) => xmlify(kv._1.split("\\."), kv._2, xml)
}
XML.save(tmp.getAbsolutePath, xml, "UTF-8", true)
XML.save(tmp.getAbsolutePath, xml, "UTF-8", xmlDecl=true)
}
finally {
fw.close
fw.close()
}
log.debug("Wrote JOOQ configuration to " + tmp.getAbsolutePath)
tmp
Expand All @@ -161,7 +148,7 @@ object JOOQPlugin extends Plugin {
// shunt any messages at warn and higher to stderr, everything else to
// stdout, thanks to http://stackoverflow.com/questions/8489551/logging-error-to-stderr-and-debug-info-to-stdout-with-log4j
val tmp = File.createTempFile("log4j", ".xml")
tmp.deleteOnExit
tmp.deleteOnExit()
val configuration =
<log4j:configuration>
<appender name="stderr" class="org.apache.log4j.ConsoleAppender">
Expand All @@ -188,7 +175,7 @@ object JOOQPlugin extends Plugin {
<appender-ref ref="stdout" />
</root>
</log4j:configuration>
XML.save(tmp.getAbsolutePath, configuration, "UTF-8", true, DocType("log4j:configuration", SystemID("log4j.dtd"), Nil))
XML.save(tmp.getAbsolutePath, configuration, "UTF-8", xmlDecl=true, DocType("log4j:configuration", SystemID("log4j.dtd"), Nil))
log.debug("Wrote log4j configuration to " + tmp.getAbsolutePath)
tmp
}
Expand All @@ -215,12 +202,12 @@ object JOOQPlugin extends Plugin {
log.debug("Using jooq config " + jcf)
val log4jConfig = generateLog4jConfig(log, logLevel)
val classpathArgument = generateClasspathArgument(log, dependencyClasspath, jcf)
val cmdLine = Seq("java", "-classpath", classpathArgument, "-Dlog4j.configuration=" + log4jConfig.toURL, "org.jooq.util.GenerationTool", "/" + jcf.getName())
val cmdLine = Seq("java", "-classpath", classpathArgument, "-Dlog4j.configuration=" + log4jConfig.toURL, "org.jooq.util.GenerationTool", "/" + jcf.getName)
log.debug("Command line is " + cmdLine.mkString(" "))
val rc = Process(cmdLine, baseDirectory) ! log
rc match {
case 0 => ;
case x => error("Failed with return code: " + x)
case x => sys.error("Failed with return code: " + x)
}
getOutputFiles(outputDirectory)
}
Expand Down