Skip to content

Commit 27e2b57

Browse files
committed
add jruby support by protobuf-java reflection API
1 parent a5f7bb8 commit 27e2b57

28 files changed

+4641
-25
lines changed

ruby/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.bundle
2+
tags
3+
.idea/
4+
lib/google/protobuf_java.jar
5+
protobuf-jruby.iml
6+
target/

ruby/Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec

ruby/Gemfile.lock

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PATH
2+
remote: .
3+
specs:
4+
google-protobuf (3.0.0.alpha.2)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
power_assert (0.2.2)
10+
rake (10.4.2)
11+
rake-compiler (0.9.5)
12+
rake
13+
rubygems-tasks (0.2.4)
14+
test-unit (3.0.9)
15+
power_assert
16+
17+
PLATFORMS
18+
java
19+
ruby
20+
21+
DEPENDENCIES
22+
google-protobuf!
23+
rake-compiler
24+
rubygems-tasks
25+
test-unit

ruby/README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,28 @@ To build this Ruby extension, you will need:
6060
* Ruby development headers
6161
* a C compiler
6262

63-
First, install the required Ruby gems:
63+
To Build the JRuby extension, you will need:
6464

65-
$ sudo gem install bundler rake rake-compiler rspec rubygems-tasks
65+
* Maven
66+
* The latest version of the protobuf java library
67+
* Install JRuby via rbenv or RVM
68+
69+
First switch to the desired platform with rbenv or RVM.
70+
71+
Then install the required Ruby gems:
72+
73+
$ gem install bundler
74+
$ bundle
6675

6776
Then build the Gem:
6877

6978
$ rake gem
7079
$ gem install pkg/protobuf-$VERSION.gem
7180

81+
To run the specs:
82+
83+
$ rake test
84+
7285
This gem includes the upb parsing and serialization library as a single-file
7386
amalgamation. It is up-to-date with upb git commit
7487
`535bc2fe2f2b467f59347ffc9449e11e47791257`.

ruby/Rakefile

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
require "rake/extensiontask"
1+
require "rubygems"
2+
require "rubygems/package_task"
3+
require "rake/extensiontask" unless RUBY_PLATFORM == "java"
24
require "rake/testtask"
35

46
spec = Gem::Specification.load("google-protobuf.gemspec")
57

6-
Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
7-
ext.ext_dir = "ext/google/protobuf_c"
8-
ext.lib_dir = "lib/google"
9-
end
8+
if RUBY_PLATFORM == "java"
9+
task :clean do
10+
system("mvn clean")
11+
end
1012

11-
Rake::TestTask.new(:test => :build) do |t|
12-
t.test_files = FileList["tests/*.rb"]
13+
task :compile do
14+
system("mvn package")
15+
end
16+
else
17+
Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
18+
ext.ext_dir = "ext/google/protobuf_c"
19+
ext.lib_dir = "lib/google"
20+
end
1321
end
1422

1523
Gem::PackageTask.new(spec) do |pkg|
1624
end
1725

26+
Rake::TestTask.new(:test => :build) do |t|
27+
t.test_files = FileList["tests/*.rb"]
28+
end
29+
1830
task :build => [:clean, :compile]
1931
task :default => [:build]
2032

ruby/google-protobuf.gemspec

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
class << Gem::Specification
2-
def find_c_source(dir)
3-
`cd #{dir}; git ls-files "*.c" "*.h" extconf.rb Makefile`.split
4-
.map{|f| "#{dir}/#{f}"}
5-
end
6-
end
7-
81
Gem::Specification.new do |s|
92
s.name = "google-protobuf"
103
s.version = "3.0.0.alpha.3.0.pre"
@@ -14,11 +7,17 @@ Gem::Specification.new do |s|
147
s.authors = ["Protobuf Authors"]
158
s.email = "protobuf@googlegroups.com"
169
s.require_paths = ["lib"]
17-
s.extensions = ["ext/google/protobuf_c/extconf.rb"]
18-
s.files = ["lib/google/protobuf.rb"] +
19-
# extension C source
20-
find_c_source("ext/google/protobuf_c")
21-
s.test_files = ["tests/basic.rb",
22-
"tests/stress.rb",
23-
"tests/generated_code_test.rb"]
10+
s.files = ["lib/google/protobuf.rb"]
11+
unless RUBY_PLATFORM == "java"
12+
s.files += `git ls-files "*.c" "*.h" extconf.rb Makefile`.split
13+
s.extensions= ["ext/google/protobuf_c/extconf.rb"]
14+
else
15+
s.files += ["lib/google/protobuf_java.jar"]
16+
end
17+
s.test_files = ["tests/basic.rb",
18+
"tests/stress.rb",
19+
"tests/generated_code_test.rb"]
20+
s.add_development_dependency "rake-compiler"
21+
s.add_development_dependency "test-unit"
22+
s.add_development_dependency "rubygems-tasks"
2423
end

ruby/lib/google/protobuf.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31-
require 'google/protobuf_c'
31+
if RUBY_PLATFORM == "java"
32+
require 'json'
33+
require 'google/protobuf_java'
34+
else
35+
require 'google/protobuf_c'
36+
end

ruby/pom.xml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.google</groupId>
8+
<artifactId>google</artifactId>
9+
<version>1</version>
10+
</parent>
11+
12+
<groupId>com.google.protobuf.jruby</groupId>
13+
<artifactId>protobuf-jruby</artifactId>
14+
<version>1.0-SNAPSHOT</version>
15+
<name>Protocol Buffer JRuby native extension</name>
16+
<description>
17+
Protocol Buffers are a way of encoding structured data in an efficient yet
18+
extensible format.
19+
</description>
20+
<inceptionYear>2014</inceptionYear>
21+
<url>https://developers.google.com/protocol-buffers/</url>
22+
<licenses>
23+
<license>
24+
<name>New BSD license</name>
25+
<url>http://www.opensource.org/licenses/bsd-license.php</url>
26+
<distribution>repo</distribution>
27+
</license>
28+
</licenses>
29+
<scm>
30+
<url>https://github.com/google/protobuf</url>
31+
<connection>
32+
scm:git:https://github.com/google/protobuf.git
33+
</connection>
34+
</scm>
35+
36+
<properties>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
<ruby.sources>lib/google</ruby.sources>
39+
<jar.finalName>protobuf_java</jar.finalName>
40+
</properties>
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-assembly-plugin</artifactId>
46+
<configuration>
47+
<finalName>${jar.finalName}</finalName>
48+
<outputDirectory>${ruby.sources}</outputDirectory>
49+
<appendAssemblyId>false</appendAssemblyId>
50+
<descriptorRefs>
51+
<descriptorRef>jar-with-dependencies</descriptorRef>
52+
</descriptorRefs>
53+
</configuration>
54+
<executions>
55+
<execution>
56+
<id>make-assembly</id>
57+
<phase>package</phase>
58+
<goals>
59+
<goal>single</goal>
60+
</goals>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
<dependencies>
67+
<dependency>
68+
<groupId>com.fasterxml.jackson.core</groupId>
69+
<artifactId>jackson-core</artifactId>
70+
<version>2.4.3</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.jruby</groupId>
74+
<artifactId>jruby-complete</artifactId>
75+
<version>1.7.13</version>
76+
<scope>provided</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.google.protobuf</groupId>
80+
<artifactId>protobuf-java</artifactId>
81+
<version>3.0.0-pre</version>
82+
</dependency>
83+
</dependencies>
84+
</project>

0 commit comments

Comments
 (0)