From e02afb36c815eb61f4f52f8c9bbe5f078e5c7bcf Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 12 Jan 2010 18:50:47 -0500 Subject: [PATCH] * Fix 'reload' behavior with respect to sbt.version * Add test for artifacts --- src/main/scala/sbt/BasicProjectTypes.scala | 3 +- src/main/scala/sbt/Main.scala | 2 +- .../artifact/project/build.properties | 2 + .../artifact/project/build/ArtifactTest.scala | 42 +++++++++++++++++++ .../artifact/src/main/scala/Test.scala | 2 + .../dependency-management/artifact/test | 20 +++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/sbt-test/dependency-management/artifact/project/build.properties create mode 100644 src/sbt-test/dependency-management/artifact/project/build/ArtifactTest.scala create mode 100644 src/sbt-test/dependency-management/artifact/src/main/scala/Test.scala create mode 100644 src/sbt-test/dependency-management/artifact/test diff --git a/src/main/scala/sbt/BasicProjectTypes.scala b/src/main/scala/sbt/BasicProjectTypes.scala index 4e48504d9..12cfa6f54 100644 --- a/src/main/scala/sbt/BasicProjectTypes.scala +++ b/src/main/scala/sbt/BasicProjectTypes.scala @@ -170,7 +170,8 @@ trait ManagedProject extends ClasspathProject * so that the Ivy 'extends' mechanism is not required. That way, the jars are only copied to one configuration.*/ def managedClasspath(config: Configuration): PathFinder = configurationClasspath(config) /** All dependencies in the given configuration. */ - final def configurationClasspath(config: Configuration): PathFinder = descendents(configurationPath(config), "*.jar") + final def configurationClasspath(config: Configuration): PathFinder = descendents(configurationPath(config), classpathFilter) + def classpathFilter: FileFilter = "*.jar" /** The base path to which dependencies in configuration 'config' are downloaded.*/ def configurationPath(config: Configuration): Path = managedDependencyPath / config.toString diff --git a/src/main/scala/sbt/Main.scala b/src/main/scala/sbt/Main.scala index 918114f0a..8578429d8 100755 --- a/src/main/scala/sbt/Main.scala +++ b/src/main/scala/sbt/Main.scala @@ -151,7 +151,7 @@ class xMain extends xsbti.AppMain { case "" :: tail => continue(project, tail, failAction) case (ExitCommand | QuitCommand) :: _ => result( Exit(NormalExitCode) ) - case RebootCommand :: tail => result( Reboot(project.defScalaVersion.value, rememberCurrent(tail), configuration) ) + case RebootCommand :: tail => throw new xsbti.FullReload(rememberCurrent(tail).toArray) case InteractiveCommand :: _ => continue(project, prompt(baseProject, project) :: arguments, interactiveContinue) case SpecificBuild(version, action) :: tail => if(Some(version) != baseProject.info.buildScalaVersion) diff --git a/src/sbt-test/dependency-management/artifact/project/build.properties b/src/sbt-test/dependency-management/artifact/project/build.properties new file mode 100644 index 000000000..2b4d7e5a1 --- /dev/null +++ b/src/sbt-test/dependency-management/artifact/project/build.properties @@ -0,0 +1,2 @@ +project.name=Test +project.version=1.0 \ No newline at end of file diff --git a/src/sbt-test/dependency-management/artifact/project/build/ArtifactTest.scala b/src/sbt-test/dependency-management/artifact/project/build/ArtifactTest.scala new file mode 100644 index 000000000..f2dcc858d --- /dev/null +++ b/src/sbt-test/dependency-management/artifact/project/build/ArtifactTest.scala @@ -0,0 +1,42 @@ +import sbt._ + +class ArtifactTest(info: ProjectInfo) extends DefaultProject(info) +{ + // use cache specific to this test + def ivyCacheDirectory = outputPath / "ivy-cache" + override def updateOptions = CacheDirectory(ivyCacheDirectory) :: super.updateOptions.toList + + // define a test repository to publish to + override def managedStyle = ManagedStyle.Maven + val publishTo = Resolver.file("Test Repo", ("test-repo") asFile) + + // define strings for defining the artifact + override def artifactID = "test" + def ext = "test2" + def classifier = "test3" + def tpe = "test1" + def vers = "1.1" + def org = "test" + // define the jar + override def jarPath = outputPath / (artifactID + "-" + vers + "-" + classifier + "." + ext) + def artifact = Artifact(artifactID, tpe, ext, classifier) + + // define the IDs to use for publishing and retrieving + def publishedID = org % artifactID % vers artifacts(artifact) + def retrieveID = org % "test-retrieve" % "2.0" + + override def projectID = if(retrieve) retrieveID else publishedID + override def libraryDependencies = if(retrieve) Set(publishedID) else super.libraryDependencies + + // switches between publish and retrieve mode + def retrieve = "retrieve".asFile.exists + // needed to add a jar with a different extension to the classpath + override def classpathFilter = "*." + ext + + // check that the test class is on the compile classpath, either because it was compiled or because it was properly retrieved + lazy val check = task { check0 } + def check0 = + try { Class.forName("test.Test", false, loader); None } + catch { case _: ClassNotFoundException | _: NoClassDefFoundError => Some("Dependency not retrieved properly") } + def loader = new java.net.URLClassLoader(compileClasspath.get.map(_.asURL).toSeq.toArray, buildScalaInstance.loader) +} diff --git a/src/sbt-test/dependency-management/artifact/src/main/scala/Test.scala b/src/sbt-test/dependency-management/artifact/src/main/scala/Test.scala new file mode 100644 index 000000000..b01b6da1c --- /dev/null +++ b/src/sbt-test/dependency-management/artifact/src/main/scala/Test.scala @@ -0,0 +1,2 @@ +package test +class Test \ No newline at end of file diff --git a/src/sbt-test/dependency-management/artifact/test b/src/sbt-test/dependency-management/artifact/test new file mode 100644 index 000000000..2e317d56f --- /dev/null +++ b/src/sbt-test/dependency-management/artifact/test @@ -0,0 +1,20 @@ +# verify that check fails when test class is not present +-> check + +# compile and jar test class +> package +# verify that check succeeds +> check + +# publish test jar to test repository +>publish + +# delete test jar and verify check fails again +> clean +-> check + +# tell project definition to switch to retrieve mode +$ touch retrieve +# verify that artifact with extension, type, and classifier can be retreieved +> update +> check \ No newline at end of file