How to get access to This scope with Project.extract(state) and currentRef

19 views
Skip to first unread message

Ezh

unread,
Apr 14, 2013, 2:32:06 PM4/14/13
to simple-b...@googlegroups.com
Hi all.

I found this link http://www.scala-sbt.org/release/docs/Extending/Build-State.html that describes scopes.
I have multiple subprojects with different names and I have task.

def myTask = (state, name in This, streams) map {
      (state, subname, streams) =>
        val extracted: Extracted = Project.extract(state)
        import extracted._
        val subname2 = name in currentRef get structure.data
        streams.log.info(subname + " == " + subname2.get)
}

The problem is the task returns correct subname for each project, but subname2 is not.
I tried

name in (currentRef, Runtime) get structure.data and others...
name in ThisProject get structure.data
name in ThisBuild get structure.data
name in This get structure.data (returns None)

but they are all wrong

How to get "name in This" from state?

King regards,
Alexey

Mark Harrah

unread,
Apr 15, 2013, 11:11:54 AM4/15/13
to simple-b...@googlegroups.com
Please elaborate. What do you mean by "wrong"?

> How to get "name in This" from state?

It is rarely necessary to use State in a task. It is really intended for commands. What is the use case?

-Mark

>
> King regards,
> Alexey
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Ezh

unread,
Apr 15, 2013, 12:51:03 PM4/15/13
to simple-b...@googlegroups.com
Thank you for response. I think that I found solution, but I am not sure about it correctness.


> Please elaborate.  What do you mean by "wrong"?

I mean that I need settings from 'This' scope, but task returns settings from other scopes like:
[info] core == root
[info] ui-view-modificator-dialogs == root
[info] ui-model-definition-dialogs == root
[info] root == root
[success] Total time: 0 s, completed 14.04.2013 22:58:48
So I want to
core == core
ui
-view-modificator-dialogs == ui-view-modificator-dialogs
an so on.


> It is rarely necessary to use State in a task.  It is really intended for commands.  What is the use case?

The case is that I need more than 15 argument and I don't want to define
implicit def t22ToTable22[A,B,C,D,E,F,G,H,I,J,K,L,N,O,P, ....](t15: (ScopedTaskable[A], ...

Right now I find the next working scheme
state, thisProjectRef, ... =>

 val extracted
: Extracted = Project.extract(state)

 val thisScope
= Load.projectScope(thisProjectRef)
 val result
= for {
 appConfiguration
<- appConfiguration in thisScope get extracted.structure.data
 ivyLoggingLevel
<- ivyLoggingLevel in thisScope get extracted.structure.data
 ivyScala
<- ivyScala in thisScope get extracted.structure.data
 name
<- name in thisScope get extracted.structure.data
 pathTarget
<- target in thisScope get extracted.structure.data
 updateConfiguration
<- updateConfiguration in thisScope get extracted.structure.data
 dependencyAddCustom
<- dependencyAddCustom in thisScope get extracted.structure.data
 dependencyIgnoreConfiguration
<- dependencyIgnoreConfiguration in thisScope get extracted.structure.data
 dependencyResourceFilter
<- dependencyResourceFilter in thisScope get extracted.structure.data
 
} yield { ...

Is there more legal way to do this?
SBT has beautiful, easy to read code, but there are no comment in interesting places for me.
And I have no time to read it all :-( for complete understanding of your logic.

Thank you very much for SBT.

King regards,
Alexey

понедельник, 15 апреля 2013 г., 19:11:54 UTC+4 пользователь Mark Harrah написал:
Reply all
Reply to author
Forward
0 new messages