Skip to content

Commit

Permalink
closes #28: Add skip-parents option
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Seeberger committed Sep 8, 2011
1 parent f55aad1 commit f8d0f28
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
5 changes: 3 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project is a plugin for "sbt 0.11.x":http://github.com/harrah/xsbt/ providi

h2. Latest changes

* #28: Add skip-parents option
* #27: Add info message "This might take some time ..." when command starts
* #24: Switch to sbt 0.11

Expand All @@ -15,9 +16,9 @@ h2. Installing sbteclipse as a sbt plugin
* Just add the below lines to your _build.sbt_ file, paying attention to the blank lines:

<pre><code>
resolvers += Classpaths.typesafeResolver
resolvers += Classpaths.typesafeSnapshots

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4-RC1")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0-SNAPSHOT")
</code></pre>

h2. Using sbteclipse to create Eclipse project files
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ organization := "com.typesafe.sbteclipse"

name := "sbteclipse"

version := "1.4-SNAPSHOT"
version := "1.4.0-SNAPSHOT"

sbtPlugin := true

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sbteclipse
v1.4
====

* #28: Add skip-parents option
* #27: Add info message "This might take some time ..." when command starts
* #24: Switch to sbt 0.11

Expand Down
30 changes: 18 additions & 12 deletions src/main/scala/com/typesafe/sbteclipse/SbtEclipsePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,29 @@ object SbtEclipsePlugin extends Plugin {

override def settings = Seq(Keys.commands += eclipseCommand)

private val (createSrc, sameTargets, skipRoot, withSources) = ("create-src", "same-targets", "skip-root", "with-sources")
private val (createSrc, sameTargets, skipParents, skipRoot, withSources) =
("create-src", "same-targets", "skip-parents", "skip-root", "with-sources")

private val args = (Space ~> createSrc |
Space ~> sameTargets |
Space ~> skipRoot |
Space ~> withSources).*
private val parsedArgs = (Space ~> createSrc |
Space ~> sameTargets |
Space ~> skipParents |
Space ~> skipRoot |
Space ~> withSources)

private val eclipseCommand = Command("eclipse")(_ => args) { (state, args) =>
private val eclipseCommand = Command("eclipse")(_ => parsedArgs) { (state, args) =>
implicit val implicitState = state

logInfo("About to create an Eclipse project for you.")
logInfo("Please hang on, because it might be necessary to perform an update and this might take some time ...")

(for (ref <- structure.allProjectRefs if (!(args contains skipRoot) || !isRootProject(ref))) yield {
val shouldSkipParents = args contains skipParents
val shouldSkipRoot = args contains skipRoot

(for {
ref <- structure.allProjectRefs
project <- Project.getProject(ref, structure) // TODO Is it safe to assume that getProject will always return Some?
if shouldSkipParents && !isParentProject(project) || shouldSkipRoot && !isRootProject(ref) || !(shouldSkipParents || shouldSkipRoot)
} yield {

val projectName = setting(Keys.name, "Missing project name for %s!" format ref.project, ref)
val scalaVersion = setting(Keys.scalaVersion, "Missing Scala version for %s!" format ref.project, ref)
Expand Down Expand Up @@ -96,11 +105,8 @@ object SbtEclipsePlugin extends Plugin {
ls map { l => Library(l, bsToSs get l) }
}
}
val projectDependencies = (Project.getProject(ref, structure) match {
case None => Seq(("Cannot resolve project for reference %s!" format ref.project).failNel)
case Some(project) => project.dependencies map { dependency =>
setting(Keys.name, "Missing project name for %s!" format ref.project, dependency.project)
}
val projectDependencies = (project.dependencies map { dependency =>
setting(Keys.name, "Missing project name for %s!" format ref.project, dependency.project)
}).sequence[({type A[B]=Validation[NonEmptyList[String], B]})#A, String]
(projectName |@|
scalaVersion |@|
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/typesafe/sbteclipse/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ package object sbteclipse {
def evaluateTask[A](taskKey: ScopedKey[Task[A]], ref: ProjectRef)(implicit state: State): Option[Result[A]] =
EvaluateTask.evaluateTask(structure, taskKey, state, ref, false, EvaluateTask.SystemProcessors)

def isParentProject(project: ResolvedProject): Boolean = !project.aggregate.isEmpty

def isRootProject(projectRef: ProjectRef)(implicit state: State): Boolean =
projectRef.project == (extracted rootProject projectRef.build)

Expand Down

0 comments on commit f8d0f28

Please sign in to comment.