Skip to content

Commit

Permalink
Merge pull request #215 from pushkarnk/swift-5-bringup
Browse files Browse the repository at this point in the history
Swift 5 bringup
  • Loading branch information
ianpartridge authored Apr 17, 2019
2 parents a4f6b25 + 8bcd857 commit a96abb2
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2
5.0
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ matrix:
- os: linux
dist: trusty
sudo: required
env: SWIFT_SNAPSHOT=4.1.3 KITURA_NIO=1
env: SWIFT_SNAPSHOT=4.2.4
- os: linux
dist: trusty
sudo: required
- os: linux
dist: trusty
sudo: required
env: KITURA_NIO=1
env: SWIFT_SNAPSHOT=4.2.4 KITURA_NIO=1
- os: osx
osx_image: xcode9.2
sudo: required
Expand All @@ -41,19 +41,18 @@ matrix:
sudo: required
env: SWIFT_SNAPSHOT=4.1.2
- os: osx
osx_image: xcode9.4
osx_image: xcode10.1
sudo: required
env: SWIFT_SNAPSHOT=4.1.2 KITURA_NIO=1
env: SWIFT_SNAPSHOT=4.2.1
- os: osx
osx_image: xcode10
osx_image: xcode10.2
sudo: required
- os: osx
osx_image: xcode10
osx_image: xcode10.1
sudo: required
env: KITURA_NIO=1
env: SWIFT_SNAPSHOT=4.2.1 KITURA_NIO=1 BREW_INSTALL_PACKAGES="libressl"

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update && brew install libressl ; fi
- git clone https://github.com/IBM-Swift/Package-Builder.git

script:
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// swift-tools-version:4.2
// swift-tools-version:5.0
/**
* Copyright IBM Corporation 2017
* Copyright IBM Corporation 2017-2019
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ import Foundation
var webSocketPackage: Package.Dependency

if ProcessInfo.processInfo.environment["KITURA_NIO"] != nil {
webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "1.0.0")
webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "2.0.0")
} else {
webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0")
}
Expand Down
67 changes: 67 additions & 0 deletions Package@swift-4.2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// swift-tools-version:4.2
/**
* Copyright IBM Corporation 2017-2019
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import PackageDescription
import Foundation

var webSocketPackage: Package.Dependency

if ProcessInfo.processInfo.environment["KITURA_NIO"] != nil {
webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "1.0.0")
} else {
webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0")
}

let package = Package(
name: "SwiftMetrics",
products: [
.library(
name: "SwiftMetrics",
targets: ["SwiftMetrics",
"SwiftMetricsKitura",
"SwiftBAMDC",
"SwiftMetricsBluemix",
"SwiftMetricsDash",
"SwiftMetricsREST",
"SwiftMetricsPrometheus"]),

.executable(name: "SwiftMetricsEmitSample", targets: ["SwiftMetricsEmitSample"]),
.executable(name: "SwiftMetricsCommonSample", targets: ["SwiftMetricsCommonSample"]),
],
dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura.git", from: "2.3.0"),
webSocketPackage,
.package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", from: "6.0.0"),
.package(url: "https://github.com/RuntimeTools/omr-agentcore", .exact("3.2.4-swift4")),
.package(url: "https://github.com/IBM-Swift/BlueCryptor", from: "1.0.0")
],
targets: [
.target(name: "SwiftMetrics", dependencies: ["agentcore", "hcapiplugin", "envplugin", "cpuplugin", "memplugin", "CloudFoundryEnv"]),
.target(name: "SwiftMetricsKitura", dependencies: ["SwiftMetrics", "Kitura"]),
.target(name: "SwiftBAMDC", dependencies: ["SwiftMetricsKitura", "Kitura-WebSocket", "Cryptor"]),
.target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC"]),
.target(name: "SwiftMetricsDash", dependencies: ["SwiftMetricsBluemix"]),
.target(name: "SwiftMetricsREST", dependencies: ["SwiftMetricsKitura"]),
.target(name: "SwiftMetricsPrometheus", dependencies:["SwiftMetricsKitura"]),
.target(name: "SwiftMetricsCommonSample", dependencies: ["SwiftMetrics"],
path: "commonSample/Sources"),
.target(name: "SwiftMetricsEmitSample", dependencies: ["SwiftMetrics"],
path: "emitSample/Sources"),
.testTarget(name: "CoreSwiftMetricsTests", dependencies: ["SwiftMetrics"]),
.testTarget(name: "SwiftMetricsRESTTests", dependencies: ["SwiftMetricsREST"])
]
)
7 changes: 6 additions & 1 deletion Sources/SwiftMetrics/SwiftMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ public class SwiftMonitor {
let values = message.components(separatedBy: "\n")
var env: [ String : String ] = [:]
for value in values {
if value.contains("="), let firstEquals = value.index(of: "=") {
#if swift(>=4.2)
let firstIndex = value.firstIndex(of: "=")
#else
let firstIndex = value.index(of: "=")
#endif
if value.contains("="), let firstEquals = firstIndex {
env[String(value[..<firstEquals])] = String(value[value.index(after: firstEquals)...])
}
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/SwiftMetricsREST/SwiftMetricsREST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ public class SwiftMetricsREST {
guard var temp_httpUrlReports = smrCollectionList[key]?.collection.httpUrls else {
continue;
}
if let index = temp_httpUrlReports.data.index(where: { $0.url == http.url && $0.method == http.requestMethod}) {
#if swift(>=4.2)
let firstIndex = temp_httpUrlReports.data.firstIndex(where: { $0.url == http.url && $0.method == http.requestMethod})
#else
let firstIndex = temp_httpUrlReports.data.index(where: { $0.url == http.url && $0.method == http.requestMethod})
#endif
if let index = firstIndex {
temp_httpUrlReports.data[index].hits += 1
if (http.duration > temp_httpUrlReports.data[index].longestResponseTime ) {
temp_httpUrlReports.data[index].longestResponseTime = http.duration
Expand Down
7 changes: 6 additions & 1 deletion Tests/SwiftMetricsRESTTests/SwiftMetricsRESTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,12 @@ class SwiftMetricsRESTTests: XCTestCase {
for tSMRMPCCcollectionUriString in tSMRMPCCresult2.collectionUris {
let tSMRMPCCsplitCollectionUriString = tSMRMPCCcollectionUriString.split(separator: "/")
let tSMRMPCCcollectionUriIDString = String(tSMRMPCCsplitCollectionUriString[tSMRMPCCsplitCollectionUriString.count - 1])
guard let index = idArray.index(of: tSMRMPCCcollectionUriIDString) else {
#if swift(>=4.2)
let firstIndex = idArray.firstIndex(of: tSMRMPCCcollectionUriIDString)
#else
let firstIndex = idArray.index(of: tSMRMPCCcollectionUriIDString)
#endif
guard let index = firstIndex else {
print("\(tSMRMPCCresult2)")
XCTFail("Collection ID \(tSMRMPCCcollectionUriIDString) not in expected range [0-2]")
return
Expand Down

0 comments on commit a96abb2

Please sign in to comment.