jarbler 0.4.1 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70f0325158bf02611ae188df443a2e22a3032f7b8e275e09d0e2ff8216476979
4
- data.tar.gz: 1d5ca40cfa30dad802a394e4b4980854d0a0bb093cf00eafece8ef5b090e5c85
3
+ metadata.gz: 97e69aa07983bce3eac767254171ee446d3d75f05cc391c95d4f8cf2be52b98b
4
+ data.tar.gz: 001b795796c7deb3fc315256a1938bd7aaae0bb98d12ef7575cc81bcf87dd913
5
5
  SHA512:
6
- metadata.gz: c3671a308f5c65bcc937676930c9792d6461db55f52e2dd6d609edb3ad1d75262164740b951d733fb71041954fc8ee3377b91122af78d0e1768e1977bc851470
7
- data.tar.gz: c33d7b1affbcf4cdd4c7cb9f1e5ecf375e083266c59e077ed28d4532ded06b301d4b88b29e9afb63ba0c2d98c699ca9315d7afd35b3bb2037728d3e602693d4b
6
+ metadata.gz: c1b459f1612a905b71b9e9a0c4f73c60c7ecc38bfe5427cb57f03bad3c8c4228ac9f501059ca0d3f6459031d101c2b580cc04037da54ae3a4d2385477c87d194
7
+ data.tar.gz: 2c5434ea23201d59276dbca474b6927e155d4556db012fcd78b1a1935500b3af8bc073d0db103c08300f92f467f416294cd908267d29e88431eebd2365a91589
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.3] - 2025-07-29
4
+
5
+ - Enable Ruby and JRuby warnings ($VERBOSE = true) in call of 'jarble' if environment variable `DEBUG` is set
6
+
7
+ ## [0.4.2] - 2025-07-24
8
+
9
+ - Native Gem extensions are also copied into the jar file if the Gem has a native extension<br/>
10
+ 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/>
11
+ Extensions of other platform types are copied as is.
12
+
3
13
  ## [0.4.1] - 2025-07-15
4
14
 
5
15
  - config attribute 'gemfile_groups' established to specify the groups of the Gemfile which should be included in the jar file
data/bin/jarble CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Ensure Ruby and JRuby warnings are enabled in debug mode
4
+ $VERBOSE = true if ENV['DEBUG']
5
+
3
6
  require 'jarbler'
4
7
 
5
8
  # call config if arguments are passed and argument = 'config'
@@ -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
- File destFile = new File(destinationDir, zipEntry.getName());
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
  }
@@ -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("#{gem_target_location}/extensions")
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jarbler
4
- VERSION = "0.4.1"
5
- VERSION_DATE = "2025-07-15"
4
+ VERSION = "0.4.3"
5
+ VERSION_DATE = "2025-07-29"
6
6
  end
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.1
4
+ version: 0.4.3
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-15 00:00:00.000000000 Z
11
+ date: 2025-07-29 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'