Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9b624db
Add repositories configuration option in swift-java.config
bo2themax Aug 26, 2025
7bf0de7
Add a repositories configuration example and fix artifactUrls output
bo2themax Aug 26, 2025
6a126ec
Update naming convention
bo2themax Aug 26, 2025
ef69b18
Rename descriptionGradleStyle
bo2themax Aug 28, 2025
5a6616b
Add JavaJson Example
bo2themax Aug 28, 2025
9416c56
Change JavaRepositoryDescriptor to enum
bo2themax Aug 28, 2025
149358a
Add JavaRepositoryTests to test dependencies resolving with custom re…
bo2themax Aug 28, 2025
52243ad
Add documentation for swift-java resolve
bo2themax Aug 28, 2025
764d586
Add another non-resolvable config to verify artifactUrls
bo2themax Aug 28, 2025
7f6cd04
Move JavaRepositoryTests to SwiftJavaToolTests
bo2themax Aug 29, 2025
8bb6cfa
Rename JavaJson to OrgAndrejsJson
bo2themax Aug 29, 2025
c57c017
Add referenced issue in the document
bo2themax Aug 29, 2025
ab8f3ab
[Test] Change minified json to pretty printed
bo2themax Aug 29, 2025
f6f9800
Remove System dependency from OrgAndrejsJsonTests
bo2themax Aug 29, 2025
de3dab3
Add more referenced documents for JavaRepositoryDescriptor
bo2themax Aug 29, 2025
f6ad15f
[Test] Add a SimpleJavaProject to JavaRepositoryTests
bo2themax Aug 29, 2025
8e0687b
Merge branch 'swiftlang:main' into main
bo2themax Aug 29, 2025
a61c518
[Test] Update error messages in JavaRepositoryTests.swift
bo2themax Aug 29, 2025
967ccaf
[Test] Add missing license headers
bo2themax Aug 31, 2025
8fe1360
Add JavaResolver in SwiftJavaToolLib to resolve for ResolveCommand
bo2themax Sep 1, 2025
be87290
[Test] Move SwiftJavaToolTests/JavaRepositoryTests
bo2themax Sep 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[Test] Move SwiftJavaToolTests/JavaRepositoryTests
  • Loading branch information
bo2themax committed Sep 1, 2025
commit be8729097b4573e4a58f937590ff27219e7458da
17 changes: 3 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,6 @@ let package = Package(
]
),

.testTarget(
name: "SwiftJavaToolTests",
dependencies: [
"SwiftJavaTool",
],
exclude: [
"SimpleJavaProject",
],
swiftSettings: [
.swiftLanguageMode(.v5),
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
]
),

.testTarget(
name: "JavaTypesTests",
dependencies: [
Expand All @@ -502,6 +488,9 @@ let package = Package(
dependencies: [
"SwiftJavaToolLib"
],
exclude: [
"SimpleJavaProject",
],
swiftSettings: [
.swiftLanguageMode(.v5),
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import Foundation
@testable import SwiftJavaConfigurationShared
@testable import SwiftJavaTool // test in terminal with sandbox disabled, if xcode can't find the module
@testable import SwiftJavaToolLib
import Testing

@Suite(.serialized)
class JavaRepositoryTests {
class JavaResolverTests {
static let localRepo: String = String.localRepoRootDirectory.appending("/All")

static let localJarRepo: String = String.localRepoRootDirectory.appending("/JarOnly")
Expand All @@ -39,16 +39,16 @@ class JavaRepositoryTests {
#if compiler(>=6.2)
@Test
func nonResolvableDependency() async throws {
try await #expect(processExitsWith: .failure, "commonCSVWithUnknownDependencies") {
await #expect(processExitsWith: .failure, "commonCSVWithUnknownDependencies") {
try await resolve(configuration: .commonCSVWithUnknownDependencies)
}
try await #expect(processExitsWith: .failure, "helloWorldInLocalRepoIncludeIOOnly") {
await #expect(processExitsWith: .failure, "helloWorldInLocalRepoIncludeIOOnly") {
try await resolve(configuration: .helloWorldInLocalRepoIncludeIOOnly)
}
try await #expect(processExitsWith: .failure, "androidCoreInCentral") {
await #expect(processExitsWith: .failure, "androidCoreInCentral") {
try await resolve(configuration: .androidCoreInCentral)
}
try await #expect(processExitsWith: .failure, "helloWorldInRepoWithoutArtifact") {
await #expect(processExitsWith: .failure, "helloWorldInRepoWithoutArtifact") {
try await resolve(configuration: .helloWorldInRepoWithoutArtifact)
}
}
Expand Down Expand Up @@ -90,18 +90,16 @@ class JavaRepositoryTests {
// Wired issue with #require, marking the function as static seems to resolve it
private func resolve(configuration: SwiftJavaConfigurationShared.Configuration) async throws {
var config = configuration
var command = try SwiftJava.ResolveCommand.parse([
"--output-directory",
".build/\(configuration.swiftModule!)/destination/SwiftJavaPlugin",

"--swift-module",
configuration.swiftModule!,
])
try config.publishSampleJavaProjectIfNeeded()
try await command.runSwiftJavaCommand(config: &config)
try await JavaResolver.runResolveCommand(
config: &config,
input: nil,
swiftModule: configuration.swiftModule!,
outputDirectory: ".build/\(configuration.swiftModule!)/destination/SwiftJavaPlugin"
)
}

extension SwiftJavaConfigurationShared.Configuration {
extension SwiftJavaConfigurationShared.Configuration: @unchecked Sendable {
static var resolvableConfigurations: [Configuration] = [
.commonCSV, .jitpackJson,
.helloWorldInTempRepo,
Expand Down Expand Up @@ -140,7 +138,7 @@ extension SwiftJavaConfigurationShared.Configuration {
]
configuration.packageToPublish = "SimpleJavaProject"

configuration.repositories = [.maven(url: JavaRepositoryTests.localRepo)]
configuration.repositories = [.maven(url: JavaResolverTests.localRepo)]
return configuration
}()

Expand All @@ -156,8 +154,8 @@ extension SwiftJavaConfigurationShared.Configuration {
static let helloWorldInRepoWithCustomArtifacts: Configuration = {
var configuration = Configuration.helloWorldInTempRepo
configuration.repositories = [
.maven(url: JavaRepositoryTests.localPomRepo, artifactUrls: [
JavaRepositoryTests.localJarRepo,
.maven(url: JavaResolverTests.localPomRepo, artifactUrls: [
JavaResolverTests.localJarRepo,
]),
]
return configuration
Expand Down Expand Up @@ -207,8 +205,8 @@ extension SwiftJavaConfigurationShared.Configuration {
var configuration = Configuration.helloWorldInTempRepo

configuration.repositories = [
.maven(url: JavaRepositoryTests.localJarRepo /* , artifactUrls: [
JavaRepositoryTests.localPomRepo
.maven(url: JavaResolverTests.localJarRepo /* , artifactUrls: [
JavaResolverTests.localPomRepo
] */ ),
]
return configuration
Expand All @@ -230,10 +228,17 @@ private extension SwiftJavaConfigurationShared.Configuration {
return
}

var gradlewPath = String.packageDirectory + "/gradlew"
if !FileManager.default.fileExists(atPath: gradlewPath) {
let currentWorkingDir = URL(filePath: .packageDirectory).appendingPathComponent(".build", isDirectory: true)
try JavaResolver.copyGradlew(to: currentWorkingDir)
gradlewPath = currentWorkingDir.appendingPathComponent("gradlew").path
}
let process = Process()
process.executableURL = URL(fileURLWithPath: .gradlewPath)
process.executableURL = URL(fileURLWithPath: gradlewPath)
let packagePath = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent(packageName).path
process.arguments = [
"-p", "\(String.packageDirectory)/Tests/SwiftJavaToolTests/\(packageName)",
"-p", "\(packagePath)",
"publishAllArtifacts",
"publishToMavenLocal", // also publish to maven local to test includeGroups"
"-q",
Expand Down Expand Up @@ -261,16 +266,14 @@ private extension String {
defer { free(path) }

let dir = String(cString: path)
// 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
precondition(dir.hasSuffix("swift-java"), "Please run the tests from the swift-java directory")
return dir
if dir.hasSuffix("swift-java") { // most likely running with `swift test`
return dir
} else {
return FileManager.default.temporaryDirectory.path
}
}

static var localRepoRootDirectory: Self {
packageDirectory + "/.build/SwiftJavaToolTests/LocalRepo"
}

static var gradlewPath: Self {
packageDirectory + "/gradlew"
}
}
Loading