14
14
15
15
import Foundation
16
16
@testable import SwiftJavaConfigurationShared
17
- @testable import SwiftJavaTool // test in terminal with sandbox disabled, if xcode can't find the module
17
+ @testable import SwiftJavaToolLib
18
18
import Testing
19
19
20
20
@Suite ( . serialized)
21
- class JavaRepositoryTests {
21
+ class JavaResolverTests {
22
22
static let localRepo : String = String . localRepoRootDirectory. appending ( " /All " )
23
23
24
24
static let localJarRepo : String = String . localRepoRootDirectory. appending ( " /JarOnly " )
@@ -39,16 +39,16 @@ class JavaRepositoryTests {
39
39
#if compiler(>=6.2)
40
40
@Test
41
41
func nonResolvableDependency( ) async throws {
42
- try await #expect( processExitsWith: . failure, " commonCSVWithUnknownDependencies " ) {
42
+ await #expect( processExitsWith: . failure, " commonCSVWithUnknownDependencies " ) {
43
43
try await resolve ( configuration: . commonCSVWithUnknownDependencies)
44
44
}
45
- try await #expect( processExitsWith: . failure, " helloWorldInLocalRepoIncludeIOOnly " ) {
45
+ await #expect( processExitsWith: . failure, " helloWorldInLocalRepoIncludeIOOnly " ) {
46
46
try await resolve ( configuration: . helloWorldInLocalRepoIncludeIOOnly)
47
47
}
48
- try await #expect( processExitsWith: . failure, " androidCoreInCentral " ) {
48
+ await #expect( processExitsWith: . failure, " androidCoreInCentral " ) {
49
49
try await resolve ( configuration: . androidCoreInCentral)
50
50
}
51
- try await #expect( processExitsWith: . failure, " helloWorldInRepoWithoutArtifact " ) {
51
+ await #expect( processExitsWith: . failure, " helloWorldInRepoWithoutArtifact " ) {
52
52
try await resolve ( configuration: . helloWorldInRepoWithoutArtifact)
53
53
}
54
54
}
@@ -90,18 +90,16 @@ class JavaRepositoryTests {
90
90
// Wired issue with #require, marking the function as static seems to resolve it
91
91
private func resolve( configuration: SwiftJavaConfigurationShared . Configuration ) async throws {
92
92
var config = configuration
93
- var command = try SwiftJava . ResolveCommand. parse ( [
94
- " --output-directory " ,
95
- " .build/ \( configuration. swiftModule!) /destination/SwiftJavaPlugin " ,
96
-
97
- " --swift-module " ,
98
- configuration. swiftModule!,
99
- ] )
100
93
try config. publishSampleJavaProjectIfNeeded ( )
101
- try await command. runSwiftJavaCommand ( config: & config)
94
+ try await JavaResolver . runResolveCommand (
95
+ config: & config,
96
+ input: nil ,
97
+ swiftModule: configuration. swiftModule!,
98
+ outputDirectory: " .build/ \( configuration. swiftModule!) /destination/SwiftJavaPlugin "
99
+ )
102
100
}
103
101
104
- extension SwiftJavaConfigurationShared . Configuration {
102
+ extension SwiftJavaConfigurationShared . Configuration : @ unchecked Sendable {
105
103
static var resolvableConfigurations : [ Configuration ] = [
106
104
. commonCSV, . jitpackJson,
107
105
. helloWorldInTempRepo,
@@ -140,7 +138,7 @@ extension SwiftJavaConfigurationShared.Configuration {
140
138
]
141
139
configuration. packageToPublish = " SimpleJavaProject "
142
140
143
- configuration. repositories = [ . maven( url: JavaRepositoryTests . localRepo) ]
141
+ configuration. repositories = [ . maven( url: JavaResolverTests . localRepo) ]
144
142
return configuration
145
143
} ( )
146
144
@@ -156,8 +154,8 @@ extension SwiftJavaConfigurationShared.Configuration {
156
154
static let helloWorldInRepoWithCustomArtifacts : Configuration = {
157
155
var configuration = Configuration . helloWorldInTempRepo
158
156
configuration. repositories = [
159
- . maven( url: JavaRepositoryTests . localPomRepo, artifactUrls: [
160
- JavaRepositoryTests . localJarRepo,
157
+ . maven( url: JavaResolverTests . localPomRepo, artifactUrls: [
158
+ JavaResolverTests . localJarRepo,
161
159
] ) ,
162
160
]
163
161
return configuration
@@ -207,8 +205,8 @@ extension SwiftJavaConfigurationShared.Configuration {
207
205
var configuration = Configuration . helloWorldInTempRepo
208
206
209
207
configuration. repositories = [
210
- . maven( url: JavaRepositoryTests . localJarRepo /* , artifactUrls: [
211
- JavaRepositoryTests .localPomRepo
208
+ . maven( url: JavaResolverTests . localJarRepo /* , artifactUrls: [
209
+ JavaResolverTests .localPomRepo
212
210
] */ ) ,
213
211
]
214
212
return configuration
@@ -230,10 +228,17 @@ private extension SwiftJavaConfigurationShared.Configuration {
230
228
return
231
229
}
232
230
231
+ var gradlewPath = String . packageDirectory + " /gradlew "
232
+ if !FileManager. default. fileExists ( atPath: gradlewPath) {
233
+ let currentWorkingDir = URL ( filePath: . packageDirectory) . appendingPathComponent ( " .build " , isDirectory: true )
234
+ try JavaResolver . copyGradlew ( to: currentWorkingDir)
235
+ gradlewPath = currentWorkingDir. appendingPathComponent ( " gradlew " ) . path
236
+ }
233
237
let process = Process ( )
234
- process. executableURL = URL ( fileURLWithPath: . gradlewPath)
238
+ process. executableURL = URL ( fileURLWithPath: gradlewPath)
239
+ let packagePath = URL ( fileURLWithPath: #file) . deletingLastPathComponent ( ) . appendingPathComponent ( packageName) . path
235
240
process. arguments = [
236
- " -p " , " \( String . packageDirectory ) /Tests/SwiftJavaToolTests/ \( packageName ) " ,
241
+ " -p " , " \( packagePath ) " ,
237
242
" publishAllArtifacts " ,
238
243
" publishToMavenLocal " , // also publish to maven local to test includeGroups"
239
244
" -q " ,
@@ -261,16 +266,14 @@ private extension String {
261
266
defer { free ( path) }
262
267
263
268
let dir = String ( cString: path)
264
- // TODO: This needs to be tested in Xcode as well, for now Xcode can't run tests, due to this issue: https://github.com/swiftlang/swift-java/issues/281
265
- precondition ( dir. hasSuffix ( " swift-java " ) , " Please run the tests from the swift-java directory " )
266
- return dir
269
+ if dir. hasSuffix ( " swift-java " ) { // most likely running with `swift test`
270
+ return dir
271
+ } else {
272
+ return FileManager . default. temporaryDirectory. path
273
+ }
267
274
}
268
275
269
276
static var localRepoRootDirectory : Self {
270
277
packageDirectory + " /.build/SwiftJavaToolTests/LocalRepo "
271
278
}
272
-
273
- static var gradlewPath : Self {
274
- packageDirectory + " /gradlew "
275
- }
276
279
}
0 commit comments