Merge pull request #5463 from dwijnand/scripted-support-prereleases

Make ScriptedLauncher support Scala pre-releases
This commit is contained in:
eugene yokota 2020-03-12 12:59:54 -04:00 committed by GitHub
commit 6c13017075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 TestInterfaceLoader interfaceLoader = new TestInterfaceLoader(interfaceURL, topLoader);
final File[] siJars = scalaProvider.jars(); final File[] siJars = scalaProvider.jars();
final URL[] lib = new URL[1]; 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; int i = 0;
@ -108,6 +108,7 @@ public final class MetaBuildLoader extends URLClassLoader {
i += 1; i += 1;
} }
} }
assert lib[0] != null : "no scala-library.jar";
final ScalaLibraryClassLoader libraryLoader = new ScalaLibraryClassLoader(lib, interfaceLoader); final ScalaLibraryClassLoader libraryLoader = new ScalaLibraryClassLoader(lib, interfaceLoader);
final FullScalaLoader fullScalaLoader = new FullScalaLoader(scalaRest, libraryLoader); final FullScalaLoader fullScalaLoader = new FullScalaLoader(scalaRest, libraryLoader);
return new MetaBuildLoader(rest, fullScalaLoader, libraryLoader, interfaceLoader); 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 # 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 # include file:// repositories. The generated repositories section should include the local Maven repository as well
$ touch repo.all $ 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 $ delete repo.all
$ touch repo.none $ touch repo.none
> checkPom > checkPom

View File

@ -115,7 +115,7 @@ object RunFromSourceMain {
private def scalaHome(bootDirectory: File, scalaVersion: String): File = { private def scalaHome(bootDirectory: File, scalaVersion: String): File = {
val log = sbt.util.LogExchange.logger("run-from-source") val log = sbt.util.LogExchange.logger("run-from-source")
val scalaHome0 = bootDirectory / s"scala-$scalaVersion" val scalaHome0 = bootDirectory / s"scala-$scalaVersion"
if ((scalaHome0 / "lib").exists) scalaHome0 if ((scalaHome0 / "lib" / "scala-library.jar").exists) scalaHome0
else { else {
log.info(s"""scalaHome ($scalaHome0) wasn't found""") log.info(s"""scalaHome ($scalaHome0) wasn't found""")
val fakeboot = bootDirectory / "fakeboot" val fakeboot = bootDirectory / "fakeboot"
@ -129,17 +129,30 @@ object RunFromSourceMain {
val lm = { val lm = {
import sbt.librarymanagement.ivy.IvyDependencyResolution import sbt.librarymanagement.ivy.IvyDependencyResolution
val ivyConfig = InlineIvyConfiguration().withLog(log) 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 val module = "org.scala-lang" % "scala-compiler" % scalaVersion
lm.retrieve(module, scalaModuleInfo = None, scalaHome1Temp, log) match { lm.retrieve(module, scalaModuleInfo = None, scalaHome1Temp, log) match {
case Left(w) => throw w.resolveException
case Right(_) => case Right(_) =>
(scalaHome1Temp ** "*.jar").get foreach { x => val jars = (scalaHome1Temp ** "*.jar").get
val Name(head, _) = x.getName assert(jars.nonEmpty, s"no jars for scala $scalaVersion")
IO.copyFile(x, scalaHome1Lib / (head + ".jar")) 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 scalaHome1

View File

@ -32,6 +32,7 @@ import xsbti.ComponentProvider;
import xsbti.CrossValue; import xsbti.CrossValue;
import xsbti.GlobalLock; import xsbti.GlobalLock;
import xsbti.Launcher; import xsbti.Launcher;
import xsbti.MavenRepository;
import xsbti.Predefined; import xsbti.Predefined;
import xsbti.PredefinedRepository; import xsbti.PredefinedRepository;
import xsbti.Repository; import xsbti.Repository;
@ -335,8 +336,15 @@ public class ScriptedLauncher {
private final ScalaProvider sp = this; private final ScalaProvider sp = this;
private final String scalaOrg = "org.scala-lang"; private final String scalaOrg = "org.scala-lang";
private final Repository[] repos = private final Repository[] repos =
new PredefinedRepository[] { new Repository[] {
() -> Predefined.Local, () -> Predefined.MavenCentral (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 = private final Launcher launcher =
new Launcher() { new Launcher() {
@ -544,4 +552,22 @@ public class ScriptedLauncher {
} catch (final IOException e) { } 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);
}
}
};
}
} }