From 899d5295c8c7f8bd5d81cdbb1eff1a11df7e26d0 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 9 Aug 2014 20:41:28 -0400 Subject: [PATCH] Adds a test case that exercises the multiple-repository -SNAPSHOT issue. #1514 * Create a project "common" which publishes a "bad" artifact. * Resolve project "dependent" which resolves the "bad" artifact into the cache. * Publish a new "common" snapshot to a diffferent repository (publishLocal) * Attempt to build the new project, leading to issues. --- .../pull-remote-snapshot-over-local/build.sbt | 58 +++++++++++++++++++ .../changes/BadCommon.scala | 2 + .../changes/GoodCommon.scala | 3 + .../common/src/main/scala/Common.scala | 3 + .../dependent/src/main/scala/User.scala | 3 + .../pull-remote-snapshot-over-local/test | 31 ++++++++++ 6 files changed, 100 insertions(+) create mode 100644 sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/build.sbt create mode 100644 sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/BadCommon.scala create mode 100644 sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/GoodCommon.scala create mode 100644 sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/common/src/main/scala/Common.scala create mode 100644 sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/dependent/src/main/scala/User.scala create mode 100644 sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/test diff --git a/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/build.sbt b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/build.sbt new file mode 100644 index 000000000..7201d4a7b --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/build.sbt @@ -0,0 +1,58 @@ +lazy val sharedResolver = + Resolver.defaultShared.nonlocal() + //MavenRepository("example-shared-repo", "file:///tmp/shared-maven-repo-bad-example") + //Resolver.file("example-shared-repo", repoDir)(Resolver.defaultPatterns) + +lazy val common = ( + project + .settings( + organization := "com.badexample", + name := "badexample", + version := "1.0-SNAPSHOT", + publishTo := Some(sharedResolver), + crossVersion := CrossVersion.Disabled, + publishMavenStyle := (publishTo.value match { + case Some(repo) => + repo match { + case repo: PatternsBasedRepository => repo.patterns.isMavenCompatible + case _: RawRepository => false // TODO - look deeper + case _: MavenRepository => true + case _ => false // TODO - Handle chain repository? + } + case _ => true + }) + ) +) + +lazy val dependent = ( + project + .settings( + // Ignore the inter-project resolver, so we force to look remotely. + resolvers += sharedResolver, + fullResolvers := fullResolvers.value.filterNot(_==projectResolver.value), + libraryDependencies += "com.badexample" % "badexample" % "1.0-SNAPSHOT" + ) +) + +TaskKey[Unit]("cleanLocalCache") := { + val ivyHome = file(sys.props.get("ivy.home") orElse sys.props.get("sbt.ivy.home") match { + case Some(home) => home + case None => s"${sys.props("user.home")}/.ivy2" + }) + val ivyCache = ivyHome / "cache" + val ivyShared = ivyHome / "shared" + val ivyLocal = ivyHome / "local" + def deleteDirContents(dir: String)(base: File): Unit = { + val toDelete = base / dir + streams.value.log.info(s"Deleting: ${toDelete.getAbsolutePath}") + IO.delete(toDelete) + } + Seq(ivyCache, ivyShared, ivyLocal).map(deleteDirContents("com.badexample")) +} + +TaskKey[Unit]("dumpResolvers") := { + streams.value.log.info(s" -- dependent/fullResolvers -- ") + (fullResolvers in dependent).value foreach { r => + streams.value.log.info(s" * ${r}") + } +} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/BadCommon.scala b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/BadCommon.scala new file mode 100644 index 000000000..4df4235d5 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/BadCommon.scala @@ -0,0 +1,2 @@ +object Common { +} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/GoodCommon.scala b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/GoodCommon.scala new file mode 100644 index 000000000..3f9b39258 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/changes/GoodCommon.scala @@ -0,0 +1,3 @@ +object Common { + def name = "common" +} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/common/src/main/scala/Common.scala b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/common/src/main/scala/Common.scala new file mode 100644 index 000000000..d6175ce12 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/common/src/main/scala/Common.scala @@ -0,0 +1,3 @@ +object Common { + +} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/dependent/src/main/scala/User.scala b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/dependent/src/main/scala/User.scala new file mode 100644 index 000000000..8bc6103c8 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/dependent/src/main/scala/User.scala @@ -0,0 +1,3 @@ +object User { + println(Common.name) +} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/test b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/test new file mode 100644 index 000000000..e0118f75f --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/pull-remote-snapshot-over-local/test @@ -0,0 +1,31 @@ +# First clean any previous test state +> cleanLocalCache + +# Validate that a bad dependency fails the compile +$ copy-file changes/BadCommon.scala common/src/main/scala/Common.scala +> common/publish + +# Force dep resolution to be successful, then compilation to fail +> dependent/update +-> dependent/compile + +# Push new good change to a DIFFERENT repository. +$ copy-file changes/GoodCommon.scala common/src/main/scala/Common.scala +> common/publishLocal + +# Force the update task to look for the new -SNAPSHOT. +> dependent/update + + +$ copy-file changes/BadCommon.scala common/src/main/scala/Common.scala +> common/publish +> dependent/update + + +$ copy-file changes/GoodCommon.scala common/src/main/scala/Common.scala +> common/publishLocal +> dependent/update + + +# This should compile now, because Ivy should look at each repository for the most up-to-date file. +> dependent/compile