<commit_before>/*
 This source file is part of the Swift.org open source project

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

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Basic
import PackageDescription
import PackageDescription4

/**
 This contains the declarative specification loaded from package manifest
 files, and the tools for working with the manifest.
*/
public final class Manifest: ObjectIdentifierProtocol {
    /// The standard filename for the manifest.
    public static var filename = basename + ".swift"

    /// The standard basename for the manifest.
    public static var basename = "Package"

    /// The path of the manifest file.
    //
    // FIXME: This doesn't belong here, we want the Manifest to be purely tied
    // to the repository state, it shouldn't matter where it is.
    public let path: AbsolutePath

    /// The repository URL the manifest was loaded from.
    //
    // FIXME: This doesn't belong here, we want the Manifest to be purely tied
    // to the repository state, it shouldn't matter where it is.
    public let url: String

    /// The raw package description representation from manifest API targets.
    /// We support v3 and v4 right now.
    public enum RawPackage {
        case v3(PackageDescription.Package)
        case v4(PackageDescription4.Package)
    }

    /// The raw package description.
    public let package: RawPackage

    /// The legacy product descriptions.
    public let legacyProducts: [PackageDescription.Product]

    /// The version this package was loaded from, if known.
    public let version: Version?

    /// The name of the package.
    public var name: String {
        return package.name
    }

    public init(
        path: AbsolutePath,
        url: String,
        package: RawPackage,
        legacyProducts: [PackageDescription.Product] = [],
        version: Version?
    ) {
        if case .v4 = package {
            precondition(legacyProducts.isEmpty, "Legacy products are not supported in v4 manfiest.")
        }
        self.path = path
        self.url = url
        self.package = package
        self.legacyProducts = legacyProducts
        self.version = version
    }
}

extension Manifest {
    /// Returns JSON representation of this manifest.
    // Note: Right now we just return the JSON representation of the package,
    // but this can be expanded to include the details about manifest too.
    public func jsonString() throws -> String {
        // FIXME: It is unfortunate to re-parse the JSON string.
        return try JSON(string:  package.jsonString).toString(prettyPrint: true)
    }
}

// Common Raw Package properties exposed in terms of PackageDescription4 models.
// This way the high level code doesn't need to concern itself with conversion.
extension Manifest.RawPackage {

    var jsonString: String {
        switch self {<commit_msg>fixing a minor typo in err message<commit_after>/*
 This source file is part of the Swift.org open source project

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

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Basic
import PackageDescription
import PackageDescription4

/**
 This contains the declarative specification loaded from package manifest
 files, and the tools for working with the manifest.
*/
public final class Manifest: ObjectIdentifierProtocol {
    /// The standard filename for the manifest.
    public static var filename = basename + ".swift"

    /// The standard basename for the manifest.
    public static var basename = "Package"

    /// The path of the manifest file.
    //
    // FIXME: This doesn't belong here, we want the Manifest to be purely tied
    // to the repository state, it shouldn't matter where it is.
    public let path: AbsolutePath

    /// The repository URL the manifest was loaded from.
    //
    // FIXME: This doesn't belong here, we want the Manifest to be purely tied
    // to the repository state, it shouldn't matter where it is.
    public let url: String

    /// The raw package description representation from manifest API targets.
    /// We support v3 and v4 right now.
    public enum RawPackage {
        case v3(PackageDescription.Package)
        case v4(PackageDescription4.Package)
    }

    /// The raw package description.
    public let package: RawPackage

    /// The legacy product descriptions.
    public let legacyProducts: [PackageDescription.Product]

    /// The version this package was loaded from, if known.
    public let version: Version?

    /// The name of the package.
    public var name: String {
        return package.name
    }

    public init(
        path: AbsolutePath,
        url: String,
        package: RawPackage,
        legacyProducts: [PackageDescription.Product] = [],
        version: Version?
    ) {
        if case .v4 = package {
            precondition(legacyProducts.isEmpty, "Legacy products are not supported in v4 manifest.")
        }
        self.path = path
        self.url = url
        self.package = package
        self.legacyProducts = legacyProducts
        self.version = version
    }
}

extension Manifest {
    /// Returns JSON representation of this manifest.
    // Note: Right now we just return the JSON representation of the package,
    // but this can be expanded to include the details about manifest too.
    public func jsonString() throws -> String {
        // FIXME: It is unfortunate to re-parse the JSON string.
        return try JSON(string:  package.jsonString).toString(prettyPrint: true)
    }
}

// Common Raw Package properties exposed in terms of PackageDescription4 models.
// This way the high level code doesn't need to concern itself with conversion.
extension Manifest.RawPackage {

    var jsonString: String {
        switch self {
{'fraction_non_alphanumeric': 0.06992321516092141, 'fraction_numerical': 0.006208135925502369, 'mean_word_length': 2.6680647094068304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5267693', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1466, 'n_words': 690}