Skip to content

Commit

Permalink
Merge branch 'jruby-1_7'
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
	lib/pom.rb
	lib/pom.xml
	maven/jruby-complete/src/templates/osgi_many_bundles_with_embedded_gems/test/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
	maven/jruby-dist/pom.rb
	maven/jruby-dist/pom.xml
	maven/jruby-dist/src/main/assembly/jruby.xml
	maven/jruby/src/templates/osgi_all_inclusive/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
mkristian committed Jun 29, 2015
2 parents 53ff459 + 643006f commit ae7b2bf
Showing 10 changed files with 169 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -60,74 +60,12 @@ public void setEnvironment(Map environment) {
|| !environment.containsKey("GEM_HOME")|| !environment.containsKey("JARS_HOME")) {
Map<String,String> env = environment == null ? new HashMap<String,String>() : new HashMap<String,String>(environment);
if (!env.containsKey("GEM_PATH")) env.put("GEM_PATH", "uri:classloader://");
if (!env.containsKey("GEM_HOME")) env.put("GEM_HOME", "uri:classloader:/" + JRUBY_HOME +
"/lib/ruby/gems/shared");
if (!env.containsKey("GEM_HOME")) env.put("GEM_HOME", "uri:classloader://");
if (!env.containsKey("JARS_HOME")) env.put("JARS_HOME", "uri:classloader://jars");
super.setEnvironment(env);
}
else {
super.setEnvironment(environment);
}
}

private org.osgi.framework.Bundle toBundle(String symbolicName) {
org.osgi.framework.BundleContext context = org.osgi.framework.FrameworkUtil.getBundle(getClass()).getBundleContext();
org.osgi.framework.Bundle bundle = null;
for (org.osgi.framework.Bundle b : context.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
bundle = b;
break;
}
}
if (bundle == null ) {
throw new RuntimeException("unknown bundle: " + symbolicName);
}
return bundle;
}

private String createUri(org.osgi.framework.Bundle cl, String ref) {
URL url = cl.getResource( ref );
if ( url == null && ref.startsWith( "/" ) ) {
url = cl.getResource( ref.substring( 1 ) );
}
if ( url == null ) {
throw new RuntimeException( "reference " + ref + " not found on classloader " + cl );
}
return "uri:" + url.toString().replaceFirst( ref + "$", "" );
}
/**
* add the classloader from the given bundle to the LOAD_PATH
* @param bundle
*/
public void addBundleToLoadPath(org.osgi.framework.Bundle bundle) {
addLoadPath(createUri(bundle, "/.jrubydir"));
}

/**
* add the classloader from the given bundle to the LOAD_PATH
* using the bundle symbolic name
*
* @param symbolicName
*/
public void addBundleToLoadPath(String symbolicName) {
addBundleToLoadPath(toBundle(symbolicName));
}

/**
* add the classloader from the given bundle to the GEM_PATH
* @param bundle
*/
public void addBundleToGemPath(org.osgi.framework.Bundle bundle) {
addGemPath(createUri(bundle, "/specifications/.jrubydir"));
}

/**
* add the classloader from the given bundle to the GEM_PATH
* using the bundle symbolic name
*
* @param symbolicName
*/
public void addBundleToGemPath(String symbolicName) {
addBundleToGemPath(toBundle(symbolicName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package org.jruby.embed.osgi;

import java.net.URL;

import org.jruby.embed.IsolatedScriptingContainer;
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.LocalVariableBehavior;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;

/**
* adds some helper methods to add Bundle to the LOAD_PATH or GEM_PATH using the
* IsolatedScriptingContainer as base.
*
* <code>new URL( uri ).openStream()</code>, i.e. <code>new URL(classloader.getResource().toString()).openStream()</code> has to work for
* those classloaders. felix, knoplerfish and equinox OSGi framework do work.
*/
public class OSGiIsolatedScriptingContainer extends IsolatedScriptingContainer {

public OSGiIsolatedScriptingContainer()
{
this(LocalContextScope.SINGLETON);
}

public OSGiIsolatedScriptingContainer( LocalContextScope scope,
LocalVariableBehavior behavior )
{
this(scope, behavior, true);
}

public OSGiIsolatedScriptingContainer( LocalContextScope scope )
{
this(scope, LocalVariableBehavior.TRANSIENT);
}

public OSGiIsolatedScriptingContainer( LocalVariableBehavior behavior )
{
this(LocalContextScope.SINGLETON, behavior);
}

public OSGiIsolatedScriptingContainer( LocalContextScope scope,
LocalVariableBehavior behavior,
boolean lazy )
{
super(scope, behavior, lazy);
}

private Bundle toBundle(String symbolicName) {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Bundle bundle = null;
for (Bundle b : context.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
bundle = b;
break;
}
}
if (bundle == null ) {
throw new RuntimeException("unknown bundle: " + symbolicName);
}
return bundle;
}

private String createUri(Bundle cl, String ref) {
URL url = cl.getResource( ref );
if ( url == null && ref.startsWith( "/" ) ) {
url = cl.getResource( ref.substring( 1 ) );
}
if ( url == null ) {
throw new RuntimeException( "reference " + ref + " not found on classloader " + cl );
}
return "uri:" + url.toString().replaceFirst( ref + "$", "" );
}
/**
* add the classloader from the given bundle to the LOAD_PATH
* @param bundle
*/
public void addBundleToLoadPath(Bundle bundle) {
addLoadPath(createUri(bundle, "/.jrubydir"));
}

/**
* add the classloader from the given bundle to the LOAD_PATH
* using the bundle symbolic name
*
* @param symbolicName
*/
public void addBundleToLoadPath(String symbolicName) {
addBundleToLoadPath(toBundle(symbolicName));
}

/**
* add the classloader from the given bundle to the GEM_PATH
* @param bundle
*/
public void addBundleToGemPath(Bundle bundle) {
addGemPath(createUri(bundle, "/specifications/.jrubydir"));
}

/**
* add the classloader from the given bundle to the GEM_PATH
* using the bundle symbolic name
*
* @param symbolicName
*/
public void addBundleToGemPath(String symbolicName) {
addBundleToGemPath(toBundle(symbolicName));
}
}
2 changes: 1 addition & 1 deletion lib/pom.rb
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ def to_pathname
end
end

gem 'ruby-maven', '3.3.2', :scope => :provided
gem 'ruby-maven', '3.3.3', :scope => :provided

default_gemnames = default_gems.collect { |g| g.name }

2 changes: 1 addition & 1 deletion lib/pom.xml
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>rubygems</groupId>
<artifactId>ruby-maven</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
<type>gem</type>
<scope>provided</scope>
</dependency>
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.IsolatedScriptingContainer;
import org.jruby.embed.osgi.OSGiIsolatedScriptingContainer;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
@@ -80,7 +80,7 @@ public void testJRubyCreate() throws Exception {
//System.setProperty( "jruby.debug.loadService", "true" );
//System.setProperty( "jruby.native.enabled", "true" );

IsolatedScriptingContainer jruby = new IsolatedScriptingContainer();
OSGiIsolatedScriptingContainer jruby = new OSGiIsolatedScriptingContainer();
jruby.addBundleToLoadPath( "org.jruby.osgi.scripts-bundle" );
jruby.addBundleToGemPath( FrameworkUtil.getBundle( Gems.class ) );

26 changes: 20 additions & 6 deletions maven/jruby-dist/pom.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'rubygems/package'
require 'fileutils'
project 'JRuby Dist' do

version = File.read( File.join( basedir, '..', '..', 'VERSION' ) ).strip
@@ -7,13 +9,12 @@
inherit "org.jruby:jruby-artifacts:#{version}"
packaging 'pom'

properties( 'tesla.dump.pom' => 'pom.xml',
'tesla.dump.readonly' => true,
'jruby.plugins.version' => '1.0.9', # Not sure why but wo this pom.xml get 1.0.8
'main.basedir' => '${project.parent.parent.basedir}' )
properties( 'main.basedir' => '${project.parent.parent.basedir}',
'ruby.maven.version' => '3.3.3',
'ruby.maven.libs.version' => '3.3.3' )

# pre-installed gems - not yet default gems !
gem 'ruby-maven', '3.3.2', :scope => 'provided'
# pre-installed gems - not default gems !
gem 'ruby-maven', '${ruby.maven.version}', :scope => 'provided'

# HACK: add torquebox repo only when building from filesystem
# not when using the pom as "dependency" in some other projects
@@ -78,6 +79,19 @@
File.chmod( 0644, f ) rescue nil if File.file?( f )
end
end

execute :dump_full_specs_of_ruby_maven do |ctx|
rubygems = File.join( ctx.project.build.directory.to_pathname, 'rubygems-provided' )
gems = File.join( rubygems, 'cache/*gem' )
default_specs = File.join( rubygems, 'specifications/default' )
FileUtils.mkdir_p( default_specs )
Dir[gems].each do |gem|
spec = Gem::Package.new( gem ).spec
File.open( File.join( default_specs, File.basename( gem ) + 'spec' ), 'w' ) do |f|
f.print( spec.to_ruby )
end
end
end
end

phase :package do
7 changes: 0 additions & 7 deletions maven/jruby-dist/src/main/assembly/bin.xml
Original file line number Diff line number Diff line change
@@ -21,13 +21,6 @@
<include>**/*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided</directory>
<outputDirectory>/lib/ruby/gems/shared</outputDirectory>
<includes>
<include>**/*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.parent.parent.basedir}</directory>
<outputDirectory>/</outputDirectory>
7 changes: 0 additions & 7 deletions maven/jruby-dist/src/main/assembly/bin200.xml
Original file line number Diff line number Diff line change
@@ -20,13 +20,6 @@
<include>**/*.pack.gz</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided</directory>
<outputDirectory>/lib/ruby/gems/shared</outputDirectory>
<includes>
<include>**/*.pack.gz</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.parent.parent.basedir}</directory>
<outputDirectory>/</outputDirectory>
41 changes: 31 additions & 10 deletions maven/jruby-dist/src/main/assembly/common.xml
Original file line number Diff line number Diff line change
@@ -10,18 +10,39 @@
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided</directory>
<outputDirectory>/lib/ruby/gems/shared</outputDirectory>
<directory>${project.build.directory}/rubygems-provided/gems/ruby-maven-${ruby.maven.version}/lib</directory>
<outputDirectory>/lib/ruby/stdlib</outputDirectory>
<includes>
<include>cache/*</include>
<include>specifications/*</include>
<include>gems/**/*</include>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided/gems/ruby-maven-${ruby.maven.version}</directory>
<outputDirectory>/lib/ruby/</outputDirectory>
<includes>
<include>.mvn/**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided/gems/ruby-maven-libs-${ruby.maven.libs.version}/lib</directory>
<outputDirectory>/lib/ruby/stdlib</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided/gems/ruby-maven-libs-${ruby.maven.libs.version}</directory>
<outputDirectory>/lib/ruby/</outputDirectory>
<includes>
<include>maven-home/**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/rubygems-provided/specifications/default</directory>
<outputDirectory>/lib/ruby/gems/shared/specifications/default</outputDirectory>
<includes>
<include>*.gemspec</include>
</includes>
<excludes>
<exclude>**/.jrubydir</exclude>
<exclude>**/*.pack.gz</exclude>
<exclude>**/*.jar</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.parent.parent.basedir}</directory>
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.IsolatedScriptingContainer;
import org.jruby.embed.osgi.OSGiIsolatedScriptingContainer;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
@@ -66,8 +66,8 @@ public void testJRubyCreate() throws InterruptedException {
System.err.println();
System.err.println();

// System.setProperty( "jruby.debug.loadService", "true" );
IsolatedScriptingContainer jruby = new IsolatedScriptingContainer();
// System.setProperty( "jruby.debug.loadService", "true" );
OSGiIsolatedScriptingContainer jruby = new OSGiIsolatedScriptingContainer();

// run a script from LOAD_PATH
String hello = (String) jruby.runScriptlet( "require 'hello'; Hello.say" );

0 comments on commit ae7b2bf

Please sign in to comment.