Skip to content

Commit

Permalink
Add swift lint and format actions (#1692)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Jan 19, 2024
1 parent bdb78ca commit 209c46b
Show file tree
Hide file tree
Showing 112 changed files with 568 additions and 474 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Swift lint and format

on:
workflow_dispatch:
push:
branches: ["main"]
paths:
- "swift/**"
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
paths:
- "swift/**"

jobs:
swift-lint:
name: Swift Lint
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install SwiftLints
run: brew install swiftformat

- name: SwiftLint
working-directory: swift
run: swiftlint --config .swiftlint.yml --strict

swift-format:
name: Swift Format
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install SwiftFormat
run: brew install swiftformat

- name: SwiftFormat
working-directory: swift
run: swiftformat --lint --verbose **/*.swift
6 changes: 3 additions & 3 deletions swift/src/Ice/AdminFacetFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AdminFacetFactory: ICEAdminFacetFactory {
return AdminFacetFacade(communicator: c,
disp: ProcessDisp(handle.getSwiftObject(ProcessI.self) {
ProcessI(handle: handle)
}))
}))
}

static func createProperties(_ communicator: ICECommunicator, handle: ICEPropertiesAdmin) -> ICEBlobjectFacade {
Expand All @@ -116,7 +116,7 @@ class AdminFacetFactory: ICEAdminFacetFactory {
return AdminFacetFacade(communicator: c,
disp: PropertiesAdminDisp(handle.getSwiftObject(PropertiesAdminI.self) {
PropertiesAdminI(communicator: c, handle: handle)
}))
}))
}

static func createUnsupported(_ communicator: ICECommunicator,
Expand All @@ -125,6 +125,6 @@ class AdminFacetFactory: ICEAdminFacetFactory {
return AdminFacetFacade(communicator: c,
disp: ObjectDisp(handle.getSwiftObject(UnsupportedAdminFacet.self) {
UnsupportedAdminFacet(handle: handle)
}))
}))
}
}
1 change: 1 addition & 0 deletions swift/src/Ice/BlobjectAsync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public struct BlobjectAsyncDisp: Disp {
public init(_ servant: BlobjectAsync) {
self.servant = servant
}

public func dispatch(request: Request, current: Current) throws -> Promise<OutputStream>? {
let inEncaps = try request.readParamEncaps()
return servant.ice_invokeAsync(inEncaps: inEncaps, current: current).map(on: nil) { invokeResult in
Expand Down
35 changes: 21 additions & 14 deletions swift/src/Ice/Communicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import PromiseKit
/// the string is the same for all modes: you don't need to specify an encoding format or mode when reading such a
/// string.
public enum ToStringMode: Swift.UInt8 {
/// Unicode Characters with ordinal values greater than 127 are kept as-is in the resulting string. Non-printable ASCII
/// characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
/// Unicode Characters with ordinal values greater than 127 are kept as-is in the resulting string. Non-printable
/// ASCII characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
case Unicode = 0
/// ASCII Characters with ordinal values greater than 127 are encoded as universal character names in the resulting
/// string: \\unnnn for BMP characters and \\Unnnnnnnn for non-BMP characters. Non-printable ASCII characters
/// with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
case ASCII = 1
/// Compat Characters with ordinal values greater than 127 are encoded as a sequence of UTF-8 bytes using octal escapes.
/// Compat Characters with ordinal values greater than 127 are encoded as a sequence of UTF-8 bytes using octal
/// escapes.
/// Characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or an octal escape. Use this mode
/// to generate strings compatible with Ice 3.6 and earlier.
case Compat = 2
Expand Down Expand Up @@ -86,7 +87,7 @@ public extension OutputStream {

/// The central object in Ice. One or more communicators can be instantiated for an Ice application. Communicator
/// instantiation is language-specific, and not specified in Slice code.
public protocol Communicator: Swift.AnyObject {
public protocol Communicator: Swift.AnyObject {
/// Destroy the communicator. This operation calls shutdown implicitly. Calling destroy cleans up
/// memory, and shuts down this communicator's client functionality and destroys all object adapters. Subsequent
/// calls to destroy are ignored.
Expand Down Expand Up @@ -195,7 +196,8 @@ public protocol Communicator: Swift.AnyObject {

/// Get the implicit context associated with this communicator.
///
/// - returns: `ImplicitContext` - The implicit context associated with this communicator; returns null when the property Ice.ImplicitContext
/// - returns: `ImplicitContext` - The implicit context associated with this communicator; returns null when the
/// property Ice.ImplicitContext
/// is not set or is set to None.
func getImplicitContext() -> ImplicitContext

Expand Down Expand Up @@ -245,16 +247,16 @@ public protocol Communicator: Swift.AnyObject {
/// for all connections associated with the communicator. Any errors that occur while flushing a connection are
/// ignored.
///
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before being sent over
/// the wire.
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before
/// being sent over the wire.
func flushBatchRequests(_ compress: CompressBatch) throws

/// Flush any pending batch requests for this communicator. This means all batch requests invoked on fixed proxies
/// for all connections associated with the communicator. Any errors that occur while flushing a connection are
/// ignored.
///
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before being sent over
/// the wire.
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before
/// being sent over the wire.
///
/// - parameter sentOn: `Dispatch.DispatchQueue?` - Optional dispatch queue used to
/// dispatch the sent callback.
Expand All @@ -265,15 +267,18 @@ public protocol Communicator: Swift.AnyObject {
/// - parameter sent: `((Swift.Bool) -> Swift.Void)` - Optional sent callback.
///
/// - returns: `PromiseKit.Promise<>` - The result of the operation
func flushBatchRequestsAsync(_ compress: CompressBatch, sentOn: Dispatch.DispatchQueue?, sentFlags: Dispatch.DispatchWorkItemFlags?, sent: ((Swift.Bool) -> Swift.Void)?) -> PromiseKit.Promise<Swift.Void>
func flushBatchRequestsAsync(_ compress: CompressBatch,
sentOn: Dispatch.DispatchQueue?,
sentFlags: Dispatch.DispatchWorkItemFlags?,
sent: ((Swift.Bool) -> Swift.Void)?) -> PromiseKit.Promise<Swift.Void>

/// Add the Admin object with all its facets to the provided object adapter. If Ice.Admin.ServerId is
/// set and the provided object adapter has a Locator, createAdmin registers the Admin's Process facet with
/// the Locator's LocatorRegistry. createAdmin must only be called once; subsequent calls raise
/// InitializationException.
///
/// - parameter adminAdapter: `ObjectAdapter?` The object adapter used to host the Admin object; if null and Ice.Admin.Endpoints is set,
/// create, activate and use the Ice.Admin object adapter.
/// - parameter adminAdapter: `ObjectAdapter?` The object adapter used to host the Admin object; if null and
/// Ice.Admin.Endpoints is set, create, activate and use the Ice.Admin object adapter.
///
/// - parameter adminId: `Identity` The identity of the Admin object.
///
Expand All @@ -286,7 +291,8 @@ public protocol Communicator: Swift.AnyObject {
/// Ice.Admin.InstanceName is not set. If Ice.Admin.DelayCreation is 0 or not set, getAdmin is called
/// by the communicator initialization, after initialization of all plugins.
///
/// - returns: `ObjectPrx?` - A proxy to the main ("") facet of the Admin object, or a null proxy if no Admin object is configured.
/// - returns: `ObjectPrx?` - A proxy to the main ("") facet of the Admin object, or a null proxy if no Admin
/// object is configured.
func getAdmin() throws -> ObjectPrx?

/// Add a new facet to the Admin object. Adding a servant with a facet that is already registered throws
Expand All @@ -310,7 +316,8 @@ public protocol Communicator: Swift.AnyObject {
///
/// - parameter _: `Swift.String` The name of the Admin facet.
///
/// - returns: `Disp?` - The servant associated with this Admin facet, or null if no facet is registered with the given name.
/// - returns: `Disp?` - The servant associated with this Admin facet, or null if no facet is registered with the
/// given name.
func findAdminFacet(_ facet: Swift.String) -> Disp?

/// Returns a map of all facets of the Admin object.
Expand Down
2 changes: 1 addition & 1 deletion swift/src/Ice/CommunicatorI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public extension Communicator {
if let sentCB = sentCB {
sentCB($0)
}
})
})
}
}

Expand Down
51 changes: 29 additions & 22 deletions swift/src/Ice/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public enum ACMClose: Swift.UInt8 {
case CloseOff = 0
/// CloseOnIdle Gracefully closes a connection that has been idle for the configured timeout period.
case CloseOnIdle = 1
/// CloseOnInvocation Forcefully closes a connection that has been idle for the configured timeout period, but only if the connection
/// has pending invocations.
/// CloseOnInvocation Forcefully closes a connection that has been idle for the configured timeout period, but
/// only if the connection has pending invocations.
case CloseOnInvocation = 2
/// CloseOnInvocationAndIdle Combines the behaviors of CloseOnIdle and CloseOnInvocation.
case CloseOnInvocationAndIdle = 3
/// CloseOnIdleForceful Forcefully closes a connection that has been idle for the configured timeout period, regardless of whether the
/// connection has pending invocations or dispatch.
/// CloseOnIdleForceful Forcefully closes a connection that has been idle for the configured timeout period,
/// regardless of whether the connection has pending invocations or dispatch.
case CloseOnIdleForceful = 4
public init() {
self = .CloseOff
Expand Down Expand Up @@ -148,7 +148,8 @@ public extension OutputStream {
public enum ACMHeartbeat: Swift.UInt8 {
/// HeartbeatOff Disables heartbeats.
case HeartbeatOff = 0
/// HeartbeatOnDispatch Send a heartbeat at regular intervals if the connection is idle and only if there are pending dispatch.
/// HeartbeatOnDispatch Send a heartbeat at regular intervals if the connection is idle and only if there are
/// pending dispatch.
case HeartbeatOnDispatch = 1
/// HeartbeatOnIdle Send a heartbeat at regular intervals when the connection is idle.
case HeartbeatOnIdle = 2
Expand Down Expand Up @@ -227,11 +228,11 @@ public struct ACM: Swift.Hashable {

/// Determines the behavior when manually closing a connection.
public enum ConnectionClose: Swift.UInt8 {
/// Forcefully Close the connection immediately without sending a close connection protocol message to the peer and waiting
/// for the peer to acknowledge it.
/// Forcefully Close the connection immediately without sending a close connection protocol message to the peer
/// and waiting for the peer to acknowledge it.
case Forcefully = 0
/// Gracefully Close the connection by notifying the peer but do not wait for pending outgoing invocations to complete. On the
/// server side, the connection will not be closed until all incoming invocations have completed.
/// Gracefully Close the connection by notifying the peer but do not wait for pending outgoing invocations to
/// complete. On the server side, the connection will not be closed until all incoming invocations have completed.
case Gracefully = 1
/// GracefullyWithWait Wait for all pending invocations to complete before closing the connection.
case GracefullyWithWait = 2
Expand Down Expand Up @@ -292,7 +293,7 @@ public extension OutputStream {
public typealias HeaderDict = [Swift.String: Swift.String]

/// Base class providing access to the connection details.
public protocol ConnectionInfo: Swift.AnyObject {
public protocol ConnectionInfo: Swift.AnyObject {
/// The information of the underyling transport or null if there's no underlying transport.
var underlying: ConnectionInfo? { get set }
/// Whether or not the connection is an incoming or outgoing connection.
Expand Down Expand Up @@ -320,7 +321,7 @@ public typealias CloseCallback = (Connection?) -> Swift.Void
public typealias HeartbeatCallback = (Connection?) -> Swift.Void

/// The user-level interface to a connection.
public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
/// Manually close the connection using the specified closure mode.
///
/// - parameter _: `ConnectionClose` Determines how the connection will be closed.
Expand All @@ -340,14 +341,15 @@ public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
/// is used by the proxy in order to receive callbacks. This is useful if the server cannot establish a connection
/// back to the client, for example because of firewalls.
///
/// - parameter _: `ObjectAdapter?` The object adapter that should be used by this connection to dispatch requests. The object
/// adapter must be activated. When the object adapter is deactivated, it is automatically removed from the
/// connection. Attempts to use a deactivated object adapter raise ObjectAdapterDeactivatedException
/// - parameter _: `ObjectAdapter?` The object adapter that should be used by this connection to dispatch requests.
/// The object adapter must be activated. When the object adapter is deactivated, it is automatically removed from
/// the connection. Attempts to use a deactivated object adapter raise ObjectAdapterDeactivatedException
func setAdapter(_ adapter: ObjectAdapter?) throws

/// Get the object adapter that dispatches requests for this connection.
///
/// - returns: `ObjectAdapter?` - The object adapter that dispatches requests for the connection, or null if no adapter is set.
/// - returns: `ObjectAdapter?` - The object adapter that dispatches requests for the connection, or null if no
/// adapter is set.
func getAdapter() -> ObjectAdapter?

/// Get the endpoint from which the connection was created.
Expand All @@ -358,15 +360,15 @@ public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
/// Flush any pending batch requests for this connection. This means all batch requests invoked on fixed proxies
/// associated with the connection.
///
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before being sent over
/// the wire.
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before
/// being sent over the wire.
func flushBatchRequests(_ compress: CompressBatch) throws

/// Flush any pending batch requests for this connection. This means all batch requests invoked on fixed proxies
/// associated with the connection.
///
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before being sent over
/// the wire.
/// - parameter _: `CompressBatch` Specifies whether or not the queued batch requests should be compressed before
/// being sent over the wire.
///
/// - parameter sentOn: `Dispatch.DispatchQueue?` - Optional dispatch queue used to
/// dispatch the sent callback.
Expand All @@ -377,7 +379,10 @@ public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
/// - parameter sent: `((Swift.Bool) -> Swift.Void)` - Optional sent callback.
///
/// - returns: `PromiseKit.Promise<>` - The result of the operation
func flushBatchRequestsAsync(_ compress: CompressBatch, sentOn: Dispatch.DispatchQueue?, sentFlags: Dispatch.DispatchWorkItemFlags?, sent: ((Swift.Bool) -> Swift.Void)?) -> PromiseKit.Promise<Swift.Void>
func flushBatchRequestsAsync(_ compress: CompressBatch,
sentOn: Dispatch.DispatchQueue?,
sentFlags: Dispatch.DispatchWorkItemFlags?,
sent: ((Swift.Bool) -> Swift.Void)?) -> PromiseKit.Promise<Swift.Void>

/// Set a close callback on the connection. The callback is called by the connection when it's closed. The callback
/// is called from the Ice thread pool associated with the connection. If the callback needs more information about
Expand Down Expand Up @@ -406,7 +411,9 @@ public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
/// - parameter sent: `((Swift.Bool) -> Swift.Void)` - Optional sent callback.
///
/// - returns: `PromiseKit.Promise<>` - The result of the operation
func heartbeatAsync(sentOn: Dispatch.DispatchQueue?, sentFlags: Dispatch.DispatchWorkItemFlags?, sent: ((Swift.Bool) -> Swift.Void)?) -> PromiseKit.Promise<Swift.Void>
func heartbeatAsync(sentOn: Dispatch.DispatchQueue?,
sentFlags: Dispatch.DispatchWorkItemFlags?,
sent: ((Swift.Bool) -> Swift.Void)?) -> PromiseKit.Promise<Swift.Void>

/// Set the active connection management parameters.
///
Expand All @@ -425,7 +432,7 @@ public protocol Connection: Swift.AnyObject, Swift.CustomStringConvertible {
/// Return the connection type. This corresponds to the endpoint type, i.e., "tcp", "udp", etc.
///
/// - returns: `Swift.String` - The type of the connection.
func `type`() -> Swift.String
func type() -> Swift.String

/// Get the timeout for the connection.
///
Expand Down
13 changes: 7 additions & 6 deletions swift/src/Ice/Current.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@ import Foundation
/// applications ignore this parameter.
public class Current {
/// The object adapter.
public var adapter: ObjectAdapter? = nil
public var adapter: ObjectAdapter?
/// Information about the connection over which the current method invocation was received. If the invocation is
/// direct due to collocation optimization, this value is set to null.
public var con: Connection? = nil
public var con: Connection?
/// The Ice object identity.
public var id: Identity = Identity()
public var id: Identity = .init()
/// The facet.
public var facet: Swift.String = ""
/// The operation name.
public var operation: Swift.String = ""
/// The mode of the operation.
public var mode: OperationMode = .Normal
/// The request context, as received from the client.
public var ctx: Context = Context()
public var ctx: Context = .init()
/// The request id unless oneway (0).
public var requestId: Swift.Int32 = 0
/// The encoding version used to encode the input and output parameters.
public var encoding: EncodingVersion = EncodingVersion()
public var encoding: EncodingVersion = .init()

public init() {}

public init(adapter: ObjectAdapter?, con: Connection?, id: Identity, facet: Swift.String, operation: Swift.String, mode: OperationMode, ctx: Context, requestId: Swift.Int32, encoding: EncodingVersion) {
public init(adapter: ObjectAdapter?, con: Connection?, id: Identity, facet: Swift.String, operation: Swift.String,
mode: OperationMode, ctx: Context, requestId: Swift.Int32, encoding: EncodingVersion) {
self.adapter = adapter
self.con = con
self.id = id
Expand Down
Loading

0 comments on commit 209c46b

Please sign in to comment.