warbler 2.1.2 → 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: 34fe8d21840c8677062066d0df7979b427676ec18dc428e268fe7973f0bb320f
4
- data.tar.gz: 5a68813d0b80ad5b705cb2cd1045ad65ef618c28ee3e9316ca179bf1f3522574
3
+ metadata.gz: c7fb231c020b4d2741d3f7bbdd82ec762779e5c2779e1000efb763c44fce75fe
4
+ data.tar.gz: a840520bcac2301dbf761fac4c1f57814eaaf45fbe6c5327b6394d30614cfc31
5
5
  SHA512:
6
- metadata.gz: 9c84e0abec9a450e7fdbacd1eb88b0f17da8da95defb6092c476e30f4d90d72cf9413cea636716ffe71cbe170904b71766a5b4e80c7ceea68cda3856e9636675
7
- data.tar.gz: b5c5aef56f17c17c2f6b30d1faa52664b72c685c82b96961efaee9fd5a5bc1a5561e0547bbd17d3824d0c61638bf3bac19c4d919d5b52b6f9070f2df0b125751
6
+ metadata.gz: 353d17017001ea0203ac7c0a5f414edee3b0f3ef21d2173352dbe46ebce78861d08961bcf55b2bca0fe12cb188e44860cd066d0f7c2ea48283e02d4ed253183e
7
+ data.tar.gz: 94a725feac177e933007be96d6320c1b2f54e08d1558f7ddd9f1d77ea42eda8f18a1d1ee6db061bd86d290ade020ac4b1b7fe6126839586ca2114846d49d7657
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.1.3
2
+ - #584, #655: chore: move boot classes out of the default package
3
+
1
4
  ## 2.1.2
2
5
 
3
6
  - #649: fix: further improve isolation of warbled jars/wars from host bundler configuration
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,39 +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
260
  If your app isn't working or starting up correctly:
262
261
 
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`
284
+
263
285
  - <b>CompatVersion errors:</b>
264
286
  If you are getting <tt>java.lang.NoClassDefFoundError: org/jruby/CompatVersion</tt> errors at start-up
265
- you are probably running Warbler with a jruby-rack version which does not yet support JRuby 10+ - it
266
- 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+`.
267
289
 
268
290
  - <b>Bundler `restart_with` errors:</b>
269
291
  If you are getting <tt>org.jruby.rack.RackInitializationException: No such file or directory - java -cp...</tt>,
270
292
  that probably means bundler is trying to switch versions dynamically during start-up because your
271
293
  `Gemfile.lock` implies a different locked version of bundler to that packaged with JRuby by default.
272
294
 
273
- JRuby/Bundler running embedded inside a jar like this does not support switching bundler versions dynamically.
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.
274
299
 
275
- This may happen due to
276
- - system gems for jruby installation upgradingg bundler to a newer version than packaged by default
277
- - running <tt>bundle update --bundler</tt>
278
- - using `BUNDLE_VERSION` to override bundle version which generating/editing your `Gemfile.lock`
279
-
280
- Options to address this
281
- - use <tt>bundle config set version system</tt> / <tt>bundle config set disable_shared_gems</tt> to avoid bundler picking system versions
282
- - ensure your `Gemfile.lock`'s <tt>BUNDLED WITH</tt> version matches the default bundler packaged with your `jruby-jars` version.
283
- You can check inside the relevant `jruby-stdlib` jar or inside a clean installation dir from your Ruby version manager of choice.
284
- - remove <tt>BUNDLED WITH</tt> entirely from `Gemfile.lock`. Sometimes bundler will add this back again; so not recommended in the longer term
285
-
286
- - <b>Rack version compatibility</b>
287
- An exception happened during JRuby-Rack startup
288
- no such file to load -- rack/chunked
289
- 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
290
- 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`.
291
-
292
300
  == Source
293
301
 
294
302
  You can get the Warbler source using Git, in any of the following ways:
@@ -310,10 +318,7 @@ After that, simply run +rake+.
310
318
  There are a few integration tests in the `integration` directory that build WAR file
311
319
  with Warbler, and run some basic smoke tests against them. You can run these like so:
312
320
 
313
- cd integration
314
- mvn verify
315
-
316
- You'll need to have Maven >= 3.1.1 installed, of course: http://maven.apache.org/
321
+ ./mvnw verify
317
322
 
318
323
  == License
319
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
 
@@ -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
  }
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
 
@@ -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
@@ -16,6 +16,8 @@ module Warbler
16
16
  class Jar
17
17
  include Trait
18
18
 
19
+ MAIN_PATH_TO_CLASS = 'warbler/JarMain.class'.freeze
20
+
19
21
  def self.detect?
20
22
  !detect_any_conflicts?
21
23
  end
@@ -34,10 +36,9 @@ module Warbler
34
36
 
35
37
  def update_archive(jar)
36
38
  unless config.manifest_file
37
- manifest = Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n"
38
- jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
39
+ jar.files[Warbler::Jar::MANIFEST_PATH] = StringIO.new(Warbler::Jar.manifest_with_main(MAIN_PATH_TO_CLASS))
39
40
  end
40
- jar.files['JarMain.class'] = jar.entry_in_jar(WARBLER_JAR, "JarMain.class")
41
+ jar.files[MAIN_PATH_TO_CLASS] = jar.entry_in_jar(WARBLER_JAR, MAIN_PATH_TO_CLASS)
41
42
  end
42
43
 
43
44
  def default_pathmaps
@@ -104,21 +104,19 @@ module Warbler
104
104
  end
105
105
  end
106
106
 
107
- def add_runnables(jar, main_class = 'WarMain')
108
- main_class = main_class.sub('.class', '') # handles WarMain.class
107
+ def add_runnables(jar, main_path_to_class = WebServer::Artifact::MAIN_PATH_TO_CLASS)
109
108
  unless config.manifest_file
110
- manifest = Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: #{main_class}\n"
111
- jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
109
+ jar.files[Warbler::Jar::MANIFEST_PATH] = StringIO.new(Warbler::Jar.manifest_with_main(main_path_to_class))
112
110
  end
113
- [ 'JarMain', 'WarMain', main_class ].uniq.each do |klass|
114
- jar.files["#{klass}.class"] = jar.entry_in_jar(WARBLER_JAR, "#{klass}.class")
111
+ [ Warbler::Traits::Jar::MAIN_PATH_TO_CLASS, WebServer::Artifact::MAIN_PATH_TO_CLASS, main_path_to_class ].uniq.each do |path_to_class|
112
+ jar.files["#{path_to_class}"] = jar.entry_in_jar(WARBLER_JAR, "#{path_to_class}")
115
113
  end
116
114
  end
117
115
 
118
116
  def add_executables(jar)
119
117
  webserver = WEB_SERVERS[config.webserver.to_s]
120
118
  webserver.add(jar)
121
- add_runnables jar, webserver.main_class || 'WarMain'
119
+ add_runnables jar, webserver.main_class || WebServer::Artifact::MAIN_PATH_TO_CLASS
122
120
  end
123
121
 
124
122
  def add_gemjar(jar)
@@ -6,5 +6,5 @@
6
6
  #++
7
7
 
8
8
  module Warbler
9
- VERSION = "2.1.2"
9
+ VERSION = "2.1.3"
10
10
  end
@@ -2,6 +2,8 @@ module Warbler
2
2
  class WebServer
3
3
  class Artifact < Struct.new(:repo, :group_id, :artifact_id, :version)
4
4
 
5
+ MAIN_PATH_TO_CLASS = 'warbler/WarMain.class'.freeze
6
+
5
7
  def path_fragment
6
8
  @path_fragment ||= "#{group_id.gsub('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.jar"
7
9
  end
@@ -82,7 +84,7 @@ module Warbler
82
84
  end
83
85
 
84
86
  def main_class
85
- 'WarMain.class'
87
+ Artifact::MAIN_PATH_TO_CLASS
86
88
  end
87
89
  end
88
90