Skip to content

Commit

Permalink
Merge pull request #12 from brightdigit/release/2.0.4
Browse files Browse the repository at this point in the history
fixed internationalization issue with version suffix
  • Loading branch information
leogdion authored Dec 19, 2017
2 parents faea066 + 954be86 commit cec2e59
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: objective-c
os: osx
osx_image: xcode9
osx_image: xcode9.2
script:
- gem install xcpretty-travis-formatter cocoapods
- npm install -g doctoc
Expand All @@ -14,8 +14,8 @@ script:

- xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer macOS" -destination 'platform=OS X,arch=x86_64' -enableCodeCoverage YES test
- bash <(curl -s https://codecov.io/bash) -cF macOS -X xcodeplist -g Tests
- xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer iOS" -destination "platform=iOS Simulator,name=iPhone 7 Plus,OS=11.0" -enableCodeCoverage YES test
- xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer iOS" -destination "platform=iOS Simulator,name=iPhone 7 Plus,OS=11.2" -enableCodeCoverage YES test
- bash <(curl -s https://codecov.io/bash) -cF iOS -X xcodeplist -g Tests
- xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=11.0" -enableCodeCoverage YES test
- xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer tvOS" -destination "platform=tvOS Simulator,name=Apple TV,OS=11.2" -enableCodeCoverage YES test
- bash <(curl -s https://codecov.io/bash) -cF tvOS -X xcodeplist -g Tests
- ruby ./Tests/CheckCocoaPodsQualityIndexes.rb SwiftVer
2 changes: 1 addition & 1 deletion Examples/macOS Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftVer

class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {

@IBOutlet weak var tableView: NSTableView!
@IBOutlet var tableView: NSTableView!
public let values = Version.example.values

override func viewDidLoad() {
Expand Down
2 changes: 1 addition & 1 deletion Source/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public extension Data {
public init?(hexString: String) {
var hex = hexString
self.init()
while hex.characters.count > 0 {
while hex.count > 0 {
let c: String = hex.substring(to: hex.index(hex.startIndex, offsetBy: 2))
hex = hex.substring(from: hex.index(hex.startIndex, offsetBy: 2))
var ch: UInt32 = 0
Expand Down
2 changes: 1 addition & 1 deletion Source/RFC3339DateFormatter.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

fileprivate let _rfc3339DateFormatter = {
private let _rfc3339DateFormatter = {
() -> DateFormatter in
let formatter = DateFormatter()
formatter.setupRFC3339DateFormatter()
Expand Down
41 changes: 33 additions & 8 deletions Source/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ public struct Version: CustomStringConvertible {
public static let build = "CFBundleVersion"
}

private static let suffixFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.minimumFractionDigits = 10
formatter.minimumIntegerDigits = 1
return formatter
}()
// private static let suffixFormatter: NumberFormatter = {
// Version.suffixFormatter(forLocale: nil)
// }()

/**
Semantic Version.
Expand Down Expand Up @@ -172,13 +169,41 @@ public struct Version: CustomStringConvertible {
return dictionary.stage(withBuildForVersion: self)?.stage
}

public func suffixFormatter(forLocale locale: Locale?) -> NumberFormatter {
let formatter = NumberFormatter()
if let locale = locale {
formatter.locale = locale
}
formatter.minimumFractionDigits = 10
formatter.minimumIntegerDigits = 1
return formatter
}

public func fullDescription(withLocale locale: Locale?) throws -> String {
let formatter = suffixFormatter(forLocale: locale)
return try fullDescription(withFormatter: formatter)
}

public func fullDescription(withFormatter formatter: NumberFormatter) throws -> String {
guard let formattedNumber = formatter.string(for: subSemVerValue) else {
throw VersionNumberSuffixFormatError(formatter: formatter, value: subSemVerValue)
}
let components = formattedNumber.components(separatedBy: formatter.decimalSeparator)
guard components.count == 2 else {
throw VersionNumberSuffixParseError(formatter: formatter, value: subSemVerValue)
}
let suffixString = components[1]
return "\(semver).\(suffixString)"
}

/**
A Full Descripton which also contains the Sub-Semantic Version value
parsed from the VersionControlInfo.
*/
@available(*, deprecated: 2.0.4, message: "Use function calls instead.")
public var fullDescription: String {
let suffixString = Version.suffixFormatter.string(for: subSemVerValue)!.components(separatedBy: ".")[1]
return "\(semver).\(suffixString)"
// swiftlint:disable:next force_try
return try! fullDescription(withLocale: nil)
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Source/VersionNumberSuffixFormatError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

public struct VersionNumberSuffixFormatError: Error {
public let formatter: NumberFormatter
public let value: Double
}
6 changes: 6 additions & 0 deletions Source/VersionNumberSuffixParseError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

public struct VersionNumberSuffixParseError: Error {
public let formatter: NumberFormatter
public let value: Double
}
2 changes: 1 addition & 1 deletion SwiftVer.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SwiftVer'
s.version = '2.0.3'
s.version = '2.0.4'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'Parses bundle and autorevision version information for use in applications and about pages.'
s.description = <<-DESC
Expand Down
5 changes: 3 additions & 2 deletions Tests/SwiftVerTests/GlobalVersionTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

class GlobalVersionTests: XCTestCase {

Expand Down Expand Up @@ -128,7 +128,8 @@ class GlobalVersionTests: XCTestCase {
let version = Version(bundle: bundle,
dictionary: MockBundle.globalBuildNumberDictionary,
versionControl: versionControlInfo)
XCTAssertEqual(version?.fullDescription, "1.1.0.0900250000")
XCTAssertEqual((try? version?.fullDescription(withLocale: Locale(identifier: "en_US")))!, "1.1.0.0900250000")
XCTAssertEqual((try? version?.fullDescription(withLocale: Locale(identifier: "nl_NL")))!, "1.1.0.0900250000")
}

public func testSubSemVerValue() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftVerTests/HashTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

class HashTests: XCTestCase {
private let hashStrings = [
Expand Down
5 changes: 3 additions & 2 deletions Tests/SwiftVerTests/IntraVersionTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

class IntraVersionTests: XCTestCase {

Expand Down Expand Up @@ -127,7 +127,8 @@ class IntraVersionTests: XCTestCase {
let version = Version(bundle: bundle,
dictionary: MockBundle.intraBuildNumberDictionary,
versionControl: versionControlInfo)
XCTAssertEqual(version?.fullDescription, "1.0.0.0700250000")
XCTAssertEqual((try? version?.fullDescription(withLocale: Locale(identifier: "en_US")))!, "1.0.0.0700250000")
XCTAssertEqual((try? version?.fullDescription(withLocale: Locale(identifier: "nl_NL")))!, "1.0.0.0700250000")
}

public func testSubSemVerValue() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftVerTests/RFC3339DateFormatterTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

class RFC3339DateFormatterTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftVerTests/SemVerTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

class SemVerTests: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

class StageBuildDictionaryProtocolTests: XCTestCase {
struct MockStageBuildDictionary: StageBuildDictionaryProtocol {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftVerTests/VersionControlInfoTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import SwiftVer
import XCTest

let versionControlInfo = VersionControlInfo(
type: VCS_TYPE,
Expand Down
10 changes: 5 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# fi
# done

iOSVersions_TRAVIS=(8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 10.0 10.1 10.2 10.3 11.0)
iOSVersions_LOCAL=(9.3 11.0)
iOSVersions_TRAVIS=(8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 10.0 10.1 10.2 10.3 11.0 11.1 11.2)
iOSVersions_LOCAL=(11.2)

[[ $TRAVIS ]] && iOSVersions=${iOSVersions_TRAVIS[*]} || iOSVersions=${iOSVersions_LOCAL[*]}

Expand All @@ -24,13 +24,13 @@ for iOSVersion in ${iOSVersions[@]}; do
xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer iOS" -destination "platform=iOS Simulator,name=iPad Air,OS=${iOSVersion}" clean test | xcpretty -f `xcpretty-travis-formatter` && exit ${PIPESTATUS[0]}
done

tvOSVersions_TRAVIS=(9.0 9.1 9.2 10.0 10.1 10.2 11.0)
tvOSVersions_LOCAL=(11.0)
tvOSVersions_TRAVIS=(9.0 9.1 9.2 10.0 10.1 10.2 11.0 11.1 11.2)
tvOSVersions_LOCAL=(11.2)

[[ $TRAVIS ]] && tvOSVersions=${tvOSVersions_TRAVIS[*]} || iOSVersions=${tvOSVersions_LOCAL[*]}

for tvOSVersion in ${tvOSVersions[@]}; do
xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=${tvOSVersion}" clean test | xcpretty -f `xcpretty-travis-formatter` && exit ${PIPESTATUS[0]}
xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer tvOS" -destination "platform=tvOS Simulator,name=Apple TV,OS=${tvOSVersion}" clean test | xcpretty -f `xcpretty-travis-formatter` && exit ${PIPESTATUS[0]}
done

xcodebuild -project SwiftVer.xcodeproj -scheme "SwiftVer macOS" -destination 'platform=OS X,arch=x86_64' clean test | xcpretty -f `xcpretty-travis-formatter` && exit ${PIPESTATUS[0]}
32 changes: 28 additions & 4 deletions swiftver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
B30724ED1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724EC1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift */; };
B30724EE1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724EC1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift */; };
B30724EF1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724EC1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift */; };
B30724F11FE864F3003DA398 /* VersionNumberSuffixParseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724F01FE864F3003DA398 /* VersionNumberSuffixParseError.swift */; };
B30724F21FE864F3003DA398 /* VersionNumberSuffixParseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724F01FE864F3003DA398 /* VersionNumberSuffixParseError.swift */; };
B30724F31FE864F3003DA398 /* VersionNumberSuffixParseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724F01FE864F3003DA398 /* VersionNumberSuffixParseError.swift */; };
B30724F41FE86525003DA398 /* VersionNumberSuffixFormatError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724EC1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift */; };
B30724F51FE86528003DA398 /* VersionNumberSuffixParseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B30724F01FE864F3003DA398 /* VersionNumberSuffixParseError.swift */; };
B31FED101F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B31FED0F1F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift */; };
B31FED111F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B31FED0F1F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift */; };
B31FED121F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B31FED0F1F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift */; };
Expand Down Expand Up @@ -146,6 +154,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
B30724EC1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionNumberSuffixFormatError.swift; sourceTree = "<group>"; };
B30724F01FE864F3003DA398 /* VersionNumberSuffixParseError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionNumberSuffixParseError.swift; sourceTree = "<group>"; };
B31FED0F1F1D529A00550DEF /* StageBuildDictionaryProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StageBuildDictionaryProtocolTests.swift; sourceTree = "<group>"; };
B337BEF01F09510E00518323 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
B337BEF11F09510E00518323 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
Expand All @@ -157,6 +167,8 @@
B338FE6F1F214CBA00617EA6 /* Hash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = "<group>"; };
B35326501F0A830D00604112 /* versions-global.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "versions-global.plist"; sourceTree = "<group>"; };
B35326581F0A843B00604112 /* versions-intra.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "versions-intra.plist"; sourceTree = "<group>"; };
B35907AB1FE89ED100E2BD61 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
B35907AC1FE89ED200E2BD61 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
B366BF001F211B3500AC0195 /* ResourceContainerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceContainerProtocol.swift; sourceTree = "<group>"; };
B366BF0C1F2184F300AC0195 /* HashTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashTests.swift; sourceTree = "<group>"; };
B37840541D92757F008FE737 /* VersionControlType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionControlType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -272,6 +284,8 @@
D95E1BD31D88D63200F94976 = {
isa = PBXGroup;
children = (
B35907AB1FE89ED100E2BD61 /* .travis.yml */,
B35907AC1FE89ED200E2BD61 /* build.sh */,
B337BEF01F09510E00518323 /* LICENSE */,
B337BEF41F09510E00518323 /* Package.swift */,
B337BEF11F09510E00518323 /* README.md */,
Expand Down Expand Up @@ -317,6 +331,8 @@
B3FE6A141D91D3630085656C /* Version.swift */,
B37840581D927595008FE737 /* VersionControlInfo.swift */,
B37840541D92757F008FE737 /* VersionControlType.swift */,
B30724EC1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift */,
B30724F01FE864F3003DA398 /* VersionNumberSuffixParseError.swift */,
);
path = Source;
sourceTree = "<group>";
Expand Down Expand Up @@ -558,7 +574,7 @@
};
};
};
buildConfigurationList = D95E1BD71D88D63300F94976 /* Build configuration list for PBXProject "swiftver" */;
buildConfigurationList = D95E1BD71D88D63300F94976 /* Build configuration list for PBXProject "SwiftVer" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
Expand Down Expand Up @@ -817,6 +833,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B30724F31FE864F3003DA398 /* VersionNumberSuffixParseError.swift in Sources */,
B30724EF1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift in Sources */,
B37840E71D92DD72008FE737 /* InfoDictionaryContainerProtocol.swift in Sources */,
B378407C1D9277DD008FE737 /* Version.swift in Sources */,
B378407D1D9277DD008FE737 /* RFC3339DateFormatter.swift in Sources */,
Expand Down Expand Up @@ -854,6 +872,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B30724F51FE86528003DA398 /* VersionNumberSuffixParseError.swift in Sources */,
B30724F41FE86525003DA398 /* VersionNumberSuffixFormatError.swift in Sources */,
B37840E81D92DD72008FE737 /* InfoDictionaryContainerProtocol.swift in Sources */,
B38B1A1B1D9210CA007AAAD7 /* Version.swift in Sources */,
B38B1A1C1D9210CA007AAAD7 /* RFC3339DateFormatter.swift in Sources */,
Expand All @@ -874,6 +894,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B30724F21FE864F3003DA398 /* VersionNumberSuffixParseError.swift in Sources */,
B30724EE1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift in Sources */,
B37840E61D92DD72008FE737 /* InfoDictionaryContainerProtocol.swift in Sources */,
B38B1A1E1D9210CA007AAAD7 /* Version.swift in Sources */,
B38B1A1F1D9210CA007AAAD7 /* RFC3339DateFormatter.swift in Sources */,
Expand Down Expand Up @@ -911,6 +933,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B30724F11FE864F3003DA398 /* VersionNumberSuffixParseError.swift in Sources */,
B30724ED1FE864D9003DA398 /* VersionNumberSuffixFormatError.swift in Sources */,
B37840E51D92DD72008FE737 /* InfoDictionaryContainerProtocol.swift in Sources */,
B3FE6A161D91D3630085656C /* Version.swift in Sources */,
B3FE6A171D91D3630085656C /* RFC3339DateFormatter.swift in Sources */,
Expand Down Expand Up @@ -1227,7 +1251,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PROJECT_BUNDLE_VERSION_SHORT = 2.0.3;
PROJECT_BUNDLE_VERSION_SHORT = 2.0.4;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand Down Expand Up @@ -1283,7 +1307,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
PROJECT_BUNDLE_VERSION_SHORT = 2.0.3;
PROJECT_BUNDLE_VERSION_SHORT = 2.0.4;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
Expand Down Expand Up @@ -1416,7 +1440,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
D95E1BD71D88D63300F94976 /* Build configuration list for PBXProject "swiftver" */ = {
D95E1BD71D88D63300F94976 /* Build configuration list for PBXProject "SwiftVer" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D95E1BEF1D88D63400F94976 /* Debug */,
Expand Down

0 comments on commit cec2e59

Please sign in to comment.