Skip to content

Commit

Permalink
Merge pull request #3 from atsusy/support-xcode8
Browse files Browse the repository at this point in the history
Support Xcode8
  • Loading branch information
ishkawa authored Sep 23, 2016
2 parents cbb08a5 + 927df11 commit f8258eb
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 61 deletions.
10 changes: 5 additions & 5 deletions UnitTests/LprojFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class LprojFileTests: XCTestCase {
override func setUp() {
super.setUp()

let cwd = NSProcessInfo.processInfo().environment["MY_SOURCE_ROOT"]
let fileManager = NSFileManager()
let cwd = ProcessInfo.processInfo.environment["MY_SOURCE_ROOT"]
let fileManager = FileManager()
fileManager.changeCurrentDirectoryPath(cwd!)

let path = NSFileManager.defaultManager().currentDirectoryPath
let URL = NSURL(fileURLWithPath: path).URLByAppendingPathComponent("DemoApp/Base.lproj")
lprojFile = LprojFile(URL: URL)
let path = FileManager.default.currentDirectoryPath
let anURL = URL(fileURLWithPath: path).appendingPathComponent("DemoApp/Base.lproj")
lprojFile = LprojFile(URL: anURL)
}

func testXibFiles() {
Expand Down
12 changes: 6 additions & 6 deletions UnitTests/StringsFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class StringsFileTests: XCTestCase {
override func setUp() {
super.setUp()

let cwd = NSProcessInfo.processInfo().environment["MY_SOURCE_ROOT"]
let fileManager = NSFileManager()
let cwd = ProcessInfo.processInfo.environment["MY_SOURCE_ROOT"]
let fileManager = FileManager()
fileManager.changeCurrentDirectoryPath(cwd!)

let directoryPath = NSFileManager.defaultManager().currentDirectoryPath
let directoryURL = NSURL(fileURLWithPath: directoryPath).URLByAppendingPathComponent("DemoApp")
localizableStringsFile = StringsFile(URL: directoryURL.URLByAppendingPathComponent("en.lproj/Localizable.strings"))
xibStringsFile = StringsFile(URL: directoryURL.URLByAppendingPathComponent("en.lproj/Main.strings"))
let directoryPath = FileManager.default.currentDirectoryPath
let directoryURL = URL(fileURLWithPath: directoryPath).appendingPathComponent("DemoApp")
localizableStringsFile = StringsFile(URL: directoryURL.appendingPathComponent("en.lproj/Localizable.strings"))
xibStringsFile = StringsFile(URL: directoryURL.appendingPathComponent("en.lproj/Main.strings"))
}

func testUpdate() {
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/TargetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class TargetTests: XCTestCase {
override func setUp() {
super.setUp()

let cwd = NSProcessInfo.processInfo().environment["MY_SOURCE_ROOT"]
let fileManager = NSFileManager()
let cwd = ProcessInfo.processInfo.environment["MY_SOURCE_ROOT"]
let fileManager = FileManager()
fileManager.changeCurrentDirectoryPath(cwd!)

target = Target(path: "DemoApp")
Expand All @@ -19,7 +19,7 @@ class TargetTests: XCTestCase {
}

func testBaseLprojFile() {
XCTAssertEqual(target.baseLprojFile!.URL.lastPathComponent!, "Base.lproj")
XCTAssertEqual(target.baseLprojFile!.URL.lastPathComponent, "Base.lproj")
}

func testLangLprojFiles() {
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
xcode:
version: 7.0
version: 8.0
environment:
LANG: en_US.UTF-8

Expand Down
17 changes: 16 additions & 1 deletion ls2xs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,19 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Yosuke Ishikawa";
TargetAttributes = {
7F9751311A89C90D005E27F8 = {
CreatedOnToolsVersion = 6.3;
};
7F9ABCD31A88E79100ACB4B9 = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
};
7F9ABCE31A88E7D700ACB4B9 = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -385,6 +387,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand All @@ -394,15 +397,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -427,6 +433,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand All @@ -436,15 +443,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -454,20 +464,23 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
7F9ABCDC1A88E79100ACB4B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
7F9ABCDD1A88E79100ACB4B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -487,6 +500,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "-.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -502,6 +516,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "-.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion ls2xs.xcodeproj/xcshareddata/xcschemes/ls2xs.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
26 changes: 13 additions & 13 deletions ls2xs/LprojFile.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Foundation

class LprojFile {
let URL: NSURL
let URL: URL
let name: String

var xibFiles: [XibFile] {
var xibFiles = [XibFile]()

for xibURL in NSFileManager.defaultManager().fileURLsInURL(URL) {
for xibURL in FileManager.default.fileURLsInURL(URL) {
if let xibFile = XibFile(URL: xibURL) {
xibFiles.append(xibFile)
}
Expand All @@ -19,7 +19,7 @@ class LprojFile {
var stringsFiles: [StringsFile] {
var stringsFiles = [StringsFile]()

for xibURL in NSFileManager.defaultManager().fileURLsInURL(URL) {
for xibURL in FileManager.default.fileURLsInURL(URL) {
if let stringsFile = StringsFile(URL: xibURL) {
stringsFiles.append(stringsFile)
}
Expand All @@ -29,22 +29,22 @@ class LprojFile {
}

var localizableStringsFile: StringsFile? {
let stringsURL = URL.URLByAppendingPathComponent("Localizable.strings")
let stringsURL = URL.appendingPathComponent("Localizable.strings")
return StringsFile(URL: stringsURL)
}

class func baseLprojInURL(URL: NSURL) -> LprojFile? {
if let URL = NSFileManager.defaultManager().fileURLsInURL(URL).filter({ URL in URL.lastPathComponent == "Base.lproj" }).first {
class func baseLprojInURL(_ URL: URL) -> LprojFile? {
if let URL = FileManager.default.fileURLsInURL(URL).filter({ URL in URL.lastPathComponent == "Base.lproj" }).first {
return LprojFile(URL: URL)
} else {
return nil
}
}

class func lprojFilesInURL(directoryURL: NSURL) -> [LprojFile] {
class func lprojFilesInURL(_ directoryURL: URL) -> [LprojFile] {
var files = [LprojFile]()

for URL in NSFileManager.defaultManager().fileURLsInURL(directoryURL) {
for URL in FileManager.default.fileURLsInURL(directoryURL) {
if let file = LprojFile(URL: URL) {
files.append(file)
}
Expand All @@ -53,18 +53,18 @@ class LprojFile {
return files
}

init?(URL: NSURL) {
init?(URL: URL) {
self.URL = URL
self.name = URL.URLByDeletingPathExtension?.lastPathComponent ?? ""
self.name = URL.deletingPathExtension().lastPathComponent

if URL.pathExtension != "lproj" || self.name.isEmpty {
return nil
}
}

func stringsFilesForXibNames(xibNames: [String]) -> [StringsFile] {
func stringsFilesForXibNames(_ xibNames: [String]) -> [StringsFile] {
return stringsFiles.filter(){ stringsFile in
xibNames.contains((stringsFile.URL.URLByDeletingPathExtension?.lastPathComponent)!)
xibNames.contains((stringsFile.URL.deletingPathExtension().lastPathComponent))
}
}
}
}
13 changes: 6 additions & 7 deletions ls2xs/NSFileManager.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import Foundation

extension NSFileManager {
func fileURLsInURL(URL: NSURL) -> [NSURL] {
let fileManager = NSFileManager.defaultManager()
let enumerator = fileManager.enumeratorAtURL(URL, includingPropertiesForKeys: [], options: .SkipsHiddenFiles) { (URL: NSURL, error: NSError) in
extension FileManager {
func fileURLsInURL(_ URL: URL) -> [URL] {
let fileManager = FileManager.default
let enumerator = fileManager.enumerator(at: URL, includingPropertiesForKeys: [], options: .skipsHiddenFiles) { (URL: URL, error: Error) in
print("error: \(error)")
return false
}

var URLs = [NSURL]()
while let URL = enumerator?.nextObject() as? NSURL {
var URLs = [URL]
while let URL = enumerator?.nextObject() as? URL {
URLs.append(URL)
}

return URLs

}
}
12 changes: 6 additions & 6 deletions ls2xs/StringsFile.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Foundation

class StringsFile {
let URL: NSURL
let URL: URL
let name: String
var dictionary: [String: String]

init?(URL: NSURL) {
init?(URL: URL) {
self.URL = URL
self.name = URL.URLByDeletingPathExtension?.lastPathComponent ?? ""
self.dictionary = (NSDictionary(contentsOfURL: URL) as? [String: String]) ?? [String: String]()
self.name = URL.deletingPathExtension().lastPathComponent
self.dictionary = (NSDictionary(contentsOf: URL) as? [String: String]) ?? [String: String]()

if URL.pathExtension != "strings" || self.name.isEmpty {
return nil
}
}

func updateValuesUsingLocalizableStringsFile(localizableStringsFile: StringsFile) {
func updateValuesUsingLocalizableStringsFile(_ localizableStringsFile: StringsFile) {
for (key, value) in dictionary {
if let newValue = localizableStringsFile.dictionary[value] {
dictionary[key] = newValue
Expand Down Expand Up @@ -44,7 +44,7 @@ class StringsFile {

do {
// TODO: handle error
try string.writeToURL(URL, atomically: true, encoding: NSUTF8StringEncoding)
try string.write(to: URL, atomically: true, encoding: String.Encoding.utf8)
} catch _ {
}
}
Expand Down
18 changes: 9 additions & 9 deletions ls2xs/Target.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

class Target {
let URL: NSURL!
let URL: URL!

var baseLprojFile: LprojFile! {
if let URL = NSFileManager.defaultManager().fileURLsInURL(URL).filter({ URL in URL.lastPathComponent == "Base.lproj" }).first {
if let URL = FileManager.default.fileURLsInURL(URL).filter({ URL in URL.lastPathComponent == "Base.lproj" }).first {
return LprojFile(URL: URL)
} else {
return nil
Expand All @@ -14,7 +14,7 @@ class Target {
var langLprojFiles: [LprojFile] {
var files = [LprojFile]()

for lprojURL in NSFileManager.defaultManager().fileURLsInURL(URL) {
for lprojURL in FileManager.default.fileURLsInURL(URL) {
if let file = LprojFile(URL: lprojURL) {
if file.URL != baseLprojFile.URL {
files.append(file)
Expand All @@ -26,8 +26,8 @@ class Target {
}

init?(path: String) {
let currentPath = NSFileManager.defaultManager().currentDirectoryPath
let inputPath = NSURL(string: currentPath)?.URLByAppendingPathComponent(path)
let currentPath = FileManager.default.currentDirectoryPath
let inputPath = Foundation.URL(string: currentPath)?.appendingPathComponent(path)
URL = inputPath

if URL == nil {
Expand All @@ -36,7 +36,7 @@ class Target {
}

if baseLprojFile == nil {
print("error: could not find Base.lproj in \(URL.path!)")
print("error: could not find Base.lproj in \(URL.path)")
return nil
}
}
Expand All @@ -45,20 +45,20 @@ class Target {
let xibNames = baseLprojFile.xibFiles.map({ $0.name })
for xibFile in baseLprojFile.xibFiles {
for lprojFile in langLprojFiles {
print("generating .strings for \(lprojFile.URL.path!)/\(xibFile.name).strings")
print("generating .strings for \(lprojFile.URL.path)/\(xibFile.name).strings")
xibFile.generateStringsInLprojFile(lprojFile)
}
}

for lprojFile in langLprojFiles {
if let localizableStringsFile = lprojFile.localizableStringsFile {
for stringsFile in lprojFile.stringsFilesForXibNames(xibNames) {
print("updating \(stringsFile.URL.path!)")
print("updating \(stringsFile.URL.path)")
stringsFile.updateValuesUsingLocalizableStringsFile(localizableStringsFile)
stringsFile.save()
}
} else {
print("warning: Localizable.strings is not found in \(lprojFile.URL.path!)")
print("warning: Localizable.strings is not found in \(lprojFile.URL.path)")
}
}

Expand Down
Loading

0 comments on commit f8258eb

Please sign in to comment.