From b8bc58d2483be44eced8e41f78c9706adb386de7 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 1 Oct 2015 03:58:20 -0400 Subject: [PATCH] Fix dependency-management/artifact --- .../dependency-management/artifact/build.sbt | 41 +++++++++++++++++ .../artifact/project/ArtifactTest.scala | 45 ------------------- 2 files changed, 41 insertions(+), 45 deletions(-) create mode 100644 sbt/src/sbt-test/dependency-management/artifact/build.sbt delete mode 100644 sbt/src/sbt-test/dependency-management/artifact/project/ArtifactTest.scala diff --git a/sbt/src/sbt-test/dependency-management/artifact/build.sbt b/sbt/src/sbt-test/dependency-management/artifact/build.sbt new file mode 100644 index 000000000..6f85caf19 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/artifact/build.sbt @@ -0,0 +1,41 @@ +import sbt.internal.inc.classpath.ClasspathUtilities + +lazy val checkFull = TaskKey[Unit]("check-full") +lazy val check = TaskKey[Unit]("check") + +lazy val root = (project in file(".")). + settings( + ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))), + publishTo := Some(Resolver.file("Test Publish Repo", file("test-repo"))), + resolvers <+= baseDirectory { base => "Test Repo" at (base / "test-repo").toURI.toString }, + moduleName := artifactID, + projectID <<= baseDirectory { base => (if(base / "retrieve" exists) retrieveID else publishedID) }, + artifact in (Compile, packageBin) := mainArtifact, + libraryDependencies <<= (libraryDependencies, baseDirectory) { (deps, base) => deps ++ (if(base / "retrieve" exists) publishedID :: Nil else Nil) }, + // needed to add a jar with a different type to the managed classpath + unmanagedClasspath in Compile <+= scalaInstance.map(_.libraryJar), + classpathTypes := Set(tpe), + check <<= checkTask(dependencyClasspath), + checkFull <<= checkTask(fullClasspath) + ) + +// define strings for defining the artifact +def artifactID = "test" +def ext = "test2" +def classifier = "test3" +def tpe = "test1" +def vers = "1.1" +def org = "test" + +def mainArtifact = Artifact(artifactID, tpe, ext, classifier) + +// define the IDs to use for publishing and retrieving +def publishedID = org % artifactID % vers artifacts(mainArtifact) +def retrieveID = org % "test-retrieve" % "2.0" + +// check that the test class is on the compile classpath, either because it was compiled or because it was properly retrieved +def checkTask(classpath: TaskKey[Classpath]) = (classpath in Compile, scalaInstance) map { (cp, si) => + val loader = ClasspathUtilities.toLoader(cp.files, si.loader) + try { Class.forName("test.Test", false, loader); () } + catch { case _: ClassNotFoundException | _: NoClassDefFoundError => sys.error("Dependency not retrieved properly") } +} diff --git a/sbt/src/sbt-test/dependency-management/artifact/project/ArtifactTest.scala b/sbt/src/sbt-test/dependency-management/artifact/project/ArtifactTest.scala deleted file mode 100644 index 052409fd0..000000000 --- a/sbt/src/sbt-test/dependency-management/artifact/project/ArtifactTest.scala +++ /dev/null @@ -1,45 +0,0 @@ - import sbt._ - import Import._ - import Keys._ - -object ArtifactTest extends Build -{ - lazy val root = Project("root", file(".")) settings( - ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))), - publishTo := Some(Resolver.file("Test Publish Repo", file("test-repo"))), - resolvers <+= baseDirectory { base => "Test Repo" at (base / "test-repo").toURI.toString }, - moduleName := artifactID, - projectID <<= baseDirectory { base => (if(base / "retrieve" exists) retrieveID else publishedID) }, - artifact in (Compile, packageBin) := mainArtifact, - libraryDependencies <<= (libraryDependencies, baseDirectory) { (deps, base) => deps ++ (if(base / "retrieve" exists) publishedID :: Nil else Nil) }, - // needed to add a jar with a different type to the managed classpath - unmanagedClasspath in Compile <+= scalaInstance.map(_.libraryJar), - classpathTypes := Set(tpe), - check <<= checkTask(dependencyClasspath), - checkFull <<= checkTask(fullClasspath) - ) - - lazy val checkFull = TaskKey[Unit]("check-full") - lazy val check = TaskKey[Unit]("check") - - // define strings for defining the artifact - def artifactID = "test" - def ext = "test2" - def classifier = "test3" - def tpe = "test1" - def vers = "1.1" - def org = "test" - - def mainArtifact = Artifact(artifactID, tpe, ext, classifier) - - // define the IDs to use for publishing and retrieving - def publishedID = org % artifactID % vers artifacts(mainArtifact) - def retrieveID = org % "test-retrieve" % "2.0" - - // check that the test class is on the compile classpath, either because it was compiled or because it was properly retrieved - def checkTask(classpath: TaskKey[Classpath]) = (classpath in Compile, scalaInstance) map { (cp, si) => - val loader = sbt.classpath.ClasspathUtilities.toLoader(cp.files, si.loader) - try { Class.forName("test.Test", false, loader); () } - catch { case _: ClassNotFoundException | _: NoClassDefFoundError => sys.error("Dependency not retrieved properly") } - } -}