mirror of https://github.com/sbt/sbt.git
Add test scenario
This commit is contained in:
parent
71ea117a39
commit
9047a49dd0
|
|
@ -0,0 +1,59 @@
|
|||
import sbt.internal.remotecache.CustomRemoteCacheArtifact
|
||||
|
||||
lazy val root = (project in file("."))
|
||||
.configs(CustomArtifact)
|
||||
.settings(
|
||||
name := "my-project",
|
||||
scalaVersion := "2.12.11",
|
||||
pushRemoteCacheTo := Some(
|
||||
MavenCache("local-cache", (ThisBuild / baseDirectory).value / "remote-cache")
|
||||
),
|
||||
remoteCacheId := "fixed-id",
|
||||
remoteCacheIdCandidates := Seq("fixed-id"),
|
||||
pushRemoteCacheConfiguration := pushRemoteCacheConfiguration.value.withOverwrite(true),
|
||||
pushRemoteCacheConfiguration / remoteCacheArtifacts += {
|
||||
val art = (CustomArtifact / artifact).value
|
||||
val packaged = CustomArtifact / packageCache
|
||||
val extractDirectory = (CustomArtifact / sourceManaged).value
|
||||
|
||||
CustomRemoteCacheArtifact(art, packaged, extractDirectory, preserveLastModified = false)
|
||||
},
|
||||
Compile / sourceGenerators += Def.task {
|
||||
val extractDirectory = (CustomArtifact / sourceManaged).value
|
||||
val output = extractDirectory / "HelloWorld.scala"
|
||||
IO.write(output, "class HelloWorld")
|
||||
Seq(output)
|
||||
}.taskValue
|
||||
)
|
||||
.settings(customArtifactSettings)
|
||||
|
||||
lazy val CustomArtifact = config("custom-artifact")
|
||||
|
||||
def customArtifactSettings: Seq[Def.Setting[_]] = {
|
||||
val classifier = "custom-artifact"
|
||||
|
||||
inConfig(CustomArtifact)(
|
||||
Seq(
|
||||
packageOptions := {
|
||||
val n = name.value + "-" + classifier
|
||||
val ver = version.value
|
||||
val orgName = organizationName.value
|
||||
|
||||
List(Package.addSpecManifestAttributes(n, ver, orgName))
|
||||
},
|
||||
sourceManaged := (Compile / target).value / "custom-artifact-gen",
|
||||
mappings := {
|
||||
val sourcesDir = sourceManaged.value
|
||||
val sources = sourcesDir.allPaths.pair(Path.relativeTo(sourcesDir))
|
||||
|
||||
sources
|
||||
},
|
||||
packageConfiguration := Defaults.packageConfigurationTask.value,
|
||||
packageCache := Defaults.packageTask.value,
|
||||
artifact := Artifact(moduleName.value, classifier),
|
||||
packagedArtifact := (artifact.value -> packageCache.value),
|
||||
artifactPath := Defaults.artifactPathSetting(artifact).value,
|
||||
artifactName := Artifact.artifactName
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
object MyClass
|
||||
|
|
@ -0,0 +1 @@
|
|||
object MyTest
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
> compile
|
||||
> pushRemoteCache
|
||||
|
||||
# Generated sources, compiled classes
|
||||
$ exists target/custom-artifact-gen/HelloWorld.scala
|
||||
$ exists target/scala-2.12/classes/HelloWorld.class
|
||||
$ exists target/scala-2.12/classes/MyClass.class
|
||||
$ exists target/scala-2.12/classes/MyClass$.class
|
||||
$ exists target/scala-2.12/zinc/inc_compile_2.12.zip
|
||||
$ exists target/scala-2.12/test-classes/MyTest.class
|
||||
$ exists target/scala-2.12/test-classes/MyTest$.class
|
||||
$ exists target/scala-2.12/test-zinc/inc_compile_2.12.zip
|
||||
|
||||
# Pom file
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id.pom
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id.pom.md5
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id.pom.sha1
|
||||
|
||||
# Compile
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-cached-compile.jar
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-cached-compile.jar.md5
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-cached-compile.jar.sha1
|
||||
|
||||
# Test
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-cached-test.jar
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-cached-test.jar.md5
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-cached-test.jar.sha1
|
||||
|
||||
# Custom artifact
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-custom-artifact.jar
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-custom-artifact.jar.md5
|
||||
$ exists remote-cache/my-project/my-project_2.12/0.0.0-fixed-id/my-project_2.12-0.0.0-fixed-id-custom-artifact.jar.sha1
|
||||
|
||||
> clean
|
||||
|
||||
$ absent target/custom-artifact-gen/HelloWorld.scala
|
||||
$ absent target/scala-2.12/classes/HelloWorld.class
|
||||
$ absent target/scala-2.12/classes/MyClass.class
|
||||
$ absent target/scala-2.12/classes/MyClass$.class
|
||||
$ absent target/scala-2.12/zinc/inc_compile_2.12.zip
|
||||
$ absent target/scala-2.12/test-classes/MyTest.class
|
||||
$ absent target/scala-2.12/test-classes/MyTest$.class
|
||||
$ absent target/scala-2.12/test-zinc/inc_compile_2.12.zip
|
||||
|
||||
> pullRemoteCache
|
||||
|
||||
# Files extracted from the cache artifacts
|
||||
$ exists target/custom-artifact-gen/HelloWorld.scala
|
||||
$ exists target/scala-2.12/classes/HelloWorld.class
|
||||
$ exists target/scala-2.12/classes/MyClass.class
|
||||
$ exists target/scala-2.12/classes/MyClass$.class
|
||||
$ exists target/scala-2.12/zinc/inc_compile_2.12.zip
|
||||
$ exists target/scala-2.12/test-classes/MyTest.class
|
||||
$ exists target/scala-2.12/test-classes/MyTest$.class
|
||||
$ exists target/scala-2.12/test-zinc/inc_compile_2.12.zip
|
||||
|
||||
# Artifacts can be pushed twice (enabled overriding)
|
||||
> pushRemoteCache
|
||||
Loading…
Reference in New Issue