[2.2.1] Nested Initialize when creating resource generator

183 views
Skip to first unread message

Alvaro Carrasco

unread,
Dec 2, 2013, 10:19:11 PM12/2/13
to simple-b...@googlegroups.com, play-fr...@googlegroups.com
I am trying to create a new task that can be appended to "resourceGenerators" in a play project. This is what I have:

    resourceGenerators in Compile <+= {(sourceDirectory in Compile) {base =>
      ClosureJsCompiler(base / "assets" / "javascripts" / "closure-library")
    }}

ClosureJsCompiler is calling AssetCompiler which returns:
  sbt.Def.Initialize[sbt.Task[Seq[java.io.File]]]

But since I am trying to give it a value from a setting by using "apply", I end up with:
  sbt.Def.Initialize[sbt.Def.Initialize[sbt.Task[Seq[java.io.File]]]]

and thus, this error:
  sbt.Def.Initialize[sbt.Task[Seq[java.io.File]]] cannot be appended to Seq[sbt.Task[Seq[java.io.File]]]

I think I need the equivalent of "flatMap", but for "apply" (flatApply?) Is there such a thing?

Am I doing this totally wrong? I couldn't figure out how to use the new macro methods for this either :(

--
Alvaro

Nilanjan Raychaudhuri

unread,
Dec 2, 2013, 11:09:03 PM12/2/13
to play-fr...@googlegroups.com, simple-b...@googlegroups.com
Assuming ClosureJsCompiler returns Initialize[Task...] you can do

ClosureJsCompiler(base / "assets" / "javascripts" / "closure-library").value

and see if helps. I wish I access to the code.

Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri

Alvaro Carrasco

unread,
Dec 3, 2013, 12:40:33 PM12/3/13
to simple-b...@googlegroups.com, play-fr...@googlegroups.com
Hi Nilanjan, thanks for your response. 

I keep trying different versions of that, this one the most promising:

resourceGenerators in Compile ++= 
  ClosureJsAssetCompiler((sourceDirectory in Compile).value / "assets" / "javascripts" / "closure-library").value

But get this error:
[error] /Users/alvarocarrasco/workspace/devstack/project/closure.scala:28: No implicit for Append.Values[Seq[sbt.Task[Seq[java.io.File]]], Seq[java.io.File]] found,
[error]   so Seq[java.io.File] cannot be appended to Seq[sbt.Task[Seq[java.io.File]]]
[error]     resourceGenerators in Compile ++= 
[error]                                   ^
[error] one error found

The source code for ClosureJsCompiler:

  def ClosureJsCompiler(closureLibraryDir: File) = AssetsCompiler("closurejs",
    (_ ** "*.js"),
    javascriptEntryPoints,
    {(name, min) =>
      name.replace(".js", if (min) ".min.js" else ".js")
    },
    {(jsFile: File, simpleCompilerOptions) => Compiler.compile(jsFile, closureLibraryDir)},
    closureCompilerOptions
  )

As you can see, it's just calling AssetsCompiler from play.

Alvaro


2013/12/2 Nilanjan Raychaudhuri <nraych...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
To post to this group, send email to simple-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-build-tool.
For more options, visit https://groups.google.com/groups/opt_out.

Nilanjan Raychaudhuri

unread,
Dec 5, 2013, 12:50:28 AM12/5/13
to play-fr...@googlegroups.com, simple-b...@googlegroups.com
How about this one:

  val closureJsAssetTask = taskKey[Seq[File]]("closure-js-compiler")

  closureJsAssetTask := Def.taskDyn {
    val dir = (sourceDirectory in Compile).value
    ClosureJsCompiler(dir)
  }.value

  resourceGenerators in Compile <+= closureJsAssetTask

sbt 0.13.1 has added something called taskValue that will simplify this even further. I wanted to solve this without using Def.taskDyn but haven't got enough time to do it right now. Hope this helps


Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri


Reply all
Reply to author
Forward
0 new messages