matheshar / simple-build-tool

Automatically exported from code.google.com/p/simple-build-tool
Other
0 stars 0 forks source link

Tasks with arguments not working correctly when called on a parent project #143

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have a plugin that contains a task that supports arguments. I'm then using 
this in a multi-module project. When you call the task on the parent project it 
does not get processed on each of the sub-projects, whereas a non argument task 
is called on each of the child projects.

Example:

Consider a plugin project:

package templemore.defect
import _root_.sbt._
trait DefectProject extends BasicScalaProject {
  protected def defectAction(args: Array[String]) = task {
    log.info("Running defect action with args: " + args)
    None
  }
  lazy val noArgs = defectAction(Array())
  lazy val withArgs = task { args => defectAction(args) }
}

This defines two tasks, a no-args and a with-args. The with-args uses the 
approach shown in the sbt wiki documentation for handling task arguments.

Now, consider a project that uses this plugin:

Plugin.scala:
import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val templemoreRepo = "templemore repo" at "http://templemore.co.uk/repo"
  val defectPlugin = "templemore" % "defect" % "1.0"
}

TestProject.scala:
import sbt._
import templemore.defect.DefectProject
class TestProject(info: ProjectInfo) extends ParentProject(info) {

  // Projects
  lazy val child1Project = project("child1", "child1", new ChildProject(_))
  lazy val child2Project = project("child2", "child2", new ChildProject(_))

  // Child Project
  class ChildProject(info: ProjectInfo) extends DefaultProject(info) with DefectProject {
  }
}

Now, running sbt on this project I can issued the no-args command on the parent 
project:
> no-args
[info] 
[info] == child2 / no-args ==
[info] Running defect action with args: [Ljava.lang.String;@672a375b
[info] == child2 / no-args ==
[info] 
[info] == child1 / no-args ==
[info] Running defect action with args: [Ljava.lang.String;@582d6583
[info] == child1 / no-args ==
[info] 
[info] == defect-test / no-args ==
[info] == defect-test / no-args ==
[success] Successful.

As you can see it runs fine. However, if I issue the with-args command:
> with-args hello
[error] No method named 'with-args' exists.
[info] Execute 'help' for a list of commands or 'actions' for a list of 
available project actions and methods.

Switching to one of the child projects and using with-args works fine:
> project child1
Set current project to child1 1.0
> with-args hello
[info] 
[info] == with-args ==
[info] Running defect action with args: [Ljava.lang.String;@5c219c51
[info] == with-args ==
[success] Successful.

I would expect that the behaviour should be consistent whether a task has 
arguments or not. 

I've attached my simple test project.

Original issue reported on code.google.com by skipoleschris@gmail.com on 3 Feb 2011 at 2:52

Attachments:

GoogleCodeExporter commented 8 years ago
This is the intended and documented behavior:

http://code.google.com/p/simple-build-tool/wiki/MethodTasks

Original comment by dmhar...@gmail.com on 3 Feb 2011 at 3:07

GoogleCodeExporter commented 8 years ago
Clarifications:
  - this is more precisely classified as a duplicate of #94
  - in sbt 0.9, the model allows for input tasks to be executed across aggregated projects, so the underlying issue is better resolved as fixed

Original comment by dmhar...@gmail.com on 17 Mar 2011 at 3:20