Use delegation instead of inheritance

This commit is contained in:
Eugene Yokota 2017-07-12 07:42:30 -04:00
parent a98c5f4c65
commit 7844190964
5 changed files with 83 additions and 11 deletions

View File

@ -6,12 +6,21 @@ import sbt.io.Hash
import sbt.librarymanagement.syntax._
/**
* Helper mixin to provide methods for library management
* Library management API to resolve dependencies.
*/
abstract class LibraryManagement extends LibraryManagementInterface {
class LibraryManagement private[sbt] (lmEngine: LibraryManagementInterface) {
import sbt.internal.librarymanagement.InternalDefaults._
import sbt.internal.librarymanagement.UpdateClassifiersUtil._
/**
* Builds a ModuleDescriptor that describes a subproject with dependencies.
*
* @param moduleSetting It contains the information about the module including the dependencies.
* @return A `ModuleDescriptor` describing a subproject and its dependencies.
*/
def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor =
lmEngine.moduleDescriptor(moduleSetting)
/**
* Build a ModuleDescriptor that describes a subproject with dependencies.
*
@ -30,6 +39,22 @@ abstract class LibraryManagement extends LibraryManagementInterface {
moduleDescriptor(moduleSetting)
}
/**
* Resolves the given module's dependencies performing a retrieval.
*
* @param module The module to be resolved.
* @param configuration The update configuration.
* @param uwconfig The configuration to handle unresolved warnings.
* @param log The logger.
* @return The result, either an unresolved warning or an update report. Note that this
* update report will or will not be successful depending on the `missingOk` option.
*/
def update(module: ModuleDescriptor,
configuration: UpdateConfiguration,
uwconfig: UnresolvedWarningConfiguration,
log: Logger): Either[UnresolvedWarning, UpdateReport] =
lmEngine.update(module, configuration, uwconfig, log)
/**
* Returns a `ModuleDescriptor` that depends on `dependencyId`.
*
@ -192,7 +217,7 @@ abstract class LibraryManagement extends LibraryManagementInterface {
}).mkString(", ")
}
/**
* Helper mixin to provide methods for publisher
*/
abstract class Publisher extends PublisherInterface
object LibraryManagement {
def apply(lmEngine: LibraryManagementInterface): LibraryManagement =
new LibraryManagement(lmEngine)
}

View File

@ -4,7 +4,7 @@ import java.io.File
import sbt.util.Logger
/**
* Interface for library management
* Interface for library management intended for library management engine authors.
*/
abstract class LibraryManagementInterface {

View File

@ -0,0 +1,47 @@
package sbt.librarymanagement
import java.io.File
import sbt.util.Logger
/**
* Library management API to publish artifacts.
*/
class Publisher private[sbt] (publisherEngine: PublisherInterface) {
/**
* Builds a ModuleDescriptor that describes a subproject with dependencies.
*
* @param moduleSetting It contains the information about the module including the dependencies.
* @return A `ModuleDescriptor` describing a subproject and its dependencies.
*/
def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor =
publisherEngine.moduleDescriptor(moduleSetting)
/**
* Publishes the given module.
*
* @param module The module to be published.
* @param configuration The publish configuration.
* @param log The logger.
*/
def publish(module: ModuleDescriptor, configuration: PublishConfiguration, log: Logger): Unit =
publisherEngine.publish(module, configuration, log)
/**
* Makes the `pom.xml` file for the given module.
*
* @param module The module for which a `.pom` file is to be created.
* @param configuration The makePomFile configuration.
* @param log The logger.
* @return The `File` containing the POM descriptor.
*/
def makePomFile(module: ModuleDescriptor,
configuration: MakePomConfiguration,
log: Logger): File =
publisherEngine.makePomFile(module, configuration, log)
}
object Publisher {
def apply(publisherEngine: PublisherInterface): Publisher =
new Publisher(publisherEngine)
}

View File

@ -5,7 +5,7 @@ package ivy
import sbt.internal.librarymanagement._
import sbt.util.Logger
class IvyLibraryManagement private[sbt] (val ivySbt: IvySbt) extends LibraryManagement {
class IvyLibraryManagement private[sbt] (val ivySbt: IvySbt) extends LibraryManagementInterface {
type Module = ivySbt.Module
override def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor = {
@ -26,5 +26,5 @@ class IvyLibraryManagement private[sbt] (val ivySbt: IvySbt) extends LibraryMana
object IvyLibraryManagement {
def apply(ivyConfiguration: IvyConfiguration): LibraryManagement =
new IvyLibraryManagement(new IvySbt(ivyConfiguration))
LibraryManagement(new IvyLibraryManagement(new IvySbt(ivyConfiguration)))
}

View File

@ -6,7 +6,7 @@ import sbt.internal.librarymanagement._
import sbt.util.Logger
import java.io.File
class IvyPublisher private[sbt] (val ivySbt: IvySbt) extends Publisher {
class IvyPublisher private[sbt] (val ivySbt: IvySbt) extends PublisherInterface {
type Module = ivySbt.Module
override def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor = {
@ -31,5 +31,5 @@ class IvyPublisher private[sbt] (val ivySbt: IvySbt) extends Publisher {
object IvyPublisher {
def apply(ivyConfiguration: IvyConfiguration): Publisher =
new IvyPublisher(new IvySbt(ivyConfiguration))
Publisher(new IvyPublisher(new IvySbt(ivyConfiguration)))
}