2013-06-18 19:01:51 +00:00
require 'java'
java_import 'java.lang.System'
2012-06-05 19:08:01 +00:00
module RedStorm
2013-07-25 03:07:03 +00:00
CWD = Dir . pwd
2012-06-26 20:06:29 +00:00
2013-07-25 03:07:03 +00:00
launch_path = File . expand_path ( File . dirname ( __FILE__ ) )
2015-09-11 22:18:25 +00:00
jar_context = ! ! ( launch_path =~ / stormjar \ .jar! \/ red_storm$ / )
2012-06-05 19:08:01 +00:00
2013-07-25 03:07:03 +00:00
if jar_context
2015-09-11 22:18:25 +00:00
BASE_PATH = 'uri:classloader:/'
2012-06-26 20:06:29 +00:00
REDSTORM_HOME = BASE_PATH
2013-07-25 03:07:03 +00:00
GEM_PATH = " #{ REDSTORM_HOME } /gems/ "
2015-09-11 17:53:21 +00:00
# Make sure that when we're loading our environment up that we properly set
# up the embedded JRuby environment:
# <https://github.com/jruby-gradle/redstorm/issues/12>
Dir . chdir ( 'uri:classloader:/' )
ENV [ 'JARS_HOME' ] = 'uri:classloader:/jars'
$LOAD_PATH . unshift ( 'uri:classloader://' )
2012-06-05 19:08:01 +00:00
else
2013-07-25 03:07:03 +00:00
BASE_PATH = CWD
REDSTORM_HOME = File . expand_path ( launch_path + '/../..' )
GEM_PATH = " #{ BASE_PATH } /target/gems/ "
2012-06-05 19:08:01 +00:00
end
2013-06-18 19:01:51 +00:00
2012-06-28 22:03:50 +00:00
unless defined? ( SPECS_CONTEXT )
ENV [ " GEM_PATH " ] = GEM_PATH
ENV [ " GEM_HOME " ] = GEM_PATH
end
2012-06-05 19:08:01 +00:00
2013-07-25 03:07:03 +00:00
TARGET_DIR = " #{ CWD } /target "
TARGET_LIB_DIR = " #{ TARGET_DIR } /lib "
TARGET_SRC_DIR = " #{ TARGET_DIR } /src "
TARGET_GEM_DIR = " #{ TARGET_DIR } /gems/gems "
TARGET_SPECS_DIR = " #{ TARGET_DIR } /gems/specifications "
TARGET_CLASSES_DIR = " #{ TARGET_DIR } /classes "
TARGET_DEPENDENCY_DIR = " #{ TARGET_DIR } /dependency "
TARGET_DEPENDENCY_UNPACKED_DIR = " #{ TARGET_DIR } /dependency-unpacked "
TARGET_CLUSTER_JAR = " #{ TARGET_DIR } /cluster-topology.jar "
REDSTORM_JAVA_SRC_DIR = " #{ REDSTORM_HOME } /src/main "
REDSTORM_LIB_DIR = " #{ REDSTORM_HOME } /lib "
SRC_EXAMPLES = " #{ REDSTORM_HOME } /examples "
DST_EXAMPLES = " #{ CWD } /examples "
2014-07-01 17:21:11 +00:00
DEFAULT_STORM_CONF_FILE = File . expand_path ( " ~/.storm/storm.yaml " ) rescue ''
2013-07-25 03:07:03 +00:00
2012-06-26 21:53:33 +00:00
def current_ruby_mode
2013-07-25 03:07:03 +00:00
version = RUBY_VERSION [ / ( \ d+ \ . \ d+)( \ . \ d+)* / , 1 ]
raise ( " unknown Ruby version #{ $1 } " ) unless [ " 1.8 " , " 1.9 " ] . include? ( version )
version
2012-06-26 21:53:33 +00:00
end
2012-06-28 17:19:03 +00:00
def jruby_mode_token ( ruby_version = nil )
version_map = { " 1.8 " = > " RUBY1_8 " , " --1.8 " = > " RUBY1_8 " , " 1.9 " = > " RUBY1_9 " , " --1.9 " = > " RUBY1_9 " }
version_map [ ruby_version . to_s ] || version_map [ RedStorm . current_ruby_mode ]
end
2013-06-18 19:01:51 +00:00
def java_runtime_version
2013-07-25 03:07:03 +00:00
System . properties [ " java.runtime.version " ] . to_s [ / ^( \ d+ \ . \ d+).[^ \ s]+$ / , 1 ] || raise ( " unknown java runtime version #{ System . properties [ " java.runtime.version " ] . to_s } " )
2013-06-18 19:01:51 +00:00
end
2012-06-26 21:53:33 +00:00
2013-06-18 19:01:51 +00:00
module_function :current_ruby_mode , :jruby_mode_token , :java_runtime_version
2012-06-05 19:08:01 +00:00
end
2015-09-11 22:18:25 +00:00
# Requiring this at the tail-end to make sure whatever modifications we needed to make to our environment works properly
require 'jars/setup'