Class: Jnlp::Jnlp
- Inherits:
-
Object
- Object
- Jnlp::Jnlp
- Defined in:
- lib/jnlp/jnlp.rb
Overview
Jnlp
A gem for encapsulating the content and resources referenced by Java Web Start jnlps
For more information about the structure of Java Web Start see:
To create a new Jnlp call Jnlp#new with a string that contains either a local path or a url.
Examples:
-
Creating a new Jnlp object from a local Java Web Start jnlp file. j = Jnlp::Jnlp.new(“authoring.jnlp”)
-
Creating a new Jnlp object from a Java Web Start jnlp referenced with a url. j = Jnlp::Jnlp.new(“jnlp.concord.org/dev/org/concord/maven-jnlp/otrunk-sensor/otrunk-sensor.jnlp”)
Once the Jnlp object is created you can call Jnlp#cache_resources to create a local cache of all the jar and nativelib resources. The structure of the cache directory and the naming using for the jar and nativelib files is the same as that used by the Java Web Start Download Servlet, see:
Example: Creating an jnlp object and caching all the resources
j = Jnlp::Jnlp.new("http://jnlp.concord.org/dev/org/concord/maven-jnlp/otrunk-sensor/otrunk-sensor.jnlp", 'web_start_cache')
Will populate the local directory: web_start_cache with the following files:
avalon-framework/avalon-framework/avalon-framework__V4.1.3.jar
commons-beanutils/commons-beanutils/commons-beanutils__V1.7.0.jar
commons-collections/commons-collections/commons-collections__V3.1.jar
commons-digester/commons-digester/commons-digester__V1.8.jar
commons-lang/commons-lang/commons-lang__V2.1.jar
commons-logging/commons-logging/commons-logging__V1.1.jar
commons-validator/commons-validator/commons-validator__V1.3.1.jar
jdom/jdom/jdom__V1.0.jar
jug/jug/jug__V1.1.2.jar
log4j/log4j/log4j__V1.2.12.jar
logkit/logkit/logkit__V1.0.1.jar
org/apache/velocity/velocity/velocity__V1.5.jar
org/apache/velocity/velocity-tools/velocity-tools__V1.3.jar
org/concord/apple-support/apple-support__V0.1.0-20071207.221705-16.jar
org/concord/data/data__V0.1.0-20080307.190013-90.jar
org/concord/datagraph/datagraph__V0.1.0-20080306.220034-101.jar
org/concord/external/ekit/ekit__V1.0.jar
org/concord/external/jep/jep__V1.0.jar
org/concord/external/rxtx/rxtx-comm/rxtx-comm__V2.1.7-r2.jar
org/concord/external/rxtx/rxtx-serial/rxtx-serial-linux-nar__V2.1.7-r2.jar
org/concord/external/rxtx/rxtx-serial/rxtx-serial-macosx-nar__V2.1.7-r2.jar
org/concord/external/rxtx/rxtx-serial/rxtx-serial-win32-nar__V2.1.7-r2.jar
org/concord/external/sound/jlayer/jlayer__V1.0.jar
org/concord/external/sound/mp3spi/mp3spi__V1.9.4.jar
org/concord/external/sound/tritonus/tritonus__V0.1.jar
org/concord/external/vecmath/vecmath__V2.0.jar
org/concord/framework/framework__V0.1.0-20080306.210010-141.jar
org/concord/frameworkview/frameworkview__V0.1.0-20080305.205955-32.jar
org/concord/ftdi-serial-wrapper/ftdi-serial-wrapper__V0.1.0-20071208.222126-20.jar
org/concord/ftdi-serial-wrapper-native/ftdi-serial-wrapper-native-win32-nar__V0.1.0-20070303.181906-4.jar
org/concord/graph/graph__V0.1.0-20071208.221811-45.jar
org/concord/graphutil/graphutil__V0.1.0-20080206.170117-89.jar
org/concord/httpclient/httpclient__V0.1.0-20071212.220020-17.jar
org/concord/loader/loader__V0.1.0-20071207.234707-24.jar
org/concord/math/math__V0.1.0-20071207.221359-24.jar
org/concord/otrunk/data-util/data-util__V0.1.0-20080215.170056-146.jar
org/concord/otrunk/otrunk-velocity/otrunk-velocity__V0.1.0-20071207.201957-21.jar
org/concord/otrunk/otrunk__V0.1.0-20080305.205802-425.jar
org/concord/otrunk-ui/otrunk-ui__V0.1.0-20080310.210028-132.jar
org/concord/portfolio/portfolio__V0.1.0-20080303.230151-55.jar
org/concord/sensor/labpro-usb/labpro-usb__V0.1.0-20071207.225156-8.jar
org/concord/sensor/labpro-usb-native/labpro-usb-native-win32-nar__V0.1.0-20070606.192155-3.jar
org/concord/sensor/sensor-dataharvest/sensor-dataharvest__V0.1.0-20070607.155431-8.jar
org/concord/sensor/sensor-pasco/sensor-pasco__V0.1.0-20070405.151628-5.jar
org/concord/sensor/sensor-vernier/sensor-vernier__V0.1.0-20080101.035208-31.jar
org/concord/sensor/sensor__V0.1.0-20080229.053155-68.jar
org/concord/sensor/ti/ti-cbl/ti-cbl-win32-nar__V0.1.1.jar
org/concord/sensor/vernier/vernier-goio/vernier-goio-macosx-nar__V1.0.0.jar
org/concord/sensor/vernier/vernier-goio/vernier-goio-win32-nar__V1.0.0.jar
org/concord/sensor-native/sensor-native__V0.1.0-20080220.200100-39.jar
org/concord/swing/swing__V0.1.0-20080303.163057-72.jar
oro/oro/oro__V2.0.8.jar
sslext/sslext/sslext__V1.2-0.jar
velocity/velocity/velocity__V1.4.jar
velocity/velocity-dep/velocity-dep__V1.4.jar"]
Adding the option _:include_pack_gz => true_ will result in also copying all the *.pack.gz versions of the resources to the local cache directory.
j = Jnlp::Jnlp.new("http://jnlp.concord.org/dev/org/concord/maven-jnlp/otrunk-sensor/otrunk-sensor.jnlp", 'web_start_cache', :include_pack_gz => true)
Adding the option :verbose => true will display a log of actions
Note:
The jnlp gem has a dependency on hpricot version 0.6.164. The most recent version of hpricot, version 0.7.0 does not yet work with JRuby.
Constant Summary collapse
- CLASSPATH_DELIMETER =
Sets the Java Classpath delimiter used when generating a Classpath string
':'
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Contains the value of the jnlp/application-desc/argument element Example: “www.concord.org”.
-
#codebase ⇒ Object
readonly
Contains the codebase attribute in the jnlp element Example:.
-
#description ⇒ Object
readonly
Contains the value of the jnlp/information/description element Example:.
-
#family ⇒ Object
readonly
Contains the name of the directory the original jnlp is located in.
-
#homepage ⇒ Object
readonly
Contains the value of the href attribute in the jnlp/information/homepage element Example:.
-
#href ⇒ Object
readonly
Contains the href attribute in the jnlp element Example:.
-
#icon ⇒ Object
readonly
Contains a Jnlp::Icon object encapsulating the jnlp/information/icon element if it exists in the original jnlp.
-
#include_pack_gz ⇒ Object
contans the boolean attribute determining whether gzipped pack200 resources should be copied to the local cache when the cache is updated.
-
#j2ses ⇒ Object
readonly
Contains an array of Jnlp::J2se objects encapsulating jnlp/resources/j2se elements.
-
#jars ⇒ Object
readonly
Contains an array of Jnlp::Resource objects encapsulating jnlp/resources/jar elements.
-
#jnlp ⇒ Object
readonly
Contains a Hpricot XML doc of the original jnlp.
-
#local_cache_dir ⇒ Object
Contains the absolute path to the local cache directory if it has been set.
-
#local_jnlp ⇒ Object
readonly
Contains a Hpricot XML doc of the jnlp converted to reference the local cache.
-
#local_jnlp_href ⇒ Object
readonly
Contains the local file-based href attribute of the local jnlp if it has been created.
-
#local_jnlp_name ⇒ Object
readonly
Contains the local file-based name attribute of the of the local jnlp if it has been created.
-
#local_resource_signatures_verified ⇒ Object
Contains a boolean value indicating if the signatures of all resources copied to local cache have been verified.
-
#main_class ⇒ Object
readonly
Contains the value of the main-class attribute in the jnlp/application-desc element Example: “www.concord.org”.
-
#name ⇒ Object
readonly
Contains the name of the jnlp.
-
#nativelibs ⇒ Object
readonly
Contains an array of Jnlp::Resource objects encapsulating jnlp/resources/nativelib elements.
-
#offline_allowed ⇒ Object
readonly
Contains a boolean value indictating the presence of the jnlp/information/offline-allowed element.
-
#path ⇒ Object
readonly
Contains the path to the original jnlp.
-
#properties ⇒ Object
readonly
Contains an array of Jnlp::Property objects encapsulating jnlp/resources/property elements.
-
#relative_local_cache_dir ⇒ Object
readonly
Contains the relative path to local cache directory if it has been set.
-
#spec ⇒ Object
readonly
Contains the spec attribute in the jnlp element Example:.
-
#title ⇒ Object
readonly
Contains the value of the jnlp/information/title element Example:.
-
#url ⇒ Object
readonly
Contains the full url of the original jnlp.
-
#vendor ⇒ Object
readonly
Contains the value of the jnlp/information/vendor element Example:.
-
#version_str ⇒ Object
readonly
Contains version string of the jnlp if it has one, otherwize nil.
Instance Method Summary collapse
-
#cache_resources(dest_dir = @local_cache_dir, options = @options) ⇒ Object
Copy all the jars and nativelib resources referenced in the Jnlp to a local cache dir passed in dest_dir.
-
#generate_local_jnlp(options = {}) ⇒ Object
Copies the original Hpricot jnlp into @local_jnlp and modifies it to reference resources in the local cache.
-
#import_jnlp(url = @url) ⇒ Object
Rebuild the Jnlp by loading and parsing the Java Web Start Jnlp located at path – path can be a local path or a url.
- #initial_heap_size(os = nil, arch = nil) ⇒ Object
-
#initialize(url = nil, cache_dir = nil, options = {}) ⇒ Jnlp
constructor
Create a new Jnlp by loading and parsing the Java Web Start Jnlp located at url – url can be a local path or a url.
- #j2se_version(os = nil, arch = nil) ⇒ Object
- #java_vm_args(os = nil, arch = nil) ⇒ Object
-
#local_classpath(options = {}) ⇒ Object
Returns a string in Java classpath format for all the jars for this jnlp The delimiter used is the ‘:’ which is valid for MacOS X and Linux.
- #max_heap_size(os = nil, arch = nil) ⇒ Object
-
#require_resources ⇒ Object
This will add all the jars for this jnlp to the effective classpath for this Java process.
-
#resource_paths(options = {}) ⇒ Object
Returns an array containing all the local paths for this jnlp’s resources.
-
#run_local(argument = @argument) ⇒ Object
This will start the jnlp as a local process.
-
#save(filename = "saved_jnlp_object") ⇒ Object
Saves a YAML version of the jnlp object.
-
#stop_local ⇒ Object
This will stop the running local process, started by Jnlp#run_local.
-
#to_jnlp(options = {}) ⇒ Object
returns the jnlp as a string.
-
#to_local_jnlp ⇒ Object
returns the local file-based jnlp as a string.
-
#write_jnlp(options = {}) ⇒ Object
Writes a local copy of the original jnlp .
-
#write_local_classpath_shell_script(filename = "#{@name[/[A-Za-z0-9_-]*/]}_classpath.sh", options = {}) ⇒ Object
Writes a shell script to the local filesystem that will export a modified CLASSPATH environmental variable with the paths to the resources used by this jnlp.
-
#write_local_jnlp(filename = @local_jnlp_name) ⇒ Object
Writes a local file-based jnlp.
Constructor Details
#initialize(url = nil, cache_dir = nil, options = {}) ⇒ Jnlp
Create a new Jnlp by loading and parsing the Java Web Start Jnlp located at url – url can be a local path or a url.
-
if you include cache_dir then the jnlp resources will be cached locally when the object is created
You can pass a hash with these options:
:include_pack_gz => true download and cache the pack.gz jar files also
:verbose => true display a log
346 347 348 349 350 351 352 353 |
# File 'lib/jnlp/jnlp.rb', line 346 def initialize(url=nil, cache_dir=nil, ={}) @url = url self.local_cache_dir = cache_dir @options = @include_pack_gz = [:include_pack_gz] @verbose = [:verbose] import_jnlp(@url) unless @url.empty? end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Contains the value of the jnlp/application-desc/argument element Example: “www.concord.org”
336 337 338 |
# File 'lib/jnlp/jnlp.rb', line 336 def argument @argument end |
#codebase ⇒ Object (readonly)
Contains the codebase attribute in the jnlp element Example:
"http://jnlp.concord.org/dev"
260 261 262 |
# File 'lib/jnlp/jnlp.rb', line 260 def codebase @codebase end |
#description ⇒ Object (readonly)
Contains the value of the jnlp/information/description element Example:
"http://www.concord.org"
295 296 297 |
# File 'lib/jnlp/jnlp.rb', line 295 def description @description end |
#family ⇒ Object (readonly)
Contains the name of the directory the original jnlp is located in. If the jnlp was originally served from a maven-jnlp server this will be the maven_jnlp_family name which duplicates the first part of the name of a versioned jnlp.
Example:
"otrunk-sensor"
179 180 181 |
# File 'lib/jnlp/jnlp.rb', line 179 def family @family end |
#homepage ⇒ Object (readonly)
Contains the value of the href attribute in the jnlp/information/homepage element Example:
"http://www.concord.org"
288 289 290 |
# File 'lib/jnlp/jnlp.rb', line 288 def homepage @homepage end |
#href ⇒ Object (readonly)
Contains the href attribute in the jnlp element Example:
"http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/all-otrunk-snapshot.jnlp"
267 268 269 |
# File 'lib/jnlp/jnlp.rb', line 267 def href @href end |
#icon ⇒ Object (readonly)
Contains a Jnlp::Icon object encapsulating the jnlp/information/icon element if it exists in the original jnlp
301 302 303 |
# File 'lib/jnlp/jnlp.rb', line 301 def icon @icon end |
#include_pack_gz ⇒ Object
contans the boolean attribute determining whether gzipped pack200 resources should be copied to the local cache when the cache is updated
246 247 248 |
# File 'lib/jnlp/jnlp.rb', line 246 def include_pack_gz @include_pack_gz end |
#j2ses ⇒ Object (readonly)
Contains an array of Jnlp::J2se objects encapsulating jnlp/resources/j2se elements
311 312 313 |
# File 'lib/jnlp/jnlp.rb', line 311 def j2ses @j2ses end |
#jars ⇒ Object (readonly)
Contains an array of Jnlp::Resource objects encapsulating jnlp/resources/jar elements
321 322 323 |
# File 'lib/jnlp/jnlp.rb', line 321 def jars @jars end |
#jnlp ⇒ Object (readonly)
Contains a Hpricot XML doc of the original jnlp
147 148 149 |
# File 'lib/jnlp/jnlp.rb', line 147 def jnlp @jnlp end |
#local_cache_dir ⇒ Object
Contains the absolute path to the local cache directory if it has been set
Example:
"/Users/stephen/dev/jetty-jnlp-proxy/cache"
229 230 231 |
# File 'lib/jnlp/jnlp.rb', line 229 def local_cache_dir @local_cache_dir end |
#local_jnlp ⇒ Object (readonly)
Contains a Hpricot XML doc of the jnlp converted to reference the local cache
151 152 153 |
# File 'lib/jnlp/jnlp.rb', line 151 def local_jnlp @local_jnlp end |
#local_jnlp_href ⇒ Object (readonly)
Contains the local file-based href attribute of the local jnlp if it has been created.
Example:
file:/Users/stephen/dev/otrunk-sensor/otrunk-sensor.jnlp"
204 205 206 |
# File 'lib/jnlp/jnlp.rb', line 204 def local_jnlp_href @local_jnlp_href end |
#local_jnlp_name ⇒ Object (readonly)
Contains the local file-based name attribute of the of the local jnlp if it has been created.
Example:
otrunk-sensor.jnlp"
213 214 215 |
# File 'lib/jnlp/jnlp.rb', line 213 def local_jnlp_name @local_jnlp_name end |
#local_resource_signatures_verified ⇒ Object
Contains a boolean value indicating if the signatures of all resources copied to local cache have been verified.
The value is nil if no local cache has been created.
Example:
true || false || nil
240 241 242 |
# File 'lib/jnlp/jnlp.rb', line 240 def local_resource_signatures_verified @local_resource_signatures_verified end |
#main_class ⇒ Object (readonly)
Contains the value of the main-class attribute in the jnlp/application-desc element Example: “www.concord.org”
331 332 333 |
# File 'lib/jnlp/jnlp.rb', line 331 def main_class @main_class end |
#name ⇒ Object (readonly)
Contains the name of the jnlp
Example:
"otrunk-sensor.jnlp"
187 188 189 |
# File 'lib/jnlp/jnlp.rb', line 187 def name @name end |
#nativelibs ⇒ Object (readonly)
Contains an array of Jnlp::Resource objects encapsulating jnlp/resources/nativelib elements
326 327 328 |
# File 'lib/jnlp/jnlp.rb', line 326 def nativelibs @nativelibs end |
#offline_allowed ⇒ Object (readonly)
Contains a boolean value indictating the presence of the jnlp/information/offline-allowed element
306 307 308 |
# File 'lib/jnlp/jnlp.rb', line 306 def offline_allowed @offline_allowed end |
#path ⇒ Object (readonly)
Contains the path to the original jnlp. This is generated by removing the codebase form the url.
Example:
"/org/concord/maven-jnlp/otrunk-sensor/otrunk-sensor.jnlp"
168 169 170 |
# File 'lib/jnlp/jnlp.rb', line 168 def path @path end |
#properties ⇒ Object (readonly)
Contains an array of Jnlp::Property objects encapsulating jnlp/resources/property elements
316 317 318 |
# File 'lib/jnlp/jnlp.rb', line 316 def properties @properties end |
#relative_local_cache_dir ⇒ Object (readonly)
Contains the relative path to local cache directory if it has been set
Example:
"cache"
221 222 223 |
# File 'lib/jnlp/jnlp.rb', line 221 def relative_local_cache_dir @relative_local_cache_dir end |
#spec ⇒ Object (readonly)
Contains the spec attribute in the jnlp element Example:
"1.0+"
253 254 255 |
# File 'lib/jnlp/jnlp.rb', line 253 def spec @spec end |
#title ⇒ Object (readonly)
Contains the value of the jnlp/information/title element Example:
"All OTrunk snapshot"
274 275 276 |
# File 'lib/jnlp/jnlp.rb', line 274 def title @title end |
#url ⇒ Object (readonly)
Contains the full url of the original jnlp
Example:
"http://jnlp.concord.org/dev/org/concord/maven-jnlp/otrunk-sensor/otrunk-sensor.jnlp"
159 160 161 |
# File 'lib/jnlp/jnlp.rb', line 159 def url @url end |
#vendor ⇒ Object (readonly)
Contains the value of the jnlp/information/vendor element Example:
"Concord Consortium"
281 282 283 |
# File 'lib/jnlp/jnlp.rb', line 281 def vendor @vendor end |
#version_str ⇒ Object (readonly)
Contains version string of the jnlp if it has one, otherwize nil
Example:
"0.1.0-20100521.210440"
195 196 197 |
# File 'lib/jnlp/jnlp.rb', line 195 def version_str @version_str end |
Instance Method Details
#cache_resources(dest_dir = @local_cache_dir, options = @options) ⇒ Object
Copy all the jars and nativelib resources referenced in the Jnlp to a local cache dir passed in dest_dir. The structure of the cache directory and the naming using for the jar and nativelib files is the same as that used by the Java Web Start Download Servlet, see:
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/jnlp/jnlp.rb', line 464 def cache_resources(dest_dir=@local_cache_dir, =@options) unless dest_dir raise ArgumentError, "Must specify destination directory when caching resources", caller end self.local_cache_dir=dest_dir @local_resource_signatures_verified = true @jars.each do |jar| @local_resource_signatures_verified &&= jar.cache_resource(dest_dir, ) end @nativelibs.each do |nativelib| @local_resource_signatures_verified &&= nativelib.cache_resource(dest_dir, ) end if @local_resource_signatures_verified generate_local_jnlp end @local_resource_signatures_verified = @local_resource_signatures_verified ? true : false end |
#generate_local_jnlp(options = {}) ⇒ Object
Copies the original Hpricot jnlp into @local_jnlp and modifies it to reference resources in the local cache.
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/jnlp/jnlp.rb', line 485 def generate_local_jnlp(={}) # # get a copy of the existing jnlp # (it should be easier than this) # @local_jnlp = Nokogiri::XML(@jnlp.to_s) # # we'll be working with the Hpricot root element # jnlp_elem = (@local_jnlp/"jnlp").first # # set the new codebase # jnlp_elem[:codebase] = "file:#{@local_cache_dir}" # # set the new href # jnlp_elem[:href] = @local_jnlp_href # # for each jar and nativelib remove the version # attribute and point the href to the local cache # @jars.each do |jar| j = @local_jnlp.at("//jar[@href=#{jar.href}]") j.remove_attribute(:version) if [:include_pack_gz] j[:href] = jar.relative_local_path_pack_gz else j[:href] = jar.relative_local_path end end @nativelibs.each do |nativelib| nl = @local_jnlp.at("//nativelib[@href=#{nativelib.href}]") nl.remove_attribute(:version) if [:include_pack_gz] nl[:href] = nativelib.relative_local_path_pack_gz else nl[:href] = nativelib.relative_local_path end end end |
#import_jnlp(url = @url) ⇒ Object
Rebuild the Jnlp by loading and parsing the Java Web Start Jnlp located at path – path can be a local path or a url.
If @local_cache_dir is set then the cache directory wll be updated also.
If @include_pack_gz is set then the gzipped pack200 versions of the resources will be cached also.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/jnlp/jnlp.rb', line 406 def import_jnlp(url=@url) @name = File.basename(url) # # @local_jnlp_href and @local_jnlp_name are only placeholders # values so far-- they will become valid when a local jnlp file # is written to the filesystem with this method: # # Jnlp#write_local_jnlp # @local_jnlp_name = "local-#{@name}" @local_jnlp_href = File.("#{Dir.pwd}/#{@local_jnlp_name}") @jnlp = Nokogiri::XML(open(url).read) @spec = (@jnlp/"jnlp").attr('spec').value @codebase = (@jnlp/"jnlp").attr('codebase').value @path = @url.gsub(@codebase, '') @family = File.basename(File.dirname(@path)) @href = (@jnlp/"jnlp").attr('href').value unless (@jnlp/"jnlp").attr('href').nil? @title, @vendor, @homepage, @description, @icon = nil, nil, nil, nil, nil unless (info = (@jnlp/"information")).empty? @title = (info/"title").inner_html.strip @vendor = (info/"vendor").inner_html.strip @homepage = (info/"homepage").empty? ? '' : (info/"homepage").attr('href').value @description = (info/"description").empty? ? '' : (info/"description").inner_html.strip icon = (info/"icon") @icon = Icon.new(icon) unless icon.empty? @offline_allowed = (info/"offline-allowed") ? true : false end @main_class = (@jnlp/"application-desc").attr('main-class').value @argument = (@jnlp/"argument").inner_html.strip @j2ses, @properties, @jars, @nativelibs = [], [], [], [] (@jnlp/"resources").each do |resources| if os = resources[:os] os = os.strip.downcase.gsub(/\W+/, '_').gsub(/^_+|_+$/, '') end if arch = resources[:arch] arch = arch.strip.downcase.gsub(/\W+/, '_').gsub(/^_+|_+$/, '') end (resources/"j2se").each { |j2se| @j2ses << J2se.new(j2se, os, arch) } (resources/"property").each { |prop| @properties << Property.new(prop, os) } (resources/"jar").each { |res| @jars << Resource.new(res, @codebase, os) } (resources/"nativelib").each { |res| @nativelibs << Resource.new(res, @codebase, os) } end maven_jnlp_version = properties.find {|p| p.name == "maven.jnlp.version"} if maven_jnlp_version @version_str = maven_jnlp_version.value[/#{@family}-(.*)/, 1] end if @local_cache_dir cache_resources(@local_cache_dir) generate_local_jnlp end end |
#initial_heap_size(os = nil, arch = nil) ⇒ Object
365 366 367 368 |
# File 'lib/jnlp/jnlp.rb', line 365 def initial_heap_size(os=nil, arch=nil) j2se = j2ses.detect { |j2se| j2se.os == os && j2se.arch == arch } j2se ? j2se.initial_heap_size : nil end |
#j2se_version(os = nil, arch = nil) ⇒ Object
355 356 357 358 |
# File 'lib/jnlp/jnlp.rb', line 355 def j2se_version(os=nil, arch=nil) j2se = j2ses.detect { |j2se| j2se.os == os && j2se.arch == arch} j2se ? j2se.version : nil end |
#java_vm_args(os = nil, arch = nil) ⇒ Object
370 371 372 373 |
# File 'lib/jnlp/jnlp.rb', line 370 def java_vm_args(os=nil, arch=nil) j2se = j2ses.detect { |j2se| j2se.os == os && j2se.arch == arch } j2se ? j2se.java_vm_args : nil end |
#local_classpath(options = {}) ⇒ Object
Returns a string in Java classpath format for all the jars for this jnlp The delimiter used is the ‘:’ which is valid for MacOS X and Linux. Windows uses the ‘;’ as a delimeter.
Pass in the optional hash: (:remove_jruby => true) and the first resource that contains the string /jruby/ will be removed from the returned classapath string.
Example:
local_classpath(:remove_jruby => true)
579 580 581 |
# File 'lib/jnlp/jnlp.rb', line 579 def local_classpath(={}) resource_paths().join(CLASSPATH_DELIMETER) end |
#max_heap_size(os = nil, arch = nil) ⇒ Object
360 361 362 363 |
# File 'lib/jnlp/jnlp.rb', line 360 def max_heap_size(os=nil, arch=nil) j2se = j2ses.detect { |j2se| j2se.os == os && j2se.arch == arch } j2se ? j2se.max_heap_size : nil end |
#require_resources ⇒ Object
This will add all the jars for this jnlp to the effective classpath for this Java process.
If you are already running in JRuby AND the jnlp references a JRuby resource the JRuby resource will not be required.
678 679 680 681 682 683 684 685 |
# File 'lib/jnlp/jnlp.rb', line 678 def require_resources if RUBY_PLATFORM =~ /java/ resource_paths(:remove_jruby => true).each {|res| require res} true else false end end |
#resource_paths(options = {}) ⇒ Object
Returns an array containing all the local paths for this jnlp’s resources.
Pass in the options hash: (:remove_jruby => true) and the first resource that contains the string /jruby/ will be removed from the returned array.
Example:
resource_paths(:remove_jruby => true)
This is useful when the jruby-complete jar has been included in the jnlp and you don’t want to require that jruby into this specific instance which is already running jruby.
Here’s an example of a jruby resource reference:
"org/jruby/jruby/jruby__V1.0RC2.jar"
Pass in the options hash: (:include_pack_gz => true) and the resources returned with be pack.gz jars instead of regular jars
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/jnlp/jnlp.rb', line 548 def resource_paths(={}) if [:include_pack_gs] cp_jars = @jars.empty? ? [] : @jars.collect {|j| j.local_path_pack_gz} cp_nativelibs = @nativelibs.empty? ? [] : @nativelibs.collect {|n| n.local_path_pack_gz} resources = cp_jars + cp_nativelibs else cp_jars = @jars.empty? ? [] : @jars.collect {|j| j.local_path} cp_nativelibs = @nativelibs.empty? ? [] : @nativelibs.collect {|n| n.local_path} resources = cp_jars + cp_nativelibs end # # FIXME: this should probably be more discriminatory # if [:remove_jruby] resources = resources.reject {|r| r =~ /\/jruby\//} end resources end |
#run_local(argument = @argument) ⇒ Object
This will start the jnlp as a local process.
This only works in MRI at this point.
691 692 693 694 695 696 697 698 |
# File 'lib/jnlp/jnlp.rb', line 691 def run_local(argument=@argument) if RUBY_PLATFORM =~ /java/ puts "not implemented in JRuby yet" else command = "java -classpath #{local_classpath} #{@main_class} '#{@argument}'" $pid = fork { exec command } end end |
#save(filename = "saved_jnlp_object") ⇒ Object
Saves a YAML version of the jnlp object.
You can later recreate the object like this:
j = YAML.load(File.read("saved_jnlp_object"))
383 384 385 |
# File 'lib/jnlp/jnlp.rb', line 383 def save(filename="saved_jnlp_object") File.open(filename, 'w') {|f| f.write YAML.dump(self)} end |
#stop_local ⇒ Object
This will stop the running local process, started by Jnlp#run_local.
This only works in MRI at this point.
705 706 707 708 709 710 711 712 |
# File 'lib/jnlp/jnlp.rb', line 705 def stop_local if RUBY_PLATFORM =~ /java/ puts "not implemented in JRuby yet" else Process.kill 15, $pid Process.wait($pid) end end |
#to_jnlp(options = {}) ⇒ Object
returns the jnlp as a string
606 607 608 609 610 611 612 613 614 |
# File 'lib/jnlp/jnlp.rb', line 606 def to_jnlp(={}) jnlp = @jnlp.to_s unless .empty? .each do |k,v| jnlp.gsub!(/(<jnlp.*?)(#{k.to_s}=)(['"])(.*?)\3(.*?)>/, "\\1\\2\\3#{v}\\3\\5>") end end jnlp end |
#to_local_jnlp ⇒ Object
returns the local file-based jnlp as a string
618 619 620 |
# File 'lib/jnlp/jnlp.rb', line 618 def to_local_jnlp @local_jnlp.to_s end |
#write_jnlp(options = {}) ⇒ Object
Writes a local copy of the original jnlp .
Writes jnlp to path of original jnlp into current working directory. A number of options can be passed modify the result.
Example:
server = 'http://localhost:4321'
jnlp_cache = 'jnlp'
new_href = "#{server}#{jnlp.path}"
jnlp.write_jnlp( { :dir => jnlp_cache, :jnlp => { :codebase => server, :href => new_href }, :snapshot => true } )
Writes a duplicate of the remote jnlp to a local path rooted at ‘jnlp/’. With the codebase and href re-written referencing: ‘localhost:4321’
In addition a duplicate of the versioned jnlp is written without the version string as a snapshot jnlp and the version string is written to this file:
jnlp-name-CURRENT_VERSION.txt
642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/jnlp/jnlp.rb', line 642 def write_jnlp(={}) dir = [:dir] || '.' path = [:path] || @path.gsub(/^\//, '') Dir.chdir(dir) do FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w') {|f| f.write to_jnlp([:jnlp]) } if [:snapshot] snapshot_path = "#{File.dirname(path)}/#{@family}.jnlp" File.open(snapshot_path, 'w') {|f| f.write to_jnlp([:jnlp]) } current_version_path = "#{File.dirname(path)}/#{@family}-CURRENT_VERSION.txt" File.open(current_version_path, 'w') {|f| f.write @version_str } end end end |
#write_local_classpath_shell_script(filename = "#{@name[/[A-Za-z0-9_-]*/]}_classpath.sh", options = {}) ⇒ Object
Writes a shell script to the local filesystem that will export a modified CLASSPATH environmental variable with the paths to the resources used by this jnlp.
Writes a jnlp to current working directory using name of original jnlp.
Pass in the optional hash: (:remove_jruby => true) and the first resource that contains the string /jruby/ will be removed from the classapath shell script.
Example:
write_local_classpath_shell_scrip(:remove_jruby => true)
599 600 601 602 |
# File 'lib/jnlp/jnlp.rb', line 599 def write_local_classpath_shell_script(filename="#{@name[/[A-Za-z0-9_-]*/]}_classpath.sh", ={}) script = "export CLASSPATH=$CLASSPATH#{local_classpath()}" File.open(filename, 'w'){|f| f.write script} end |
#write_local_jnlp(filename = @local_jnlp_name) ⇒ Object
Writes a local file-based jnlp.
Will write jnlp to current working directory using name of original jnlp with “local-” prefix.
662 663 664 665 666 667 668 669 670 |
# File 'lib/jnlp/jnlp.rb', line 662 def write_local_jnlp(filename=@local_jnlp_name) destination = File.(filename) unless @local_jnlp_href == destination @local_jnlp_href = destination @local_jnlp_name = File.basename(destination) self.generate_local_jnlp end File.open(filename, 'w') {|f| f.write to_local_jnlp } end |