-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/4.1.1' into versions
- Loading branch information
Showing
14 changed files
with
134 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Sources/BartyCrouchKit/OldCommandLine/ExtractLocStrings.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Created by Christos Koninis on 25/09/2019. | ||
|
||
import Foundation | ||
|
||
/// Class to handle extractLocStrings's tool file argument list. It provides methods to serialize the file list to an argument plist file. See | ||
/// https://github.com/Flinesoft/BartyCrouch/issues/92 | ||
class ExtractLocStrings { | ||
/// extractLocStrings tools supports instead of passing files as arguments in the command line to pass a plist with the files. This is the format of that | ||
/// plist. | ||
struct File: Codable, Equatable { | ||
var path: String | ||
} | ||
struct ArgumentsPlist: Codable, Equatable { | ||
var files: [File] = [] | ||
|
||
init(filePaths: [String]) { | ||
files = filePaths.map(File.init) | ||
} | ||
} | ||
|
||
/// Serializes the extractLocStrings's file arguments to an argument plist file. | ||
/// | ||
/// - Parameter files: A array containing the list of files. | ||
/// - Returns: The argument plist file that contains the list of file arguments. | ||
/// - Throws: An error if any value throws an error during plist encoding. | ||
func writeFilesArgumentsInPlist(_ files: [String]) throws -> String { | ||
let data = try encodeFilesArguments(files) | ||
let tempPlistFilePath = createTemporaryArgumentsPlistFile() | ||
try data.write(to: tempPlistFilePath) | ||
|
||
return tempPlistFilePath.path | ||
} | ||
|
||
/// Serializes the extractLocStrings's file arguments to byte array | ||
/// | ||
/// - Parameter files: A array containing the list of files. | ||
/// - Returns: A plist encoded value of the supplied array | ||
func encodeFilesArguments(_ files: [String]) throws -> Data { | ||
let encoder = PropertyListEncoder() | ||
encoder.outputFormat = .xml | ||
|
||
return try encoder.encode(ArgumentsPlist(filePaths: files)) | ||
} | ||
|
||
private func createTemporaryArgumentsPlistFile() -> URL { | ||
let temporaryFilename = ProcessInfo().globallyUniqueString | ||
var temporaryPath = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) | ||
temporaryPath.appendPathComponent(temporaryFilename) | ||
temporaryPath.appendPathExtension("plist") | ||
|
||
return temporaryPath | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Tests/BartyCrouchKitTests/CommandLine/ExtractLocStringsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Created by Christos Koninis on 25/09/2019. | ||
|
||
@testable import BartyCrouchKit | ||
import XCTest | ||
|
||
// swiftlint:disable force_try | ||
|
||
class ExtractLocStringsTests: XCTestCase { | ||
func testEncodedArgumentPlistFormat() { | ||
let files = ["file.m", "otherfile.swift", "/path/of/anotherfile.swift"] | ||
// Disabling whitespace_comment_start due to false positives | ||
// swiftlint:disable whitespace_comment_start | ||
let expectedArgumentsPlistString = """ | ||
<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> | ||
<plist version=\"1.0\"><dict><key>files</key><array><dict><key>path</key><string>file.m</string></dict><dict><key>path</key><string>otherfile.swift\ | ||
</string></dict><dict><key>path</key><string>/path/of/anotherfile.swift</string></dict></array></dict></plist> | ||
""" | ||
|
||
let argumentsPlistData = try! ExtractLocStrings().encodeFilesArguments(files) | ||
let argumentsPlist = try! argumentsPlistFromData(argumentsPlistData) | ||
let expectedArgumentsPlist = try! argumentsPlistFromData(expectedArgumentsPlistString.data(using: .utf8)!) | ||
|
||
XCTAssertEqual(argumentsPlist, expectedArgumentsPlist) | ||
} | ||
|
||
private func argumentsPlistFromData(_ data: Data) throws -> ExtractLocStrings.ArgumentsPlist { | ||
return try PropertyListDecoder().decode(ExtractLocStrings.ArgumentsPlist.self, from: data) | ||
} | ||
} |
71 changes: 0 additions & 71 deletions
71
Tests/BartyCrouchKitTests/CommandLine/GenStringsCommanderTests.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters