From 835ee0d1b380e3dba4cd21445136af0f5940501c Mon Sep 17 00:00:00 2001 From: Eric Bowman Date: Thu, 25 Oct 2012 14:28:13 +0100 Subject: [PATCH] XSBT-5: maven-style ivy repo support in the launcher config Change-Id: I22c1ff126961d61d92e2e45a5b7eff329d3def90 Reviewed-on: https://gerrit.gilt.com/10950 Reviewed-by: Eric Bowman Tested-by: Eric Bowman --- ivy/IvyInterface.scala | 9 +++++++++ launch.specification | 2 +- launch/ConfigurationParser.scala | 11 +++++++++-- launch/LaunchConfiguration.scala | 2 +- launch/Update.scala | 5 +++-- .../interface/src/main/java/xsbti/IvyRepository.java | 1 + main/Defaults.scala | 2 +- src/sphinx/Detailed-Topics/Launcher.rst | 2 +- 8 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ivy/IvyInterface.scala b/ivy/IvyInterface.scala index 0f37aa241..b1b9b9fcd 100644 --- a/ivy/IvyInterface.scala +++ b/ivy/IvyInterface.scala @@ -81,6 +81,15 @@ final class Patterns(val ivyPatterns: Seq[String], val artifactPatterns: Seq[Str private[sbt] def mavenStyle(): Patterns = Patterns(ivyPatterns, artifactPatterns, true) private[sbt] def withIvys(patterns: Seq[String]): Patterns = Patterns(patterns ++ ivyPatterns, artifactPatterns, isMavenCompatible) private[sbt] def withArtifacts(patterns: Seq[String]): Patterns = Patterns(ivyPatterns, patterns ++ artifactPatterns, isMavenCompatible) + override def toString = "Patterns(ivyPatterns=%s, artifactPatterns=%s, isMavenCompatible=%s)".format(ivyPatterns, artifactPatterns, isMavenCompatible) + override def equals(obj: Any): Boolean = { + obj match { + case other: Patterns => + ivyPatterns == other.ivyPatterns && artifactPatterns == other.artifactPatterns && isMavenCompatible == other.isMavenCompatible + case _ => false + } + } + override def hashCode: Int = 617 * ivyPatterns.## + 37 * artifactPatterns.## + isMavenCompatible.hashCode } object Patterns { diff --git a/launch.specification b/launch.specification index 501f7be8a..e6f5247c9 100644 --- a/launch.specification +++ b/launch.specification @@ -66,7 +66,7 @@ configuration ::= scala app repositories boot log app-properties repository ::= ( predefinedRepository | customRepository ) nl predefinedRepository ::= 'local' | 'maven-local' | 'maven-central' | 'scala-tools-releases' | 'scala-tools-snapshots' - customRepository ::= label ':' url [',' pattern] + customRepository ::= label ':' url [[',' pattern] ',' pattern [',' 'mavenCompatible']] property ::= label ':' propertyDefinition (',' propertyDefinition)* nl propertyDefinition ::= mode '=' (set | prompt) diff --git a/launch/ConfigurationParser.scala b/launch/ConfigurationParser.scala index 639ffa1b3..c399854fe 100644 --- a/launch/ConfigurationParser.scala +++ b/launch/ConfigurationParser.scala @@ -182,9 +182,16 @@ class ConfigurationParser m.toList.map { case (key, None) => Predefined(key) case (key, Some(value)) => - val r = trim(substituteVariables(value).split(",",3)) + val r = trim(substituteVariables(value).split(",",4)) val url = try { new URL(r(0)) } catch { case e: MalformedURLException => error("Invalid URL specified for '" + key + "': " + e.getMessage) } - if(r.length == 3) Ivy(key, url, r(1), r(2)) else if(r.length == 2) Ivy(key, url, r(1), r(1)) else Maven(key, url) + r.tail match { + case both :: "mavenCompatible" :: Nil => Ivy(key, url, both, both, mavenCompatible=true) + case ivy :: art :: "mavenCompatible" :: Nil => Ivy(key, url, ivy, art, mavenCompatible=true) + case ivy :: art :: Nil => Ivy(key, url, ivy, art, mavenCompatible=false) + case both :: Nil => Ivy(key, url, both, both, mavenCompatible=false) + case Nil => Maven(key, url) + case _ => error("Could not parse %s: %s".format(key, value)) + } } } def getAppProperties(m: LabelMap): List[AppProperty] = diff --git a/launch/LaunchConfiguration.scala b/launch/LaunchConfiguration.scala index 4ce99fac0..c50ef86dd 100644 --- a/launch/LaunchConfiguration.scala +++ b/launch/LaunchConfiguration.scala @@ -71,7 +71,7 @@ object Application object Repository { 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 Ivy(id: String, url: URL, ivyPattern: String, artifactPattern: String, mavenCompatible: Boolean) 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)) diff --git a/launch/Update.scala b/launch/Update.scala index e88b24318..dddb31014 100644 --- a/launch/Update.scala +++ b/launch/Update.scala @@ -291,7 +291,7 @@ final class Update(config: UpdateConfiguration) repo match { 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 i: xsbti.IvyRepository => urlResolver(i.id, i.url.toString, i.ivyPattern, i.artifactPattern, i.mavenCompatible) case p: xsbti.PredefinedRepository => p.id match { case Local => localResolver(settings.getDefaultIvyUserDir.getAbsolutePath) case MavenLocal => mavenLocal @@ -310,12 +310,13 @@ final class Update(config: UpdateConfiguration) } } /** Uses the pattern defined in BuildConfiguration to download sbt from Google code.*/ - private def urlResolver(id: String, base: String, ivyPattern: String, artifactPattern: String) = + private def urlResolver(id: String, base: String, ivyPattern: String, artifactPattern: String, mavenCompatible: Boolean) = { val resolver = new URLResolver resolver.setName(id) resolver.addIvyPattern(adjustPattern(base, ivyPattern)) resolver.addArtifactPattern(adjustPattern(base, artifactPattern)) + resolver.setM2compatible(mavenCompatible) resolver } private def adjustPattern(base: String, pattern: String): String = diff --git a/launch/interface/src/main/java/xsbti/IvyRepository.java b/launch/interface/src/main/java/xsbti/IvyRepository.java index c488bd140..5895654cd 100644 --- a/launch/interface/src/main/java/xsbti/IvyRepository.java +++ b/launch/interface/src/main/java/xsbti/IvyRepository.java @@ -8,4 +8,5 @@ public interface IvyRepository extends Repository URL url(); String ivyPattern(); String artifactPattern(); + boolean mavenCompatible(); } diff --git a/main/Defaults.scala b/main/Defaults.scala index f805f94a8..839e318c8 100755 --- a/main/Defaults.scala +++ b/main/Defaults.scala @@ -1217,7 +1217,7 @@ object Classpaths repo match { case m: xsbti.MavenRepository => MavenRepository(m.id, m.url.toString) - case i: xsbti.IvyRepository => Resolver.url(i.id, i.url)(Patterns(i.ivyPattern :: Nil, i.artifactPattern :: Nil, false)) + case i: xsbti.IvyRepository => Resolver.url(i.id, i.url)(Patterns(i.ivyPattern :: Nil, i.artifactPattern :: Nil, i.mavenCompatible)) case p: xsbti.PredefinedRepository => p.id match { case Predefined.Local => Resolver.defaultLocal case Predefined.MavenLocal => Resolver.mavenLocal diff --git a/src/sphinx/Detailed-Topics/Launcher.rst b/src/sphinx/Detailed-Topics/Launcher.rst index 478dd265b..1775ed3bf 100644 --- a/src/sphinx/Detailed-Topics/Launcher.rst +++ b/src/sphinx/Detailed-Topics/Launcher.rst @@ -106,7 +106,7 @@ by the following grammar. ``'nl'`` is a newline or end of file and resources: "resources" ":" `path` ("," `path`)* repository: ( `predefinedRepository` | `customRepository` ) `nl` predefinedRepository: "local" | "maven-local" | "maven-central" - customRepository: `label` ":" `url` [ ["," `ivyPattern`] "," `artifactPattern`] + customRepository: `label` ":" `url` [ ["," `ivyPattern`] "," `artifactPattern` [", mavenCompatible"]] property: `label` ":" `propertyDefinition` ("," `propertyDefinition`)* propertyDefinition: `mode` "=" (`set` | `prompt`) mode: "quick" | "new" | "fill"