Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

enable Autoplugin #6

Open
wants to merge 2 commits 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
9 changes: 5 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sbt-jrebel-plugin

sbt-jrebel-plugin is a plugin for [Simple Build Tool](http://www.scala-sbt.org) that generates configuration files (rebel.xml) for [JRebel](http://www.zeroturnaround.com/jrebel/). A rebel.xml is not always required but is recommended because if you don't have one, JRebel cannot understand the layout of your project and might fail to reload changes. You also cannot reload changes from separate projects.

**Supported SBT versions: 0.13.x**
**Supported SBT versions: 0.13.x and 1.x**

## Features

Expand All @@ -25,11 +25,12 @@ __You should always disable sbt-jrebel-plugin when publishing artifacts somewher

Add the plugin declaration to project/plugins.sbt:

addSbtPlugin("fi.gekkio.sbtplugins" % "sbt-jrebel-plugin" % "0.10.0")
addSbtPlugin("fi.gekkio.sbtplugins" % "sbt-jrebel-plugin" % "0.20.0")

Then include the plugin settings in your project definition:
Then enable the plugin and include settings in your project definition (build.sbt):

seq(jrebelSettings: _*)
enablePlugins(JRebelPlugin)
JRebelPlugin.projectSettings

If you are using [xsbt-web-plugin](https://github.com/earldouglas/xsbt-web-plugin) and want to reload web resources, also add this:

Expand Down
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ organization := "fi.gekkio.sbtplugins"

name := "sbt-jrebel-plugin"

version := "0.10.0"
version := "0.20.0"

crossSbtVersions := Seq("0.13.16", "1.0.2")

sbtPlugin := true

Expand Down
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
60 changes: 33 additions & 27 deletions src/main/scala/JRebelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sbt.Keys._
import sbt.Scope.GlobalScope
import scala.xml._

object JRebelPlugin extends Plugin {
object JRebelPlugin extends AutoPlugin {
object jrebel {
val classpath = SettingKey[Seq[File]]("jrebel-classpath")
val enabled = SettingKey[Boolean]("jrebel-enabled")
Expand All @@ -16,14 +16,16 @@ object JRebelPlugin extends Plugin {
val jrebelGenerate = TaskKey[Seq[File]]("jrebel-generate")

val jrebelSettings: Seq[Def.Setting[_]] = Seq[Setting[_]](
jrebel.classpath <<= Seq(Keys.classDirectory in Compile, Keys.classDirectory in Test).join,
jrebel.classpath := (Seq(Keys.classDirectory in Compile, Keys.classDirectory in Test).join).value,
jrebel.enabled := (java.lang.Package.getPackage("com.zeroturnaround.javarebel") != null),
jrebel.rebelXml <<= (resourceManaged in Compile) { _ / "rebel.xml" },
jrebel.rebelXml := ((resourceManaged in Compile) { _ / "rebel.xml" }).value,
jrebel.webLinks := Seq(),
jrebelGenerate <<= rebelXmlTask,
resourceGenerators in Compile <+= jrebelGenerate
jrebelGenerate := rebelXmlTask.value,
resourceGenerators in Compile += Def.task { jrebelGenerate.value }
)

override lazy val projectSettings = jrebelSettings

private def dirXml(dir: File) = <dir name={ dir.absolutePath } />

private def webLinkXml(link: File) =
Expand All @@ -33,27 +35,31 @@ object JRebelPlugin extends Plugin {
</link>
</web>

private def rebelXmlTask: Def.Initialize[Task[Seq[File]]] =
(jrebel.enabled, jrebel.classpath, jrebel.rebelXml, jrebel.webLinks, state) map {
(enabled, classpath, rebelXml, webLinks, state) =>
if (!enabled) Nil
else {
val xml =
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
{ classpath.map(dirXml) }
</classpath>
{
webLinks.map(webLinkXml)
}
</application>

IO.touch(rebelXml)
XML.save(rebelXml.absolutePath, xml, "UTF-8", true)

state.log.info("Wrote rebel.xml to %s".format(rebelXml.absolutePath))

rebelXml :: Nil
}
private def rebelXmlTask: Def.Initialize[Task[Seq[File]]] = Def.task {
val enabled = jrebel.enabled.value
val classpath = jrebel.classpath.value
val rebelXml = jrebel.rebelXml.value
val webLinks = jrebel.webLinks.value
val s = state.value

if (!enabled) Nil
else {
val xml =
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
{ classpath.map(dirXml) }
</classpath>
{
webLinks.map(webLinkXml)
}
</application>

IO.touch(rebelXml)
XML.save(rebelXml.absolutePath, xml, "UTF-8", true)

s.log.info("Wrote rebel.xml to %s".format(rebelXml.absolutePath))

rebelXml :: Nil
}
}
}