Skip to content

Commit

Permalink
Revert "Deprecate FileSystemProvider and RenderNodeProvider (#1108)…
Browse files Browse the repository at this point in the history
…" (#1116)

This reverts commit d82da96.
  • Loading branch information
compnerd authored Dec 5, 2024
1 parent 8bc4631 commit cd3f5ba
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Foundation
This class provides a simple way to transform a `FileSystemProvider` into a `RenderNodeProvider` to feed an index builder.
The data from the disk is fetched and processed in an efficient way to build a navigator index.
*/
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
public class FileSystemRenderNodeProvider: RenderNodeProvider {

/// The internal `FileSystemProvider` reference.
Expand Down
74 changes: 12 additions & 62 deletions Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Foundation
import Crypto

/// A protocol to provide data to be indexed.
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
public protocol RenderNodeProvider {
/// Get an instance of `RenderNode` to be processed by the index.
/// - Note: Returning `nil` will end the indexing process.
Expand All @@ -22,6 +21,8 @@ public protocol RenderNodeProvider {
func getProblems() -> [Problem]
}



/**
A `NavigatorIndex` contains all the necessary information to display the data inside a navigator.
The data ranges from the tree to the necessary pieces of information to filter the content and perform actions in a fast way.
Expand Down Expand Up @@ -478,12 +479,8 @@ extension NavigatorIndex {
open class Builder {

/// The data provider.
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released")
public let renderNodeProvider: RenderNodeProvider?

/// The documentation archive to build an index from.
public let archiveURL: URL?

/// The output URL.
public let outputURL: URL

Expand Down Expand Up @@ -557,38 +554,26 @@ extension NavigatorIndex {
/// Indicates if the page title should be used instead of the navigator title.
private let usePageTitle: Bool


/// Maps the icon render references in the navigator items created by this builder
/// to their image references.
///
/// Use the `NavigatorItem.icon` render reference to look up the full image reference
/// for any custom icons used in this navigator index.
var iconReferences = [String : ImageReference]()


/// Create a new a builder with the given data provider and output URL.
/// - Parameters:
/// - archiveURL: The location of the documentation archive that the builder builds an navigator index for.
/// - renderNodeProvider: The `RenderNode` provider to use.
/// - outputURL: The location where the builder will write the the built navigator index.
/// - bundleIdentifier: The bundle identifier of the documentation that the builder builds a navigator index for.
/// - sortRootChildrenByName: Configure the builder to sort root's children by name.
/// - groupByLanguage: Configure the builder to group the entries by language.
/// - writePathsOnDisk: Configure the builder to write each navigator item's path components to the location.
/// - usePageTitle: Configure the builder to use the "page title" instead of the "navigator title" as the title for each entry.
public init(archiveURL: URL? = nil, outputURL: URL, bundleIdentifier: String, sortRootChildrenByName: Bool = false, groupByLanguage: Bool = false, writePathsOnDisk: Bool = true, usePageTitle: Bool = false) {
self.archiveURL = archiveURL
self.renderNodeProvider = nil
self.outputURL = outputURL
self.bundleIdentifier = bundleIdentifier
self.sortRootChildrenByName = sortRootChildrenByName
self.groupByLanguage = groupByLanguage
self.writePathsOnDisk = writePathsOnDisk
self.usePageTitle = usePageTitle
}

@available(*, deprecated, renamed: "init(archiveURL:outputURL:bundleIdentifier:sortRootChildrenByName:groupByLanguage:writePathsOnDisk:usePageTitle:)", message: "Use 'init(archiveURL:outputURL:bundleIdentifier:sortRootChildrenByName:groupByLanguage:writePathsOnDisk:usePageTitle:)' instead. This deprecated API will be removed after 6.2 is released")
@_disfavoredOverload
public init(renderNodeProvider: RenderNodeProvider? = nil, outputURL: URL, bundleIdentifier: String, sortRootChildrenByName: Bool = false, groupByLanguage: Bool = false, writePathsOnDisk: Bool = true, usePageTitle: Bool = false) {
self.renderNodeProvider = renderNodeProvider
self.archiveURL = nil
self.outputURL = outputURL
self.bundleIdentifier = bundleIdentifier
self.sortRootChildrenByName = sortRootChildrenByName
Expand Down Expand Up @@ -1260,43 +1245,13 @@ extension NavigatorIndex {
problems.append(problem)
}


/// Build the index using the render nodes files in the provided documentation archive.
/// - Returns: A list containing all the errors encountered during indexing.
/// - Precondition: Either ``archiveURL`` or ``renderNodeProvider`` is set.
/**
Build the index using the passed instance of `RenderNodeProvider` if available.
- Returns: A list containing all the problems encountered during indexing.
- Note: If a provider is not available, this method would generate a fatal error.
*/
public func build() -> [Problem] {
if let archiveURL {
return _build(archiveURL: archiveURL)
} else {
return (self as _DeprecatedRenderNodeProviderAccess)._legacyBuild()
}
}

// After 6.2 is released, move this into `build()`.
private func _build(archiveURL: URL) -> [Problem] {
setup()

let dataDirectory = archiveURL.appendingPathComponent(NodeURLGenerator.Path.dataFolderName, isDirectory: true)
for file in FileManager.default.recursiveFiles(startingPoint: dataDirectory) where file.pathExtension.lowercased() == "json" {
do {
let data = try Data(contentsOf: file)
let renderNode = try RenderNode.decode(fromJSON: data)
try index(renderNode: renderNode)
} catch {
problems.append(error.problem(source: file,
severity: .warning,
summaryPrefix: "RenderNode indexing process failed"))
}
}

finalize()

return problems
}

@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released")
fileprivate func _legacyBuild() -> [Problem] {
precondition(renderNodeProvider != nil, "Calling `build()` without an `archiveURL` or `renderNodeProvider` set is not permitted.")
precondition(renderNodeProvider != nil, "Calling build without a renderNodeProvider set is not permitted.")

setup()

Expand All @@ -1319,6 +1274,7 @@ extension NavigatorIndex {
return availabilityIDs[Int(availabilityID)]
}
}

}

fileprivate extension Error {
Expand Down Expand Up @@ -1387,9 +1343,3 @@ enum PathHasher: String {
}
}
}

private protocol _DeprecatedRenderNodeProviderAccess {
// This private function accesses the deprecated RenderNodeProvider
func _legacyBuild() -> [Problem]
}
extension NavigatorIndex.Builder: _DeprecatedRenderNodeProviderAccess {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand All @@ -11,14 +11,12 @@
import Foundation

/// A type that vends a tree of virtual filesystem objects.
@available(*, deprecated, message: "Use 'FileManagerProtocol.recursiveFiles(startingPoint:)' instead. This deprecated API will be removed after 6.2 is released.")
public protocol FileSystemProvider {
/// The organization of the files that this provider provides.
var fileSystem: FSNode { get }
}

/// An element in a virtual filesystem.
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
public enum FSNode {
/// A file in a filesystem.
case file(File)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ extension LocalFileSystemDataProvider: DocumentationWorkspaceDataProvider {
}
}

@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
fileprivate extension [FSNode] {
/// Returns the first file that matches a given predicate.
/// - Parameter predicate: A closure that takes a file as its argument and returns a Boolean value indicating whether the file should be returned from this function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import Foundation

/// A type that provides documentation bundles that it discovers by traversing the local file system.
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
public struct LocalFileSystemDataProvider: FileSystemProvider {
public var identifier: String = UUID().uuidString

Expand Down
72 changes: 0 additions & 72 deletions Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension ConvertAction {
init(outputURL: URL, bundleID: DocumentationBundle.Identifier) throws {
let indexURL = outputURL.appendingPathComponent("index", isDirectory: true)
indexBuilder = Synchronized<NavigatorIndex.Builder>(
NavigatorIndex.Builder(
NavigatorIndex.Builder(renderNodeProvider: nil,
outputURL: indexURL,
bundleIdentifier: bundleID.rawValue,
sortRootChildrenByName: true,
Expand Down
11 changes: 6 additions & 5 deletions Sources/SwiftDocCUtilities/Action/Actions/IndexAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import SwiftDocC

/// An action that creates an index of a documentation bundle.
public struct IndexAction: AsyncAction {
let archiveURL: URL
let rootURL: URL
let outputURL: URL
let bundleIdentifier: String

var diagnosticEngine: DiagnosticEngine

/// Initializes the action with the given validated options, creates or uses the given action workspace & context.
public init(archiveURL: URL, outputURL: URL, bundleIdentifier: String, diagnosticEngine: DiagnosticEngine = .init()) {
public init(documentationBundleURL: URL, outputURL: URL, bundleIdentifier: String, diagnosticEngine: DiagnosticEngine = .init()) throws {
// Initialize the action context.
self.archiveURL = archiveURL
self.rootURL = documentationBundleURL
self.outputURL = outputURL
self.bundleIdentifier = bundleIdentifier

self.diagnosticEngine = diagnosticEngine
self.diagnosticEngine.add(DiagnosticConsoleWriter(formattingOptions: [], baseURL: archiveURL))
self.diagnosticEngine.add(DiagnosticConsoleWriter(formattingOptions: [], baseURL: documentationBundleURL))
}

/// Converts each eligible file from the source documentation bundle,
Expand All @@ -40,7 +40,8 @@ public struct IndexAction: AsyncAction {
}

private func buildIndex() throws -> [Problem] {
let indexBuilder = NavigatorIndex.Builder(archiveURL: archiveURL,
let dataProvider = try LocalFileSystemDataProvider(rootURL: rootURL)
let indexBuilder = NavigatorIndex.Builder(renderNodeProvider: FileSystemRenderNodeProvider(fileSystemProvider: dataProvider),
outputURL: outputURL,
bundleIdentifier: bundleIdentifier,
sortRootChildrenByName: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ struct TransformForStaticHostingAction: AsyncAction {
)

// Create a StaticHostableTransformer targeted at the archive data folder
let transformer = StaticHostableTransformer(dataDirectory: rootURL.appendingPathComponent(NodeURLGenerator.Path.dataFolderName), fileManager: fileManager, outputURL: outputURL, indexHTMLData: indexHTMLData)
let dataProvider = try LocalFileSystemDataProvider(rootURL: rootURL.appendingPathComponent(NodeURLGenerator.Path.dataFolderName))
let transformer = StaticHostableTransformer(dataProvider: dataProvider, fileManager: fileManager, outputURL: outputURL, indexHTMLData: indexHTMLData)
try transformer.transform()

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand All @@ -12,10 +12,10 @@ import Foundation

extension IndexAction {
/// Initializes ``IndexAction`` from the options in the ``Index`` command.
init(fromIndexCommand index: Docc.Index) {
init(fromIndexCommand index: Docc.Index) throws {
// Initialize the `IndexAction` from the options provided by the `Index` command
self.init(
archiveURL: index.documentationArchive.urlOrFallback,
try self.init(
documentationBundleURL: index.documentationBundle.urlOrFallback,
outputURL: index.outputURL,
bundleIdentifier: index.bundleIdentifier)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Docc {

/// The user-provided path to a `.doccarchive` documentation archive.
@OptionGroup()
public var documentationArchive: DocCArchiveOption
public var documentationBundle: DocCArchiveOption

/// The user-provided bundle name to use for the produced index.
@Option(help: "The bundle name for the index.")
Expand All @@ -33,11 +33,11 @@ extension Docc {

/// The path to the directory that all build output should be placed in.
public var outputURL: URL {
documentationArchive.urlOrFallback.appendingPathComponent("index", isDirectory: true)
documentationBundle.urlOrFallback.appendingPathComponent("index", isDirectory: true)
}

public func run() async throws {
let indexAction = IndexAction(fromIndexCommand: self)
let indexAction = try IndexAction(fromIndexCommand: self)
try await indexAction.performAndHandleResult()
}
}
Expand Down
Loading

0 comments on commit cd3f5ba

Please sign in to comment.