jarbler 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/jarbler/JarMain.java +87 -1
- data/lib/jarbler/builder.rb +16 -1
- data/lib/jarbler/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af40fd597f65765920d0825c739db3604cd8ec0d6a975889e10b9f17b0869dce
|
4
|
+
data.tar.gz: 3b887f4cb0ce06669a78da49cdc3f28fd7137cca0e7cd7eeebd60cfc1f8a3f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b07fc51c641293913293b3d3cf4713e306f73c3f746237406905dfe973f31ca08497db7a35ebb1d870bc89a2690aa5775fbfe84c1bd120108cc3c7bb4e8fe786
|
7
|
+
data.tar.gz: 6b8ef9fe88116c68b47ad5fc7d3f7923d8a8e0d5c5b511fbe1c9a9a179841ab95035fa65dd3761f7d1466e2d0df9176b8061eed9dc548109290499cb07f04783
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.2] - 2025-07-24
|
4
|
+
|
5
|
+
- Native Gem extensions are also copied into the jar file if the Gem has a native extension<br/>
|
6
|
+
If the extension is of platform type 'universal-java-XX' then the 'XX' in the dir name 'universal-java-XX' is corrected with the real Java major version at start of the jar file.<br/>
|
7
|
+
Extensions of other platform types are copied as is.
|
8
|
+
|
3
9
|
## [0.4.1] - 2025-07-15
|
4
10
|
|
5
11
|
- config attribute 'gemfile_groups' established to specify the groups of the Gemfile which should be included in the jar file
|
data/lib/jarbler/JarMain.java
CHANGED
@@ -157,6 +157,11 @@ class JarMain {
|
|
157
157
|
//debug("JRuby set property 'jruby.gem.home' to '" + full_gem_home + "'");
|
158
158
|
//System.setProperty("jruby.gem.home", full_gem_home);
|
159
159
|
|
160
|
+
// Enable JRuby warnings, not proof to really function
|
161
|
+
System.setProperty("jruby.log.warnings", "true");
|
162
|
+
System.setProperty("jruby.cli.verbose", "true");
|
163
|
+
// System.setProperty("jruby.debug.fullTrace", "true");
|
164
|
+
|
160
165
|
debug("JRuby program starts with the following arguments: ");
|
161
166
|
for (String arg : mainArgs) {
|
162
167
|
debug(" - " + arg);
|
@@ -244,7 +249,16 @@ class JarMain {
|
|
244
249
|
*/
|
245
250
|
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
|
246
251
|
try {
|
247
|
-
|
252
|
+
String destFileName = zipEntry.getName();
|
253
|
+
|
254
|
+
// the platform name in extension dir depends on the the target java version, therfore we replace the platform name here
|
255
|
+
if (destFileName.contains("universal-java-XX")) {
|
256
|
+
String newPlatformName = "universal-java-" + javaMajorRelease4RubyPlatform();
|
257
|
+
debug ("Replacing platform name in file '" + destFileName + "' from 'universal-java-XX' to '" + newPlatformName + "'");
|
258
|
+
destFileName = destFileName.replace("universal-java-XX", newPlatformName);
|
259
|
+
}
|
260
|
+
|
261
|
+
File destFile = new File(destinationDir, destFileName);
|
248
262
|
|
249
263
|
String destDirPath = destinationDir.getCanonicalPath();
|
250
264
|
String destFilePath = destFile.getCanonicalPath();
|
@@ -348,4 +362,76 @@ class JarMain {
|
|
348
362
|
System.err.println(errorSummary);
|
349
363
|
}
|
350
364
|
}
|
365
|
+
|
366
|
+
/**
|
367
|
+
* Get the major release of the Java platform a'la universal-java-XX
|
368
|
+
* @return [int] The major release of the Java platform, e.g. "java-universal-11"
|
369
|
+
*/
|
370
|
+
|
371
|
+
private static int javaMajorRelease4RubyPlatform() {
|
372
|
+
try {
|
373
|
+
// --- Ansatz 1: Für Java 9 und höher (empfohlen) ---
|
374
|
+
// Versuche, Runtime.version() zu verwenden.
|
375
|
+
// Wir nutzen Reflection, damit der Code auch mit einem Java 8 JDK kompiliert werden kann,
|
376
|
+
// aber trotzdem die moderne API verwendet, wenn er auf einem Java 9+ JRE läuft.
|
377
|
+
Class<?> runtimeClass = Class.forName("java.lang.Runtime");
|
378
|
+
Method versionMethod = runtimeClass.getMethod("version");
|
379
|
+
Object versionObject = versionMethod.invoke(null); // Runtime.version() ist eine statische Methode
|
380
|
+
|
381
|
+
// Hole die "major" Methode vom zurückgegebenen Runtime.Version Objekt
|
382
|
+
Class<?> versionClass = Class.forName("java.lang.Runtime$Version");
|
383
|
+
Method majorMethod = versionClass.getMethod("major");
|
384
|
+
return (int) majorMethod.invoke(versionObject);
|
385
|
+
|
386
|
+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | java.lang.reflect.InvocationTargetException e) {
|
387
|
+
// --- Ansatz 2: Fallback für Java 8 und älter ---
|
388
|
+
// Dieser Block wird ausgeführt, wenn Runtime.version() nicht verfügbar ist
|
389
|
+
// (z.B. auf Java 8) oder wenn Reflection fehlschlägt.
|
390
|
+
|
391
|
+
String javaVersion = System.getProperty("java.version");
|
392
|
+
// Beispiele für java.version:
|
393
|
+
// Java 8: "1.8.0_291"
|
394
|
+
// Java 11: "11.0.11"
|
395
|
+
// Java 17: "17.0.2"
|
396
|
+
// Java 9: "9" (manchmal ohne weitere Punkte)
|
397
|
+
|
398
|
+
// Prüfe, ob es sich um das alte "1.x.y" Format handelt
|
399
|
+
if (javaVersion.startsWith("1.")) {
|
400
|
+
// Für "1.x.y_z" ist die Hauptversion 'x'
|
401
|
+
// Beispiel: "1.8.0_291" -> '8'
|
402
|
+
try {
|
403
|
+
return Integer.parseInt(javaVersion.substring(2, 3));
|
404
|
+
} catch (NumberFormatException ex) {
|
405
|
+
// Sollte nicht passieren, aber zur Sicherheit
|
406
|
+
System.err.println("Fehler beim Parsen der Java 1.x Version: " + javaVersion + " - " + ex.getMessage());
|
407
|
+
return -1;
|
408
|
+
}
|
409
|
+
} else {
|
410
|
+
// Für "x.y.z" oder "x" Format (Java 9+ Stil)
|
411
|
+
// Beispiel: "11.0.11" -> '11', "17.0.2" -> '17', "9" -> '9'
|
412
|
+
int dotIndex = javaVersion.indexOf('.');
|
413
|
+
if (dotIndex != -1) {
|
414
|
+
try {
|
415
|
+
return Integer.parseInt(javaVersion.substring(0, dotIndex));
|
416
|
+
} catch (NumberFormatException ex) {
|
417
|
+
System.err.println("Fehler beim Parsen der Java x.y Version: " + javaVersion + " - " + ex.getMessage());
|
418
|
+
return -1;
|
419
|
+
}
|
420
|
+
} else {
|
421
|
+
// Fallback für den Fall, dass nur die Hauptversion angegeben ist (z.B. "9", "10", "11")
|
422
|
+
try {
|
423
|
+
return Integer.parseInt(javaVersion);
|
424
|
+
} catch (NumberFormatException ex) {
|
425
|
+
System.err.println("Fehler beim Parsen der Java Hauptversion: " + javaVersion + " - " + ex.getMessage());
|
426
|
+
return -1;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
}
|
430
|
+
} catch (NumberFormatException e) {
|
431
|
+
// Dieser Catch-Block fängt Fehler ab, die auftreten, wenn System.getProperty("java.version")
|
432
|
+
// ein unerwartetes Format hat, das nicht geparst werden kann.
|
433
|
+
System.err.println("Fehler beim Parsen der Java-Versionszeichenkette: " + System.getProperty("java.version") + " - " + e.getMessage());
|
434
|
+
return -1;
|
435
|
+
}
|
436
|
+
}
|
351
437
|
}
|
data/lib/jarbler/builder.rb
CHANGED
@@ -95,11 +95,15 @@ module Jarbler
|
|
95
95
|
# @return [void]
|
96
96
|
def copy_needed_gems_to_staging(staging_dir, ruby_minor_version)
|
97
97
|
gem_target_location = "#{staging_dir}/gems/jruby/#{ruby_minor_version}"
|
98
|
+
|
99
|
+
# Replace universal-java-XX with the correct platform for the current Java version after unzipping of the jar file
|
100
|
+
extension_target_location = "#{gem_target_location}/extensions/universal-java-XX/#{ruby_minor_version}"
|
101
|
+
|
98
102
|
FileUtils.mkdir_p("#{gem_target_location}/bin")
|
99
103
|
FileUtils.mkdir_p("#{gem_target_location}/build_info")
|
100
104
|
FileUtils.mkdir_p("#{gem_target_location}/cache")
|
101
105
|
FileUtils.mkdir_p("#{gem_target_location}/doc")
|
102
|
-
FileUtils.mkdir_p(
|
106
|
+
FileUtils.mkdir_p(extension_target_location)
|
103
107
|
FileUtils.mkdir_p("#{gem_target_location}/gems")
|
104
108
|
FileUtils.mkdir_p("#{gem_target_location}/specifications")
|
105
109
|
FileUtils.mkdir_p("#{gem_target_location}/bundler/bin")
|
@@ -115,8 +119,10 @@ module Jarbler
|
|
115
119
|
# differentiate between Gems from git/bundler and Gems from rubygems
|
116
120
|
if spec.source.is_a?(Bundler::Source::Git)
|
117
121
|
# Copy the Gem from bundler/gems including the gemspec
|
122
|
+
debug "Adding Bundler Gem from dir '#{spec.gem_dir}' into jar file at temporary location '#{gem_target_location}/gems'"
|
118
123
|
file_utils_copy(spec.gem_dir, "#{gem_target_location}/bundler/gems")
|
119
124
|
spec.executables.each do |executable|
|
125
|
+
debug "Adding executable of Bundler Gem from dir '#{spec.bin_dir}#{executable}/' into jar file at temporary location '#{gem_target_location}/bundler/bin'"
|
120
126
|
file_utils_copy("#{spec.bin_dir}/#{executable}", "#{gem_target_location}/bundler/bin")
|
121
127
|
end
|
122
128
|
else # Gem is from rubygems
|
@@ -124,10 +130,19 @@ module Jarbler
|
|
124
130
|
# Should the default gems are also copied to the staging directory?
|
125
131
|
unless spec.default_gem? # Do not copy default gems, because they are already included in the jruby jars standard library
|
126
132
|
# copy the Gem and gemspec separately
|
133
|
+
debug "Adding local Gem from dir '#{spec.gem_dir}' into jar file at temporary location '#{gem_target_location}/gems'"
|
127
134
|
file_utils_copy(spec.gem_dir, "#{gem_target_location}/gems")
|
135
|
+
|
136
|
+
if spec.extension_dir && Dir.exist?(spec.extension_dir)
|
137
|
+
debug "Adding extension from dir '#{spec.extension_dir}' into jar file at temporary location '#{extension_target_location}'"
|
138
|
+
puts "Adding extension from dir '#{spec.extension_dir}' into jar file but extension is not for platform 'universal-java-xx'!!!" unless spec.extension_dir['universal-java']
|
139
|
+
file_utils_copy(spec.extension_dir, extension_target_location)
|
140
|
+
end
|
141
|
+
|
128
142
|
# spec.loaded_from contains the path to the gemspec file including the path prefix "default/" for default gems
|
129
143
|
file_utils_copy(spec.loaded_from, "#{gem_target_location}/specifications")
|
130
144
|
spec.executables.each do |executable|
|
145
|
+
debug "Adding executable of local Gem from dir '#{spec.bin_dir}#{executable}/' into jar file at temporary location '#{gem_target_location}/bin'"
|
131
146
|
file_utils_copy("#{spec.bin_dir}/#{executable}", "#{gem_target_location}/bin")
|
132
147
|
end
|
133
148
|
end
|
data/lib/jarbler/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jarbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ramm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Pack a Ruby app combined with JRuby runtime and all its Gem dependencies
|
14
14
|
into a jar file to simply run the app on any Java platform by '> java -jar file.jar'
|