Permalink
Browse files

Refactored classpathEntryTransformer.

  • Loading branch information...
1 parent 5428bf6 commit 4f9066fb9d659d0274236a667f5c2e1c9c9d7b38 Heiko Seeberger committed Jan 5, 2012
@@ -20,10 +20,10 @@ package com.typesafe.sbteclipse.core
import EclipsePlugin.{
EclipseClasspathEntry,
+ EclipseClasspathEntryTransformerFactory,
EclipseCreateSrc,
EclipseExecutionEnvironment,
- EclipseKeys,
- eclipseDefaultClasspathEntryTransformer
+ EclipseKeys
}
import java.io.{ FileWriter, Writer }
import java.util.Properties
@@ -88,14 +88,15 @@ private object Eclipse {
project <- Project.getProject(ref, structure) if project.aggregate.isEmpty || !skipParents
} yield {
val configs = configurations(ref)
- (name(ref) |@|
+ (classpathEntryTransformerFactory(ref).createTransformer(ref, state) |@|
+ name(ref) |@|
buildDirectory |@|
baseDirectory(ref) |@|
mapConfigs(configs, srcDirectories(ref, createSrc(ref))) |@|
scalacOptions(ref) |@|
mapConfigs(configs, externalDependencies(ref, withSourceArg getOrElse withSource(ref))) |@|
mapConfigs(configs, projectDependencies(ref, project))
- )(effect(classpathEntryTransformer(ref), preTasks(ref)))
+ )(effect(preTasks(ref)))
}
effects.sequence[ValidationNELS, IO[String]] map (_.sequence)
}
@@ -118,8 +119,8 @@ private object Eclipse {
(configurations map f).sequence map (_.flatten.distinct)
def effect(
- classpathEntryTransformer: (Seq[EclipseClasspathEntry], State) => Seq[EclipseClasspathEntry],
preTasks: Seq[(TaskKey[_], ProjectRef)])(
+ classpathEntryTransformer: Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry],
name: String,
buildDirectory: File,
baseDirectory: File,
@@ -163,7 +164,7 @@ private object Eclipse {
</projectDescription>
def classpath(
- classpathEntryTransformer: (Seq[EclipseClasspathEntry], State) => Seq[EclipseClasspathEntry],
+ classpathEntryTransformer: Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry],
buildDirectory: File,
baseDirectory: File,
srcDirectories: Seq[(File, File)],
@@ -177,7 +178,7 @@ private object Eclipse {
(projectDependencies map EclipseClasspathEntry.Project) ++
(Seq("org.eclipse.jdt.launching.JRE_CONTAINER") map EclipseClasspathEntry.Con) ++
(Seq("bin") map EclipseClasspathEntry.Output)
- <classpath>{ classpathEntryTransformer(entries, state) map (_.toXml) }</classpath>
+ <classpath>{ classpathEntryTransformer(entries) map (_.toXml) }</classpath>
}
}
@@ -302,8 +303,8 @@ private object Eclipse {
def withSource(ref: Reference)(implicit state: State) =
setting(EclipseKeys.withSource in ref).fold(_ => false, id)
- def classpathEntryTransformer(ref: Reference)(implicit state: State) =
- setting(EclipseKeys.classpathEntryTransformer in ref).fold(_ => eclipseDefaultClasspathEntryTransformer, id)
+ def classpathEntryTransformerFactory(ref: Reference)(implicit state: State) =
+ setting(EclipseKeys.classpathEntryTransformerFactory in ref).fold(_ => EclipseClasspathEntryTransformerFactory.Default, id)
def configurations(ref: Reference)(implicit state: State) =
setting(EclipseKeys.configurations in ref).fold(
@@ -18,7 +18,18 @@
package com.typesafe.sbteclipse.core
-import sbt.{ Configuration, Configurations, File, Plugin, Setting, SettingKey, State, TaskKey }
+import sbt.{
+ Configuration,
+ Configurations,
+ File,
+ Plugin,
+ ProjectRef,
+ ResolvedProject,
+ Setting,
+ SettingKey,
+ State,
+ TaskKey
+}
import sbt.Keys.{ baseDirectory, commands }
import scala.xml.{ Attribute, Elem, Null, Text }
@@ -34,19 +45,6 @@ trait EclipsePlugin {
)
}
- def eclipseIdentityClasspathEntryTransformer: (Seq[EclipseClasspathEntry], State) => Seq[EclipseClasspathEntry] =
- (entries, _) => entries
-
- def eclipseDefaultClasspathEntryTransformer: (Seq[EclipseClasspathEntry], State) => Seq[EclipseClasspathEntry] =
- (entries, _) => entries collect {
- case EclipseClasspathEntry.Lib(path, _) if path contains "scala-library.jar" =>
- EclipseClasspathEntry.Con("org.scala-ide.sdt.launching.SCALA_CONTAINER")
- case EclipseClasspathEntry.Lib(path, _) if path contains "scala-compiler.jar" =>
- EclipseClasspathEntry.Con("org.scala-ide.sdt.launching.SCALA_COMPILER_CONTAINER")
- case entry =>
- entry
- }
-
object EclipseKeys {
import EclipseOpts._
@@ -65,10 +63,10 @@ trait EclipsePlugin {
prefix(WithSource),
"Download and link sources for library dependencies?")
- val classpathEntryTransformer: SettingKey[(Seq[EclipseClasspathEntry], State) => Seq[EclipseClasspathEntry]] =
- SettingKey[(Seq[EclipseClasspathEntry], State) => Seq[EclipseClasspathEntry]](
- prefix("classpathEntryCollector"),
- "Determines how classpath entries are transformed before written into XML.")
+ val classpathEntryTransformerFactory: SettingKey[EclipseClasspathEntryTransformerFactory] =
+ SettingKey[EclipseClasspathEntryTransformerFactory](
+ prefix("classpathEntryTransformerFactory"),
+ "Creates a transformer for classpath entries.")
val commandName: SettingKey[String] =
SettingKey[String](
@@ -156,4 +154,34 @@ trait EclipsePlugin {
val All = ValueSet(Unmanaged, Managed, Source, Resource)
}
+
+ trait EclipseClasspathEntryTransformerFactory {
+ def createTransformer(ref: ProjectRef, state: State): ValidationNELS[Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry]]
+ }
+
+ object EclipseClasspathEntryTransformerFactory {
+
+ object Identity extends EclipseClasspathEntryTransformerFactory {
+ import scalaz.Scalaz._
+ override def createTransformer(ref: ProjectRef, state: State): ValidationNELS[Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry]] =
+ ((entries: Seq[EclipseClasspathEntry]) => entries).success
+ }
+
+ object Default extends EclipseClasspathEntryTransformerFactory {
+ import scalaz.Scalaz._
+ override def createTransformer(ref: ProjectRef, state: State): ValidationNELS[Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry]] = {
+ val transformer =
+ (entries: Seq[EclipseClasspathEntry]) => entries collect {
+ case EclipseClasspathEntry.Lib(path, _) if path contains "scala-library.jar" =>
+ EclipseClasspathEntry.Con("org.scala-ide.sdt.launching.SCALA_CONTAINER")
+ case EclipseClasspathEntry.Lib(path, _) if path contains "scala-compiler.jar" =>
+ EclipseClasspathEntry.Con("org.scala-ide.sdt.launching.SCALA_COMPILER_CONTAINER")
+ case entry =>
+ entry
+ }
+ transformer.success
+ }
+ }
+
+ }
}

0 comments on commit 4f9066f

Please sign in to comment.