Skip to content

Fix how we spell "classpath" consistently #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Samples/JavaSieve/Sources/JavaSieve/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import JavaKit
import JavaMath

let jvm = try JavaVirtualMachine.shared(classPath: ["QuadraticSieve-1.0.jar"])
let jvm = try JavaVirtualMachine.shared(classpath: ["QuadraticSieve-1.0.jar"])
do {
let sieveClass = try JavaClass<SieveOfEratosthenes>(environment: jvm.environment())
for prime in sieveClass.findPrimes(100)! {
Expand Down
2 changes: 1 addition & 1 deletion Samples/JavaSieve/Sources/JavaSieve/swift-java.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"classPath" : "QuadraticSieve-1.0.jar",
"classpath" : "QuadraticSieve-1.0.jar",
"classes" : {
"com.gazman.quadratic_sieve.QuadraticSieve" : "QuadraticSieve",
"com.gazman.quadratic_sieve.core.BaseFact" : "BaseFact",
Expand Down
22 changes: 11 additions & 11 deletions Sources/Java2Swift/JavaToSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,38 +136,38 @@ struct JavaToSwift: ParsableCommand {

// Form a class path from all of our input sources:
// * Command-line option --classpath
var classPathPieces: [String] = classpath
var classpathPieces: [String] = classpath
switch generationMode {
case .configuration(jarFile: let jarFile):
// * Jar file (in `-jar` mode)
classPathPieces.append(jarFile)
classpathPieces.append(jarFile)
case .classWrappers(let config):
// * Class path specified in the configuration file (if any)
config.classPath.map { classPathPieces.append($0) }
config.classpath.map { classpathPieces.append($0) }
}

// * Classes paths from all dependent configuration files
for (_, config) in dependentConfigs {
config.classPath.map { classPathPieces.append($0) }
config.classpath.map { classpathPieces.append($0) }
}

// Bring up the Java VM.
let jvm = try JavaVirtualMachine.shared(classPath: classPathPieces)
let jvm = try JavaVirtualMachine.shared(classpath: classpathPieces)

// Run the generation step.
let classPath = classPathPieces.joined(separator: ":")
let classpath = classpathPieces.joined(separator: ":")
switch generationMode {
case .configuration(jarFile: let jarFile):
try emitConfiguration(
forJarFile: jarFile,
classPath: classPath,
classpath: classpath,
environment: jvm.environment()
)

case .classWrappers(let config):
try generateWrappers(
config: config,
classPath: classPath,
classpath: classpath,
dependentConfigs: dependentConfigs,
environment: jvm.environment()
)
Expand All @@ -177,7 +177,7 @@ struct JavaToSwift: ParsableCommand {
/// Generate wrapper
mutating func generateWrappers(
config: Configuration,
classPath: String,
classpath: String,
dependentConfigs: [(String, Configuration)],
environment: JNIEnvironment
) throws {
Expand Down Expand Up @@ -340,10 +340,10 @@ struct JavaToSwift: ParsableCommand {

mutating func emitConfiguration(
forJarFile jarFileName: String,
classPath: String,
classpath: String,
environment: JNIEnvironment
) throws {
var configuration = Configuration(classPath: classPath)
var configuration = Configuration(classpath: classpath)

let jarFile = try JarFile(jarFileName, false, environment: environment)
for entry in jarFile.entries()! {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Java2SwiftLib/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package typealias JavaVersion = Int
/// must be kept in sync.
package struct Configuration: Codable {
/// The Java class path that should be passed along to the Java2Swift tool.
package var classPath: String? = nil
package var classpath: String? = nil

/// The Java classes that should be translated to Swift. The keys are
/// canonical Java class names (e.g., java.util.Vector) and the values are
Expand All @@ -32,12 +32,12 @@ package struct Configuration: Codable {
package var targetCompatibility: JavaVersion?

package init(
classPath: String? = nil,
classpath: String? = nil,
classes: [String : String] = [:],
sourceCompatibility: JavaVersion? = nil,
targetCompatibility: JavaVersion? = nil
) {
self.classPath = classPath
self.classpath = classpath
self.classes = classes
self.sourceCompatibility = sourceCompatibility
self.targetCompatibility = targetCompatibility
Expand Down
20 changes: 10 additions & 10 deletions Sources/JavaKit/JavaKitVM/JavaVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public final class JavaVirtualMachine: @unchecked Sendable {
/// Initialize a new Java virtual machine instance.
///
/// - Parameters:
/// - classPath: The directories, JAR files, and ZIP files in which the JVM
/// - classpath: The directories, JAR files, and ZIP files in which the JVM
/// should look to find classes. This maps to the VM option
/// `-Djava.class.path=`.
/// - vmOptions: Options that should be passed along to the JVM, which will
/// be prefixed by the class-path argument described above.
/// - ignoreUnrecognized: Whether the JVM should ignore any VM options it
/// does not recognize.
private init(
classPath: [String] = [],
classpath: [String] = [],
vmOptions: [String] = [],
ignoreUnrecognized: Bool = false
) throws {
Expand All @@ -64,14 +64,14 @@ public final class JavaVirtualMachine: @unchecked Sendable {

// Construct the complete list of VM options.
var allVMOptions: [String] = []
if !classPath.isEmpty {
if !classpath.isEmpty {
let fileManager = FileManager.default
for path in classPath {
for path in classpath {
if !fileManager.fileExists(atPath: path) {
throw JavaKitError.classPathEntryNotFound(entry: path, classPath: classPath)
throw JavaKitError.classpathEntryNotFound(entry: path, classpath: classpath)
}
}
let colonSeparatedClassPath = classPath.joined(separator: ":")
let colonSeparatedClassPath = classpath.joined(separator: ":")
allVMOptions.append("-Djava.class.path=\(colonSeparatedClassPath)")
}
allVMOptions.append(contentsOf: vmOptions)
Expand Down Expand Up @@ -183,15 +183,15 @@ extension JavaVirtualMachine {
/// calls.
///
/// - Parameters:
/// - classPath: The directories, JAR files, and ZIP files in which the JVM
/// - classpath: The directories, JAR files, and ZIP files in which the JVM
/// should look to find classes. This maps to the VM option
/// `-Djava.class.path=`.
/// - vmOptions: Options that should be passed along to the JVM, which will
/// be prefixed by the class-path argument described above.
/// - ignoreUnrecognized: Whether the JVM should ignore any VM options it
/// does not recognize.
public static func shared(
classPath: [String] = [],
classpath: [String] = [],
vmOptions: [String] = [],
ignoreUnrecognized: Bool = false
) throws -> JavaVirtualMachine {
Expand Down Expand Up @@ -225,7 +225,7 @@ extension JavaVirtualMachine {
let javaVirtualMachine: JavaVirtualMachine
do {
javaVirtualMachine = try JavaVirtualMachine(
classPath: classPath,
classpath: classpath,
vmOptions: vmOptions,
ignoreUnrecognized: ignoreUnrecognized
)
Expand Down Expand Up @@ -289,6 +289,6 @@ extension JavaVirtualMachine {
}

enum JavaKitError: Error {
case classPathEntryNotFound(entry: String, classPath: [String])
case classpathEntryNotFound(entry: String, classpath: [String])
}
}
6 changes: 3 additions & 3 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ The resulting configuration file will look something like this:

```json
{
"classPath" : "QuadraticSieve-1.0.jar",
"classpath" : "QuadraticSieve-1.0.jar",
"classes" : {
"com.gazman.quadratic_sieve.QuadraticSieve" : "QuadraticSieve",
"com.gazman.quadratic_sieve.core.BaseFact" : "BaseFact",
Expand Down Expand Up @@ -206,7 +206,7 @@ Putting it all together, we can define a main program in `Sources/JavaSieve/main
```swift
import JavaKit

let jvm = try JavaVirtualMachine.shared(classPath: ["QuadraticSieve-1.0.jar"])
let jvm = try JavaVirtualMachine.shared(classpath: ["QuadraticSieve-1.0.jar"])
do {
let sieveClass = try JavaClass<SieveOfEratosthenes>(environment: jvm.environment())
for prime in sieveClass.findPrimes(100)! {
Expand All @@ -217,7 +217,7 @@ do {
}
```

Note that we are passing the Jar file in the `classPath` argument when initializing the `JavaVirtualMachine` instance. Otherwise, the program will fail with an error because it cannot find the Java class `com.gazman.quadratic_sieve.primes.SieveOfEratosthenes`.
Note that we are passing the Jar file in the `classpath` argument when initializing the `JavaVirtualMachine` instance. Otherwise, the program will fail with an error because it cannot find the Java class `com.gazman.quadratic_sieve.primes.SieveOfEratosthenes`.

### Downcasting

Expand Down