-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1565 from Gedochao/decompose-inputs
Decompose & refactor `Inputs`
- Loading branch information
Showing
36 changed files
with
347 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
modules/build/src/main/scala/scala/build/input/Element.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package scala.build.input | ||
|
||
import scala.build.preprocessing.ScopePath | ||
import scala.util.matching.Regex | ||
|
||
sealed abstract class Element extends Product with Serializable | ||
|
||
sealed trait SingleElement extends Element | ||
|
||
sealed trait AnyScript extends Element | ||
|
||
sealed abstract class OnDisk extends Element { | ||
def path: os.Path | ||
} | ||
|
||
sealed abstract class Virtual extends SingleElement { | ||
def content: Array[Byte] | ||
|
||
def source: String | ||
|
||
def subPath: os.SubPath = { | ||
val idx = source.lastIndexOf('/') | ||
os.sub / source.drop(idx + 1) | ||
} | ||
|
||
def scopePath: ScopePath = | ||
ScopePath(Left(source), subPath) | ||
} | ||
|
||
sealed abstract class VirtualSourceFile extends Virtual { | ||
def isStdin: Boolean = source.startsWith("<stdin>") | ||
|
||
def isSnippet: Boolean = source.startsWith("<snippet>") | ||
|
||
protected def generatedSourceFileName(fileSuffix: String): String = | ||
if (isStdin) s"stdin$fileSuffix" | ||
else if (isSnippet) s"${source.stripPrefix("<snippet>-")}$fileSuffix" | ||
else s"virtual$fileSuffix" | ||
} | ||
|
||
sealed trait SingleFile extends OnDisk with SingleElement | ||
|
||
sealed trait SourceFile extends SingleFile { | ||
def subPath: os.SubPath | ||
} | ||
|
||
sealed trait Compiled extends Element | ||
|
||
sealed trait AnyScalaFile extends Compiled | ||
|
||
sealed trait ScalaFile extends AnyScalaFile { | ||
def base: os.Path | ||
|
||
def subPath: os.SubPath | ||
|
||
def path: os.Path = base / subPath | ||
} | ||
|
||
final case class Script(base: os.Path, subPath: os.SubPath) | ||
extends OnDisk with SourceFile with AnyScalaFile with AnyScript { | ||
lazy val path: os.Path = base / subPath | ||
} | ||
|
||
final case class SourceScalaFile(base: os.Path, subPath: os.SubPath) | ||
extends OnDisk with SourceFile with ScalaFile | ||
|
||
final case class ProjectScalaFile(base: os.Path, subPath: os.SubPath) | ||
extends OnDisk with SourceFile with ScalaFile | ||
|
||
final case class JavaFile(base: os.Path, subPath: os.SubPath) | ||
extends OnDisk with SourceFile with Compiled { | ||
lazy val path: os.Path = base / subPath | ||
} | ||
|
||
final case class CFile(base: os.Path, subPath: os.SubPath) | ||
extends OnDisk with SourceFile with Compiled { | ||
lazy val path = base / subPath | ||
} | ||
|
||
final case class MarkdownFile(base: os.Path, subPath: os.SubPath) | ||
extends OnDisk with SourceFile { | ||
lazy val path: os.Path = base / subPath | ||
} | ||
|
||
final case class Directory(path: os.Path) extends OnDisk with Compiled | ||
|
||
final case class ResourceDirectory(path: os.Path) extends OnDisk | ||
|
||
final case class VirtualScript(content: Array[Byte], source: String, wrapperPath: os.SubPath) | ||
extends Virtual with AnyScalaFile with AnyScript | ||
|
||
object VirtualScript { | ||
val VirtualScriptNameRegex: Regex = "(^stdin$|^snippet\\d*$)".r | ||
} | ||
|
||
final case class VirtualScalaFile(content: Array[Byte], source: String) | ||
extends VirtualSourceFile with AnyScalaFile { | ||
def generatedSourceFileName: String = generatedSourceFileName(".scala") | ||
} | ||
|
||
final case class VirtualJavaFile(content: Array[Byte], source: String) | ||
extends VirtualSourceFile with Compiled { | ||
def generatedSourceFileName: String = generatedSourceFileName(".java") | ||
} | ||
|
||
final case class VirtualData(content: Array[Byte], source: String) | ||
extends Virtual |
Oops, something went wrong.