winstone 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,6 @@
1
+
2
+ = Winstone Server Gem Changelog
3
+
4
+ == Version 0.0.1
5
+
6
+ * Initial release.
data/README ADDED
@@ -0,0 +1,13 @@
1
+ = Winstone -- Gem wrapper for winstone server
2
+
3
+ = Installing Winstone
4
+
5
+ == Installing Winstone
6
+ $ gem install winstone
7
+
8
+ == Usage
9
+
10
+ winstone install - installs winstone
11
+ winstone <params> - runs the winstone server
12
+ winstone lite <params> - runs the winstone (lite) server
13
+
@@ -0,0 +1,71 @@
1
+ # Rakefile for winstone
2
+
3
+ task :default => :gemspec
4
+
5
+ begin
6
+ require 'bundler'
7
+
8
+ begin
9
+ require 'jeweler'
10
+
11
+ Jeweler::Tasks.new do |gemspec|
12
+ gemspec.name = "winstone"
13
+ gemspec.summary = "Gem wrapper for winstone server (Summary)."
14
+ gemspec.description = "Gem wrapper for winstone server."
15
+ gemspec.email = "alexander.shvets@gmail.com"
16
+ gemspec.homepage = "http://github.com/shvets/winstone"
17
+ gemspec.authors = ["Alexander Shvets"]
18
+ gemspec.files = FileList["CHANGES", "winstone.gemspec", "Rakefile", "README", "VERSION",
19
+ "lib/**/*", "bin/**/*"]
20
+
21
+ gemspec.executables = ['winstone']
22
+ gemspec.requirements = ["none"]
23
+ gemspec.bindir = "bin"
24
+
25
+ gemspec.add_bundler_dependencies
26
+
27
+ gemspec.post_install_message = <<-TEXT
28
+
29
+ -------------------------------------------------------------------------------
30
+
31
+ Please now run:
32
+
33
+ $ winstone install
34
+
35
+ NB. This will download jars that this gem needs to run from the internet.
36
+ It will put them into ~/.winstone/assets.
37
+
38
+ -------------------------------------------------------------------------------
39
+ TEXT
40
+
41
+ end
42
+ rescue LoadError
43
+ puts "Jeweler not available. Install it s with: [sudo] gem install jeweler"
44
+ end
45
+ rescue LoadError
46
+ puts "Bundler not available. Install it s with: [sudo] gem install bundler"
47
+ end
48
+
49
+
50
+ desc "Release the gem"
51
+ task :"release:gem" do
52
+ %x(
53
+ rake gemspec
54
+ rake build
55
+ rake install
56
+ git add .
57
+ )
58
+ puts "Commit message:"
59
+ message = STDIN.gets
60
+
61
+ version = "#{File.open(File::dirname(__FILE__) + "/VERSION").readlines().first}"
62
+
63
+ %x(
64
+ git commit -m "#{message}"
65
+
66
+ git push origin master
67
+
68
+ gem push pkg/winstone-#{version}.gem
69
+ )
70
+ end
71
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "jeweler"
5
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
4
+
5
+ require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
6
+ require 'jar_wrapper'
7
+
8
+ class WinstoneStarter
9
+
10
+ USAGE= <<-TEXT
11
+ Usage:
12
+ winstone help - this help
13
+ winstone install - installs winstone
14
+ winstone <server-params> - runs the winstone server
15
+ winstone lite <server-params> - runs winstone (lite) server
16
+ TEXT
17
+
18
+ def initialize
19
+ @wrapper = JarWrapper.new
20
+ end
21
+
22
+ def run
23
+ install_dir = ENV['HOME'] + "/.winstone/assets"
24
+ verion = "0.9.10"
25
+
26
+ source1 = "http://surfnet.dl.sourceforge.net/project/winstone/winstone/v#{verion}/winstone-#{verion}.jar"
27
+ source2 = "http://surfnet.dl.sourceforge.net/project/winstone/winstone/v#{verion}/winstone-lite-#{verion}.jar"
28
+
29
+ target1 = install_dir + "/winstone-#{verion}.jar"
30
+ target2 = install_dir + "/winstone-lite-#{verion}.jar"
31
+
32
+ jar_file1 = install_dir + "/winstone-#{verion}.jar"
33
+ jar_file2 = install_dir + "/winstone-lite-#{verion}.jar"
34
+
35
+ case ARGV.shift
36
+ when /(-v)|(--version)/ then
37
+ puts "Version: #{File.open(File::dirname(__FILE__) + "/../VERSION").readlines().first}"
38
+ when 'install' then
39
+ @wrapper.install source1, target1
40
+ @wrapper.install source2, target2
41
+ puts
42
+ when 'help' then
43
+ puts USAGE and return
44
+ when 'lite' then
45
+ puts ARGV
46
+ @wrapper.run 'winstone', jar_file1, ["-Xmx1024m", "-Xss1024k" ], ARGV
47
+ else
48
+ puts ARGV
49
+ @wrapper.run 'winstone', jar_file2, ["-Xmx1024m", "-Xss1024k" ], ARGV
50
+ end
51
+ end
52
+ end
53
+
54
+ WinstoneStarter.new.run
@@ -0,0 +1,6 @@
1
+ @ECHO OFF
2
+ IF NOT "%~f0" == "~f0" GOTO :WinNT
3
+ @"ruby.exe" "C:/Ruby/ruby-1.9.1/bin/winstone" %1 %2 %3 %4 %5 %6 %7 %8 %9
4
+ GOTO :EOF
5
+ :WinNT
6
+ @"ruby.exe" "%~dpn0" %*
@@ -0,0 +1,16 @@
1
+ require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
2
+
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require 'fileutils'
7
+ require 'net/http'
8
+
9
+ require 'jar_wrapper/jar_wrapper'
10
+ require 'jar_wrapper/runner'
11
+ require 'jar_wrapper/jvm_options_probe'
12
+
13
+ require 'rbconfig'
14
+ WINDOZE = Config::CONFIG['host_os'] =~ /mswin|mingw|windows/
15
+
16
+ WINDOZE ? (require "zip/zipfilesystem") : (require 'zip/zip')
@@ -0,0 +1,68 @@
1
+ require 'open-uri'
2
+
3
+ class JarWrapper
4
+ def download_file_to(uri, destination_file)
5
+ print " downloading #{uri}... "; $stdout.flush
6
+
7
+ temp = destination_file + ".part"
8
+ FileUtils.mkdir_p(File.dirname(destination_file))
9
+
10
+ File.open(temp, "wb") do |out_file|
11
+ open(uri) do |in_file|
12
+ done = false
13
+
14
+ while(!done) do
15
+ buffer = in_file.read(1024*1000)
16
+ out_file.write(buffer)
17
+
18
+ if buffer.nil? || buffer.size == 0
19
+ done = true
20
+ else
21
+ print("#"); $stdout.flush
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ if File.open(temp).read(200) =~ /Access Denied/
28
+ puts "\n\n*** Error downloading #{uri}, got Access Denied from S3."
29
+ FileUtils.rm_rf(temp)
30
+ exit
31
+ end
32
+
33
+ FileUtils.cp(temp, destination_file)
34
+ FileUtils.rm_rf(temp)
35
+ puts "\ndone!"
36
+ end
37
+
38
+ # unzip a .zip file into the directory it is located
39
+ def unzip_file(path)
40
+ print "unzipping #{path}..."; $stdout.flush
41
+ source = File.expand_path(path)
42
+ Dir.chdir(File.dirname(source)) do
43
+ Zip::ZipFile.open(source) do |zipfile|
44
+ zipfile.entries.each do |entry|
45
+ FileUtils.mkdir_p(File.dirname(entry.name))
46
+ begin
47
+ entry.extract
48
+ rescue Zip::ZipDestinationFileExistsError
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def install source, destination
56
+ download_file_to(source, destination)
57
+
58
+ unzip_file(destination) if destination =~ /\.zip$/
59
+ end
60
+
61
+ def run name, jar_file, java_opts, args
62
+ runner = Runner.new
63
+
64
+ runner.run name, jar_file, java_opts, args
65
+ end
66
+ end
67
+
68
+
@@ -0,0 +1,35 @@
1
+ require 'rbconfig'
2
+
3
+ require 'open3' unless Config::CONFIG['host_os'] =~ /mswin|mingw|windows/
4
+
5
+ class JvmOptionsProbe
6
+
7
+ def initialize
8
+ @d32 = @d64 = @client = false
9
+
10
+ if WINDOZE
11
+ @help = `java -h`
12
+ @d32 = (@help == `java -d32`) ? true : false
13
+ @d64 = (@help == `java -d64`) ? true : false
14
+ @client = (@help == `java -client`) ? true : false
15
+ else
16
+ @help = Open3.popen3("java -h")[2].readlines
17
+ @d32 = (@help == Open3.popen3("java -d32")[2].readlines) ? true : false
18
+ @d64 = (@help == Open3.popen3("java -d64")[2].readlines) ? true : false
19
+ @client = (@help == Open3.popen3("java -client")[2].readlines) ? true : false
20
+ end
21
+ end
22
+
23
+ def can_use_d32?
24
+ @d32
25
+ end
26
+
27
+ def can_use_d64?
28
+ @d64
29
+ end
30
+
31
+ def can_use_client?
32
+ @client
33
+ end
34
+ end
35
+
@@ -0,0 +1,118 @@
1
+
2
+ class Runner
3
+ def run name, jar_file, java_opts, args
4
+ @jar_file = jar_file
5
+
6
+ # forking = ARGV.include?("--fork") and ARGV.first != "install"
7
+ # no_runner = ARGV.include?("--no-sub-jruby")
8
+ # jruby = Config::CONFIG["RUBY_INSTALL_NAME"] == "jruby"
9
+ # osx = !(RUBY_PLATFORM =~/(windows|linux)/)
10
+ # begin
11
+ # if forking and not jruby
12
+ # # jRuby doesn't support fork() because of the runtime stuff...
13
+ # forking = false
14
+ # puts 'Forking failed, attempting to start anyway...' if (pid = fork) == -1
15
+ # exit unless pid.nil? # kill the parent process
16
+ #
17
+ # if pid.nil?
18
+ # # reopen the standard pipes to nothingness
19
+ # # STDIN.reopen Redcar.null_device
20
+ # # STDOUT.reopen Redcar.null_device, 'a'
21
+ # STDERR.reopen STDOUT
22
+ # end
23
+ # elsif forking and SPOON_AVAILABLE and ::Spoon.supported?
24
+ # # so we need to try something different...
25
+ #
26
+ # forking = false
27
+ # construct_command do |command|
28
+ # command.push('--silent')
29
+ # ::Spoon.spawnp(*command)
30
+ # end
31
+ # exit 0
32
+ # elsif forking
33
+ # raise NotImplementedError, "Something weird has happened. Please contact us."
34
+ # end
35
+ # rescue NotImplementedError
36
+ # puts $!.class.name + ": " + $!.message
37
+ # puts "Forking isn't supported on this system. Sorry."
38
+ # puts "Starting normally..."
39
+ # end
40
+ #
41
+ # return if no_runner
42
+ # return if jruby and not osx
43
+
44
+ construct_command(name, java_opts, args) do |command|
45
+ exec(command.join(" "))
46
+ end
47
+
48
+ end
49
+
50
+ # Trade in this Ruby instance for a JRuby instance, loading in a
51
+ # starter script and passing it some arguments.
52
+ # If --jruby is passed, use the installed version of jruby, instead of
53
+ # our vendored jarred one (useful for gems).
54
+ def construct_command(name, java_opts=[], args="")
55
+ bin = File.expand_path(File.join(File.dirname(__FILE__), %w{.. .. bin #{name}}))
56
+ ENV['RUBYOPT'] = nil # disable other native args
57
+
58
+ # Windows XP updates
59
+
60
+ # if RUBY_PLATFORM =~ /window/
61
+ # bin = "\"#{bin}\""
62
+ # jruby_complete = "\"#{jruby_complete}\""
63
+ # end
64
+
65
+ # unfortuanately, ruby doesn't support [a, *b, c]
66
+ command = ["java"]
67
+ command.push(*java_args)
68
+
69
+ command.push(*java_opts) if java_opts.length > 0
70
+ command.push("-jar", @jar_file)
71
+ #command.push("-Djruby.memory.max=500m", "-Djruby.stack.max=1024k", "-cp", jruby_complete, "org.jruby.Main")
72
+
73
+ command.push "--debug" if debug_mode?
74
+ # command.push(bin)
75
+ # command.push(*cleaned_args)
76
+ # command.push("--no-sub-jruby", "--ignore-stdin")
77
+ command.push(*args)
78
+
79
+ puts command.join(' ')
80
+ yield command
81
+ end
82
+
83
+ # def cleaned_args
84
+ # # We should never pass --fork to a subprocess
85
+ # result = ARGV.find_all {|arg| arg != '--fork'}.map do |arg|
86
+ # if arg =~ /--(.+)=(.+)/
87
+ # "--" + $1 + "=\"" + $2 + "\""
88
+ # else
89
+ # arg
90
+ # end
91
+ # end
92
+ # result.delete("install")
93
+ # result
94
+ # end
95
+
96
+ def debug_mode?
97
+ ARGV.include?("--debug")
98
+ end
99
+
100
+ def java_args
101
+ str = []
102
+ if Config::CONFIG["host_os"] =~ /darwin/
103
+ str.push "-XstartOnFirstThread"
104
+ end
105
+
106
+ # if ARGV.include?("--load-timings")
107
+ # str.push "-Djruby.debug.loadService.timing=true"
108
+ # end
109
+
110
+ jvm_options_probe = JvmOptionsProbe.new
111
+
112
+ str.push "-d32" if jvm_options_probe.can_use_d32?
113
+ str.push "-client" if jvm_options_probe.can_use_client?
114
+
115
+ str
116
+ end
117
+ end
118
+
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{winstone}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Alexander Shvets}]
12
+ s.date = %q{2011-09-22}
13
+ s.description = %q{Gem wrapper for winstone server.}
14
+ s.email = %q{alexander.shvets@gmail.com}
15
+ s.executables = [%q{winstone}]
16
+ s.extra_rdoc_files = [
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ "CHANGES",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/Gemfile",
25
+ "bin/winstone",
26
+ "bin/winstone.bat",
27
+ "lib/jar_wrapper.rb",
28
+ "lib/jar_wrapper/jar_wrapper.rb",
29
+ "lib/jar_wrapper/jvm_options_probe.rb",
30
+ "lib/jar_wrapper/runner.rb",
31
+ "winstone.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/shvets/winstone}
34
+ s.post_install_message = %q{
35
+ -------------------------------------------------------------------------------
36
+
37
+ Please now run:
38
+
39
+ $ winstone install
40
+
41
+ NB. This will download jars that this gem needs to run from the internet.
42
+ It will put them into ~/.winstone/assets.
43
+
44
+ -------------------------------------------------------------------------------
45
+ }
46
+ s.require_paths = [%q{lib}]
47
+ s.requirements = [%q{none}]
48
+ s.rubygems_version = %q{1.8.6}
49
+ s.summary = %q{Gem wrapper for winstone server (Summary).}
50
+
51
+ if s.respond_to? :specification_version then
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_runtime_dependency(%q<zip>, [">= 0"])
57
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_runtime_dependency(%q<zip>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<jeweler>, [">= 0"])
61
+ s.add_dependency(%q<zip>, [">= 0"])
62
+ s.add_dependency(%q<jeweler>, [">= 0"])
63
+ s.add_dependency(%q<zip>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<jeweler>, [">= 0"])
67
+ s.add_dependency(%q<zip>, [">= 0"])
68
+ s.add_dependency(%q<jeweler>, [">= 0"])
69
+ s.add_dependency(%q<zip>, [">= 0"])
70
+ end
71
+ end
72
+
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: winstone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Shvets
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jeweler
16
+ requirement: &2152424340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152424340
25
+ - !ruby/object:Gem::Dependency
26
+ name: zip
27
+ requirement: &2152423500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2152423500
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &2152422480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2152422480
47
+ - !ruby/object:Gem::Dependency
48
+ name: zip
49
+ requirement: &2152416620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2152416620
58
+ description: Gem wrapper for winstone server.
59
+ email: alexander.shvets@gmail.com
60
+ executables:
61
+ - winstone
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - README
65
+ files:
66
+ - CHANGES
67
+ - README
68
+ - Rakefile
69
+ - VERSION
70
+ - bin/Gemfile
71
+ - bin/winstone
72
+ - bin/winstone.bat
73
+ - lib/jar_wrapper.rb
74
+ - lib/jar_wrapper/jar_wrapper.rb
75
+ - lib/jar_wrapper/jvm_options_probe.rb
76
+ - lib/jar_wrapper/runner.rb
77
+ - winstone.gemspec
78
+ homepage: http://github.com/shvets/winstone
79
+ licenses: []
80
+ post_install_message: ! "\n -------------------------------------------------------------------------------\n\n
81
+ \ Please now run:\n\n $ winstone install\n\n NB. This will download
82
+ jars that this gem needs to run from the internet.\n It will put them into
83
+ ~/.winstone/assets.\n\n -------------------------------------------------------------------------------\n"
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements:
100
+ - none
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Gem wrapper for winstone server (Summary).
106
+ test_files: []