bring more integration tests back online with associated fixes

This commit is contained in:
Mark Harrah 2011-02-23 19:19:44 -05:00
parent ba8f43a23e
commit 9db4afd222
46 changed files with 147 additions and 202 deletions

View File

@ -24,23 +24,24 @@ object ClassToAPI
def toDefinitions(c: Class[_]): Seq[api.ClassLike] =
{
import api.DefinitionType.{ClassDef, Module, Trait}
val enclPkg = packageName(c)
val mods = modifiers(c.getModifiers)
val acc = access(c.getModifiers)
val acc = access(c.getModifiers, enclPkg)
val annots = annotations(c.getAnnotations)
val name = c.getName
val tpe = if(Modifier.isInterface(c.getModifiers)) Trait else ClassDef
lazy val (static, instance) = structure(c)
lazy val (static, instance) = structure(c, enclPkg)
val cls = new api.ClassLike(tpe, strict(Empty), lzy(instance), typeParameters(c.getTypeParameters), name, acc, mods, annots)
def makeStatic(s: api.Structure) =
new api.ClassLike(Module, strict(Empty), strict(s), Array(), name, acc, mods, annots)
cls :: static.map(makeStatic).toList
}
def structure(c: Class[_]): (Option[api.Structure], api.Structure) =
def structure(c: Class[_], enclPkg: Option[String]): (Option[api.Structure], api.Structure) =
{
val methods = mergeMap(c, c.getMethods, c.getDeclaredMethods, methodToDef)
val fields = mergeMap(c, c.getFields, c.getDeclaredFields, fieldToDef)
val constructors = mergeMap(c, c.getConstructors, c.getDeclaredConstructors, constructorToDef)
val methods = mergeMap(c, c.getMethods, c.getDeclaredMethods, methodToDef(enclPkg))
val fields = mergeMap(c, c.getFields, c.getDeclaredFields, fieldToDef(enclPkg))
val constructors = mergeMap(c, c.getConstructors, c.getDeclaredConstructors, constructorToDef(enclPkg))
val classes = merge[Class[_]](c, c.getClasses, c.getDeclaredClasses, toDefinitions, (_: Seq[Class[_]]).partition(isStatic), _.getEnclosingClass != c)
val all = (methods ++ fields ++ constructors ++ classes)
val parentTypes = parents(c)
@ -59,30 +60,30 @@ object ClassToAPI
def upperBounds(ts: Array[Type]): api.Type =
new api.Structure(lzy(types(ts)), emptyDefArray, emptyDefArray)
def fieldToDef(f: Field): api.FieldLike =
def fieldToDef(enclPkg: Option[String])(f: Field): api.FieldLike =
{
val name = f.getName
val accs = access(f.getModifiers)
val accs = access(f.getModifiers, enclPkg)
val mods = modifiers(f.getModifiers)
val annots = annotations(f.getDeclaredAnnotations)
val tpe = reference(f.getGenericType)
if(mods.isFinal) new api.Val(tpe, name, accs, mods, annots) else new api.Var(tpe, name, accs, mods, annots)
}
def methodToDef(m: Method): api.Def =
defLike(m.getName, m.getModifiers, m.getDeclaredAnnotations, m.getTypeParameters, m.getParameterAnnotations, m.getGenericParameterTypes, Some(m.getGenericReturnType), m.getGenericExceptionTypes, m.isVarArgs)
def methodToDef(enclPkg: Option[String])(m: Method): api.Def =
defLike(m.getName, m.getModifiers, m.getDeclaredAnnotations, m.getTypeParameters, m.getParameterAnnotations, m.getGenericParameterTypes, Some(m.getGenericReturnType), m.getGenericExceptionTypes, m.isVarArgs, enclPkg)
def constructorToDef(c: Constructor[_]): api.Def =
defLike("<init>", c.getModifiers, c.getDeclaredAnnotations, c.getTypeParameters, c.getParameterAnnotations, c.getGenericParameterTypes, None, c.getGenericExceptionTypes, c.isVarArgs)
def constructorToDef(enclPkg: Option[String])(c: Constructor[_]): api.Def =
defLike("<init>", c.getModifiers, c.getDeclaredAnnotations, c.getTypeParameters, c.getParameterAnnotations, c.getGenericParameterTypes, None, c.getGenericExceptionTypes, c.isVarArgs, enclPkg)
def defLike[T <: GenericDeclaration](name: String, mods: Int, annots: Array[Annotation], tps: Array[TypeVariable[T]], paramAnnots: Array[Array[Annotation]], paramTypes: Array[Type], retType: Option[Type], exceptions: Array[Type], varArgs: Boolean): api.Def =
def defLike[T <: GenericDeclaration](name: String, mods: Int, annots: Array[Annotation], tps: Array[TypeVariable[T]], paramAnnots: Array[Array[Annotation]], paramTypes: Array[Type], retType: Option[Type], exceptions: Array[Type], varArgs: Boolean, enclPkg: Option[String]): api.Def =
{
val varArgPosition = if(varArgs) paramTypes.length - 1 else -1
val isVarArg = List.tabulate(paramTypes.length)(_ == varArgPosition)
val pa = (paramAnnots, paramTypes, isVarArg).zipped map { case (a,p,v) => parameter(a,p,v) }
val params = new api.ParameterList(pa, false)
val ret = retType match { case Some(rt) => reference(rt); case None => Empty }
new api.Def(Array(params), ret, typeParameters(tps), name, access(mods), modifiers(mods), annotations(annots) ++ exceptionAnnotations(exceptions))
new api.Def(Array(params), ret, typeParameters(tps), name, access(mods, enclPkg), modifiers(mods), annotations(annots) ++ exceptionAnnotations(exceptions))
}
def exceptionAnnotations(exceptions: Array[Type]): Array[api.Annotation] =
@ -140,10 +141,10 @@ object ClassToAPI
import Modifier.{isAbstract, isFinal}
new api.Modifiers( isAbstract(i), false, isFinal(i), false, false, false)
}
def access(i: Int): api.Access =
def access(i: Int, pkg: Option[String]): api.Access =
{
import Modifier.{isPublic, isPrivate, isProtected}
if(isPublic(i)) Public else if(isPrivate(i)) Private else if(isProtected(i)) Protected else error("Invalid modifiers " + i + " : no access flag set")
if(isPublic(i)) Public else if(isPrivate(i)) Private else if(isProtected(i)) Protected else packagePrivate(pkg)
}
def annotations(a: Array[Annotation]): Array[api.Annotation] = a map annotation
@ -209,6 +210,7 @@ object ClassToAPI
val Private = new api.Private(Unqualified)
val Protected = new api.Protected(Unqualified)
val Unqualified = new api.Unqualified
def packagePrivate(pkg: Option[String]): api.Access = new api.Private(new api.IdQualifier(pkg getOrElse ""))
val ArrayRef = reference("scala.Array")
val Throws = reference("scala.throws")

View File

@ -328,11 +328,21 @@ object Default
private[this] val allSubpaths = (_: File).###.***.xx.toSeq
def packageBin = (CompileInputs, CompileTask) map { (in, _) => allSubpaths(in.config.classesDirectory) }
def packageBin = concat(classMappings, resourceMappings)
def packageDoc = DocTask map allSubpaths
def packageSrc = (Resources, ResourceDirectories, Sources, SourceDirectories, Base) map {
(rs, rds, srcs, sds, base) => ( (rs x relativeTo(rds)) ++ (srcs x (relativeTo(sds)|relativeTo(base)) ) ).toSeq
def packageSrc = concat(resourceMappings, sourceMappings)
private type Mappings = Initialize[Task[Seq[(File, String)]]]
def concat(as: Mappings, bs: Mappings) = (as zipWith bs)( (a,b) => (a :^: b :^: KNil) map { case a :+: b :+: HNil => a ++ b } )
def classMappings = (CompileInputs, CompileTask) map { (in, _) => allSubpaths(in.config.classesDirectory) }
// drop base directories, since there are no valid mappings for these
def sourceMappings = (Sources, SourceDirectories, Base) map { (srcs, sdirs, base) =>
( (srcs --- sdirs --- base) x (relativeTo(sdirs)|relativeTo(base))) toSeq
}
def resourceMappings = (Resources, ResourceDirectories) map { (rs, rdirs) =>
(rs --- rdirs) x relativeTo(rdirs) toSeq
}
def jarName = JarName <<= (ModuleName, Version, ScalaVersion, CrossPaths) { (n,v, sv, withCross) =>
ArtifactName(base = n, version = v, config = "", tpe = "", ext = "jar", cross = if(withCross) sv else "")
}

View File

@ -34,7 +34,7 @@ object Package
}
def mergeAttributes(a1: Attributes, a2: Attributes) = a1 ++= a2
// merges m2 into m1 (mutating m1 in the process)
// merges `mergeManifest` into `manifest` (mutating `manifest` in the process)
def mergeManifests(manifest: Manifest, mergeManifest: Manifest)
{
mergeAttributes(manifest.getMainAttributes, mergeManifest.getMainAttributes)
@ -87,7 +87,7 @@ object Package
}
def makeJar(sources: Seq[(File, String)], jar: File, manifest: Manifest)
{
println("Packaging...")
println("Packaging " + jar.getAbsolutePath + " ...")
IO.delete(jar)
IO.jar(sources, jar, manifest)
println("Done packaging.")

View File

@ -55,10 +55,13 @@ class AggressiveCompile(cacheDirectory: File)
val compile0 = (include: Set[File], callback: AnalysisCallback) => {
IO.createDirectory(outputDirectory)
val incSrc = sources.filter(include)
val (javaSrcs, scalaSrcs) = incSrc partition javaOnly
println("Compiling:\n\t" + incSrc.mkString("\n\t"))
val arguments = cArgs(incSrc, classpath, outputDirectory, options.options)
compiler.compile(arguments, callback, maxErrors, log)
val javaSrcs = incSrc.filter(javaOnly)
if(!scalaSrcs.isEmpty)
{
val arguments = cArgs(incSrc, classpath, outputDirectory, options.options)
compiler.compile(arguments, callback, maxErrors, log)
}
if(!javaSrcs.isEmpty)
{
import Path._

View File

@ -0,0 +1,5 @@
LibraryDependencies ++= Seq(
"com.novocode" % "junit-interface" % "0.5" % "test",
"junit" % "junit" % "4.8" % "test",
"org.scala-lang" % "scala-compiler" % "2.8.1"
)

View File

@ -1,3 +0,0 @@
project.organization=test
project.name=Interpreter Project Test
project.version=1.0

View File

@ -1,8 +0,0 @@
import sbt._
class P(info: ProjectInfo) extends DefaultProject(info)
{
val bryanjswift = "Bryan J Swift Repository" at "http://repos.bryanjswift.com/maven2/"
val junitInterface = "com.novocode" % "junit-interface" % "0.4.0" % "test"
val junit = "junit" % "junit" % "4.7" % "test"
}

View File

@ -1,13 +1,10 @@
> set build.scala.versions 2.7.7 2.8.0.RC1
> reload
> +update
> +run 1
> +test
> +clean
> run 1
> test:test
> clean
> +run 2
> +test
> +clean
> run 2
> test:test
> clean
> +run -1
> +test
> run -1
> test:test

View File

@ -0,0 +1,4 @@
LibraryDependencies ++= Seq(
"org.scala-tools.testing" %% "specs" % "1.6.7.2" % "test",
"org.scala-lang" % "scala-compiler" % "2.8.1"
)

View File

@ -1,2 +0,0 @@
project.name=Run And Compiler
project.version=1.0

View File

@ -1,7 +0,0 @@
import sbt._
class A(info: ProjectInfo) extends DefaultProject(info)
{
val snaps = ScalaToolsSnapshots
val specs28 = "org.scala-tools.testing" %% "specs" % "1.6.5-SNAPSHOT" % "test"
}

View File

@ -1,3 +1 @@
> ++2.8.0.RC2
> update
> test
> test:test

View File

@ -1,5 +0,0 @@
#Project properties
#Sat Apr 18 15:26:14 EDT 2009
project.organization=empty
project.name=Java Dependency Analysis
project.version=1.0

View File

@ -1 +1 @@
> +compile
> compile

View File

@ -0,0 +1,12 @@
ScalaSource in Configurations.Compile <<= Source( _ / " scala test " )
JavaSource in Configurations.Compile <<= Source( _ / " java test " )
TaskKey("init") <<= (ScalaSource in Configurations.Compile, JavaSource in Configurations.Compile) map { (ss, js) =>
import IO._
createDirectories(ss :: js :: Nil)
copyFile(file("changes") / "Test.scala", ss / " Test s.scala")
copyFile(file("changes") / "A.java", js / "a" / "A.java")
delete(file("changes"))
}

View File

@ -1,2 +0,0 @@
project.name=Arg File Test
project.version=1.0

View File

@ -1,7 +0,0 @@
import sbt._
class A(info: ProjectInfo) extends DefaultProject(info)
{
override def mainScalaSourcePath = sourcePath / " scala test "
override def mainJavaSourcePath = sourcePath / " java test "
}

View File

@ -1 +1,2 @@
> init
> run

View File

@ -1,3 +0,0 @@
project.organization=empty
project.name=Java Test
project.version=1.0

View File

@ -3,4 +3,8 @@ package test;
public final class R {
public static final int y = 4;
public static int x = (new stest.S()).y();
public static void main(String[] args)
{
assert(args[0] == "1");
}
}

View File

@ -1 +1 @@
> +compile
> run 1

View File

@ -1,5 +0,0 @@
#Project properties
#Sat Apr 18 15:22:08 EDT 2009
project.organization=empty
project.name=Java Test
project.version=1.0

View File

@ -1,9 +0,0 @@
import sbt._
// verify that javaCompileOptions are used
class JavaProject(info: ProjectInfo) extends DefaultProject(info)
{
// make the source target 1.4 so that we get an error when these options are used
override def javaCompileOptions = ("-source" :: "1.4" :: Nil).map(JavaCompileOption(_))
println(FileUtilities.classLocationFile[JavaProject])
}

View File

@ -1,7 +1,4 @@
# need explicit versions here because we want:
# fail forall versions
# and not
# fail for any version
-> ++2.7.7 compile
-> ++2.8.0-SNAPSHOT compile
-> ++2.7.2 compile
> 'set JavacOptions :== Nil'
> compile
> 'set JavacOptions ++= Seq("-source", "1.4")'
-> compile

View File

@ -1,3 +0,0 @@
project.organization=empty
project.name=Java Test
project.version=1.0

View File

@ -1,2 +0,0 @@
project.name=Test
project.version=1.0

View File

@ -1,6 +0,0 @@
import sbt._
class TestProject(info: ProjectInfo) extends DefaultProject(info)
{
override def compileOrder = CompileOrder.JavaThenScala
}

View File

@ -1,5 +0,0 @@
package fj;
public interface F<A, B> {
B f(A a);
}

View File

@ -1,11 +0,0 @@
package scalaz
trait Dual[A] {
val value : A
}
object Dual {
implicit def dual[A](a: A) = new Dual[A] {
val value = a
}
}

View File

@ -1,3 +0,0 @@
package test
trait FImpl[A,B] extends fj.F[A,B]

View File

@ -1,4 +0,0 @@
> clean
> test
# this will fail if the sources are recompiled again (see the project definition)
> test

View File

@ -0,0 +1,11 @@
import sbt.complete.DefaultParsers._
InputKey("check-output") <<= {
val parser = token(Space ~> ( ("exists" ^^^ true) | ("absent" ^^^ false) ) )
def action(result: TaskKey[Boolean]) =
(ClassDirectory in Configurations.Compile, result) map { (dir, shouldExist) =>
if((dir / "Anon.class").exists != shouldExist) error("Top level class incorrect" )
else if( (dir / "Anon$1.class").exists != shouldExist) error("Inner class incorrect" )
}
InputTask(s => parser)(action)
}

View File

@ -1,2 +0,0 @@
project.name=Test
project.version=1.0

View File

@ -1,13 +0,0 @@
import sbt._
class AnonTest(info: ProjectInfo) extends DefaultProject(info)
{
override def compileOrder = CompileOrder.JavaThenScala
lazy val checkOutput = task { args => println(args.mkString); checkOutputTask(args(0) == "exists") }
private def checkOutputTask(shouldExist: Boolean) =
task
{
if((mainCompilePath / "Anon.class").exists != shouldExist) Some("Top level class incorrect" )
else if( (mainCompilePath / "Anon$1.class").exists != shouldExist) Some("Inner class incorrect" )
else None
}
}

View File

@ -1,6 +1,6 @@
$ copy-file changes/Anon.java src/main/java/Anon.java
> +compile
> +check-output exists
> compile
> check-output exists
$ delete src/main/java/Anon.java
> +compile
> +check-output absent
> compile
> check-output absent

View File

@ -1,4 +0,0 @@
#Project properties
#Tue Feb 03 14:28:27 EST 2009
project.name=Lazy Package Name
project.version=0.1.1

View File

@ -1,6 +0,0 @@
import sbt._
class Test(info: ProjectInfo) extends DefaultProject(info)
{
override def disableCrossPaths = true
}

View File

@ -1,11 +1,22 @@
# 'lazy-name' is not an appropriate name anymore
# This test verifies that package uses the updated name
# after changing the version. It no longer serves
# much purpose other than checking that the 'set' command
# re-evaluates the project data.
> 'set Name :== "lazy-package-name"'
> set CrossPaths :== false
> 'set Version :== "0.1.1"'
> package
$ exists "target/lazy-package-name-0.1.1.jar"
> clean
> increment-version
> 'set Version :== "0.1.2"'
> package
$ exists "target/lazy-package-name-0.1.2.jar"
> clean
> increment-version
> 'set Version :== "0.1.3"'
> package
$ exists "target/lazy-package-name-0.1.3.jar"
$ exists "target/lazy-package-name-0.1.3.jar"

View File

@ -0,0 +1,22 @@
import java.util.jar.{Attributes, Manifest}
import Path.makeString
import Keys.{Package, ScalaInstance}
import Configurations.Compile
Name :== "Jar Manifest Test"
Version :== "0.2"
CrossPaths :== false
MainClass :== Some("jartest.Main")
PackageOptions in (Compile, Package) <<= (PackageOptions in (Compile, Package), ScalaInstance) map { (opts, si) =>
def manifestExtra =
{
val mf = new Manifest
mf.getMainAttributes.put(Attributes.Name.CLASS_PATH, makeString(si.libraryJar :: Nil) )
mf
}
opts :+ sbt.Package.JarManifest(manifestExtra)
}

View File

@ -1,4 +0,0 @@
#Project properties
#Mon Feb 02 20:49:59 EST 2009
project.name=Jar Manifest Test
project.version=0.2

View File

@ -1,15 +0,0 @@
import sbt._
class ManifestTestProject(info: ProjectInfo) extends DefaultProject(info)
{
override def mainClass = Some("jartest.Main")
def manifestExtra =
{
import java.util.jar._
val mf = new Manifest
mf.getMainAttributes.put(Attributes.Name.CLASS_PATH, buildScalaInstance.libraryJar.getAbsolutePath)
mf
}
override def packageOptions = JarManifest(manifestExtra) :: super.packageOptions.toList
override def disableCrossPaths = true
}

View File

@ -0,0 +1,16 @@
Name :== "Main Resources Test"
Version :== "0.1"
CrossPaths :== false
PackageOptions <<= (PackageOptions, Keys.ScalaInstance) map { (opts, si) =>
def manifestExtra =
{
import java.util.jar._
val mf = new Manifest
mf.getMainAttributes.put(Attributes.Name.CLASS_PATH, si.libraryJar.getAbsolutePath)
mf
}
sbt.Package.JarManifest(manifestExtra) +: opts
}

View File

@ -1,4 +0,0 @@
#Project properties
#Mon Feb 02 20:49:59 EST 2009
project.name=Main Resources Test
project.version=0.1

View File

@ -1,15 +0,0 @@
import sbt._
class ManifestTestProject(info: ProjectInfo) extends DefaultProject(info)
{
override def mainClass = Some("jartest.Main")
def manifestExtra =
{
import java.util.jar._
val mf = new Manifest
mf.getMainAttributes.put(Attributes.Name.CLASS_PATH, buildScalaInstance.libraryJar.getAbsolutePath)
mf
}
override def packageOptions = JarManifest(manifestExtra) :: super.packageOptions.toList
override def disableCrossPaths = true
}