jnlp 0.0.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.
@@ -0,0 +1,196 @@
1
+ # :main: Jnlp::Jnlp
2
+ # :title: Jnlp::Jnlp RDoc
3
+ #
4
+ # to regenerate and display this rdoc:
5
+ # rdoc -U -SN jnlp.rb otrunk.rb ; open doc/index.html
6
+ #
7
+ require 'open-uri'
8
+ require 'hpricot'
9
+ require 'fileutils'
10
+ require 'net/http'
11
+ require 'date'
12
+
13
+ if RUBY_PLATFORM =~ /java/
14
+ import java.util.jar.JarInputStream unless defined? JarInputStream
15
+ import java.io.FileInputStream unless defined? FileInputStream
16
+ import java.net.URL unless defined? URL
17
+ import java.util.Collection unless defined? Collection
18
+ import java.util.List unless defined? List
19
+ import java.util.ArrayList unless defined? ArrayList
20
+ #
21
+ # Used to refer to Java classes in the java.io package.
22
+ # Some of the class names in the java.io package have the
23
+ # same name as existing Ruby classes. This creates a namespace
24
+ # scope for referring to the Java classes.
25
+ #
26
+ # Example:
27
+ #
28
+ # JavaIO::File.new("dummy.txt")
29
+ #
30
+ module JavaIO
31
+ include_package "java.io"
32
+ end
33
+ #
34
+ # Used to refer to Java classes in the net.sf.sail.emf.launch package.
35
+ #
36
+ # Example:
37
+ #
38
+ #
39
+ #
40
+ module SailEmfLaunch
41
+ include_package "net.sf.sail.emf.launch"
42
+ end
43
+ #
44
+ # Used to refer to Java classes in the net.sf.sail.core.bundle package.
45
+ #
46
+ # Example:
47
+ #
48
+ # bundleManager = SailCoreBundle::BundleManager.new
49
+ #
50
+ module SailCoreBundle
51
+ include_package "net.sf.sail.core.bundle"
52
+ end
53
+ #
54
+ # Used to refer to Java classes in the net.sf.sail.core.util.
55
+ #
56
+ # Example:
57
+ #
58
+ # manager = serviceContext.getService(SailCoreService::SessionManager.class)
59
+ #
60
+ module SailCoreService
61
+ include_package "net.sf.sail.core.service"
62
+ end
63
+ #
64
+ # Used to refer to Java classes in: net.sf.sail.core.util
65
+ #
66
+ # Example:
67
+ #
68
+ #
69
+ #
70
+ module SailCoreServiceImpl
71
+ include_package "net.sf.sail.core.service.impl"
72
+ end
73
+ #
74
+ # Used to refer to Java classes in: net.sf.sail.core.util
75
+ #
76
+ # Example:
77
+ #
78
+ #
79
+ #
80
+ module SailCoreUtil
81
+ include_package "net.sf.sail.core.util"
82
+ end
83
+ end
84
+
85
+ module Jnlp #:nodoc:
86
+ #
87
+ #
88
+ require "#{File.expand_path(File.dirname(__FILE__))}/jnlp.rb"
89
+ #
90
+ # Jnlp::Otrunk is a subclass of Jnlp::Jnlp that adds SAIL
91
+ # SAIL-Otrunk specific methods for execution.of the jnlp
92
+ # locally without using Java Web Start.
93
+ #
94
+ # It assumes a default main-class of:
95
+ #
96
+ # net.sf.sail.emf.launch.EMFLauncher2
97
+ #
98
+ # and by default uses the argument in the original jnlp.
99
+ # Both of these values can be overridden.
100
+ #
101
+ # Example:
102
+ #
103
+ # j = Jnlp::Otrunk.new('http://rails.dev.concord.org/sds/2/offering/144/jnlp/540/view?sailotrunk.otmlurl=http://continuum.concord.org/otrunk/examples/BasicExamples/document-edit.otml&sailotrunk.hidetree=false', 'cache'); nil
104
+ #
105
+ #
106
+ class Otrunk < Jnlp
107
+ #
108
+ # This will start the jnlp locally in Java without
109
+ # using Java Web Start
110
+ #
111
+ # This method works in MRI by forking and using exec
112
+ # to start a separate javavm process.
113
+ #
114
+ #
115
+ # JRuby Note:
116
+ #
117
+ # In JRuby the jars are required which makes them available
118
+ # to JRuby -- but to make this work you will need to also
119
+ # included them on the CLASSPATH.
120
+ #
121
+ # The convienence method Jnlp#write_local_classpath_shell_script
122
+ # can be used to create a shell script to set the classpath.
123
+ #
124
+ # If you are using the JRuby interactive console you will need to
125
+ # exclude any reference to a separate jruby included in the jnlp.
126
+ #
127
+ # Example in JRuby jirb:
128
+ #
129
+ # j = Jnlp::Otrunk.new('http://rails.dev.concord.org/sds/2/offering/144/jnlp/540/view?sailotrunk.otmlurl=http://continuum.concord.org/otrunk/examples/BasicExamples/document-edit.otml&sailotrunk.hidetree=false', 'cache'); nil
130
+ # j.write_local_classpath_shell_script('document-edit_classpath.sh', :remove_jruby => true)
131
+ #
132
+ # Now exit jirb and execute this in the shell:
133
+ #
134
+ # source document-edit_classpath.sh
135
+ #
136
+ # Now restart jirb:
137
+ #
138
+ # j = Jnlp::Otrunk.new('http://rails.dev.concord.org/sds/2/offering/144/jnlp/540/view?sailotrunk.otmlurl=http://continuum.concord.org/otrunk/examples/BasicExamples/document-edit.otml&sailotrunk.hidetree=false', 'cache'); nil
139
+ # j.run_local
140
+ #
141
+ # You can optionally pass in jnlp and main-class arguments
142
+ # If these paramaters are not present Otrunk#run_local will
143
+ # use:
144
+ #
145
+ # net.sf.sail.emf.launch.EMFLauncher2
146
+ #
147
+ # as the default main class and the default argument in
148
+ # the original jnlp.
149
+ #
150
+ def run_local(argument=@argument, main_class='net.sf.sail.emf.launch.EMFLauncher2')
151
+ if RUBY_PLATFORM =~ /java/
152
+
153
+ java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)
154
+
155
+ require_resources
156
+ configUrl = URL.new(JavaIO::File.new("dummy.txt").toURL, argument)
157
+ # configUrl = URL.new("document-edit.config")
158
+ unless @bundleManager
159
+ @bundleManager = SailCoreBundle::BundleManager.new
160
+ @serviceContext = @bundleManager.getServiceContext
161
+ @bundleManager.setContextURL(configUrl)
162
+ #
163
+ # Add the <code>bundles</code> configured in this bundles xml file. The format of the file
164
+ # is XMLEncoder
165
+ #
166
+ @bundleManager.addBundles(configUrl.openStream)
167
+ #
168
+ # Have all the bundles register their services, and then do any linking
169
+ # to other registered services
170
+ #
171
+ @bundleManager.initializeBundles
172
+ #
173
+ # Start the session manager
174
+ #
175
+ @manager = @serviceContext.getService(SailCoreService::SessionManager.java_class)
176
+ end
177
+ @manager.start(@serviceContext)
178
+ else
179
+ command = "java -classpath #{local_classpath} #{main_class} '#{argument}'"
180
+ $pid = fork { exec command }
181
+ end
182
+ end
183
+ #
184
+ # This will stop the locally run OTrunk process.
185
+ # This only works in MRI at this point.
186
+ #
187
+ def stop_local
188
+ if RUBY_PLATFORM =~ /java/
189
+ @manager.stop(@serviceContext)
190
+ else
191
+ Process.kill 15, $pid
192
+ Process.wait($pid)
193
+ end
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,9 @@
1
+ module Jnlp #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 3
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/jnlp.rb ADDED
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Jnlp
5
+ require 'jnlp/jnlp.rb'
6
+ require 'jnlp/otrunk.rb'
7
+ require 'jnlp/version.rb'
8
+ end
data/log/debug.log ADDED
File without changes
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/jnlp.rb'}"
9
+ puts "Loading jnlp gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/jnlp/version.rb'
15
+
16
+ version = Jnlp::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/jnlp'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)