From 9047a49dd0d54800b4433a999f53cf4dcfcfab93 Mon Sep 17 00:00:00 2001 From: Maksim Ochenashko Date: Tue, 23 Jun 2020 10:19:05 +0300 Subject: [PATCH] Add test scenario --- .../sbt-test/actions/remote-cache/build.sbt | 59 +++++++++++++++++++ .../remote-cache/src/main/scala/MyClass.scala | 1 + .../remote-cache/src/test/scala/MyTest.scala | 1 + sbt/src/sbt-test/actions/remote-cache/test | 58 ++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 sbt/src/sbt-test/actions/remote-cache/build.sbt create mode 100644 sbt/src/sbt-test/actions/remote-cache/src/main/scala/MyClass.scala create mode 100644 sbt/src/sbt-test/actions/remote-cache/src/test/scala/MyTest.scala create mode 100644 sbt/src/sbt-test/actions/remote-cache/test diff --git a/sbt/src/sbt-test/actions/remote-cache/build.sbt b/sbt/src/sbt-test/actions/remote-cache/build.sbt new file mode 100644 index 000000000..9e58f260f --- /dev/null +++ b/sbt/src/sbt-test/actions/remote-cache/build.sbt @@ -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 + ) + ) +} \ No newline at end of file diff --git a/sbt/src/sbt-test/actions/remote-cache/src/main/scala/MyClass.scala b/sbt/src/sbt-test/actions/remote-cache/src/main/scala/MyClass.scala new file mode 100644 index 000000000..7c7f7e635 --- /dev/null +++ b/sbt/src/sbt-test/actions/remote-cache/src/main/scala/MyClass.scala @@ -0,0 +1 @@ +object MyClass \ No newline at end of file diff --git a/sbt/src/sbt-test/actions/remote-cache/src/test/scala/MyTest.scala b/sbt/src/sbt-test/actions/remote-cache/src/test/scala/MyTest.scala new file mode 100644 index 000000000..d27811abd --- /dev/null +++ b/sbt/src/sbt-test/actions/remote-cache/src/test/scala/MyTest.scala @@ -0,0 +1 @@ +object MyTest \ No newline at end of file diff --git a/sbt/src/sbt-test/actions/remote-cache/test b/sbt/src/sbt-test/actions/remote-cache/test new file mode 100644 index 000000000..e90fade3e --- /dev/null +++ b/sbt/src/sbt-test/actions/remote-cache/test @@ -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 \ No newline at end of file