warbler 2.1.1 → 2.1.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: b68e1cba9a7e9e892eb9f5950fe177c07a7bba4f349813e7bb9b18e82ad9bbcc
4
- data.tar.gz: b0ed237291f26d1a79204499007d1527a97899214672474ef7cacd0aeb8591c4
3
+ metadata.gz: c7fb231c020b4d2741d3f7bbdd82ec762779e5c2779e1000efb763c44fce75fe
4
+ data.tar.gz: a840520bcac2301dbf761fac4c1f57814eaaf45fbe6c5327b6394d30614cfc31
5
5
  SHA512:
6
- metadata.gz: 577dc3b4f393e6f4891e42806efdd64ab3ce8d3d222ff6b8ba6994a5f9376461ebcde493433d8875468cfacd8b63ec9fd058d26d8e6672e54458aa4120420e47
7
- data.tar.gz: d6a263d75de2a1f2f179751face07f9b922002a7bcaa7b0534289a2188067e52ac8131fd814014421008912cb183d3afb120a6d51566072c3c737a4ed90b05b4
6
+ metadata.gz: 353d17017001ea0203ac7c0a5f414edee3b0f3ef21d2173352dbe46ebce78861d08961bcf55b2bca0fe12cb188e44860cd066d0f7c2ea48283e02d4ed253183e
7
+ data.tar.gz: 94a725feac177e933007be96d6320c1b2f54e08d1558f7ddd9f1d77ea42eda8f18a1d1ee6db061bd86d290ade020ac4b1b7fe6126839586ca2114846d49d7657
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 2.1.3
2
+ - #584, #655: chore: move boot classes out of the default package
3
+
4
+ ## 2.1.2
5
+
6
+ - #649: fix: further improve isolation of warbled jars/wars from host bundler configuration
7
+ - #648: fix: further improve isolation of warbled jars/wars from user/host gem paths
8
+ - #465: fix: remove duplication of bundler path gems in warbled jars/wars
9
+ - #331: fix: correct support for `gem_excludes` inside bundler git specs
10
+ - chore: relax jruby-rack requirement to allow compatibility with upcoming 2.0.x
11
+
1
12
  ## 2.1.1
2
13
 
3
14
  - #624, #635, #623: fix: ensure compatibility with JRuby 10.1
data/Gemfile CHANGED
@@ -3,7 +3,12 @@ source "https://rubygems.org/"
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
- gem 'rdoc', '~> 7.0', :require => nil
6
+ gem 'rdoc', '< 8', :require => nil
7
+ gem 'rspec', '~> 3.0'
8
+ gem 'drb', '~> 2.2', '>= 2.2.3'
9
+
10
+ # JBundler is unsupported on JRuby 10.1
11
+ gem 'jbundler', '~> 0.9.5' if RUBY_VERSION.to_f < 4.0
7
12
 
8
13
  if defined?(JRUBY_VERSION)
9
14
  # force jruby-jars to use current JRuby version for testing
data/README.rdoc CHANGED
@@ -11,15 +11,14 @@ Ruby applications to assemble and Just Work.
11
11
  == Compatibility
12
12
 
13
13
  Warbler Status JRuby Java JRuby-Rack Rails Notes
14
- ------- ---------- ---------- ---- ---------- --------- ----------------------------------------------
15
- 2.1 Maintained 9.4 → 10.1 8+ 1.2 → 1.3 5.0 → 8.0 Rails 8.1 may be OK with pure Ruby webservers.
14
+ ------- ---------- ---------- ---- ---------- --------- -----
15
+ 2.1 Maintained 9.4 → 10.1 8+ 1.2 → 2.0 5.0 → 8.1
16
16
  2.0 EOL 9.2 → 9.3 6+ 1.1 → 1.2 → 6.1
17
17
  1.4 EOL 1.1 → 1.7 5+ ? ?
18
18
 
19
- For running wars with specific Java web servers, consult jruby-rack compatibility (
20
- {master}[https://github.com/jruby/jruby-rack/tree/master],
21
- {1.2-stable}[https://github.com/jruby/jruby-rack/tree/1.2-stable],
22
- {1.1-stable}[https://github.com/jruby/jruby-rack/tree/1.1-stable] ).
19
+ For running wars with specific Java web servers, consult {JRuby-Rack compatibility}[https://github.com/jruby/jruby-rack#compatibility]
20
+ to decide which JRuby-Rack version you may need to use. While warbler is compatible with multiple jruyb-rackversions, it does not
21
+ know your target webserver, so you may need to further restrict your JRuby-Rack version
23
22
 
24
23
  == Getting Started
25
24
 
@@ -177,7 +176,7 @@ script for your Rack-based application. You will probably need to specify
177
176
  framework and application gems in +config/warble.rb+ unless you're using Bundler
178
177
  to manage your gems. <tt>ENV['RACK_ENV']</tt> will be set to +production+.
179
178
 
180
- See {the examples in the jruby-rack project}[http://github.com/jruby/jruby-rack/tree/master/examples/]
179
+ See {the examples in the JRuby-Rack project}[http://github.com/jruby/jruby-rack/tree/master/examples/]
181
180
  of how to configure Warbler to package Camping and Sinatra apps.
182
181
 
183
182
  === Configuration Notes
@@ -256,45 +255,48 @@ task to give you more insight into what's going on.
256
255
  If you think you found a bug, please file one at
257
256
  https://github.com/jruby/warbler/issues.
258
257
 
259
- === Common issues with executable wars
258
+ === Common issues with wars
260
259
 
261
- If your app isn't working or starting up correctly:
260
+ If your app isn't working or starting up correctly:
262
261
 
263
- - <b>Missing Logging:</b>
264
- If your boot process is failing silently (or with a logging warning), try configuring the logger
265
- manually:
266
-
267
- java "-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog" -jar my_app.war
262
+ - <b>Jruby-Rack version not compatible with JRuby version</b>
263
+ jruby-rack-2.0.0 requires Ruby version >= 3.4.0. The current ruby version is 3.1.7.
264
+ jruby-rack-1.3.0 requires Ruby version >= 3.4.0. The current ruby version is 3.1.7.
265
+ Warbler is compatible with multiple JRuby-Rack versions which have different JRuby requirements. You are trying to use
266
+ a JRuby-Rack version which does not support your JRuby version; without using bundler to resolve dependencies.
267
+ - Consult {JRuby-Rack compatibility}[https://github.com/jruby/jruby-rack#compatibility]
268
+ - Use a bundler `:development` group to install warbler, and ensure bundler is running with your intended runtime
269
+ JRuby version so the JRuby-Rack dependency is resolved correctly.
270
+
271
+ - <b>Rack version compatibility</b>
272
+ An exception happened during JRuby-Rack startup
273
+ no such file to load -- rack/chunked
274
+ You are trying to use Rack 3.x with a JRuby-Rack version that does not yet support Rack 3. Try upgrading to a compatible
275
+ JRuby-Rack version, or lock rack at a compatibile version with <tt>gem 'rack', '~> 2.2.0'</tt>. Note that Rack `2.2` requires Rails < `8.1`.
276
+
277
+ - <b>Rack missing at runtime</b>
278
+ org.jruby.exceptions.LoadError: (LoadError) cannot load such file -- rack
279
+ JRuby-Rack no longer vendors Rack - make sure the rack gem is available to the application (e.g. add it to the Gemfile or install it into the gem path)
280
+ You are trying to use JRuby-Rack 1.3+, without a bundle or gem path that resolves an appropriate Rack version via the
281
+ `jruby-rack` gem's runtime dependency. Try one of (with appropriate rack version):
282
+ - Bundler: add <tt>gem 'rack', '~> 2.2.0'</tt> or similar as a default/runtime dependency to your `Gemfile`
283
+ - Rubygems: add <tt>config.gems['rack'] = '~> 2.2.0'</tt> to your `config/warble.rb`
268
284
 
269
285
  - <b>CompatVersion errors:</b>
270
286
  If you are getting <tt>java.lang.NoClassDefFoundError: org/jruby/CompatVersion</tt> errors at start-up
271
- you are probably running Warbler with a jruby-rack version which does not yet support JRuby 10+ - it
272
- swallows the true error making debugging impossible. Ensure you're on jruby-rack `1.2.7+`.
287
+ you are probably running Warbler with a JRuby-Rack version which does not yet support JRuby 10+ - it
288
+ swallows the true error making debugging impossible. Ensure you're on JRuby-Rack `1.2.7+`.
273
289
 
274
290
  - <b>Bundler `restart_with` errors:</b>
275
291
  If you are getting <tt>org.jruby.rack.RackInitializationException: No such file or directory - java -cp...</tt>,
276
292
  that probably means bundler is trying to switch versions dynamically during start-up because your
277
293
  `Gemfile.lock` implies a different locked version of bundler to that packaged with JRuby by default.
278
294
 
279
- JRuby/Bundler running embedded inside a jar like this does not support switching bundler versions dynamically.
280
-
281
- This may happen due to
282
- - system gems for jruby installation upgradingg bundler to a newer version than packaged by default
283
- - running <tt>bundle update --bundler</tt>
284
- - using `BUNDLE_VERSION` to override bundle version which generating/editing your `Gemfile.lock`
295
+ JRuby/Bundler running embedded inside a jar like this does not support switching bundler versions dynamically
296
+ - Ensure you're on warbler `2.1.2+` and/or JRuby-Rack `1.2.8+` which attempts to workaround this issue
297
+ - If that doesn't help, ensure you are using `BUNDLE_VERSION=system` when bundling/warbling your application to ensure
298
+ the identical embedded JRuby bundler version is used during warbling and runtime.
285
299
 
286
- Options to address this
287
- - use <tt>bundle config set version system</tt> / <tt>bundle config set disable_shared_gems</tt> to avoid bundler picking system versions
288
- - ensure your `Gemfile.lock`'s <tt>BUNDLED WITH</tt> version matches the default bundler packaged with your `jruby-jars` version.
289
- You can check inside the relevant `jruby-stdlib` jar or inside a clean installation dir from your Ruby version manager of choice.
290
- - remove <tt>BUNDLED WITH</tt> entirely from `Gemfile.lock`. Sometimes bundler will add this back again; so not recommended in the longer term
291
-
292
- - <b>Rack version compatibility</b>
293
- An exception happened during JRuby-Rack startup
294
- no such file to load -- rack/chunked
295
- You are trying to use Rack 3.x with a jruby-rack version that does not yet support Rack 3. Try upgrading to a compatible
296
- jruby-rack version, or lock rack at a compatibile version with <tt>gem 'rack', '~> 2.2.0'</tt>. Note that Rack `2.2` requires Rails < `8.1`.
297
-
298
300
  == Source
299
301
 
300
302
  You can get the Warbler source using Git, in any of the following ways:
@@ -316,10 +318,7 @@ After that, simply run +rake+.
316
318
  There are a few integration tests in the `integration` directory that build WAR file
317
319
  with Warbler, and run some basic smoke tests against them. You can run these like so:
318
320
 
319
- cd integration
320
- mvn verify
321
-
322
- You'll need to have Maven >= 3.1.1 installed, of course: http://maven.apache.org/
321
+ ./mvnw verify
323
322
 
324
323
  == License
325
324
 
data/Rakefile CHANGED
@@ -10,41 +10,37 @@ require 'bundler/gem_helper'
10
10
  Bundler::GemHelper.install_tasks :dir => File.dirname(__FILE__)
11
11
 
12
12
  require 'rake/clean'
13
- CLEAN << "pkg" << "doc" << Dir['integration/**/target'] << "lib/warbler_jar.jar"
13
+ CLEAN << "pkg" << "doc" << Dir['**/target'] << "lib/warbler_jar.jar"
14
14
 
15
15
  require 'rspec/core/rake_task'
16
16
  RSpec::Core::RakeTask.new(:spec) do |t|
17
- t.rspec_opts = ['--color', "--format documentation"]
17
+ t.rspec_opts = ['--force-color', "--format documentation"]
18
18
  end
19
19
 
20
20
  task :spec => :jar
21
21
 
22
22
  task :default => :spec
23
23
 
24
- # use Mavenfile to define :jar task
25
- require 'maven/ruby/maven'
26
- mvn = Maven::Ruby::Maven.new
27
- mvn << "-Djruby.version=#{JRUBY_VERSION}"
28
- mvn << "-Dbundler.version=#{Bundler::VERSION}"
29
- mvn << '--no-transfer-progress'
30
- mvn << '--color=always'
24
+ # drive the java build (pom.xml) with regular maven
25
+ require File.expand_path('lib/warbler/version', File.dirname(__FILE__))
26
+
27
+ def mvn(*goals)
28
+ args = %W[./mvnw -B --no-transfer-progress -Dstyle.color=always
29
+ -Drevision=#{Warbler::VERSION} -Djruby.version=#{JRUBY_VERSION}]
30
+ args << "-Djruby-rack.version=#{ENV['JRUBY_RACK_VERSION']}" if ENV['JRUBY_RACK_VERSION']
31
+ # scrub the outer bundler env (RUBYOPT/BUNDLE_*) so JRuby subprocesses inside the
32
+ # maven build don't try to load this project's Gemfile
33
+ Bundler.with_unbundled_env { sh(*args, *goals) }
34
+ end
31
35
 
32
36
  desc 'compile java sources and build jar'
33
37
  task :jar do
34
- success = mvn.prepare_package
35
- exit(1) unless success
38
+ mvn 'prepare-package'
36
39
  end
37
40
 
38
41
  desc 'run some integration test'
39
- task :integration => :jar do
40
- success = mvn.verify
41
- exit(1) unless success
42
- end
43
-
44
- desc 'generate the pom.xml from the Mavenfile'
45
- task :pom do
46
- success = mvn.validate('-Dpolyglot.dump.pom=pom.xml')
47
- exit(1) unless success
42
+ task :integration => :build do
43
+ mvn 'verify'
48
44
  end
49
45
 
50
46
  # Make sure jar gets compiled before the gem is built
data/ext/pom.xml ADDED
@@ -0,0 +1,59 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+
5
+ <parent>
6
+ <groupId>org.jruby.warbler</groupId>
7
+ <artifactId>warbler</artifactId>
8
+ <version>${revision}</version>
9
+ <relativePath>../pom.xml</relativePath>
10
+ </parent>
11
+
12
+ <artifactId>warbler-jar</artifactId>
13
+ <packaging>jar</packaging>
14
+
15
+ <dependencies>
16
+ <dependency>
17
+ <groupId>org.jruby</groupId>
18
+ <artifactId>jruby</artifactId>
19
+ <version>${jruby.version}</version>
20
+ <scope>provided</scope>
21
+ </dependency>
22
+ </dependencies>
23
+
24
+ <build>
25
+ <finalName>warbler_jar</finalName>
26
+ <plugins>
27
+ <plugin>
28
+ <groupId>org.apache.maven.plugins</groupId>
29
+ <artifactId>maven-clean-plugin</artifactId>
30
+ <configuration>
31
+ <filesets>
32
+ <fileset>
33
+
34
+ <directory>../lib</directory>
35
+ <includes>
36
+ <include>warbler_jar.jar</include>
37
+ </includes>
38
+ </fileset>
39
+ </filesets>
40
+ </configuration>
41
+ </plugin>
42
+ <plugin>
43
+ <groupId>org.apache.maven.plugins</groupId>
44
+ <artifactId>maven-jar-plugin</artifactId>
45
+ <configuration>
46
+ <outputDirectory>../lib</outputDirectory>
47
+ </configuration>
48
+ <executions>
49
+ <execution>
50
+ <!-- build the jar before the (rake-driven) gem packaging rather than at package -->
51
+ <id>default-jar</id>
52
+ <phase>prepare-package</phase>
53
+ </execution>
54
+ </executions>
55
+ </plugin>
56
+ </plugins>
57
+ </build>
58
+
59
+ </project>
@@ -5,9 +5,10 @@
5
5
  * See the file LICENSE.txt for details.
6
6
  */
7
7
 
8
+ package warbler;
9
+
8
10
  import java.io.Closeable;
9
11
  import java.io.File;
10
- import java.io.FileOutputStream;
11
12
  import java.io.IOException;
12
13
  import java.io.InputStream;
13
14
  import java.io.OutputStream;
@@ -18,6 +19,7 @@ import java.net.URI;
18
19
  import java.net.URISyntaxException;
19
20
  import java.net.URL;
20
21
  import java.net.URLClassLoader;
22
+ import java.nio.file.Files;
21
23
  import java.util.ArrayList;
22
24
  import java.util.Arrays;
23
25
  import java.util.Deque;
@@ -71,7 +73,9 @@ public class JarMain implements Closeable {
71
73
  }
72
74
 
73
75
  extractRoot = File.createTempFile("jruby", "extract");
76
+ //noinspection ResultOfMethodCallIgnored
74
77
  extractRoot.delete();
78
+ //noinspection ResultOfMethodCallIgnored
75
79
  extractRoot.mkdirs();
76
80
  closeables.add(() -> deleteAll(extractRoot));
77
81
 
@@ -95,6 +99,7 @@ public class JarMain implements Closeable {
95
99
  protected URL extractEntry(final JarEntry entry, String path) throws Exception {
96
100
  File file = new File(extractRoot, path);
97
101
  if (entry.isDirectory()) {
102
+ //noinspection ResultOfMethodCallIgnored
98
103
  file.mkdirs();
99
104
  return null;
100
105
  }
@@ -108,9 +113,12 @@ public class JarMain implements Closeable {
108
113
  return null;
109
114
  }
110
115
  final File parent = file.getParentFile();
111
- if (parent != null) parent.mkdirs();
116
+ if (parent != null) {
117
+ //noinspection ResultOfMethodCallIgnored
118
+ parent.mkdirs();
119
+ }
112
120
 
113
- transferAndClose(() -> entryStream, () -> new FileOutputStream(file));
121
+ transferAndClose(() -> entryStream, () -> Files.newOutputStream(file.toPath()));
114
122
  file.deleteOnExit();
115
123
  // if (false) debug(entry.getName() + " extracted to " + file.getPath());
116
124
  return file.toURI().toURL();
@@ -122,7 +130,7 @@ public class JarMain implements Closeable {
122
130
  }
123
131
 
124
132
  protected Object newScriptingContainer(final URL[] jars) throws Exception {
125
- setSystemProperty("org.jruby.embed.class.path", "");
133
+ System.setProperty("org.jruby.embed.class.path", "");
126
134
  URLClassLoader scriptingClassLoader = new URLClassLoader(jars);
127
135
  closeables.add(scriptingClassLoader);
128
136
  Class<?> scriptingContainerClass = Class.forName("org.jruby.embed.ScriptingContainer", true, scriptingClassLoader);
@@ -196,6 +204,7 @@ public class JarMain implements Closeable {
196
204
  }
197
205
  }
198
206
  }
207
+ //noinspection ResultOfMethodCallIgnored
199
208
  f.delete();
200
209
  } catch (IOException e) {
201
210
  error(e);
@@ -272,7 +281,7 @@ public class JarMain implements Closeable {
272
281
  private static final boolean debug;
273
282
 
274
283
  static {
275
- debug = Boolean.parseBoolean(getSystemProperty("warbler.debug", "false"));
284
+ debug = Boolean.parseBoolean(System.getProperty("warbler.debug", "false"));
276
285
  }
277
286
 
278
287
  static boolean isDebug() {
@@ -285,43 +294,7 @@ public class JarMain implements Closeable {
285
294
  * for wrappers like procrun
286
295
  */
287
296
  private static boolean isSystemExitEnabled() {
288
- return getSystemProperty("warbler.skip_system_exit") == null; //omission enables System.exit use
289
- }
290
-
291
- static String getSystemProperty(final String name) {
292
- return getSystemProperty(name, null);
293
- }
294
-
295
- static String getSystemProperty(final String name, final String defaultValue) {
296
- try {
297
- return System.getProperty(name, defaultValue);
298
- } catch (SecurityException e) {
299
- return defaultValue;
300
- }
301
- }
302
-
303
- static boolean setSystemProperty(final String name, final String value) {
304
- try {
305
- System.setProperty(name, value);
306
- return true;
307
- } catch (SecurityException e) {
308
- return false;
309
- }
310
- }
311
-
312
- static String getENV(final String name) {
313
- return getENV(name, null);
314
- }
315
-
316
- static String getENV(final String name, final String defaultValue) {
317
- try {
318
- if (System.getenv().containsKey(name)) {
319
- return System.getenv().get(name);
320
- }
321
- return defaultValue;
322
- } catch (SecurityException e) {
323
- return defaultValue;
324
- }
297
+ return System.getProperty("warbler.skip_system_exit") == null; //omission enables System.exit use
325
298
  }
326
299
 
327
300
  // Can be replaced with InputStream.transferTo(OutputStream) in Java 11+
@@ -5,6 +5,8 @@
5
5
  * See the file LICENSE.txt for details.
6
6
  */
7
7
 
8
+ package warbler;
9
+
8
10
  import java.io.ByteArrayInputStream;
9
11
  import java.io.File;
10
12
  import java.io.FileNotFoundException;
@@ -122,7 +124,9 @@ public class WarMain extends JarMain {
122
124
 
123
125
  private File createWebRoot() throws IOException {
124
126
  File warblerRoot = File.createTempFile("warbler", "webroot");
127
+ //noinspection ResultOfMethodCallIgnored
125
128
  warblerRoot.delete();
129
+ //noinspection ResultOfMethodCallIgnored
126
130
  warblerRoot.mkdirs();
127
131
  closeables.add(() -> deleteAll(warblerRoot));
128
132
 
@@ -148,10 +152,10 @@ public class WarMain extends JarMain {
148
152
  if ( is != null ) props.load(is);
149
153
  } catch (Exception ignore) { }
150
154
 
151
- String port = getSystemProperty("warbler.port", getENV("PORT"));
155
+ String port = System.getProperty("warbler.port", System.getenv().get("PORT"));
152
156
  port = port == null ? "8080" : port;
153
- String host = getSystemProperty("warbler.host", "0.0.0.0");
154
- String webserverConfig = getSystemProperty("warbler.webserver_config", getENV("WARBLER_WEBSERVER_CONFIG"));
157
+ String host = System.getProperty("warbler.host", "0.0.0.0");
158
+ String webserverConfig = System.getProperty("warbler.webserver_config", System.getenv().get("WARBLER_WEBSERVER_CONFIG"));
155
159
  String embeddedWebserverConfig = new URI("jar", entryPath(WEBSERVER_CONFIG), null).toURL().toString();
156
160
  webserverConfig = webserverConfig == null ? embeddedWebserverConfig : webserverConfig;
157
161
  for ( Map.Entry<Object, Object> entry : props.entrySet() ) {
@@ -167,7 +171,7 @@ public class WarMain extends JarMain {
167
171
  if (props.getProperty("props") != null) {
168
172
  String[] propsToSet = props.getProperty("props").split(",");
169
173
  for ( String key : propsToSet ) {
170
- setSystemProperty(key, props.getProperty(key));
174
+ System.setProperty(key, props.getProperty(key));
171
175
  }
172
176
  }
173
177
 
@@ -304,22 +308,21 @@ public class WarMain extends JarMain {
304
308
 
305
309
  protected String locateExecutableScript(final String executable, final CharSequence envPreScript) {
306
310
  return ( envPreScript == null ? "" : envPreScript + " \n" ) +
307
- "begin\n" + // locate the executable within gemspecs :
308
- " require 'rubygems' unless defined?(Gem) \n" +
309
- " begin\n" + // add bundled gems to load path :
310
- " require 'bundler' \n" +
311
- " rescue LoadError\n" + // bundler not used
312
- " else\n" +
313
- " env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] \n" + // init.rb sets ENV['RAILS_ENV'] ||= ...
314
- " env ? Bundler.setup(:default, env) : Bundler.setup(:default) \n" +
315
- " end if ENV_JAVA['warbler.bundler.setup'] != 'false' \n" + // java -Dwarbler.bundler.setup=false -jar my.war -S pry
316
- " exec = '"+ executable +"' \n" +
317
- " spec = Gem::Specification.find { |s| s.executables.include?(exec) } \n" +
318
- " spec ? spec.bin_file(exec) : nil \n" +
319
- // returns the full path to the executable
320
- "rescue SystemExit => e\n" +
321
- " e.status\n" +
322
- "end";
311
+ "begin\n" + // locate the executable within gemspecs :
312
+ " begin\n" + // add bundled gems to load path :
313
+ " require 'bundler' \n" +
314
+ " rescue LoadError\n" + // bundler not used
315
+ " else\n" +
316
+ " env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] \n" + // init.rb sets ENV['RAILS_ENV'] ||= ...
317
+ " env ? Bundler.setup(:default, env) : Bundler.setup(:default) \n" +
318
+ " end if ENV_JAVA['warbler.bundler.setup'] != 'false' \n" + // java -Dwarbler.bundler.setup=false -jar my.war -S pry
319
+ " exec = '"+ executable +"' \n" +
320
+ " spec = Gem::Specification.find { |s| s.executables.include?(exec) } \n" +
321
+ " spec ? spec.bin_file(exec) : nil \n" +
322
+ // returns the full path to the executable
323
+ "rescue SystemExit => e\n" +
324
+ " e.status\n" +
325
+ "end";
323
326
  }
324
327
 
325
328
  protected void initJRubyScriptingEnv(Object scriptingContainer) throws Exception {
@@ -5,13 +5,15 @@
5
5
  * See the file LICENSE.txt for details.
6
6
  */
7
7
 
8
- import java.io.Closeable;
8
+ package warbler;
9
+
9
10
  import java.io.File;
10
- import java.io.FileInputStream;
11
11
  import java.io.FileNotFoundException;
12
12
  import java.io.FileOutputStream;
13
13
  import java.io.IOException;
14
14
  import java.io.InputStream;
15
+ import java.nio.file.Files;
16
+ import java.nio.file.Paths;
15
17
  import java.util.regex.Matcher;
16
18
  import java.util.regex.Pattern;
17
19
  import java.util.zip.ZipEntry;
@@ -46,15 +48,8 @@ public class WarblerJar {
46
48
  }
47
49
 
48
50
  RubyHash hash = (RubyHash) entries;
49
- try {
50
- FileOutputStream file = newFile(jar_path);
51
- try {
52
- ZipOutputStream zip = new ZipOutputStream(file);
53
- addEntries(context, zip, hash);
54
- zip.finish();
55
- } finally {
56
- close(file);
57
- }
51
+ try (ZipOutputStream zip = new ZipOutputStream(newFile(jar_path))) {
52
+ addEntries(context, zip, hash);
58
53
  } catch (IOException e) {
59
54
  if (runtime.isDebug()) {
60
55
  e.printStackTrace(runtime.getOut());
@@ -69,21 +64,16 @@ public class WarblerJar {
69
64
  public static IRubyObject entry_in_jar(ThreadContext context, IRubyObject self,
70
65
  IRubyObject jar_path, IRubyObject entry) {
71
66
  final Ruby runtime = context.runtime;
72
- try {
73
- InputStream entryStream = getStream(jar_path.convertToString().getUnicodeValue(),
74
- entry.convertToString().getUnicodeValue());
75
- try {
76
- byte[] buf = new byte[16384];
77
- ByteList bytes = new ByteList();
78
- int bytesRead;
79
- while ((bytesRead = entryStream.read(buf)) != -1) {
80
- bytes.append(buf, 0, bytesRead);
81
- }
82
- IRubyObject stringio = runtime.getModule("StringIO");
83
- return stringio.callMethod(context, "new", runtime.newString(bytes));
84
- } finally {
85
- close(entryStream);
67
+ try (InputStream entryStream = getStream(jar_path.convertToString().getUnicodeValue(),
68
+ entry.convertToString().getUnicodeValue())) {
69
+ byte[] buf = new byte[16384];
70
+ ByteList bytes = new ByteList();
71
+ int bytesRead;
72
+ while ((bytesRead = entryStream.read(buf)) != -1) {
73
+ bytes.append(buf, 0, bytesRead);
86
74
  }
75
+ IRubyObject stringio = runtime.getModule("StringIO");
76
+ return stringio.callMethod(context, "new", runtime.newString(bytes));
87
77
  } catch (IOException e) {
88
78
  if (runtime.isDebug()) {
89
79
  e.printStackTrace(runtime.getOut());
@@ -93,7 +83,7 @@ public class WarblerJar {
93
83
  }
94
84
 
95
85
  private static void addEntries(ThreadContext context, ZipOutputStream zip, RubyHash entries) throws IOException {
96
- RubyArray keys = entries.keys().sort(context, Block.NULL_BLOCK);
86
+ RubyArray<?> keys = entries.keys().sort(context, Block.NULL_BLOCK);
97
87
  for (int i = 0; i < keys.getLength(); i++) {
98
88
  IRubyObject key = keys.entry(i);
99
89
  IRubyObject value = entries.op_aref(context, key);
@@ -118,17 +108,12 @@ public class WarblerJar {
118
108
  path = value.convertToString().getUnicodeValue();
119
109
  }
120
110
 
121
- try {
122
- InputStream inFile = getStream(path, null);
123
- try {
124
- zip.putNextEntry(new ZipEntry(entryName));
125
- byte[] buf = new byte[16384];
126
- int bytesRead;
127
- while ((bytesRead = inFile.read(buf)) != -1) {
128
- zip.write(buf, 0, bytesRead);
129
- }
130
- } finally {
131
- close(inFile);
111
+ try (InputStream inFile = getStream(path, null)) {
112
+ zip.putNextEntry(new ZipEntry(entryName));
113
+ byte[] buf = new byte[16384];
114
+ int bytesRead;
115
+ while ((bytesRead = inFile.read(buf)) != -1) {
116
+ zip.write(buf, 0, bytesRead);
132
117
  }
133
118
  } catch (IOException e) {
134
119
  System.err.println("File not found; " + path + " not in archive");
@@ -146,13 +131,6 @@ public class WarblerJar {
146
131
  path.convertToString().getUnicodeValue());
147
132
  }
148
133
 
149
- private static void close(Closeable c) {
150
- try {
151
- c.close();
152
- } catch (Exception e) {
153
- }
154
- }
155
-
156
134
  private static final Pattern PROTOCOL = Pattern.compile("^[a-z][a-z0-9]+:");
157
135
 
158
136
  private static InputStream getStream(String jar, String entry) throws IOException {
@@ -163,7 +141,7 @@ public class WarblerJar {
163
141
  }
164
142
 
165
143
  String[] path = jar.split("!/");
166
- InputStream stream = new FileInputStream(path[0]);
144
+ InputStream stream = Files.newInputStream(Paths.get(path[0]));
167
145
  for (int i = 1; i < path.length; i++) {
168
146
  stream = entryInJar(stream, path[i]);
169
147
  }
@@ -60,8 +60,10 @@ module Warbler
60
60
  # Whether to include dependent gems (default true)
61
61
  attr_accessor :gem_dependencies
62
62
 
63
- # Array of regular expressions matching relative paths in gems to
64
- # be excluded from the war. Default contains no exclusions.
63
+ # Array of regular expressions matching paths *inside* packed gems to be
64
+ # excluded from the archive. Paths are matched relative to each gem's root
65
+ # (for git-sourced gems: the repository checkout root). Default contains no
66
+ # exclusions.
65
67
  attr_accessor :gem_excludes
66
68
 
67
69
  # Whether to exclude **/*.log files (default is true)
data/lib/warbler/jar.rb CHANGED
@@ -21,8 +21,13 @@ module Warbler
21
21
  include RakeHelper
22
22
  include PlatformHelper
23
23
 
24
+ MANIFEST_PATH = 'META-INF/MANIFEST.MF'
24
25
  DEFAULT_MANIFEST = %{Manifest-Version: 1.0\nCreated-By: Warbler #{Warbler::VERSION}\n\n}
25
26
 
27
+ def self.manifest_with_main(main_path_to_class)
28
+ DEFAULT_MANIFEST.chomp + "Main-Class: #{main_path_to_class.sub('.class', '').tr('/', '.')}\n"
29
+ end
30
+
26
31
  attr_reader :files
27
32
  attr_reader :app_filelist
28
33
 
@@ -219,7 +224,7 @@ module Warbler
219
224
  # OK if the gem does not exists as its un-packed on the "shared" path
220
225
  # ... at least gem spec.spec_file should exists although not crucial
221
226
  if JRUBY_VERSION != JRubyJars::VERSION
222
- warn "skipping #{spec.name} default gem (assuming its part of jruby-jars #{JRubyJars::VERSION})" unless silent?
227
+ warn "skipping #{spec.name} default gem (assuming its part of jruby-jars #{JRubyJars::VERSION})"
223
228
  end
224
229
  else
225
230
  warn "skipping #{spec.name} gem (#{full_gem_path.to_s} does not exist)"
@@ -334,6 +339,10 @@ module Warbler
334
339
 
335
340
  # Java-boosted jar creation for JRuby; replaces #create_jar and
336
341
  # #entry_in_jar with Java version
337
- require 'warbler_jar' if defined?(JRUBY_VERSION)
342
+ if defined?(JRUBY_VERSION)
343
+ require 'jruby'
344
+ require 'warbler_jar'
345
+ Java::Warbler::WarblerJar.create(JRuby.runtime)
346
+ end
338
347
  end
339
348
  end