Skip to content

Commit cd3f5ba

Browse files
authored
Revert "Deprecate FileSystemProvider and RenderNodeProvider (#1108)" (#1116)
This reverts commit d82da96.
1 parent 8bc4631 commit cd3f5ba

16 files changed

+147
-221
lines changed

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex+Ext.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Foundation
1414
This class provides a simple way to transform a `FileSystemProvider` into a `RenderNodeProvider` to feed an index builder.
1515
The data from the disk is fetched and processed in an efficient way to build a navigator index.
1616
*/
17-
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
1817
public class FileSystemRenderNodeProvider: RenderNodeProvider {
1918

2019
/// The internal `FileSystemProvider` reference.

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Foundation
1212
import Crypto
1313

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

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

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

484-
/// The documentation archive to build an index from.
485-
public let archiveURL: URL?
486-
487484
/// The output URL.
488485
public let outputURL: URL
489486

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

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

565+
567566
/// Create a new a builder with the given data provider and output URL.
568567
/// - Parameters:
569-
/// - archiveURL: The location of the documentation archive that the builder builds an navigator index for.
568+
/// - renderNodeProvider: The `RenderNode` provider to use.
570569
/// - outputURL: The location where the builder will write the the built navigator index.
571570
/// - bundleIdentifier: The bundle identifier of the documentation that the builder builds a navigator index for.
572571
/// - sortRootChildrenByName: Configure the builder to sort root's children by name.
573572
/// - groupByLanguage: Configure the builder to group the entries by language.
574573
/// - writePathsOnDisk: Configure the builder to write each navigator item's path components to the location.
575574
/// - usePageTitle: Configure the builder to use the "page title" instead of the "navigator title" as the title for each entry.
576-
public init(archiveURL: URL? = nil, outputURL: URL, bundleIdentifier: String, sortRootChildrenByName: Bool = false, groupByLanguage: Bool = false, writePathsOnDisk: Bool = true, usePageTitle: Bool = false) {
577-
self.archiveURL = archiveURL
578-
self.renderNodeProvider = nil
579-
self.outputURL = outputURL
580-
self.bundleIdentifier = bundleIdentifier
581-
self.sortRootChildrenByName = sortRootChildrenByName
582-
self.groupByLanguage = groupByLanguage
583-
self.writePathsOnDisk = writePathsOnDisk
584-
self.usePageTitle = usePageTitle
585-
}
586-
587-
@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")
588-
@_disfavoredOverload
589575
public init(renderNodeProvider: RenderNodeProvider? = nil, outputURL: URL, bundleIdentifier: String, sortRootChildrenByName: Bool = false, groupByLanguage: Bool = false, writePathsOnDisk: Bool = true, usePageTitle: Bool = false) {
590576
self.renderNodeProvider = renderNodeProvider
591-
self.archiveURL = nil
592577
self.outputURL = outputURL
593578
self.bundleIdentifier = bundleIdentifier
594579
self.sortRootChildrenByName = sortRootChildrenByName
@@ -1260,43 +1245,13 @@ extension NavigatorIndex {
12601245
problems.append(problem)
12611246
}
12621247

1263-
1264-
/// Build the index using the render nodes files in the provided documentation archive.
1265-
/// - Returns: A list containing all the errors encountered during indexing.
1266-
/// - Precondition: Either ``archiveURL`` or ``renderNodeProvider`` is set.
1248+
/**
1249+
Build the index using the passed instance of `RenderNodeProvider` if available.
1250+
- Returns: A list containing all the problems encountered during indexing.
1251+
- Note: If a provider is not available, this method would generate a fatal error.
1252+
*/
12671253
public func build() -> [Problem] {
1268-
if let archiveURL {
1269-
return _build(archiveURL: archiveURL)
1270-
} else {
1271-
return (self as _DeprecatedRenderNodeProviderAccess)._legacyBuild()
1272-
}
1273-
}
1274-
1275-
// After 6.2 is released, move this into `build()`.
1276-
private func _build(archiveURL: URL) -> [Problem] {
1277-
setup()
1278-
1279-
let dataDirectory = archiveURL.appendingPathComponent(NodeURLGenerator.Path.dataFolderName, isDirectory: true)
1280-
for file in FileManager.default.recursiveFiles(startingPoint: dataDirectory) where file.pathExtension.lowercased() == "json" {
1281-
do {
1282-
let data = try Data(contentsOf: file)
1283-
let renderNode = try RenderNode.decode(fromJSON: data)
1284-
try index(renderNode: renderNode)
1285-
} catch {
1286-
problems.append(error.problem(source: file,
1287-
severity: .warning,
1288-
summaryPrefix: "RenderNode indexing process failed"))
1289-
}
1290-
}
1291-
1292-
finalize()
1293-
1294-
return problems
1295-
}
1296-
1297-
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released")
1298-
fileprivate func _legacyBuild() -> [Problem] {
1299-
precondition(renderNodeProvider != nil, "Calling `build()` without an `archiveURL` or `renderNodeProvider` set is not permitted.")
1254+
precondition(renderNodeProvider != nil, "Calling build without a renderNodeProvider set is not permitted.")
13001255

13011256
setup()
13021257

@@ -1319,6 +1274,7 @@ extension NavigatorIndex {
13191274
return availabilityIDs[Int(availabilityID)]
13201275
}
13211276
}
1277+
13221278
}
13231279

13241280
fileprivate extension Error {
@@ -1387,9 +1343,3 @@ enum PathHasher: String {
13871343
}
13881344
}
13891345
}
1390-
1391-
private protocol _DeprecatedRenderNodeProviderAccess {
1392-
// This private function accesses the deprecated RenderNodeProvider
1393-
func _legacyBuild() -> [Problem]
1394-
}
1395-
extension NavigatorIndex.Builder: _DeprecatedRenderNodeProviderAccess {}

Sources/SwiftDocC/Infrastructure/Workspace/FileSystemProvider.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

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

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

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

2019
/// An element in a virtual filesystem.
21-
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
2220
public enum FSNode {
2321
/// A file in a filesystem.
2422
case file(File)

Sources/SwiftDocC/Infrastructure/Workspace/LocalFileSystemDataProvider+BundleDiscovery.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ extension LocalFileSystemDataProvider: DocumentationWorkspaceDataProvider {
142142
}
143143
}
144144

145-
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released.")
146145
fileprivate extension [FSNode] {
147146
/// Returns the first file that matches a given predicate.
148147
/// - 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.

Sources/SwiftDocC/Infrastructure/Workspace/LocalFileSystemDataProvider.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import Foundation
1212

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

Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift

Lines changed: 0 additions & 72 deletions
This file was deleted.

Sources/SwiftDocCUtilities/Action/Actions/Convert/Indexer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension ConvertAction {
3636
init(outputURL: URL, bundleID: DocumentationBundle.Identifier) throws {
3737
let indexURL = outputURL.appendingPathComponent("index", isDirectory: true)
3838
indexBuilder = Synchronized<NavigatorIndex.Builder>(
39-
NavigatorIndex.Builder(
39+
NavigatorIndex.Builder(renderNodeProvider: nil,
4040
outputURL: indexURL,
4141
bundleIdentifier: bundleID.rawValue,
4242
sortRootChildrenByName: true,

Sources/SwiftDocCUtilities/Action/Actions/IndexAction.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import SwiftDocC
1313

1414
/// An action that creates an index of a documentation bundle.
1515
public struct IndexAction: AsyncAction {
16-
let archiveURL: URL
16+
let rootURL: URL
1717
let outputURL: URL
1818
let bundleIdentifier: String
1919

2020
var diagnosticEngine: DiagnosticEngine
2121

2222
/// Initializes the action with the given validated options, creates or uses the given action workspace & context.
23-
public init(archiveURL: URL, outputURL: URL, bundleIdentifier: String, diagnosticEngine: DiagnosticEngine = .init()) {
23+
public init(documentationBundleURL: URL, outputURL: URL, bundleIdentifier: String, diagnosticEngine: DiagnosticEngine = .init()) throws {
2424
// Initialize the action context.
25-
self.archiveURL = archiveURL
25+
self.rootURL = documentationBundleURL
2626
self.outputURL = outputURL
2727
self.bundleIdentifier = bundleIdentifier
2828

2929
self.diagnosticEngine = diagnosticEngine
30-
self.diagnosticEngine.add(DiagnosticConsoleWriter(formattingOptions: [], baseURL: archiveURL))
30+
self.diagnosticEngine.add(DiagnosticConsoleWriter(formattingOptions: [], baseURL: documentationBundleURL))
3131
}
3232

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

4242
private func buildIndex() throws -> [Problem] {
43-
let indexBuilder = NavigatorIndex.Builder(archiveURL: archiveURL,
43+
let dataProvider = try LocalFileSystemDataProvider(rootURL: rootURL)
44+
let indexBuilder = NavigatorIndex.Builder(renderNodeProvider: FileSystemRenderNodeProvider(fileSystemProvider: dataProvider),
4445
outputURL: outputURL,
4546
bundleIdentifier: bundleIdentifier,
4647
sortRootChildrenByName: true,

Sources/SwiftDocCUtilities/Action/Actions/TransformForStaticHostingAction.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ struct TransformForStaticHostingAction: AsyncAction {
9292
)
9393

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

9899
}

Sources/SwiftDocCUtilities/ArgumentParsing/ActionExtensions/IndexAction+CommandInitialization.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

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

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

1313
extension IndexAction {
1414
/// Initializes ``IndexAction`` from the options in the ``Index`` command.
15-
init(fromIndexCommand index: Docc.Index) {
15+
init(fromIndexCommand index: Docc.Index) throws {
1616
// Initialize the `IndexAction` from the options provided by the `Index` command
17-
self.init(
18-
archiveURL: index.documentationArchive.urlOrFallback,
17+
try self.init(
18+
documentationBundleURL: index.documentationBundle.urlOrFallback,
1919
outputURL: index.outputURL,
2020
bundleIdentifier: index.bundleIdentifier)
2121
}

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/Index.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension Docc {
2121

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

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

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

3939
public func run() async throws {
40-
let indexAction = IndexAction(fromIndexCommand: self)
40+
let indexAction = try IndexAction(fromIndexCommand: self)
4141
try await indexAction.performAndHandleResult()
4242
}
4343
}

0 commit comments

Comments
 (0)