Skip to content

Commit

Permalink
use java to load service
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Mar 2, 2016
1 parent e6f7255 commit 613bbc6
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.jar
MANIFEST.MF
target
*~
53 changes: 53 additions & 0 deletions extensions/basic/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require_relative 'lib/basic/version'

def create_manifest
title = 'Implementation-Title: rpextras (example JRuby Extension)'
version = format('Implementation-Version: %s', BasicExample::VERSION)
file = File.open('MANIFEST.MF', 'w') do |f|
f.puts(title)
f.puts(version)
end
end

task default: [:init, :compile, :test]

desc 'Create Manifest'
task :init do
create_manifest
end

desc 'Build gem'
task :gem do
sh 'gem build jruby_art.gemspec'
end

desc 'Compile'
task :compile do
sh 'mvn package'
sh 'mv target/rpextras.jar lib'
end

desc 'Test'
task :test do
sh 'jruby test/deglut_spec_test.rb'
sh 'jruby test/vecmath_spec_test.rb'
sh 'jruby test/math_tool_test.rb'
sh 'jruby test/helper_methods_test.rb'
sh 'jruby test/aabb_spec_test.rb'
home = File.expand_path('~')
config = File.exist?(format('%s/.jruby_art/config.yml', home))
if config
ruby 'test/k9_run_test.rb'
else
warn format('You should create %s/.jruby_art/config.yml to run sketch tests', home)
end
end

desc 'clean'
task :clean do
Dir['./**/*.%w{jar gem}'].each do |path|
puts 'Deleting #{path} ...'
File.delete(path)
end
FileUtils.rm_rf('./target')
end
32 changes: 32 additions & 0 deletions extensions/basic/jruby-ext/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative '../lib/basic/version'

def create_manifest
title = 'Implementation-Title: jruby-ext (example JRuby Extension)'
version = format('Implementation-Version: %s', BasicExample::VERSION)
file = File.open('MANIFEST.MF', 'w') do |f|
f.puts(title)
f.puts(version)
end
end

task default: [:init, :compile]

desc 'Create Manifest'
task :init do
create_manifest
end

desc 'Compile'
task :compile do
sh 'mvn package'
sh 'mv target/jruby-ext.jar ../lib'
end

desc 'clean'
task :clean do
Dir['./**/*.%w{jar}'].each do |path|
puts 'Deleting #{path} ...'
File.delete(path)
end
FileUtils.rm_rf('./target')
end
20 changes: 10 additions & 10 deletions extensions/basic/jruby-ext/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'source.directory' => 'src/main/java', # poxy Eclipse folders
'project.build.sourceEncoding' => 'utf-8',
'polyglot.dump.pom' => 'pom.xml',
'jruby.api' => 'http://jruby.org/apidocs/'
'jruby.api' => 'http://jruby.org/apidocs/',
)

jar 'org.jruby:jruby:9.0.5.0'
Expand All @@ -36,25 +36,25 @@
plugin :dependency, '2.8'
plugin(
:compiler, '3.3',
'source' => '${maven.compiler.source}',
'target' => '${maven.compiler.target}'
source: '${maven.compiler.source}',
target: '${maven.compiler.target}'
)
plugin(
:javadoc, '2.10.3',
'detectOfflineLinks' => 'false',
'links' => ['${jruby.api}']
detect_offline_links: 'false',
links: ['${jruby.api}']
)
plugin(
:jar, '2.6'
# 'archive' => {
# 'manifestFile' => 'MANIFEST.MF'
# }
:jar, '2.6',
archive: {
manifestFile: 'MANIFEST.MF' # camel case reqd
}
)
end

build do
default_goal 'package'
source_directory '${source.directory}'
final_name 'basic'
final_name 'jruby-ext'
end
end
9 changes: 7 additions & 2 deletions extensions/basic/jruby-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DO NOT MODIFIY - GENERATED CODE
<build>
<sourceDirectory>${source.directory}</sourceDirectory>
<defaultGoal>package</defaultGoal>
<finalName>basic</finalName>
<finalName>jruby-ext</finalName>
<pluginManagement>
<plugins>
<plugin>
Expand All @@ -74,7 +74,7 @@ DO NOT MODIFIY - GENERATED CODE
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
<detectOfflineLinks>false</detectOfflineLinks>
<detect_offline_links>false</detect_offline_links>
<links>
<link>${jruby.api}</link>
</links>
Expand All @@ -83,6 +83,11 @@ DO NOT MODIFIY - GENERATED CODE
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestFile>MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down
9 changes: 4 additions & 5 deletions extensions/basic/lib/basic.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "java"
$CLASSPATH << File.join(File.dirname(__FILE__), "..", "jruby-ext", "target", "classes")

require "com/purbon/basic"
require 'java'
require_relative 'jruby-ext.jar'
com.purbon.BasicService.new.basicLoad(JRuby.runtime)


return if $0 != __FILE__
Expand Down Expand Up @@ -40,4 +39,4 @@ class MyRubyClass
##
# Using the same method but as static method defined in the module.
##
puts Foo.build_string
puts Foo.build_string
6 changes: 6 additions & 0 deletions extensions/basic/lib/basic/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# encoding: utf-8
# frozen_string_literal: true
# A wrapper for version
module BasicExample
VERSION = '1.0.0'
end
43 changes: 43 additions & 0 deletions extensions/basic/test/basic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "java"
$CLASSPATH << File.join(File.dirname(__FILE__), "..", "jruby-ext", "target", "classes")

require "com/purbon/basic"


return if $0 != __FILE__

##
# If executed directly this class runs a few methods comming out of the extensions
# defined in this project.
##

##
# Using a class created in the jruby side, this class has for example a method with aliases, etc.
##
bar = Bar.new

##
# Calling a method form the class that has two names, throw aliases. This method return a simple
# string from the java side.
##
puts bar.say
puts bar.shout

puts bar.add(4, 4)

##
# Using a module defined in the extensione.
# Foo is a module defined in jruby extension point.
##
class MyRubyClass
include Foo
end

##
# Using a method defined in the module, but form the created class.
##
puts MyRubyClass.new.build_string
##
# Using the same method but as static method defined in the module.
##
puts Foo.build_string

0 comments on commit 613bbc6

Please sign in to comment.