Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use thor for executable, use jeweler to create gem, set custom gem bu…

…ild task to work with maven layout
  • Loading branch information...
commit 5e1351d61e8167b39aef5c952cff79ba62962b6e 1 parent 9f9b5df
@mguymon authored
View
25 .gitignore
@@ -1,9 +1,22 @@
-.*
-*.class
+# rcov generated
+coverage
+coverage.data
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+# Maven
target
-# Package Files #
-*.jar
-*.war
-*.ear
+# All other doty files
+.*
View
3  Gemfile
@@ -1,8 +1,11 @@
source "http://rubygems.org"
gem "lock_jar", "~> 0.5.2"
+gem "thor", "> 0.14.0"
group :development do
gem "rspec", "~> 2.11.0"
gem "bundler", "~> 1.1.4"
+ gem "jeweler", "~> 1.8.4"
end
+
View
25 Gemfile.lock
@@ -1,15 +1,21 @@
GEM
remote: http://rubygems.org/
specs:
- commander (4.1.2)
- highline (~> 1.6.11)
diff-lcs (1.1.3)
- highline (1.6.14)
- lock_jar (0.5.2)
- commander (~> 4.1.2)
- highline (~> 1.6.13)
- naether (~> 0.8.5)
- naether (0.8.5-java)
+ git (1.2.5)
+ jeweler (1.8.4)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ rdoc
+ json (1.7.5-java)
+ lock_jar (0.5.6)
+ naether (~> 0.8.6)
+ thor (> 0.14.0)
+ naether (0.8.6-java)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
@@ -18,11 +24,14 @@ GEM
rspec-expectations (2.11.2)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.2)
+ thor (0.16.0)
PLATFORMS
java
DEPENDENCIES
bundler (~> 1.1.4)
+ jeweler (~> 1.8.4)
lock_jar (~> 0.5.2)
rspec (~> 2.11.0)
+ thor (> 0.14.0)
View
176 LICENSE
@@ -0,0 +1,176 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
View
131 Rakefile
@@ -0,0 +1,131 @@
+# encoding: utf-8
+
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+
+namespace :solr_sail do
+ require "fileutils"
+ task :setup_target_gem do
+ unless File.exists?( "target" )
+ raise "Run `mvn package` to build java first"
+ end
+
+ unless File.exists?( "target/gem" )
+ Dir.mkdir( "target/gem" )
+ end
+
+ unless File.exists?( "target/gem/lib" )
+ FileUtils.mkdir_p( "target/gem/lib/solr_sail" )
+ end
+
+ unless File.exists?( "target/gem/bin" )
+ FileUtils.mkdir_p( "target/gem/bin" )
+ end
+
+ # copy ruby source over
+ Dir.glob("src/main/ruby/**/*.rb") do |file|
+ FileUtils.copy( file, file.gsub("src/main/ruby", "target/gem/lib"))
+ end
+
+ # copy executable
+ Dir.glob("src/main/bin/**") do |file|
+ FileUtils.copy( file, file.gsub("src/main/bin", "target/gem/bin"))
+ end
+
+ FileUtils.copy( 'Gemfile', "target/gem/Gemfile" )
+ FileUtils.copy( 'Gemfile.lock', "target/gem/Gemfile.lock" )
+ FileUtils.copy( 'Jarfile', "target/gem/Jarfile" )
+ FileUtils.copy( 'Jarfile.lock', "target/gem/Jarfile.lock" )
+ FileUtils.copy( 'LICENSE', "target/gem/LICENSE" )
+ FileUtils.copy( 'README.md', "target/gem/README.md" )
+ FileUtils.copy( 'pom.xml', "target/gem/pom.xml" )
+ FileUtils.copy( 'VERSION', "target/gem/VERSION" )
+
+ version = IO.read('VERSION').strip
+ FileUtils.copy( "target/solrsail-#{version}.jar", "target/gem/solrsail-#{version}.jar" )
+
+ # Change dir so relevant files have the correct paths
+ Dir.chdir( "target/gem" )
+ end
+
+ task :version_return_from_target do
+ FileUtils.copy( 'VERSION', "../../." )
+ Dir.chdir( "../../" )
+ end
+
+ task :copy_gem_from_target do
+ unless File.exists?( "../../pkg" )
+ Dir.mkdir( "../../pkg" )
+ end
+
+ version = IO.read('VERSION').strip
+
+ #source = File.expand_path("pkg/solr_sail-#{version}#{"-java" if platform =='java'}.gem")
+
+ source = File.expand_path("pkg/solr_sail-#{version}-java.gem")
+ dest = File.expand_path( "../../pkg/." )
+ puts "copying #{source} to #{dest}"
+ FileUtils.copy( source, dest )
+ end
+end
+
+
+require 'rake'
+
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "solr_sail"
+ gem.platform = "java"
+ gem.homepage = "http://github.com/mguymon/solr_sail"
+ gem.license = "MIT"
+ gem.summary = %Q{Solr Server for JRuby}
+ gem.description = %Q{Solr Server for JRuby}
+ gem.email = "michael@tobedevoured.com"
+ gem.authors = ["Michael Guymon"]
+ gem.require_paths = %w[lib]
+ gem.executable = "solrsail"
+
+ # all files in target/gem should be included, expect for pkg
+ gem.files = Dir.glob("**/*").select{ |path| !(path =~ /^pkg/) }
+end
+Jeweler::RubygemsDotOrgTasks.new
+
+Rake::Task["build"].enhance ["solr_sail:setup_target_gem"]
+Rake::Task["version_required"].enhance ["solr_sail:setup_target_gem"]
+Rake::Task["gemspec:release"].enhance ["solr_sail:setup_target_gem"]
+
+Rake::Task["version:bump:major"].enhance ['solr_sail:version_return_from_target']
+Rake::Task["version:bump:minor"].enhance ['solr_sail:version_return_from_target']
+Rake::Task["version:bump:patch"].enhance ['solr_sail:version_return_from_target']
+
+Rake::Task["build"].enhance do
+ Rake::Task['solr_sail:copy_gem_from_target'].invoke
+end
+
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = 'src/test/spec/**/*_spec.rb'
+end
+
+task :test => :spec
+
+task :default => :test
+
+require 'rdoc/task'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "solr_sail #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('src/main/ruby/**/*.rb')
+end
View
5 src/main/bin/solrsail
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'solr_sail/cli'
+
+SolrSail::CLI.start
View
2  src/main/java/com/tobedevoured/solrsail/JettyServer.java
@@ -36,7 +36,7 @@ public JettyServer() {
}
@Command
- public void run() throws Exception {
+ public void start() throws Exception {
System.setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi");
System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");
View
14 src/main/java/com/tobedevoured/solrsail/SolrConfig.java
@@ -33,12 +33,20 @@
private String solrHome;
public SolrConfig() {
- Config config = ConfigFactory.load();
- solrHome = config.getString("solrsail.solr.home");
+ loadDefaultConfig();
}
public SolrConfig( String solrHome ) {
- this.solrHome = solrHome;
+ if ( solrHome != null ) {
+ this.solrHome = solrHome;
+ } else {
+ loadDefaultConfig();
+ }
+ }
+
+ public void loadDefaultConfig() {
+ Config config = ConfigFactory.load();
+ solrHome = config.getString("solrsail.solr.home");
}
public String getSolrHome() {
View
21 src/main/ruby/solr_sail.rb
@@ -2,24 +2,25 @@
require 'lock_jar'
require 'java'
-class SolrSail
+module SolrSail
@@version = IO.read("VERSION").strip
- @@jar = File.expand_path("#{File.dirname(__FILE__)}/solrsail-#{@@version}.jar")
+ @@jar = File.expand_path("#{File.dirname(__FILE__)}/../solrsail-#{@@version}.jar")
+ @@lockfile = File.expand_path("#{File.dirname(__FILE__)}/../Jarfile.lock")
- def version
+ def self.version
@@version
end
# Find lockjar relative to the gem install
- def default_lockfile
- File.expand_path("#{File.dirname(__FILE__)}/Jarfile.lock")
+ def self.default_lockfile
+ @@lockfile
end
- def default_jar
+ def self.default_jar
@@jar
end
- def install_config( opts )
+ def self.install_config( opts )
opts = { :jar => default_jar, :lockfile => default_lockfile }.merge( opts )
lockfile = opts.delete(:lockfile)
jar = opts.delete(:jar)
@@ -30,11 +31,11 @@ def install_config( opts )
LockJar.install( lockfile, opts )
LockJar.load( lockfile, opts )
- solr_config = com.tobedevoured.solrsail.SolrConfig.new
+ solr_config = com.tobedevoured.solrsail.SolrConfig.new( opts[:dest] )
solr_config.install()
end
- def run( opts )
+ def self.start( opts )
opts = { :jar => default_jar, :lockfile => default_lockfile }.merge( opts )
lockfile = opts.delete(:lockfile)
jar = opts.delete(:jar)
@@ -45,6 +46,6 @@ def run( opts )
LockJar.load( lockfile, opts )
jetty = com.tobedevoured.solrsail.JettyServer.new
- jetty.run
+ jetty.start
end
end
View
19 src/main/ruby/solr_sail/cli.rb
@@ -0,0 +1,19 @@
+require 'rubygems'
+require 'thor'
+require 'solr_sail'
+
+module SolrSail
+ class CLI < Thor
+ desc "install", "Install Solr config"
+ method_option :dest, :aliases => "-d", :default => 'solr', :desc => "Path to install solr config"
+ def install
+ SolrSail.install_config( :dest => options[:dest] )
+ end
+
+ desc "start", "Run Solr"
+ method_option :dest, :aliases => "-d", :default => 'solr', :desc => "Path to install solr config"
+ def start
+ SolrSail.start( :dest => options[:dest] )
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.