Make ScriptedLauncher support Scala pre-releases

Also add a dash of sanity checks here and there.
This commit is contained in:
Dale Wijnand 2020-03-04 22:52:03 +00:00
parent 0b12862caf
commit b58c99efee
4 changed files with 52 additions and 13 deletions

View File

@ -92,7 +92,7 @@ public final class MetaBuildLoader extends URLClassLoader {
final TestInterfaceLoader interfaceLoader = new TestInterfaceLoader(interfaceURL, topLoader);
final File[] siJars = scalaProvider.jars();
final URL[] lib = new URL[1];
final URL[] scalaRest = new URL[siJars.length - 1];
final URL[] scalaRest = new URL[Math.max(0, siJars.length - 1)];
{
int i = 0;
@ -108,6 +108,7 @@ public final class MetaBuildLoader extends URLClassLoader {
i += 1;
}
}
assert lib[0] != null : "no scala-library.jar";
final ScalaLibraryClassLoader libraryLoader = new ScalaLibraryClassLoader(lib, interfaceLoader);
final FullScalaLoader fullScalaLoader = new FullScalaLoader(scalaRest, libraryLoader);
return new MetaBuildLoader(rest, fullScalaLoader, libraryLoader, interfaceLoader);

View File

@ -1,11 +1,10 @@
# write the default pom. The only repositories should be Scala Tools Releases and Snapshots
> checkPom https://oss.sonatype.org/content/repositories/releases/ https://oss.sonatype.org/content/repositories/snapshots/
> checkPom https://scala-ci.typesafe.com/artifactory/scala-integration/ https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots/ https://oss.sonatype.org/content/repositories/releases/ https://oss.sonatype.org/content/repositories/snapshots/
# include file:// repositories. The generated repositories section should include the local Maven repository as well
$ touch repo.all
> checkPom https://oss.sonatype.org/content/repositories/releases/ https://oss.sonatype.org/content/repositories/snapshots/ file://*.m2/repository/
> checkPom https://scala-ci.typesafe.com/artifactory/scala-integration/ https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots/ https://oss.sonatype.org/content/repositories/releases/ https://oss.sonatype.org/content/repositories/snapshots/ file://*.m2/repository/
# include file:// repositories. The generated repositories section should include the local Maven repository as well
$ delete repo.all
$ touch repo.none
> checkPom

View File

@ -115,7 +115,7 @@ object RunFromSourceMain {
private def scalaHome(bootDirectory: File, scalaVersion: String): File = {
val log = sbt.util.LogExchange.logger("run-from-source")
val scalaHome0 = bootDirectory / s"scala-$scalaVersion"
if ((scalaHome0 / "lib").exists) scalaHome0
if ((scalaHome0 / "lib" / "scala-library.jar").exists) scalaHome0
else {
log.info(s"""scalaHome ($scalaHome0) wasn't found""")
val fakeboot = bootDirectory / "fakeboot"
@ -129,17 +129,30 @@ object RunFromSourceMain {
val lm = {
import sbt.librarymanagement.ivy.IvyDependencyResolution
val ivyConfig = InlineIvyConfiguration().withLog(log)
IvyDependencyResolution(ivyConfig)
IvyDependencyResolution(
ivyConfig.withResolvers(
ivyConfig.resolvers ++ Seq(
"scala-ea" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
"scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots/",
)
)
)
}
val Name = """(.*)(\-[\d|\.]+)\.jar""".r
val Name = """(.*)(?:\-[\d.]+)\.jar""".r
val BinPre = """(.*)(?:\-[\d.]+)-(?:bin|pre)-.*\.jar""".r
val module = "org.scala-lang" % "scala-compiler" % scalaVersion
lm.retrieve(module, scalaModuleInfo = None, scalaHome1Temp, log) match {
case Left(w) => throw w.resolveException
case Right(_) =>
(scalaHome1Temp ** "*.jar").get foreach { x =>
val Name(head, _) = x.getName
IO.copyFile(x, scalaHome1Lib / (head + ".jar"))
val jars = (scalaHome1Temp ** "*.jar").get
assert(jars.nonEmpty, s"no jars for scala $scalaVersion")
jars.foreach { f =>
val name = f.getName match {
case Name(name) => name
case BinPre(name) => name
}
IO.copyFile(f, scalaHome1Lib / s"$name.jar")
}
case Left(w) => sys.error(w.toString)
}
}
scalaHome1

View File

@ -32,6 +32,7 @@ import xsbti.ComponentProvider;
import xsbti.CrossValue;
import xsbti.GlobalLock;
import xsbti.Launcher;
import xsbti.MavenRepository;
import xsbti.Predefined;
import xsbti.PredefinedRepository;
import xsbti.Repository;
@ -335,8 +336,15 @@ public class ScriptedLauncher {
private final ScalaProvider sp = this;
private final String scalaOrg = "org.scala-lang";
private final Repository[] repos =
new PredefinedRepository[] {
() -> Predefined.Local, () -> Predefined.MavenCentral
new Repository[] {
(PredefinedRepository) () -> Predefined.Local,
(PredefinedRepository) () -> Predefined.MavenCentral,
newMavenRepo(
"scala-ea",
"https://scala-ci.typesafe.com/artifactory/scala-integration/"),
newMavenRepo(
"scala-pr",
"https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots/")
};
private final Launcher launcher =
new Launcher() {
@ -544,4 +552,22 @@ public class ScriptedLauncher {
} catch (final IOException e) {
}
}
private static MavenRepository newMavenRepo(final String id, final String url) {
return new MavenRepository() {
@Override
public String id() {
return id;
}
@Override
public URL url() {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
};
}
}