Create base context

This commit is contained in:
Pedro Piñera 2018-04-26 16:31:41 +02:00
parent 9183a88635
commit b900345d9a
4 changed files with 77 additions and 27 deletions

View File

@ -27,6 +27,7 @@
B9553DEA2090690000050311 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9553DE92090690000050311 /* Shell.swift */; };
B9553DEC2090F62C00050311 /* GraphNodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9553DEB2090F62C00050311 /* GraphNodeTests.swift */; };
B9553DEF2090F6EC00050311 /* MockShell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9553DED2090F6AE00050311 /* MockShell.swift */; };
B9553DF12092181500050311 /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9553DF02092181500050311 /* Context.swift */; };
B95895F3208A2ACF00F00ACF /* ProjectGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B95895F2208A2ACF00F00ACF /* ProjectGenerator.swift */; };
B95895F5208A2ADB00F00ACF /* GeneratorContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = B95895F4208A2ADB00F00ACF /* GeneratorContext.swift */; };
B95895F7208A2B5800F00ACF /* GeneratorError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B95895F6208A2B5800F00ACF /* GeneratorError.swift */; };
@ -250,6 +251,7 @@
B9553DE92090690000050311 /* Shell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shell.swift; sourceTree = "<group>"; };
B9553DEB2090F62C00050311 /* GraphNodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphNodeTests.swift; sourceTree = "<group>"; };
B9553DED2090F6AE00050311 /* MockShell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockShell.swift; sourceTree = "<group>"; };
B9553DF02092181500050311 /* Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
B95895F2208A2ACF00F00ACF /* ProjectGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectGenerator.swift; sourceTree = "<group>"; };
B95895F4208A2ADB00F00ACF /* GeneratorContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratorContext.swift; sourceTree = "<group>"; };
B95895F6208A2B5800F00ACF /* GeneratorError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratorError.swift; sourceTree = "<group>"; };
@ -595,6 +597,7 @@
B9B629A720864E3A00EE9E07 /* App.swift */,
B9B629A820864E3A00EE9E07 /* Signals.swift */,
B9553DE92090690000050311 /* Shell.swift */,
B9553DF02092181500050311 /* Context.swift */,
);
path = Utils;
sourceTree = "<group>";
@ -953,6 +956,7 @@
B9B629B920864E5400EE9E07 /* XcodeRepresentable.swift in Sources */,
B9B629B420864E4700EE9E07 /* SPUUpdater+CommandLine.swift in Sources */,
B9FB2DE32086542F00BC2FB3 /* Target.swift in Sources */,
B9553DF12092181500050311 /* Context.swift in Sources */,
B9B629CE20864E9800EE9E07 /* BuildConfiguration.swift in Sources */,
B9FB2DDE208653DD00BC2FB3 /* GraphLoaderCache.swift in Sources */,
B9B629B620864E4700EE9E07 /* SPUStandardUpdaterController+App.swift in Sources */,

View File

@ -1,30 +1,30 @@
import Foundation
/// Generator context protocol.
protocol GeneratorContexting: AnyObject {
protocol GeneratorContexting: Contexting {
/// Graph that is beging generated.
var graph: Graphing { get }
/// Printer.
var printer: Printing { get }
}
/// Generator context.
class GeneratorContext: GeneratorContexting {
class GeneratorContext: Context, GeneratorContexting {
/// Graph that is being generated.
let graph: Graphing
/// Printer.
let printer: Printing
/// Initializes the generator with its attributes.
///
/// - Parameters:
/// - graph: graph that is being generated.
/// - printer: printer.
/// - fileHandler: file handler.
/// - shell: shell.
init(graph: Graphing,
printer: Printing = Printer()) {
printer: Printing = Printer(),
fileHandler: FileHandling = FileHandler(),
shell: Shelling = Shell()) {
self.graph = graph
self.printer = printer
super.init(fileHandler: fileHandler,
shell: shell,
printer: printer)
}
}

View File

@ -2,40 +2,28 @@ import Basic
import Foundation
/// Protocol that defines the interface of the context that is used during the graph loading.
protocol GraphLoaderContexting: AnyObject {
protocol GraphLoaderContexting: Contexting {
/// Manifest loader that is used to get a JSON representation of the manifests.
var manifestLoader: GraphManifestLoading { get }
/// Contains a reference to the manifests that are parsed during the graph loading.
var cache: GraphLoaderCaching { get }
/// Util to handle files.
var fileHandler: FileHandling { get }
/// Circular dependency detector.
var circularDetector: GraphCircularDetecting { get }
/// Shell.
var shell: Shelling { get }
}
/// Object passed during the graph loading that contains utils to be used.
class GraphLoaderContext: GraphLoaderContexting {
class GraphLoaderContext: Context, GraphLoaderContexting {
/// Manifest loader. It's used to get a JSON representation of the manifests.
let manifestLoader: GraphManifestLoading
/// Contains a reference to the manifests that are parsed during the graph loading.
let cache: GraphLoaderCaching
/// Util to handle files.
let fileHandler: FileHandling
/// Circular dependency detector.
let circularDetector: GraphCircularDetecting
/// Shell.
let shell: Shelling
/// Initializes the context with its attributes.
///
/// - Parameters:
@ -44,15 +32,33 @@ class GraphLoaderContext: GraphLoaderContexting {
/// - fileHandler: Util to handle files.
/// - circularDetector: Circular dependency detector.
/// - shell: shell.
/// - printer: printer.
init(manifestLoader: GraphManifestLoading = GraphManifestLoader(),
cache: GraphLoaderCaching = GraphLoaderCache(),
fileHandler: FileHandling = FileHandler(),
circularDetector: GraphCircularDetecting = GraphCircularDetector(),
shell: Shelling = Shell()) {
shell: Shelling = Shell(),
printer: Printing = Printer()) {
self.manifestLoader = manifestLoader
self.cache = cache
self.fileHandler = fileHandler
self.circularDetector = circularDetector
self.shell = shell
super.init(fileHandler: fileHandler, shell: shell, printer: printer)
}
/// Initializes the graph loader context with a context and the extra attributes that the graph loader context has.
///
/// - Parameters:
/// - context: base context.
/// - manifestLoader: manifest loader.
/// - cache: graph loader cache.
/// - circularDetector: circular dependencies detector.
init(context: Context,
manifestLoader: GraphManifestLoading = GraphManifestLoader(),
cache: GraphLoaderCaching = GraphLoaderCache(),
circularDetector: GraphCircularDetecting = GraphCircularDetector()) {
self.manifestLoader = manifestLoader
self.cache = cache
self.circularDetector = circularDetector
super.init(fileHandler: context.fileHandler, shell: context.shell, printer: context.printer)
}
}

View File

@ -0,0 +1,40 @@
import Foundation
/// Context protocol.
protocol Contexting: AnyObject {
/// Shell.
var shell: Shelling { get }
/// Util to handle files.
var fileHandler: FileHandling { get }
/// Printer.
var printer: Printing { get }
}
/// xcbuddy uses contexts as a dependency injection mechanism.
/// Contexts are initialized by the commands and passed to the different components that will use the dependencies defined in them.
class Context: Contexting {
/// Util to handle files.
let fileHandler: FileHandling
/// Shell.
let shell: Shelling
/// Printer.
let printer: Printing
/// Initializes the context with its attributess.
///
/// - Parameters:
/// - fileHandler: file handler.
/// - shell: shell.
/// - printer: printer.
init(fileHandler: FileHandling,
shell: Shelling,
printer: Printing) {
self.fileHandler = fileHandler
self.shell = shell
self.printer = printer
}
}