Skip to content

Commit

Permalink
Refactoring oh oh
Browse files Browse the repository at this point in the history
  • Loading branch information
ValiHar committed Jul 13, 2020
1 parent b44cdc3 commit 882633d
Show file tree
Hide file tree
Showing 46 changed files with 460 additions and 222 deletions.
8 changes: 4 additions & 4 deletions Bubo/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let package = Package(
.product(name: "SwiftGraph", package: "SwiftGraph"),
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
.product(name: "IndexStoreDB", package: "IndexStoreDB"),
.target(name: "ResourceManagerModule")
]
),
.target(
Expand All @@ -36,11 +35,12 @@ let package = Package(
.product(name: "SwiftGraph", package: "SwiftGraph"),
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
.product(name: "IndexStoreDB", package: "IndexStoreDB"),
.product(name: "ColorizeSwift", package: "ColorizeSwift")
.product(name: "ColorizeSwift", package: "ColorizeSwift"),
.target(name: "GraphBuilderModule")
]
),
.target(
name: "ServiceManagerModule",
name: "ServiceAnalyserModule",
dependencies: [
.product(name: "SwiftGraph", package: "SwiftGraph"),
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
Expand All @@ -57,7 +57,7 @@ let package = Package(
.product(name: "SwiftGraph", package: "SwiftGraph"),
.target(name: "GraphBuilderModule"),
.target(name: "ResourceManagerModule"),
.target(name: "ServiceManagerModule")
.target(name: "ServiceAnalyserModule")
]),
.testTarget(
name: "BuboTests",
Expand Down
3 changes: 1 addition & 2 deletions Bubo/Sources/Bubo/CommandLineInterface/RootCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ struct Bubo: ParsableCommand {
List.self,
Remove.self,
Open.self,
Service.self,
Analysis.self
Service.self
])
struct Options: ParsableArguments {
@Argument(help: "The name of the service living inside the Bubo project")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Foundation
import ArgumentParser


extension Bubo {
extension Bubo.Service {

/// **Subcommand**: The root for all analysis subcommands that can be run on a project or service
struct Analysis: ParsableCommand {
struct Analyse: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "All analysises performed on a service or project",
abstract: "All analyses performed on a service or project",
subcommands: [
Crawl.self,
Graph.self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

import Foundation
import ArgumentParser
import ResourceManagerModule
import ServiceManagerModule
import ServiceAnalyserModule


extension Bubo.Analysis {
extension Bubo.Service.Analyse {

/// **Subcommand**: Subcommand to generate a dependency graph and save it to a .dot file
struct Graph: ParsableCommand {
Expand Down Expand Up @@ -40,10 +39,10 @@ extension Bubo.Analysis {
return
}
let serviceManager = ServiceManager(service: service, pName: options.projectName)
guard serviceManager.createDependencyGraph() != nil else {
guard serviceManager.structuralAnalyser.createDependencyGraph() != nil else {
return
}
serviceManager.writeToDot()
serviceManager.structuralAnalyser.writeToDot()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ArgumentParser
import ResourceManagerModule


extension Bubo.Analysis {
extension Bubo.Service.Analyse {

/// **Subcommand**: Crawl a specified service and outout all its files to stdout
struct Crawl: ParsableCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ extension Bubo {
List.self,
Pull.self,
Refresh.self,
Remove.self
Remove.self,
Analyse.self
])
}
}
60 changes: 60 additions & 0 deletions Bubo/Sources/Bubo/Messages.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Created by Valentin Hartig on 25.04.20.
//

import Foundation
import ColorizeSwift


/// Output an error message on stdout.
///
/// - parameter msg: The message to output.

public func errorMessage(msg: String) -> Void {
print("ERROR: \(msg)" .red())
}


/// Output a warning message on stdout.
///
/// - parameter msg: The message to output.

public func warningMessage(msg: String) -> Void {
print("WARNING: \(msg)" .yellow())
}


/// Output a success message on stdout.
///
/// - parameter msg: The message to output.

public func successMessage(msg: String) -> Void {
print("\(msg)" .green())
}


/// Output a header message on stdout that seperates different main operations.
///
/// - parameter msg: The message to output.

public func headerMessage(msg: String) -> Void {
print(msg .bold())
}


/// Output a standard output message on stdout. These are only displayed if the verbose mode is activated.
///
/// - parameter msg: The message to output.

public func outputMessage(msg: String) -> Void {
print(msg .dim())
}


/// Output an abort message on stdout when an operation is aborted due to an error
///
/// - parameter msg: The message to output

public func abortMessage(msg: String) -> Void {
print("ABORT: \(msg)" .red())
}
7 changes: 3 additions & 4 deletions Bubo/Sources/GraphBuilderModule/GraphBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Foundation
import SwiftGraph
import SwiftSyntax
import IndexStoreDB
import ResourceManagerModule


/// Creates a dependency graph for a service (a Swift package) based on a set of parsed tokens from a syntax parser
Expand Down Expand Up @@ -34,15 +33,15 @@ public class GraphBuilder {


/// Constructs a GraphBuilder object and initialises the indexing server needed to query raw indexing data
public init(service: ServiceConfiguration) {
public init(packageRoot: URL, fileURLs: [URL]) {
headerMessage(msg: "Initialising graph builder...")
self.graph = RefinedDependencyGraph<Node>()
self.parser = Parser()
parser.parse(service: service)
parser.parse(files: fileURLs)
successMessage(msg: "Files parsed")

/// Building the index store path --> this is the path where the raw indexing data generated by the compiler during build process lies
let indexStorePath = service.gitRootURL
let indexStorePath = packageRoot
.appendingPathComponent(".build")
.appendingPathComponent("debug")
.appendingPathComponent("index")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import IndexStoreDB
import ResourceManagerModule


/// Represents an IndexingDatabase instance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import IndexStoreDB
import ResourceManagerModule


/// The indexingserver object provides an endpoint to query an indexing database
Expand Down
60 changes: 60 additions & 0 deletions Bubo/Sources/GraphBuilderModule/Messages.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Created by Valentin Hartig on 25.04.20.
//

import Foundation
import ColorizeSwift


/// Output an error message on stdout.
///
/// - parameter msg: The message to output.

public func errorMessage(msg: String) -> Void {
print("ERROR: \(msg)" .red())
}


/// Output a warning message on stdout.
///
/// - parameter msg: The message to output.

public func warningMessage(msg: String) -> Void {
print("WARNING: \(msg)" .yellow())
}


/// Output a success message on stdout.
///
/// - parameter msg: The message to output.

public func successMessage(msg: String) -> Void {
print("\(msg)" .green())
}


/// Output a header message on stdout that seperates different main operations.
///
/// - parameter msg: The message to output.

public func headerMessage(msg: String) -> Void {
print(msg .bold())
}


/// Output a standard output message on stdout. These are only displayed if the verbose mode is activated.
///
/// - parameter msg: The message to output.

public func outputMessage(msg: String) -> Void {
print(msg .dim())
}


/// Output an abort message on stdout when an operation is aborted due to an error
///
/// - parameter msg: The message to output

public func abortMessage(msg: String) -> Void {
print("ABORT: \(msg)" .red())
}
16 changes: 8 additions & 8 deletions Bubo/Sources/GraphBuilderModule/Parser/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import Foundation
import SwiftSyntax
import ResourceManagerModule

/// A syntax parser that uses a **SwiftSyntax** `SyntaxVisitor` to craw the AST of a sourcefile and generate relevant tokens
public class Parser {
Expand All @@ -21,16 +20,17 @@ public class Parser {
///
/// - parameter service: The service that should be parsed

public func parse(service: ServiceConfiguration) -> Void {
for file in service.files {
public func parse(files: [URL]) -> Void {
outputMessage(msg: "Parsing files ...")
for url in files {

/// Only parse .swift files
if file.fileURL.pathExtension == "swift" {
outputMessage(msg: "Parsing file \(file.fileName)")
if url.pathExtension == "swift" {

do {
/// Try to parse the swift source file and generate the parse context
let sourceFileSyntax = try SyntaxParser.parse(file.fileURL)
let parseContext = ParseContext(fileURL: file.fileURL, sourceFileSyntax: sourceFileSyntax)
let sourceFileSyntax = try SyntaxParser.parse(url)
let parseContext = ParseContext(fileURL: url, sourceFileSyntax: sourceFileSyntax)

/// Create the token generator and let it walk over the AST
let tokenGenerator: TokenGenerator = TokenGenerator(parseContext: parseContext)
Expand All @@ -40,7 +40,7 @@ public class Parser {
tokens.append(contentsOf: tokenGenerator.tokens)
tokenExtensions.merge(tokenGenerator.tokenExtensions){ (current, _) in current }
} catch {
warningMessage(msg: "Couldn't parse source file \(file.fileName)")
warningMessage(msg: "Couldn't parse source file at \(url.path)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import Foundation
import IndexStoreDB
import ResourceManagerModule

extension GraphBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import Foundation
import IndexStoreDB
import ResourceManagerModule

extension GraphBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//

import Foundation
import ResourceManagerModule

extension GraphBuilder {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//
// File.swift
//
//
// Created by Valentin Hartig on 07.07.20.
//

import Foundation
import ResourceManagerModule


extension GraphBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import Foundation

import GraphBuilderModule


extension ResourceManager {
Expand Down
Loading

0 comments on commit 882633d

Please sign in to comment.