Skip to content

Commit

Permalink
Ease development
Browse files Browse the repository at this point in the history
  • Loading branch information
laurilehmijoki committed Jun 12, 2014
1 parent e33f895 commit ec176ce
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
60 changes: 34 additions & 26 deletions bin/s3_website
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,47 @@ class Cli < Thor
def push
project_root = File.expand_path(File.dirname(__FILE__)+ '/..')
logger = Logger.new(options[:verbose])
# Find the jar
jar_file = resolve_jar project_root, logger
# Then run it
run_s3_website_jar(jar_file, logger)
success =
if run_with_sbt(project_root)
Dir.chdir(project_root) {
system './sbt assembly' # Build the jar
}
system "java -cp #{project_root}/target/scala-2.11/s3_website.jar #{resolve_java_command 'push'}"
else
# Find the jar
jar_file = resolve_jar(project_root, logger)
# Then run it
run_s3_website_jar(jar_file, logger)
end

if success
exit 0
else
exit 1
end
end

desc 'cfg SUBCOMMAND ...ARGS', 'Operate on the config file'
subcommand 'cfg', Cfg
end

def run_with_sbt(project_root)
File.exists? (project_root + '/project/sbt-launch.jar')
end

def resolve_java_command(command_name)
args = ARGV.join(' ').sub(command_name, '')
"s3.website.#{command_name.capitalize} #{args}"
end

def run_s3_website_jar(jar_file, logger)
java_installed = resolve_exit_status('which java') or resolve_exit_status('java -version')
unless java_installed
logger.info_msg "Cannot find Java. s3_website push is implemented in Scala, and it needs Java to run."
autoinstall_java_or_print_help_and_exit(logger)
end
args = ARGV.join(' ').sub('push', '')
logger.debug_msg "Using #{jar_file}"
if system("java -cp #{jar_file} s3.website.Push #{args}")
exit 0
else
exit 1
end
system("java -cp #{jar_file} #{resolve_java_command 'push'}")
end

def resolve_exit_status(cmd)
Expand Down Expand Up @@ -146,13 +164,11 @@ def autoinstall_java_or_print_help_and_exit(logger)
end

def resolve_jar(project_root, logger)
development_jar_path =
project_root + '/target/scala-2.11/s3_website.jar'
released_jar_lookup_paths = [
jar_lookup_paths = [
project_root + "/s3_website-#{S3Website::VERSION}.jar",
(ENV['TMPDIR'] || '/tmp') + "/s3_website-#{S3Website::VERSION}.jar"
]
found_jar = ([development_jar_path] + released_jar_lookup_paths).
found_jar = jar_lookup_paths.
select { |jar_path|
File.exists? jar_path
}.
Expand All @@ -171,25 +187,17 @@ def resolve_jar(project_root, logger)
if found_jar and jar_has_valid_checksum(found_jar, logger)
found_jar
else
is_development = File.exists?(project_root + '/.git')
if is_development
Dir.chdir(project_root) {
system "./sbt assembly"
}
development_jar_path
else
download_jar(released_jar_lookup_paths, logger)
end
download_jar(jar_lookup_paths, logger)
end
end

def download_jar(released_jar_lookup_paths, logger)
def download_jar(jar_lookup_paths, logger)
tag_name = "v#{S3Website::VERSION}"
downloaded_jar = released_jar_lookup_paths.select { |jar_path|
downloaded_jar = jar_lookup_paths.select { |jar_path|
File.writable? File.dirname(jar_path)
}.first
unless downloaded_jar
logger.fail_msg "Neither #{released_jar_lookup_paths.join ' or '} is writable. Cannot download s3_website.jar."
logger.fail_msg "Neither #{jar_lookup_paths.join ' or '} is writable. Cannot download s3_website.jar."
logger.fail_msg "Set either directory as writable to the current user and try again."
exit 1
end
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This project uses [Semantic Versioning](http://semver.org).

## 2.1.9

* Separate development and production code more clearly in the s3_website
executable

## 2.1.8

* Remove unused code in the s3_website executable
Expand Down
2 changes: 1 addition & 1 deletion lib/s3_website/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module S3Website
VERSION = '2.1.8'
VERSION = '2.1.9'
end

0 comments on commit ec176ce

Please sign in to comment.