Skip to content

Commit

Permalink
Library management API
Browse files Browse the repository at this point in the history
This splits the core of LM and Ivy-based implementation.

- InlineConfiguration is renamed to ModuleConfiguration
- IvyScala is renamed to ScalaModuleInfo
- UpdateConfiguration, RetrieveConfiguration, PublishConfiguration are refactored to use builder pattern.
- Adds ConfigRef for referencing Configuration
- Moves syntax related things into `sbt.librarymagement.syntax`
  • Loading branch information
eed3si9n committed Jul 11, 2017
1 parent f8d3718 commit 0211517
Show file tree
Hide file tree
Showing 246 changed files with 2,441 additions and 1,632 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
librarymanagement module for sbt
================================

```
git clone --no-hardlinks --branch 0.13 sbt sbt-modules/librarymanagement
cd sbt-modules/librarymanagement
git filter-branch --index-filter 'git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- ivy util/cross' --prune-empty
git reset --hard
git gc --aggressive
git prune
git cb 1.0
```scala
scala> import java.io.File
import java.io.File

scala> import sbt.librarymanagement._, syntax._
import sbt.librarymanagement._
import syntax._

scala> val log = sbt.util.LogExchange.logger("test")
log: sbt.internal.util.ManagedLogger = sbt.internal.util.ManagedLogger@c439b0f

scala> val lm = {
import sbt.librarymanagement.ivy._
val ivyConfig = InlineIvyConfiguration().withLog(log)
IvyLibraryManagement(ivyConfig)
}
lm: sbt.librarymanagement.LibraryManagement = sbt.librarymanagement.ivy.IvyLibraryManagement@11c07acb

scala> val module = "commons-io" % "commons-io" % "2.5"
module: sbt.librarymanagement.ModuleID = commons-io:commons-io:2.5

scala> lm.retrieve(module, scalaModuleInfo = None, new File("target"), log)
res0: Either[sbt.librarymanagement.UnresolvedWarning,Vector[java.io.File]] = Right(Vector(target/jars/commons-io/commons-io/commons-io-2.5.jar, target/jars/commons-io/commons-io/commons-io-2.5.jar, target/jars/commons-io/commons-io/commons-io-2.5.jar))
```
23 changes: 18 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def commonSettings: Seq[Setting[_]] = Seq(
)

lazy val lmRoot = (project in file("."))
.aggregate(lm)
.aggregate(lmCore, lmIvy)
.settings(
inThisBuild(
Seq(
Expand Down Expand Up @@ -60,12 +60,12 @@ lazy val lmRoot = (project in file("."))
customCommands
)

lazy val lm = (project in file("librarymanagement"))
lazy val lmCore = (project in file("core"))
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
.settings(
commonSettings,
name := "librarymanagement",
libraryDependencies ++= Seq(ivy,
jsch,
name := "librarymanagement-core",
libraryDependencies ++= Seq(jsch,
scalaReflect.value,
scalaCompiler.value,
launcherInterface,
Expand Down Expand Up @@ -94,7 +94,20 @@ lazy val lm = (project in file("librarymanagement"))
}
)
.configure(addSbtIO, addSbtUtilLogging, addSbtUtilPosition, addSbtUtilCache)

lazy val lmIvy = (project in file("ivy"))
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
.dependsOn(lmCore)
.settings(
commonSettings,
name := "librarymanagement-ivy",
libraryDependencies ++= Seq(ivy, scalaTest, scalaCheck),
managedSourceDirectories in Compile +=
baseDirectory.value / "src" / "main" / "contraband-scala",
sourceManaged in (Compile, generateContrabands) := baseDirectory.value / "src" / "main" / "contraband-scala",
contrabandFormatsForType in generateContrabands in Compile := DatatypeConfig.getFormats,
scalacOptions in (Compile, console) --= Vector("-Ywarn-unused-import", "-Ywarn-unused", "-Xlint"),
)

def customCommands: Seq[Setting[_]] = Seq(
commands += Command.command("release") { state =>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
final class GetClassifiersConfiguration private (
val module: sbt.librarymanagement.GetClassifiersModule,
val excludes: Vector[scala.Tuple2[sbt.librarymanagement.ModuleID, scala.Vector[sbt.librarymanagement.ConfigRef]]],
val updateConfiguration: sbt.librarymanagement.UpdateConfiguration,
val sourceArtifactTypes: Vector[String],
val docArtifactTypes: Vector[String]) extends Serializable {



override def equals(o: Any): Boolean = o match {
case x: GetClassifiersConfiguration => (this.module == x.module) && (this.excludes == x.excludes) && (this.updateConfiguration == x.updateConfiguration) && (this.sourceArtifactTypes == x.sourceArtifactTypes) && (this.docArtifactTypes == x.docArtifactTypes)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (37 * (17 + "GetClassifiersConfiguration".##) + module.##) + excludes.##) + updateConfiguration.##) + sourceArtifactTypes.##) + docArtifactTypes.##)
}
override def toString: String = {
"GetClassifiersConfiguration(" + module + ", " + excludes + ", " + updateConfiguration + ", " + sourceArtifactTypes + ", " + docArtifactTypes + ")"
}
protected[this] def copy(module: sbt.librarymanagement.GetClassifiersModule = module, excludes: Vector[scala.Tuple2[sbt.librarymanagement.ModuleID, scala.Vector[sbt.librarymanagement.ConfigRef]]] = excludes, updateConfiguration: sbt.librarymanagement.UpdateConfiguration = updateConfiguration, sourceArtifactTypes: Vector[String] = sourceArtifactTypes, docArtifactTypes: Vector[String] = docArtifactTypes): GetClassifiersConfiguration = {
new GetClassifiersConfiguration(module, excludes, updateConfiguration, sourceArtifactTypes, docArtifactTypes)
}
def withModule(module: sbt.librarymanagement.GetClassifiersModule): GetClassifiersConfiguration = {
copy(module = module)
}
def withExcludes(excludes: Vector[scala.Tuple2[sbt.librarymanagement.ModuleID, scala.Vector[sbt.librarymanagement.ConfigRef]]]): GetClassifiersConfiguration = {
copy(excludes = excludes)
}
def withUpdateConfiguration(updateConfiguration: sbt.librarymanagement.UpdateConfiguration): GetClassifiersConfiguration = {
copy(updateConfiguration = updateConfiguration)
}
def withSourceArtifactTypes(sourceArtifactTypes: Vector[String]): GetClassifiersConfiguration = {
copy(sourceArtifactTypes = sourceArtifactTypes)
}
def withDocArtifactTypes(docArtifactTypes: Vector[String]): GetClassifiersConfiguration = {
copy(docArtifactTypes = docArtifactTypes)
}
}
object GetClassifiersConfiguration {

def apply(module: sbt.librarymanagement.GetClassifiersModule, excludes: Vector[scala.Tuple2[sbt.librarymanagement.ModuleID, scala.Vector[sbt.librarymanagement.ConfigRef]]], updateConfiguration: sbt.librarymanagement.UpdateConfiguration, sourceArtifactTypes: Vector[String], docArtifactTypes: Vector[String]): GetClassifiersConfiguration = new GetClassifiersConfiguration(module, excludes, updateConfiguration, sourceArtifactTypes, docArtifactTypes)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait GetClassifiersConfigurationFormats { self: sbt.librarymanagement.GetClassifiersModuleFormats with sbt.librarymanagement.ModuleIDFormats with sbt.librarymanagement.ConfigRefFormats with sbt.librarymanagement.UpdateConfigurationFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val GetClassifiersConfigurationFormat: JsonFormat[sbt.librarymanagement.GetClassifiersConfiguration] = new JsonFormat[sbt.librarymanagement.GetClassifiersConfiguration] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.librarymanagement.GetClassifiersConfiguration = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val module = unbuilder.readField[sbt.librarymanagement.GetClassifiersModule]("module")
val excludes = unbuilder.readField[Vector[scala.Tuple2[sbt.librarymanagement.ModuleID, scala.Vector[sbt.librarymanagement.ConfigRef]]]]("excludes")
val updateConfiguration = unbuilder.readField[sbt.librarymanagement.UpdateConfiguration]("updateConfiguration")
val sourceArtifactTypes = unbuilder.readField[Vector[String]]("sourceArtifactTypes")
val docArtifactTypes = unbuilder.readField[Vector[String]]("docArtifactTypes")
unbuilder.endObject()
sbt.librarymanagement.GetClassifiersConfiguration(module, excludes, updateConfiguration, sourceArtifactTypes, docArtifactTypes)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.librarymanagement.GetClassifiersConfiguration, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("module", obj.module)
builder.addField("excludes", obj.excludes)
builder.addField("updateConfiguration", obj.updateConfiguration)
builder.addField("sourceArtifactTypes", obj.sourceArtifactTypes)
builder.addField("docArtifactTypes", obj.docArtifactTypes)
builder.endObject()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
final class GetClassifiersModule private (
val id: sbt.librarymanagement.ModuleID,
val scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo],
val dependencies: Vector[sbt.librarymanagement.ModuleID],
val configurations: Vector[sbt.librarymanagement.Configuration],
val classifiers: Vector[String]) extends Serializable {



override def equals(o: Any): Boolean = o match {
case x: GetClassifiersModule => (this.id == x.id) && (this.scalaModuleInfo == x.scalaModuleInfo) && (this.dependencies == x.dependencies) && (this.configurations == x.configurations) && (this.classifiers == x.classifiers)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (37 * (17 + "GetClassifiersModule".##) + id.##) + scalaModuleInfo.##) + dependencies.##) + configurations.##) + classifiers.##)
}
override def toString: String = {
"GetClassifiersModule(" + id + ", " + scalaModuleInfo + ", " + dependencies + ", " + configurations + ", " + classifiers + ")"
}
protected[this] def copy(id: sbt.librarymanagement.ModuleID = id, scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo] = scalaModuleInfo, dependencies: Vector[sbt.librarymanagement.ModuleID] = dependencies, configurations: Vector[sbt.librarymanagement.Configuration] = configurations, classifiers: Vector[String] = classifiers): GetClassifiersModule = {
new GetClassifiersModule(id, scalaModuleInfo, dependencies, configurations, classifiers)
}
def withId(id: sbt.librarymanagement.ModuleID): GetClassifiersModule = {
copy(id = id)
}
def withScalaModuleInfo(scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo]): GetClassifiersModule = {
copy(scalaModuleInfo = scalaModuleInfo)
}
def withScalaModuleInfo(scalaModuleInfo: sbt.librarymanagement.ScalaModuleInfo): GetClassifiersModule = {
copy(scalaModuleInfo = Option(scalaModuleInfo))
}
def withDependencies(dependencies: Vector[sbt.librarymanagement.ModuleID]): GetClassifiersModule = {
copy(dependencies = dependencies)
}
def withConfigurations(configurations: Vector[sbt.librarymanagement.Configuration]): GetClassifiersModule = {
copy(configurations = configurations)
}
def withClassifiers(classifiers: Vector[String]): GetClassifiersModule = {
copy(classifiers = classifiers)
}
}
object GetClassifiersModule {

def apply(id: sbt.librarymanagement.ModuleID, scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo], dependencies: Vector[sbt.librarymanagement.ModuleID], configurations: Vector[sbt.librarymanagement.Configuration], classifiers: Vector[String]): GetClassifiersModule = new GetClassifiersModule(id, scalaModuleInfo, dependencies, configurations, classifiers)
def apply(id: sbt.librarymanagement.ModuleID, scalaModuleInfo: sbt.librarymanagement.ScalaModuleInfo, dependencies: Vector[sbt.librarymanagement.ModuleID], configurations: Vector[sbt.librarymanagement.Configuration], classifiers: Vector[String]): GetClassifiersModule = new GetClassifiersModule(id, Option(scalaModuleInfo), dependencies, configurations, classifiers)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait GetClassifiersModuleFormats { self: sbt.librarymanagement.ModuleIDFormats with sbt.librarymanagement.ScalaModuleInfoFormats with sbt.librarymanagement.ConfigurationFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val GetClassifiersModuleFormat: JsonFormat[sbt.librarymanagement.GetClassifiersModule] = new JsonFormat[sbt.librarymanagement.GetClassifiersModule] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.librarymanagement.GetClassifiersModule = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val id = unbuilder.readField[sbt.librarymanagement.ModuleID]("id")
val scalaModuleInfo = unbuilder.readField[Option[sbt.librarymanagement.ScalaModuleInfo]]("scalaModuleInfo")
val dependencies = unbuilder.readField[Vector[sbt.librarymanagement.ModuleID]]("dependencies")
val configurations = unbuilder.readField[Vector[sbt.librarymanagement.Configuration]]("configurations")
val classifiers = unbuilder.readField[Vector[String]]("classifiers")
unbuilder.endObject()
sbt.librarymanagement.GetClassifiersModule(id, scalaModuleInfo, dependencies, configurations, classifiers)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.librarymanagement.GetClassifiersModule, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("id", obj.id)
builder.addField("scalaModuleInfo", obj.scalaModuleInfo)
builder.addField("dependencies", obj.dependencies)
builder.addField("configurations", obj.configurations)
builder.addField("classifiers", obj.classifiers)
builder.endObject()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
final class IvyFileConfiguration private (
validate: Boolean,
scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo],
val file: java.io.File,
val autoScalaTools: Boolean) extends sbt.librarymanagement.ModuleSettings(validate, scalaModuleInfo) with Serializable {

private def this(file: java.io.File, autoScalaTools: Boolean) = this(false, None, file, autoScalaTools)

override def equals(o: Any): Boolean = o match {
case x: IvyFileConfiguration => (this.validate == x.validate) && (this.scalaModuleInfo == x.scalaModuleInfo) && (this.file == x.file) && (this.autoScalaTools == x.autoScalaTools)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (17 + "IvyFileConfiguration".##) + validate.##) + scalaModuleInfo.##) + file.##) + autoScalaTools.##)
}
override def toString: String = {
"IvyFileConfiguration(" + validate + ", " + scalaModuleInfo + ", " + file + ", " + autoScalaTools + ")"
}
protected[this] def copy(validate: Boolean = validate, scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo] = scalaModuleInfo, file: java.io.File = file, autoScalaTools: Boolean = autoScalaTools): IvyFileConfiguration = {
new IvyFileConfiguration(validate, scalaModuleInfo, file, autoScalaTools)
}
def withValidate(validate: Boolean): IvyFileConfiguration = {
copy(validate = validate)
}
def withScalaModuleInfo(scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo]): IvyFileConfiguration = {
copy(scalaModuleInfo = scalaModuleInfo)
}
def withScalaModuleInfo(scalaModuleInfo: sbt.librarymanagement.ScalaModuleInfo): IvyFileConfiguration = {
copy(scalaModuleInfo = Option(scalaModuleInfo))
}
def withFile(file: java.io.File): IvyFileConfiguration = {
copy(file = file)
}
def withAutoScalaTools(autoScalaTools: Boolean): IvyFileConfiguration = {
copy(autoScalaTools = autoScalaTools)
}
}
object IvyFileConfiguration {

def apply(file: java.io.File, autoScalaTools: Boolean): IvyFileConfiguration = new IvyFileConfiguration(false, None, file, autoScalaTools)
def apply(validate: Boolean, scalaModuleInfo: Option[sbt.librarymanagement.ScalaModuleInfo], file: java.io.File, autoScalaTools: Boolean): IvyFileConfiguration = new IvyFileConfiguration(validate, scalaModuleInfo, file, autoScalaTools)
def apply(validate: Boolean, scalaModuleInfo: sbt.librarymanagement.ScalaModuleInfo, file: java.io.File, autoScalaTools: Boolean): IvyFileConfiguration = new IvyFileConfiguration(validate, Option(scalaModuleInfo), file, autoScalaTools)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
// DO NOT EDIT MANUALLY
package sbt.librarymanagement
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait IvyFileConfigurationFormats { self: sbt.librarymanagement.IvyScalaFormats with sjsonnew.BasicJsonProtocol =>
trait IvyFileConfigurationFormats { self: sbt.librarymanagement.ScalaModuleInfoFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val IvyFileConfigurationFormat: JsonFormat[sbt.librarymanagement.IvyFileConfiguration] = new JsonFormat[sbt.librarymanagement.IvyFileConfiguration] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.librarymanagement.IvyFileConfiguration = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val validate = unbuilder.readField[Boolean]("validate")
val ivyScala = unbuilder.readField[Option[sbt.librarymanagement.IvyScala]]("ivyScala")
val scalaModuleInfo = unbuilder.readField[Option[sbt.librarymanagement.ScalaModuleInfo]]("scalaModuleInfo")
val file = unbuilder.readField[java.io.File]("file")
val autoScalaTools = unbuilder.readField[Boolean]("autoScalaTools")
unbuilder.endObject()
sbt.librarymanagement.IvyFileConfiguration(validate, ivyScala, file, autoScalaTools)
sbt.librarymanagement.IvyFileConfiguration(validate, scalaModuleInfo, file, autoScalaTools)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.librarymanagement.IvyFileConfiguration, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("validate", obj.validate)
builder.addField("ivyScala", obj.ivyScala)
builder.addField("scalaModuleInfo", obj.scalaModuleInfo)
builder.addField("file", obj.file)
builder.addField("autoScalaTools", obj.autoScalaTools)
builder.endObject()
Expand Down
Loading

0 comments on commit 0211517

Please sign in to comment.