jettywrapper 2.0.3 → 2.0.5

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
- SHA1:
3
- metadata.gz: 41090c9b128c286ef7693a2cea00c70de5896f1d
4
- data.tar.gz: 869ac3689c8c830a01a3f3a6582f75010c3a3848
2
+ SHA256:
3
+ metadata.gz: 9aab47a746d8488e896d855548985c985b4abcddad5556fb8d2019222ea82753
4
+ data.tar.gz: 2bf1d679dadada05247dbee295319e226b9eb342fb1e2b287b78b1b9adeca9f9
5
5
  SHA512:
6
- metadata.gz: 88128ee21fe30aadce3a2b8ec72bda31879c98aca9e298a9ae520e42edfd8daf9256f4faf52e5bb3e771c8f214592acfb5410c1ce79b0dc5cc4b7a5fb0d2273c
7
- data.tar.gz: 3123a2564cbd8e24f2650b74bf47517b048fe2a259159732c1fc210482ac52fdd1151975d10e52d9a65ec5ecb93752f18787ffd1f8686b7266789aacb2b34dce
6
+ metadata.gz: 8028fdb12e6b2b5426d623eaaf56d75c1484761314705c3e91ea92c900fd608df9aa2e57e7b490433d48643fd16e344cc2e9e2c10c91dc11ab4e6cd36c9d5afb
7
+ data.tar.gz: fd90273b4cf93853194904a10d4178d7faba23c415bb67feb35a72925c962c800ea204df9707f9cb830028d436150f2fe5cb8e74fd33741dbb1682fd6ab23da5
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
+ sudo: false
1
2
  language: ruby
2
-
3
3
  matrix:
4
4
  include:
5
5
  - rvm: 2.1
@@ -12,7 +12,3 @@ matrix:
12
12
  gemfile: gemfiles/rails4.1.gemfile
13
13
  - rvm: jruby-19mode
14
14
  gemfile: gemfiles/rails4.2.gemfile
15
-
16
- notifications:
17
- irc: "irc.freenode.org#projecthydra"
18
-
data/CONTRIBUTING.md CHANGED
@@ -3,6 +3,13 @@
3
3
  We want your help to make Project Hydra great.
4
4
  There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
5
5
 
6
+ ## Code of Conduct
7
+
8
+ The Hydra community is dedicated to providing a welcoming and positive experience for all its
9
+ members, whether they are at a formal gathering, in a social setting, or taking part in activities
10
+ online. Please see our [Code of Conduct](https://wiki.duraspace.org/display/hydra/Code+of+Conduct)
11
+ for more information.
12
+
6
13
  ## Hydra Project Intellectual Property Licensing and Ownership
7
14
 
8
15
  All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
@@ -16,8 +23,10 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
16
23
 
17
24
  * Reporting Issues
18
25
  * Making Changes
26
+ * Documenting Code
27
+ * Committing Changes
19
28
  * Submitting Changes
20
- * Merging Changes
29
+ * Reviewing and Merging Changes
21
30
 
22
31
  ### Reporting Issues
23
32
 
@@ -38,8 +47,28 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
38
47
  * Then checkout the new branch with `git checkout fix/master/my_contribution`.
39
48
  * Please avoid working directly on the `master` branch.
40
49
  * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
50
+ * Make sure you have added sufficient tests and documentation for your changes.
51
+ * Test functionality with RSpec; est features / UI with Capybara.
52
+ * Run _all_ the tests to assure nothing else was accidentally broken.
53
+
54
+ ### Documenting Code
55
+
56
+ * All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
57
+ * Documentation should seek to answer the question "why does this code exist?"
58
+ * Document private / protected methods as desired.
59
+ * If you are working in a file with no prior documentation, do try to document as you gain understanding of the code.
60
+ * If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
61
+ * This work greatly increases the usability of the code base and supports the on-ramping of new committers.
62
+ * We will all be understanding of one another's time constraints in this area.
63
+ * YARD examples:
64
+ * [Hydra::Works::RemoveGenericFile](https://github.com/projecthydra-labs/hydra-works/blob/master/lib/hydra/works/services/generic_work/remove_generic_file.rb)
65
+ * [ActiveTriples::LocalName::Minter](https://github.com/ActiveTriples/active_triples-local_name/blob/master/lib/active_triples/local_name/minter.rb)
66
+ * [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
+
68
+ ### Committing changes
69
+
41
70
  * Make commits of logical units.
42
- * Your commit should include a high level description of your work in HISTORY.textile
71
+ * Your commit should include a high level description of your work in HISTORY.textile
43
72
  * Check for unnecessary whitespace with `git diff --check` before committing.
44
73
  * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
45
74
  * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
@@ -60,7 +89,9 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
60
89
 
61
90
  class PostsController
62
91
  def index
63
- respond_with Post.limit(10)
92
+ respond_to do |wants|
93
+ wants.html { render 'index' }
94
+ end
64
95
  end
65
96
  end
66
97
 
@@ -72,38 +103,53 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
72
103
  long to fit in 72 characters
73
104
  ```
74
105
 
75
- * Make sure you have added the necessary tests for your changes.
76
- * Run _all_ the tests to assure nothing else was accidentally broken.
77
- * When you are ready to submit a pull request
78
-
79
106
  ### Submitting Changes
80
107
 
81
- [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
82
-
83
108
  * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
84
109
  * Make sure your branch is up to date with its parent branch (i.e. master)
85
110
  * `git checkout master`
86
111
  * `git pull --rebase`
87
112
  * `git checkout <your-branch>`
88
113
  * `git rebase master`
89
- * It is likely a good idea to run your tests again.
90
- * Squash the commits for your branch into one commit
91
- * `git rebase --interactive HEAD~<number-of-commits>` ([See Github help](https://help.github.com/articles/interactive-rebase))
92
- * To determine the number of commits on your branch: `git log master..<your-branch> --oneline | wc -l`
114
+ * It is a good idea to run your tests again.
115
+ * If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
116
+ * [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
117
+ * `git rebase --interactive master` ([See Github help](https://help.github.com/articles/interactive-rebase))
93
118
  * Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
94
119
  * Push your changes to a topic branch in your fork of the repository.
95
120
  * Submit a pull request from your fork to the project.
96
121
 
97
- ### Merging Changes
122
+ ### Reviewing and Merging Changes
123
+
124
+ We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
125
+ Common checks that may occur in our repositories:
126
+
127
+ 1. Travis CI - where our automated tests are running
128
+ 2. Hound CI - where we check for style violations
129
+ 3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
130
+ 4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
131
+
132
+ If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
133
+
134
+ *Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (Travis CI is usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
135
+
136
+ #### Things to Consider When Reviewing
137
+
138
+ First, the person contributing the code is putting themselves out there. Be mindful of what you say in a review.
139
+
140
+ * Ask clarifying questions
141
+ * State your understanding and expectations
142
+ * Provide example code or alternate solutions, and explain why
143
+
144
+ This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
98
145
 
99
- * It is considered "poor from" to merge your own request.
100
- * Please take the time to review the changes and get a sense of what is being changed. Things to consider:
101
146
  * Does the commit message explain what is going on?
102
- * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
147
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactors_
148
+ * Do new or changed methods, modules, and classes have documentation?
103
149
  * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
104
- * Did the Travis tests complete successfully?
105
- * If you are uncertain, bring other contributors into the conversation by creating a comment that includes their @username.
106
- * If you like the pull request, but want others to chime in, create a +1 comment and tag a user.
150
+ * Does the description of the new/changed specs match your understanding of what the spec is doing?
151
+
152
+ If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
107
153
 
108
154
  # Additional Resources
109
155
 
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec path: File.expand_path('..', __FILE__)
4
4
 
5
- gem 'simplecov'
data/README.md CHANGED
@@ -1,70 +1,83 @@
1
1
  # Jettywrapper [![Version](https://badge.fury.io/gh/projecthydra%2Fjettywrapper.png)](http://badge.fury.io/gh/projecthydra%2Fjettywrapper) [![Build Status](https://travis-ci.org/projecthydra/jettywrapper.png?branch=master)](https://travis-ci.org/projecthydra/jettywrapper)
2
2
 
3
- This gem is designed to make it easier to integrate a jetty servlet container into a rails project.
4
- Jettywrapper provides rake tasks for starting and stopping jetty, as well as the method `Jettywrapper.wrap` that will start
5
- the server before the block and stop the server after the block, which is useful for automated testing.
3
+ NOTICE: Because of changes introduced in Solr 5, we can no longer update jettywrapper to use modern versions of Solr. Therefore we discourage you from using jettywrapper in new projects. No further development is anticipated for jettywrapper. Consider using [solr_wrapper](https://github.com/cbeer/solr_wrapper) and [fcrepo_wrapper](https://github.com/cbeer/fcrepo_wrapper) instead.
6
4
 
7
- By default, Jettywrapper is designed to work with Rails projects that use the Hydra gem, and downloads an instance of a
8
- [hydra-jetty](https://github.com/projecthydra/hydra-jetty) project zipfile. However, it can be configured to
9
- download any Jetty-based project on Github.
5
+ This gem is designed to make it easier to integrate a jetty servlet container into a project with web service dependencies. This can be especially useful for developing and testing projects requiring, for example, a Solr and/or a Fedora server.
10
6
 
11
- Jettywrapper supports
7
+ Jettywrapper provides rake tasks for starting and stopping jetty, as well as the method `Jettywrapper.wrap` that will start the server before the block and stop the server after the block, which is useful for automated testing.
12
8
 
13
- * ruby 2.0.0
14
- * ruby 1.9.3
15
- * ruby 1.8.7
16
- * ree 1.8.7
17
- * jruby 1.6.6+
9
+ Jettywrapper can be configured to work with any Jetty-based zip file, such as [blacklight-jetty](https://github.com/projectblacklight/blacklight-jetty) (Solr only) or [hydra-jetty](https://github.com/projecthydra/hydra-jetty) (Solr + Fedora). Jettywrapper uses hydra-jetty by default.
18
10
 
19
- ## Configuring Jettywrapper
11
+ ## Requirements
20
12
 
21
- Jettywrapper starts the process with a list of options that you can specify in `config/jetty.yml`, otherwise a default is used.
22
- You can provide a per-environment configuration, or you can have a default configuration which will be used when a per-environment
23
- configuration is not specified. Such a configuration might look like:
13
+ 1. ruby -- Jettywrapper supports the ruby versions in its [.travis.yml](.travis.yml) file.
14
+ 2. bundler -- this ruby gem must be installed.
15
+ 3. java -- Jetty is a java based servlet container; the version of java required depends on the version of jetty you are using (in the jetty-based zip file).
24
16
 
25
- default:
26
-  jetty_port: 8983
27
-  java_opts:
28
-    - "-XX:MaxPermSize=128m"
29
-    - "-Xmx256m"
17
+ ## Installation
30
18
 
31
- You can also configure a specific version of hydra-jetty. This is placed in your codebase, usually in a rake task
19
+ Generally, you will only use a jetty instance for your project's web service dependencies during development and testing, not for production. So you would add this to your Gemfile:
20
+
21
+ ```
22
+ group :development, :test do
23
+ gem 'jettywrapper'
24
+ end
25
+ ```
26
+
27
+ Or, if your project is a gem, you would add this to your .gemspec file:
28
+
29
+ ```
30
+ Gem::Specification.new do |s|
31
+ s.add_development_dependency 'jettywrapper'
32
+ end
33
+ ```
34
+
35
+ Then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install jettywrapper
32
42
 
33
- Jettywrapper.hydra_jetty_version = "v1.2.3"
34
43
 
35
- Alternatively, you can use a completely different Jetty-based repository, Hydra-related or not
44
+ ## Usage
36
45
 
37
- Jettywrapper.url = "https://github.com/myorg/my-jetty/archive/master.zip"
46
+ ### Configuration
38
47
 
39
- The name of the zip file can either be a branch name, such as master or develop, or the tag name of a released version.
40
- Basically, any url that Github provides as a *.zip file will work.
48
+ See [Configuring jettywrapper](https://github.com/projecthydra/jettywrapper/wiki/Configuring-jettywrapper).
41
49
 
42
- ## Example rake task
50
+ If you don't need both Solr and Fedora, we recommend you avoid the default [hydra-jetty](https://github.com/projecthydra/hydra-jetty). If you only need Solr, use [blacklight-jetty](https://github.com/projectblacklight/blacklight-jetty).
51
+
52
+ ### Gotchas
53
+
54
+ * Jetty may take a while to spin up
55
+ * Jetty may not shut down cleanly
56
+
57
+ See [Using jettywrapper](https://github.com/projecthydra/jettywrapper/wiki/Using-jettywrapper) for more information and what to do.
58
+
59
+ ### Example Rake Task
60
+
61
+ See [Using jettywrapper](https://github.com/projecthydra/jettywrapper/wiki/Using-jettywrapper) for more information.
43
62
 
44
63
  ```ruby
45
64
  require 'jettywrapper'
46
- Jettywrapper.url = "https://github.com/myorg/my-jetty/archive/testing-feature-branch.zip"
47
- desc "Hudson build"
48
- task :hudson do
49
- jetty_params = Jettywrapper.load_config.merge({:jetty_home => File.expand_path(File.dirname(__FILE__) + '/../jetty')})
50
- error = Jettywrapper.wrap(jetty_params) do
51
- Rake::Task["spec"].invoke
65
+
66
+ desc 'run the tests for continuous integration'
67
+ task ci: ['jetty:clean', 'myproj:configure_jetty'] do
68
+ ENV['environment'] = 'test'
69
+ jetty_params = Jettywrapper.load_config
70
+ jetty_params[:startup_wait] = 60
71
+
72
+ error = nil
73
+ error = Jettywrapper.wrap(jetty_params) do
74
+ # run the tests
75
+ Rake::Task['spec'].invoke
52
76
  end
53
77
  raise "test failures: #{error}" if error
54
78
  end
55
79
  ```
56
80
 
57
- ## Testing the gem
58
-
59
- If you haven't already, clone the git repository
60
-
61
- git clone git@github.com:projecthydra/jettywrapper.git
62
- cd jettywrapper
63
-
64
- Install the gems
65
-
66
- bundle install
67
-
68
- Run the tests
81
+ ## Contributing
69
82
 
70
- rake
83
+ See [CONTRIBUTING.md](https://github.com/projecthydra/jettywrapper/blob/master/CONTRIBUTING.md) to help us make this project better.
data/Rakefile CHANGED
@@ -20,21 +20,6 @@ RSpec::Core::RakeTask.new(:spec => 'jetty:clean') do |spec|
20
20
  # spec.spec_files = FileList['spec/**/*_spec.rb']
21
21
  end
22
22
 
23
- RSpec::Core::RakeTask.new(:coverage) do |spec|
24
- ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
25
- ENV['COVERAGE'] = 'true' unless ruby_engine == 'jruby'
26
-
27
- if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.8/
28
- spec.rcov = true
29
- spec.rcov_opts = %w{--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data}
30
- end
31
- end
32
-
33
- task :clean do
34
- puts 'Cleaning old coverage.data'
35
- FileUtils.rm('coverage.data') if(File.exists? 'coverage.data')
36
- end
37
-
38
23
  # Use yard to build docs
39
24
  begin
40
25
  require 'yard'
@@ -54,5 +39,4 @@ rescue LoadError
54
39
  end
55
40
  end
56
41
 
57
- #task :default => [:coverage, :doc]
58
42
  task :default => [:spec]
data/jettywrapper.gemspec CHANGED
@@ -19,15 +19,15 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_rubygems_version = ">= 1.3.6"
21
21
 
22
- s.add_dependency "logger"
23
22
  s.add_dependency "childprocess"
24
23
  s.add_dependency "i18n"
25
24
  s.add_dependency "activesupport", ">=3.0.0"
26
- s.add_dependency 'rubyzip'
25
+ s.add_dependency 'rubyzip', "~> 1.0"
27
26
 
28
27
  s.add_development_dependency "rspec", '~> 3.2'
29
28
  s.add_development_dependency "rspec-its"
30
29
  s.add_development_dependency 'rake'
30
+ s.add_development_dependency 'simplecov'
31
31
 
32
32
  s.add_development_dependency 'yard'
33
33
  end
@@ -1,3 +1,3 @@
1
1
  class Jettywrapper
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.5"
3
3
  end
data/lib/jettywrapper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'singleton'
2
1
  require 'fileutils'
3
2
  require 'shellwords'
4
3
  require 'socket'
@@ -10,14 +9,13 @@ require 'erb'
10
9
  require 'yaml'
11
10
  require 'logger'
12
11
  require 'open-uri'
12
+ require 'tempfile'
13
13
  require 'zip'
14
14
 
15
- Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if defined?(Rake)
15
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if (defined?(Rake::VERSION))
16
16
 
17
- # Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
18
17
  class Jettywrapper
19
18
 
20
- include Singleton
21
19
  include ActiveSupport::Benchmarkable
22
20
 
23
21
  attr_accessor :jetty_home # Jetty's home directory
@@ -27,16 +25,29 @@ class Jettywrapper
27
25
  attr_accessor :solr_home # Solr's home directory. Default is jetty_home/solr
28
26
  attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
29
27
  attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
28
+ attr_accessor :java_command # Path to the Java executable
29
+ attr_accessor :java_version # Minimum java version
30
30
  attr_accessor :jetty_opts # Options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
31
31
 
32
- # configure the singleton with some defaults
33
32
  def initialize(params = {})
34
33
  self.base_path = self.class.app_root
34
+ configure(params)
35
35
  end
36
36
 
37
+ def configure params
38
+ self.quiet = params[:quiet].nil? ? true : params[:quiet]
39
+ self.jetty_home = params[:jetty_home ] || File.expand_path(File.join(self.base_path, 'jetty'))
40
+ self.solr_home = params[:solr_home ] || File.join( self.jetty_home, "solr")
41
+ self.port = params[:jetty_port ] || 8888
42
+ self.startup_wait = params[:startup_wait] || 5
43
+ self.java_opts = params[:java_opts ] || []
44
+ self.java_command = params[:java_command] || default_java_command
45
+ self.java_version = params[:java_version]
46
+ self.jetty_opts = params[:jetty_opts ] || []
47
+ end
37
48
 
38
49
  # Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
39
- # Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
50
+ # Methods outside the class << self block must be called on Jettywrapper.instance or a Jettywrapper object, as instance methods.
40
51
  class << self
41
52
 
42
53
  attr_writer :hydra_jetty_version, :url, :tmp_dir, :jetty_dir, :env
@@ -193,17 +204,14 @@ class Jettywrapper
193
204
  def configure(params = {})
194
205
  jetty_server = self.instance
195
206
  jetty_server.reset_process!
196
- jetty_server.quiet = params[:quiet].nil? ? true : params[:quiet]
197
-
198
- jetty_server.jetty_home = params[:jetty_home] || File.expand_path(File.join(app_root, 'jetty'))
199
- jetty_server.solr_home = params[:solr_home] || File.join( jetty_server.jetty_home, "solr")
200
- jetty_server.port = params[:jetty_port] || 8888
201
- jetty_server.startup_wait = params[:startup_wait] || 5
202
- jetty_server.java_opts = params[:java_opts] || []
203
- jetty_server.jetty_opts = params[:jetty_opts] || []
207
+ jetty_server.configure params
204
208
  return jetty_server
205
209
  end
206
210
 
211
+ def instance
212
+ @instance ||= Jettywrapper.new
213
+ end
214
+
207
215
  # Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
208
216
  # jetty, and return the error.
209
217
  # @example Using this method in a rake task
@@ -324,6 +332,35 @@ class Jettywrapper
324
332
  end
325
333
  end
326
334
 
335
+ def check_java_version! java_path, required_java_version
336
+ Tempfile.open("java-version-output") do |f|
337
+ process = ChildProcess.build(java_path, "-version")
338
+ process.io.stderr = f
339
+ process.start
340
+
341
+ begin
342
+ process.poll_for_exit(10)
343
+ rescue ChildProcess::TimeoutError
344
+ process.stop # tries increasingly harsher methods to kill the process.
345
+ end
346
+
347
+ f.rewind
348
+ err = f.read
349
+
350
+ java_version = if version = err.match(/java version "([^"]+)"/)
351
+ version[1]
352
+ else
353
+ raise "Java not found, or an error was encountered when running `#{java_path} -version`: #{err}"
354
+ end
355
+
356
+ unless Gem::Dependency.new('', required_java_version.gsub("_", ".")).match?('', java_version.gsub("_", "."))
357
+ raise "Java #{required_java_version} is required to run Jetty. Found Java #{java_version} when running `#{java_path} -version`."
358
+ end
359
+ end
360
+
361
+ true
362
+ end
363
+
327
364
  def logger=(logger)
328
365
  @@logger = logger
329
366
  end
@@ -342,7 +379,7 @@ class Jettywrapper
342
379
 
343
380
  # What command is being run to invoke jetty?
344
381
  def jetty_command
345
- ["java", java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
382
+ [java_command, java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
346
383
  end
347
384
 
348
385
  def java_variables
@@ -350,6 +387,12 @@ class Jettywrapper
350
387
  "-Dsolr.solr.home=#{Shellwords.escape(@solr_home)}"]
351
388
  end
352
389
 
390
+ def check_java_version!
391
+ if java_version
392
+ @checked_java_version ||= Jettywrapper.check_java_version!(java_command, java_version)
393
+ end
394
+ end
395
+
353
396
  # Start the jetty server. Check the pid file to see if it is running already,
354
397
  # and stop it if so. After you start jetty, write the PID to a file.
355
398
  # This is the instance start method. It must be called on Jettywrapper.instance
@@ -363,6 +406,8 @@ class Jettywrapper
363
406
  logger.debug "jetty_home: #{@jetty_home}"
364
407
  logger.debug "jetty_command: #{jetty_command.join(' ')}"
365
408
 
409
+ check_java_version!
410
+
366
411
  # Check to see if we can start.
367
412
  # 1. If there is a pid, check to see if it is really running
368
413
  # 2. Check to see if anything is blocking the port we want to use
@@ -485,4 +530,22 @@ class Jettywrapper
485
530
  def pid
486
531
  File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
487
532
  end
533
+
534
+ private
535
+
536
+ def default_java_command
537
+ # Use the same JAVA_HOME lookup as Solr
538
+ @default_java_command ||= if ENV["JAVA_HOME"]
539
+ if File.exists? File.join(ENV["JAVA_HOME"], "bin", "java")
540
+ File.join(ENV["JAVA_HOME"], "bin", "java")
541
+ end
542
+
543
+ if File.exists? File.join(ENV["JAVA_HOME"], "amd64", "bin", "java")
544
+ File.join(ENV["JAVA_HOME"], "amd64", "bin", "java")
545
+ end
546
+ end
547
+
548
+ @default_java_command ||= "java"
549
+ end
550
+
488
551
  end
@@ -104,6 +104,19 @@ module Hydra
104
104
  end
105
105
  end
106
106
 
107
+ describe "#check_java_version!" do
108
+ it "should check for a required minimum version of java" do
109
+ expect(Jettywrapper.check_java_version!("java", ">= 1.2")).to eq true
110
+ end
111
+
112
+ it "should raise an exception if java can't be found" do
113
+ expect { Jettywrapper.check_java_version!("/bin/cat", ">= 1.2") }.to raise_error /Java not found/
114
+ end
115
+
116
+ it "should raise an exception if the version of java is not new enough" do
117
+ expect { Jettywrapper.check_java_version!("java", ">= 999.999") }.to raise_error /999.999 is required to run Jetty/
118
+ end
119
+ end
107
120
  end
108
121
  end
109
122
  end
@@ -364,6 +364,12 @@ require 'fileutils'
364
364
  expect(File.file? swp.pid_path).to eql(false)
365
365
  end
366
366
 
367
+ it "can pass the java executable in the configuration" do
368
+ subject = Jettywrapper.new(java_command: "/dev/null/java")
369
+ allow_any_instance_of(Jettywrapper).to receive(:process).and_return(double('proc', :start => nil, :pid=>2323))
370
+ expect(subject.jetty_command.first).to eq "/dev/null/java"
371
+ end
372
+
367
373
  describe "creates a pid file" do
368
374
  let(:ts) { Jettywrapper.configure(@jetty_params) }
369
375
  describe "when the environment isn't set" do
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,5 @@
1
- $: << File.join(File.dirname(__FILE__), "/../../lib")
2
-
3
- if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
4
- require 'simplecov'
5
- require 'simplecov-rcov'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
8
- SimpleCov.start
9
- end
1
+ require 'simplecov'
2
+ SimpleCov.start
10
3
 
11
4
  require 'rspec/its'
12
5
  require 'jettywrapper'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jettywrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -10,22 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-24 00:00:00.000000000 Z
13
+ date: 2018-12-05 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: logger
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: '0'
29
15
  - !ruby/object:Gem::Dependency
30
16
  name: childprocess
31
17
  requirement: !ruby/object:Gem::Requirement
@@ -72,16 +58,16 @@ dependencies:
72
58
  name: rubyzip
73
59
  requirement: !ruby/object:Gem::Requirement
74
60
  requirements:
75
- - - ">="
61
+ - - "~>"
76
62
  - !ruby/object:Gem::Version
77
- version: '0'
63
+ version: '1.0'
78
64
  type: :runtime
79
65
  prerelease: false
80
66
  version_requirements: !ruby/object:Gem::Requirement
81
67
  requirements:
82
- - - ">="
68
+ - - "~>"
83
69
  - !ruby/object:Gem::Version
84
- version: '0'
70
+ version: '1.0'
85
71
  - !ruby/object:Gem::Dependency
86
72
  name: rspec
87
73
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +110,20 @@ dependencies:
124
110
  - - ">="
125
111
  - !ruby/object:Gem::Version
126
112
  version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: simplecov
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: yard
129
129
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +156,6 @@ files:
156
156
  - LICENSE
157
157
  - README.md
158
158
  - Rakefile
159
- - TODO.txt
160
159
  - config/jetty.yml
161
160
  - gemfiles/rails4.1.gemfile
162
161
  - gemfiles/rails4.2.gemfile
@@ -188,9 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
187
  version: 1.3.6
189
188
  requirements: []
190
189
  rubyforge_project:
191
- rubygems_version: 2.4.5
190
+ rubygems_version: 2.7.6
192
191
  signing_key:
193
192
  specification_version: 4
194
193
  summary: Convenience tasks for working with jetty from within a ruby project.
195
194
  test_files: []
196
- has_rdoc:
data/TODO.txt DELETED
@@ -1,3 +0,0 @@
1
- Next up:
2
-
3
- Check whether a port is open before you attempt to start jetty. I've put a method in place, but I need to work on something else for awhile and I haven't fully implemented this yet.