Skip to content

Commit

Permalink
expose launcher repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
harrah committed Jul 20, 2011
1 parent 0b3ec05 commit 67db9cc
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 30 deletions.
2 changes: 1 addition & 1 deletion launch/ConfigurationParser.scala
Expand Up @@ -137,7 +137,7 @@ class ConfigurationParser
val app = new Application(org, name, rev, main, components, toBoolean(crossVersioned), classpathExtra)
(app, classifiers)
}
def getRepositories(m: LabelMap): List[Repository] =
def getRepositories(m: LabelMap): List[xsbti.Repository] =
{
import Repository.{Ivy, Maven, Predefined}
m.toList.map {
Expand Down
3 changes: 2 additions & 1 deletion launch/Launch.scala
Expand Up @@ -89,6 +89,7 @@ class Launch private[xsbt](val bootDirectory: File, val lockBoot: Boolean, val i

def globalLock: xsbti.GlobalLock = Locks
def ivyHome = ivyOptions.ivyHome.orNull
def ivyRepositories = repositories.toArray

class JNAProvider extends Provider
{
Expand Down Expand Up @@ -151,7 +152,7 @@ class Launch private[xsbt](val bootDirectory: File, val lockBoot: Boolean, val i
}
object Launcher
{
def apply(bootDirectory: File, repositories: List[Repository]): xsbti.Launcher =
def apply(bootDirectory: File, repositories: List[xsbti.Repository]): xsbti.Launcher =
apply(bootDirectory, IvyOptions(None, Classifiers(Nil, Nil), repositories))
def apply(bootDirectory: File, ivyOptions: IvyOptions): xsbti.Launcher =
apply(bootDirectory, ivyOptions, GetLocks.find)
Expand Down
24 changes: 8 additions & 16 deletions launch/LaunchConfiguration.scala
Expand Up @@ -20,7 +20,7 @@ final case class LaunchConfiguration(scalaVersion: Value[String], ivyConfigurati
LaunchConfiguration(new Explicit(newScalaVersion), ivyConfiguration.copy(classifiers = classifiers0), app.withVersion(new Explicit(newAppVersion)), boot, logging, appProperties)
def map(f: File => File) = LaunchConfiguration(scalaVersion, ivyConfiguration, app.map(f), boot.map(f), logging, appProperties)
}
final case class IvyOptions(ivyHome: Option[File], classifiers: Classifiers, repositories: List[Repository])
final case class IvyOptions(ivyHome: Option[File], classifiers: Classifiers, repositories: List[xsbti.Repository])

sealed trait Value[T]
final class Explicit[T](val value: T) extends Value[T] {
Expand Down Expand Up @@ -61,25 +61,17 @@ object Application
}
}

sealed trait Repository
object Repository
{
final case class Maven(id: String, url: URL) extends Repository
final case class Ivy(id: String, url: URL, ivyPattern: String, artifactPattern: String) extends Repository
final case class Predefined(id: Predefined.Value) extends Repository

object Predefined extends Enumeration
{
val Local = value("local")
val MavenLocal = value("maven-local")
val MavenCentral = value("maven-central")
val ScalaToolsReleases = value("scala-tools-releases")
val ScalaToolsSnapshots = value("scala-tools-snapshots")
def apply(s: String): Predefined = Predefined(toValue(s))
final case class Maven(id: String, url: URL) extends xsbti.MavenRepository
final case class Ivy(id: String, url: URL, ivyPattern: String, artifactPattern: String) extends xsbti.IvyRepository
final case class Predefined(id: xsbti.Predefined) extends xsbti.PredefinedRepository
object Predefined {
def apply(s: String): Predefined = Predefined(xsbti.Predefined.toValue(s))
}

def isMavenLocal(repo: Repository) = repo == Predefined(Predefined.MavenLocal)
def defaults: List[Repository] = Predefined.elements.map(Predefined.apply).toList
def isMavenLocal(repo: xsbti.Repository) = repo match { case p: xsbti.PredefinedRepository => p.id == xsbti.Predefined.MavenLocal; case _ => false }
def defaults: List[xsbti.Repository] = xsbti.Predefined.values.map(Predefined.apply).toList
}

final case class Search(tpe: Search.Value, paths: List[File])
Expand Down
25 changes: 13 additions & 12 deletions launch/Update.scala
Expand Up @@ -32,7 +32,7 @@ sealed trait UpdateTarget { def tpe: String; def classifiers: List[String] }
final class UpdateScala(val classifiers: List[String]) extends UpdateTarget { def tpe = "scala" }
final class UpdateApp(val id: Application, val classifiers: List[String]) extends UpdateTarget { def tpe = "app" }

final class UpdateConfiguration(val bootDirectory: File, val ivyHome: Option[File], val scalaVersion: String, val repositories: List[Repository])
final class UpdateConfiguration(val bootDirectory: File, val ivyHome: Option[File], val scalaVersion: String, val repositories: List[xsbti.Repository])

/** Ensures that the Scala and application jars exist for the given versions or else downloads them.*/
final class Update(config: UpdateConfiguration)
Expand Down Expand Up @@ -229,7 +229,7 @@ final class Update(config: UpdateConfiguration)
artifact.getQualifiedExtraAttributes.keys.exists(_.asInstanceOf[String] startsWith "m:")
}
// exclude the local Maven repository for Scala -SNAPSHOTs
private def includeRepo(repo: Repository) = !(Repository.isMavenLocal(repo) && isSnapshot(scalaVersion) )
private def includeRepo(repo: xsbti.Repository) = !(Repository.isMavenLocal(repo) && isSnapshot(scalaVersion) )
private def isSnapshot(scalaVersion: String) = scalaVersion.endsWith(Snapshot)
private[this] val Snapshot = "-SNAPSHOT"
private[this] val ChangingPattern = ".*" + Snapshot
Expand All @@ -243,19 +243,20 @@ final class Update(config: UpdateConfiguration)
settings.addRepositoryCacheManager(manager)
settings.setDefaultRepositoryCacheManager(manager)
}
private def toIvyRepository(settings: IvySettings, repo: Repository) =
private def toIvyRepository(settings: IvySettings, repo: xsbti.Repository) =
{
import Repository.{Ivy, Maven, Predefined}
import Predefined._
import xsbti.Predefined._
repo match
{
case Maven(id, url) => mavenResolver(id, url.toString)
case Ivy(id, url, ivyPattern, artifactPattern) => urlResolver(id, url.toString, ivyPattern, artifactPattern)
case Predefined(Local) => localResolver(settings.getDefaultIvyUserDir.getAbsolutePath)
case Predefined(MavenLocal) => mavenLocal
case Predefined(MavenCentral) => mavenMainResolver
case Predefined(ScalaToolsReleases) => mavenResolver("Scala-Tools Maven2 Repository", "http://scala-tools.org/repo-releases")
case Predefined(ScalaToolsSnapshots) => scalaSnapshots(scalaVersion)
case m: xsbti.MavenRepository => mavenResolver(m.id, m.url.toString)
case i: xsbti.IvyRepository => urlResolver(i.id, i.url.toString, i.ivyPattern, i.artifactPattern)
case p: xsbti.PredefinedRepository => p.id match {
case Local => localResolver(settings.getDefaultIvyUserDir.getAbsolutePath)
case MavenLocal => mavenLocal
case MavenCentral => mavenMainResolver
case ScalaToolsReleases => mavenResolver("Scala-Tools Maven2 Repository", "http://scala-tools.org/repo-releases")
case ScalaToolsSnapshots => scalaSnapshots(scalaVersion)
}
}
}
private def onDefaultRepositoryCacheManager(settings: IvySettings)(f: DefaultRepositoryCacheManager => Unit)
Expand Down
11 changes: 11 additions & 0 deletions launch/interface/src/main/java/xsbti/IvyRepository.java
@@ -0,0 +1,11 @@
package xsbti;

import java.net.URL;

public interface IvyRepository extends Repository
{
String id();
URL url();
String ivyPattern();
String artifactPattern();
}
1 change: 1 addition & 0 deletions launch/interface/src/main/java/xsbti/Launcher.java
Expand Up @@ -10,6 +10,7 @@ public interface Launcher
public ClassLoader topLoader();
public GlobalLock globalLock();
public File bootDirectory();
public xsbti.Repository[] ivyRepositories();
// null if none set
public File ivyHome();
}
9 changes: 9 additions & 0 deletions launch/interface/src/main/java/xsbti/MavenRepository.java
@@ -0,0 +1,9 @@
package xsbti;

import java.net.URL;

public interface MavenRepository extends Repository
{
String id();
URL url();
}
27 changes: 27 additions & 0 deletions launch/interface/src/main/java/xsbti/Predefined.java
@@ -0,0 +1,27 @@
package xsbti;

public enum Predefined
{
Local("local"),
MavenLocal("maven-local"),
MavenCentral("maven-central"),
ScalaToolsReleases("scala-tools-releases"),
ScalaToolsSnapshots("scala-tools-snapshots");

private final String label;
private Predefined(String label) { this.label = label; }
public String toString() { return label; }

public static Predefined toValue(String s)
{
for(Predefined p : values())
if(s.equals(p.toString()))
return p;

StringBuilder msg = new StringBuilder("Expected one of ");
for(Predefined p : values())
msg.append(p.toString()).append(", ");
msg.append("got '").append(s).append("'.");
throw new RuntimeException(msg.toString());
}
}
@@ -0,0 +1,6 @@
package xsbti;

public interface PredefinedRepository extends Repository
{
Predefined id();
}
3 changes: 3 additions & 0 deletions launch/interface/src/main/java/xsbti/Repository.java
@@ -0,0 +1,3 @@
package xsbti;

public interface Repository {}

0 comments on commit 67db9cc

Please sign in to comment.