Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adds some rack appliction using the new ClassPathLayout of jruby-rack
  • Loading branch information
mkristian committed Jan 14, 2015
1 parent a042abb commit ce87497
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 0 deletions.
1 change: 1 addition & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/.gitignore
@@ -0,0 +1 @@
pkg
4 changes: 4 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/.jrubydir
@@ -0,0 +1,4 @@
.
config.ru
gems
specifications
80 changes: 80 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/Mavenfile
@@ -0,0 +1,80 @@
#-*- mode: ruby -*-

# it is war-file
packaging 'war'

# get jruby dependencies
properties( 'jruby.version' => '@project.version@',
'jruby.plugins.version' => '1.0.7',
'project.build.sourceEncoding' => 'utf-8',
'public.dir' => '${basedir}/public' )

pom( 'org.jruby:jruby', '${jruby.version}' )

jar( 'org.jruby.rack:jruby-rack', '1.1.18',
:exclusions => [ 'org.jruby:jruby-complete' ] )


# ruby-maven will dump an equivalent pom.xml
properties[ 'tesla.dump.pom' ] = 'pom.xml'

# a gem to be used
gem 'flickraw', '0.9.7'

repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'rubygems-releases' )

jruby_plugin :gem, :includeRubygemsInResources => true, :includeLibDirectoryInResources => true do
execute_goal :initialize
end

# not really needed but for completeness:
# pack the war with that ruby-like directory layout
plugin( :war, '2.2',
:warSourceDirectory => '${public.dir}' )

resource :directory => '${basedir}', :includes => [ 'config.ru', '.jrubydir' ]

# start jetty for the tests
plugin( 'org.eclipse.jetty:jetty-maven-plugin', '9.1.3.v20140225',
:path => '/',
:webAppSourceDirectory => '${public.dir}',
:stopPort => 9999,
:stopKey => 'foo' ) do
execute_goal( 'start', :id => 'start jetty', :phase => 'pre-integration-test', :daemon => true )
execute_goal( 'stop', :id => 'stop jetty', :phase => 'post-integration-test' )
end

# download files during the tests
result = nil
execute 'download', :phase => 'integration-test' do
require 'open-uri'
result = open( 'http://localhost:8080' ).string
puts result
end

# verify the downloads
execute 'check download', :phase => :verify do
expected = 'hello world:'
unless result.match( /^#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'self: uri:classloader://config.ru'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'PWD: uri:classloader://'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'Gem.path: ."uri:classloader://",'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
# TODO get rid off this over normalization
expected = 'uri:classloader:/gems/flickraw-0.9.7'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
end
# vim: syntax=Ruby
19 changes: 19 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/config.ru
@@ -0,0 +1,19 @@
#-*- mode: ruby -*-

use Rack::ShowExceptions

require 'hello_world'

run lambda { |env|
require 'flickraw'
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
[ "self: #{__FILE__}\n", "PWD: #{Dir.pwd}\n", "Gem.path: #{Gem.path.inspect}\n", Gem.loaded_specs['flickraw'].gem_dir + "\n", HelloWorld.new + "\n" ]
]
}

# vim: syntax=Ruby
7 changes: 7 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/lib/hello_world.rb
@@ -0,0 +1,7 @@
require 'openssl'

class HelloWorld < String
def initialize
super "hello world: #{OpenSSL::Random.random_bytes( 16 ).inspect}"
end
end
151 changes: 151 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/pom.xml
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>no_group_id_given</groupId>
<artifactId>j2ee_jetty_rack</artifactId>
<version>0.0.0</version>
<packaging>war</packaging>
<name>j2ee_jetty_rack</name>
<properties>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.7</jruby.plugins.version>
<tesla.dump.pom>pom.xml</tesla.dump.pom>
<public.dir>${basedir}/public</public.dir>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<tesla.version>0.1.1</tesla.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>${jruby.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jruby.rack</groupId>
<artifactId>jruby-rack</artifactId>
<version>1.1.18</version>
<exclusions>
<exclusion>
<artifactId>jruby-complete</artifactId>
<groupId>org.jruby</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>flickraw</artifactId>
<version>0.9.7</version>
<type>gem</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>config.ru</include>
<include>.jrubydir</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<goals>
<goal>initialize</goal>
</goals>
</execution>
</executions>
<configuration>
<includeRubygemsInResources>true</includeRubygemsInResources>
<includeLibDirectoryInResources>true</includeLibDirectoryInResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceDirectory>${public.dir}</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.3.v20140225</version>
<executions>
<execution>
<id>start jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<path>/</path>
<webAppSourceDirectory>${public.dir}</webAppSourceDirectory>
<stopPort>9999</stopPort>
<stopKey>foo</stopKey>
</configuration>
</plugin>
<plugin>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-maven-plugin</artifactId>
<version>${tesla.version}</version>
<executions>
<execution>
<id>download</id>
<phase>integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>download</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
<execution>
<id>check download</id>
<phase>verify</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>check download</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-ruby</artifactId>
<version>${tesla.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/public/WEB-INF/.gitignore
@@ -0,0 +1,2 @@
classes
config.ru
22 changes: 22 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/public/WEB-INF/web.xml
@@ -0,0 +1,22 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>jruby.rack.layout_class</param-name>
<param-value>JRuby::Rack::ClassPathLayout</param-value>
</context-param>

<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.jruby.rack.RackServletContextListener</listener-class>
</listener>
</web-app>

1 comment on commit ce87497

@headius
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this commit broke 1.7's j2ee build on Travis: https://travis-ci.org/jruby/jruby/jobs/46985622#L853

Looks like some dependency is compiled to Java 7 bytecode.

Please sign in to comment.