1818
1919package com .typesafe .sbteclipse .core
2020
21+ import sbt ._
2122import EclipsePlugin .{
2223 EclipseClasspathEntry ,
2324 EclipseTransformerFactory ,
@@ -39,7 +40,6 @@ import sbt.{
3940 Configurations ,
4041 EvaluateTask ,
4142 File ,
42- Inc ,
4343 Incomplete ,
4444 Keys ,
4545 ModuleID ,
@@ -52,8 +52,7 @@ import sbt.{
5252 State ,
5353 TaskKey ,
5454 ThisBuild ,
55- UpdateReport ,
56- Value
55+ UpdateReport
5756}
5857import sbt .fileToRichFile
5958import sbt .internal .BuildStructure
@@ -100,7 +99,9 @@ private object Eclipse extends EclipseSDTConfig {
10099 import EclipseExecutionEnvironment ._
101100 import EclipseOpts ._
102101 import sbt .complete .DefaultParsers ._
103- val (head :: tail) = valueSeq map (_.toString)
102+ val parsedValues = valueSeq.toList.map(_.toString)
103+ val head = parsedValues.head
104+ val tail = parsedValues.tail
104105 val executionEnvironments = tail.foldLeft(head : Parser [String ])(_ | _)
105106 (Space ~> ExecutionEnvironment ~ (" =" ~> executionEnvironments)) map { case (k, v) => k -> withName(v) }
106107 }
@@ -109,7 +110,9 @@ private object Eclipse extends EclipseSDTConfig {
109110 import EclipseJDTMode ._
110111 import EclipseOpts ._
111112 import sbt .complete .DefaultParsers ._
112- val (head :: tail) = valueSeq map (_.toString)
113+ val parsedValues = valueSeq.toList.map(_.toString)
114+ val head = parsedValues.head
115+ val tail = parsedValues.tail
113116 val jdtModes = tail.foldLeft(head : Parser [String ])(_ | _)
114117 (Space ~> JDTMode ~ (" =" ~> jdtModes)) map { case (k, v) => k -> withName(v) }
115118 }
@@ -160,7 +163,7 @@ private object Eclipse extends EclipseSDTConfig {
160163 builderAndNatures(projectFlavor(ref, state)),
161164 state))
162165 }
163- effects.toList.sequence[Validation , IO [String ]].map((list : List [IO [String ]]) => list.toStream. sequence.map(_.toList))
166+ effects.toList.sequence[Validation , IO [String ]].map((list : List [IO [String ]]) => list.sequence.map(_.toList))
164167 }
165168
166169 def removeExtendedConfigurations (configurations : Seq [Configuration ]): Seq [Configuration ] = {
@@ -230,8 +233,8 @@ private object Eclipse extends EclipseSDTConfig {
230233 projectDependencies,
231234 jreContainer,
232235 state)
233- _ <- saveXml(baseDirectory / " .project" , new RuleTransformer (projectTransformers : _ * )(projectXml(name, builderAndNatures, linkedSrcDirectories)))
234- _ <- saveXml(baseDirectory / " .classpath" , new RuleTransformer (classpathTransformers : _ * )(cp))
236+ _ <- saveXml(baseDirectory / " .project" , new RuleTransformer (projectTransformers* )(projectXml(name, builderAndNatures, linkedSrcDirectories)))
237+ _ <- saveXml(baseDirectory / " .classpath" , new RuleTransformer (classpathTransformers* )(cp))
235238 _ <- saveProperties(baseDirectory / " .settings" / " org.eclipse.core.resources.prefs" , Seq ((" encoding/<project>" -> " UTF-8" )))
236239 _ <- saveProperties(baseDirectory / " .settings" / " org.scala-ide.sdt.core.prefs" , scalacOptions ++: compileOrder.map { order => Seq ((" compileorder" -> order)) }.getOrElse(Nil ))
237240 _ <- handleJDTSettings(jdtMode, baseDirectory, jreContainer)
@@ -330,10 +333,10 @@ private object Eclipse extends EclipseSDTConfig {
330333 dir
331334 }
332335 val entries = srcEntries ++ linkEntries ++
333- (projectDependencies map EclipseClasspathEntry .Project ) ++
336+ (projectDependencies map EclipseClasspathEntry .Project .apply ) ++
334337 (externalDependencies map libEntry(buildDirectory, baseDirectory, relativizeLibs, state)) ++
335- (Seq (jreContainer) map EclipseClasspathEntry .Con ) ++
336- (Seq (classDirectory) map EclipseClasspathEntry .Output )
338+ (Seq (jreContainer) map EclipseClasspathEntry .Con .apply ) ++
339+ (Seq (classDirectory) map EclipseClasspathEntry .Output .apply )
337340 <classpath >{ entries map (_.toXml) }</classpath >
338341 }
339342 }
@@ -389,7 +392,7 @@ private object Eclipse extends EclipseSDTConfig {
389392 if (buildDirectory === baseDirectory) Some (" ." ) else sbt.IO .relativize(buildDirectory, baseDirectory)
390393 val relativizedFile = sbt.IO .relativize(buildDirectory, file)
391394 val relativized = (relativizedBase |@| relativizedFile)((base, file) =>
392- s " ${base split FileSepPattern map (part => if (part != " ." ) " .." else part) mkString FileSep }${FileSep }${file}" )
395+ s " ${base. split( FileSepPattern ). map(part => if (part != " ." ) " .." else part). mkString( FileSep ) }${FileSep }${file}" )
393396 if (relativizeLibs) relativized getOrElse file.getAbsolutePath else file.getAbsolutePath
394397 }
395398 EclipseClasspathEntry .Lib (path(lib.binary), lib.source map path, lib.javadoc map path)
@@ -484,7 +487,8 @@ private object Eclipse extends EclipseSDTConfig {
484487 dirs(ValueSet (), Keys .unmanagedSourceDirectories),
485488 dirs(ValueSet (), Keys .unmanagedResourceDirectories),
486489 dirs(ValueSet (ManagedSrc ), Keys .managedSourceDirectories),
487- dirs(ValueSet (ManagedResources ), Keys .managedResourceDirectories)) reduceLeft (_ +++ _)
490+ dirs(ValueSet (ManagedResources ), Keys .managedResourceDirectories)
491+ ).sequence.map(_.flatten)
488492 }
489493
490494 def scalacOptions (ref : ProjectRef , state : State ): Validation [Seq [(String , String )]] = {
@@ -511,7 +515,7 @@ private object Eclipse extends EclipseSDTConfig {
511515 def moduleReports (key : TaskKey [UpdateReport ]) =
512516 evalTask(key) map { updateReport =>
513517 for {
514- configurationReport <- ( updateReport configuration configuration).toSeq
518+ configurationReport <- updateReport. configuration( configuration).toSeq
515519 moduleReports <- configurationReport.modules
516520 } yield moduleReports
517521 }
@@ -528,14 +532,24 @@ private object Eclipse extends EclipseSDTConfig {
528532 def moduleFileToArtifactFile (binaries : Map [ModuleID , File ], sources : Map [ModuleID , File ], javadocs : Map [ModuleID , File ]) =
529533 for ((moduleId, binaryFile) <- binaries)
530534 yield binaryFile -> Lib (binaryFile)(sources get moduleId)(javadocs get moduleId)
531- def libs (files : Seq [Attributed [File ]], moduleFiles : Map [File , Lib ]): Seq [Lib ] = {
532- var result : Seq [Lib ] = files.files map { file => moduleFiles.get(file).getOrElse(Lib (file)(None )(None )) }
535+ def classpathFile (a : Attributed [? ], conv : xsbti.FileConverter ): File =
536+ a.data match {
537+ case file : File => file
538+ case ref : xsbti.VirtualFileRef => conv.toPath(ref).toFile
539+ }
540+
541+ def libs (files : Seq [Attributed [? ]], conv : xsbti.FileConverter , moduleFiles : Map [File , Lib ]): Seq [Lib ] = {
542+ var result : Seq [Lib ] = files.map { a =>
543+ val file = classpathFile(a, conv)
544+ moduleFiles.get(file).getOrElse(Lib (file)(None )(None ))
545+ }
533546 if (createSrc(ref, state)(configuration).contains(EclipseCreateSrc .ManagedClasses )) {
534547 result = result ++ managedClassDirectories(ref, state)(configuration).filter(_.exists).map(Lib (_)(None )(None ))
535548 }
536549 result
537550 }
538551 val externalDependencyClasspath : Validation [sbt.Keys .Classpath ] = evalTask(Keys .externalDependencyClasspath)
552+ val fileConverter = settingValidation((ref / Keys .fileConverter), state)
539553 val moduleFiles : Validation [Map [File , Lib ]] = {
540554 lazy val classifierModuleReports = moduleReports(Keys .updateClassifiers)
541555
@@ -551,14 +565,14 @@ private object Eclipse extends EclipseSDTConfig {
551565
552566 sources |+| javadoc match {
553567 case Some (_) => {
554- val binaryModuleToFile = moduleToFile(moduleReports(Keys .update))
568+ val binaryModuleToFile = moduleToFile(moduleReports(Keys .update), (_, _) => true )
555569
556570 (binaryModuleToFile |@| classifierModuleToFile(sources) |@| classifierModuleToFile(javadoc))(moduleFileToArtifactFile)
557571 }
558572 case None => Map [File , Lib ]().success
559573 }
560574 }
561- val externalDependencies = (externalDependencyClasspath |@| moduleFiles)(libs)
575+ val externalDependencies = (externalDependencyClasspath |@| fileConverter |@| moduleFiles)(libs)
562576 state.log.debug(
563577 s " External dependencies for configuration ' ${configuration}' and withSource ' ${withSource}' and withJavadoc ' ${withJavadoc}': ${externalDependencies}" )
564578 externalDependencies
@@ -731,8 +745,8 @@ private object Eclipse extends EclipseSDTConfig {
731745 new File (normalizeName(file.getAbsolutePath))
732746
733747 def normalizeName (filename : String ): String = {
734- if (filename contains " .." ) {
735- val parts = (filename split " [\\ /]+" ).toList
748+ if (filename. contains( " .." ) ) {
749+ val parts = (filename. split( " [\\ /]+" ) ).toList
736750 def fix (parts : List [String ], result : String ): String = parts match {
737751 case Nil => result
738752 case a :: " .." :: rest => fix(rest, result)
@@ -751,7 +765,11 @@ private object Eclipse extends EclipseSDTConfig {
751765
752766 def boolOpt (key : String ): Parser [(String , Boolean )] = {
753767 import sbt .complete .DefaultParsers ._
754- (Space ~> key ~ (" =" ~> (" true" | " false" ))) map { case (k, v) => k -> v.toBoolean }
768+ val parserValues = List (" true" , " false" ).map(s => s : Parser [String ])
769+ val head = parserValues.head
770+ val tail = parserValues.tail
771+ val bools = tail.foldLeft(head)(_ | _)
772+ (Space ~> key ~ (" =" ~> bools)) map { case (k, v) => k -> v.toBoolean }
755773 }
756774
757775 /**
@@ -773,8 +791,11 @@ private object Eclipse extends EclipseSDTConfig {
773791 def evaluateTask [A ](key : TaskKey [A ], ref : ProjectRef , state : State ): Validation [A ] = {
774792 val taskConfig = EvaluateTask .extractedTaskConfig(Project .extract(state), structure(state), state)
775793 EvaluateTask (structure(state), key, state, ref, taskConfig) match {
776- case Some ((_, Value (a))) => a.success
777- case Some ((_, Inc (inc))) => s " Error evaluating task ' ${key.key}': ${Incomplete .show(inc.tpe)}" .failureNel
794+ case Some ((_, result)) =>
795+ result.toEither.fold(
796+ inc => s " Error evaluating task ' ${key.key}': ${Incomplete .show(inc.tpe)}" .failureNel,
797+ _.success
798+ )
778799 case None => s " Undefined task ' ${key.key}' for ' ${ref.project}'! " .failureNel
779800 }
780801 }
0 commit comments