lib/generators/templates/application/common/merb.thor in merb-gen-0.9.10 vs lib/generators/templates/application/common/merb.thor in merb-gen-0.9.11
- old
+ new
@@ -3,11 +3,11 @@
require 'thor'
require 'fileutils'
require 'yaml'
# Important - don't change this line or its position
-MERB_THOR_VERSION = '0.0.52'
+MERB_THOR_VERSION = '0.1.0'
##############################################################################
module ColorfulMessages
@@ -299,11 +299,11 @@
end
end
end
end
end
-
+
private
def executable_wrapper(spec, bin_file_name, minigems = true)
requirements = ['minigems', 'rubygems']
requirements.reverse! unless minigems
@@ -323,10 +323,11 @@
end
if File.directory?(gems_dir = File.join(Dir.pwd, 'gems')) ||
File.directory?(gems_dir = File.join(File.dirname(__FILE__), '..', 'gems'))
$BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
+ ENV["PATH"] = "\#{File.dirname(__FILE__)}:\#{gems_dir}/bin:\#{ENV["PATH"]}"
if (local_gem = Dir[File.join(gems_dir, "specifications", "#{spec.name}-*.gemspec")].last)
version = File.basename(local_gem)[/-([\\.\\d]+)\\.gemspec$/, 1]
end
end
@@ -474,12 +475,13 @@
end
end
end
def install_dependency(dependency, opts = {})
- opts[:version] ||= dependency.version_requirements.to_s
- Merb::Gem.install(dependency.name, default_install_options.merge(opts))
+ version = dependency.version_requirements.to_s
+ install_opts = default_install_options.merge(:version => version)
+ Merb::Gem.install(dependency.name, install_opts.merge(opts))
end
def install_dependency_from_source(dependency, opts = {})
matches = Dir[File.join(source_dir, "**", dependency.name, "{Rakefile,Thorfile}")]
matches.reject! { |m| File.basename(m) == 'Thorfile' }
@@ -758,12 +760,14 @@
# When comp == 'missing' then filter on missing dependencies
if only_missing = comp == 'missing'
message "Preparing to install missing gems #{where} using #{strategy} strategy..."
comp = nil
+ clobber = false
else
message "Preparing to install #{where} using #{strategy} strategy..."
+ clobber = true
end
# If comp given, filter on known stack components
deps = comp ? Merb::Stack.select_component_dependencies(dependencies, comp) : dependencies
self.system, self.local, self.missing = Merb::Gem.partition_dependencies(deps, gem_dir)
@@ -775,11 +779,11 @@
if deps.empty?
warning "No dependencies to install..."
else
puts "#{deps.length} dependencies to install..."
- install_dependencies(strategy, deps)
+ install_dependencies(strategy, deps, clobber)
end
# Show current dependency info now that we're done
puts # Seperate output
list('local', comp)
@@ -871,14 +875,25 @@
# merb:dependencies:configure --force # overwrite the default config file
# merb:dependencies:configure --version 0.9.8 # configure specific framework version
# merb:dependencies:configure --config-file file.yml # write to the specified config file
desc 'configure [comp]', 'Create a dependencies config file'
- method_options "--dry-run" => :boolean, "--force" => :boolean
+ method_options "--dry-run" => :boolean, "--force" => :boolean, "--versions" => :boolean
def configure(comp = nil)
# If comp given, filter on known stack components
deps = comp ? Merb::Stack.select_component_dependencies(dependencies, comp) : dependencies
+
+ # If --versions is set, update the version_requirements with the actual version available
+ if options[:versions]
+ specs = local_gemspecs
+ deps.each do |dep|
+ if spec = specs.find { |s| s.name == dep.name }
+ dep.version_requirements = ::Gem::Requirement.create(spec.version)
+ end
+ end
+ end
+
config = YAML.dump(deps.map { |d| d.to_s })
puts "#{config}\n"
if File.exists?(config_file) && !options[:force]
error "File already exists! Use --force to overwrite."
else
@@ -900,35 +915,37 @@
if self.respond_to?(method = :"#{strategy}_strategy", true)
method
end
end
- def install_dependencies(strategy, deps)
+ def install_dependencies(strategy, deps, clobber = true)
if method = strategy?(strategy)
# Clobber existing local dependencies
- clobber_dependencies!
+ clobber_dependencies! if clobber
# Run the chosen strategy - collect files installed from stable gems
installed_from_stable = send(method, deps).map { |d| d.name }
- # Sleep a bit otherwise the following steps won't see the new files
- sleep(deps.length) if deps.length > 0
-
- # Leave a file to denote the strategy that has been used for this dependency
- self.local.each do |spec|
- next unless File.directory?(spec.full_gem_path)
- unless installed_from_stable.include?(spec.name)
- FileUtils.touch(File.join(spec.full_gem_path, "#{strategy}.strategy"))
- else
- FileUtils.touch(File.join(spec.full_gem_path, "stable.strategy"))
- end
- end
+ unless dry_run?
+ # Sleep a bit otherwise the following steps won't see the new files
+ sleep(deps.length) if deps.length > 0 && deps.length <= 10
+
+ # Leave a file to denote the strategy that has been used for this dependency
+ self.local.each do |spec|
+ next unless File.directory?(spec.full_gem_path)
+ unless installed_from_stable.include?(spec.name)
+ FileUtils.touch(File.join(spec.full_gem_path, "#{strategy}.strategy"))
+ else
+ FileUtils.touch(File.join(spec.full_gem_path, "stable.strategy"))
+ end
+ end
- # Add local binaries for the installed framework dependencies
- comps = Merb::Stack.all_components & deps.map { |d| d.name }
- comps << { :no_minigems => 'merb-gen' }
- ensure_bin_wrapper_for(*comps)
+ # Add local binaries for the installed framework dependencies
+ comps = Merb::Stack.all_components & deps.map { |d| d.name }
+ comps << { :no_minigems => 'merb-gen' }
+ ensure_bin_wrapper_for(*comps)
+ end
return true
end
false
end
@@ -965,11 +982,11 @@
if framework_components.include?(dep.name)
dep.version_requirements = version_req
end
end
end
-
+
deps
end
def config_dependencies
if File.exists?(config_file)
@@ -1035,19 +1052,16 @@
installed_from_rubygems = []
# Selectively update repositories for the matching dependencies
update_dependency_repositories(deps) unless dry_run?
- # Skip gem dependencies to prevent them from being installed from stable;
- # however, core dependencies will be retrieved from source when available
- install_opts = { :ignore_dependencies => true }
if core = deps.find { |d| d.name == 'merb-core' }
if dry_run?
note "Installing #{core.name}..."
else
- if install_dependency_from_source(core, install_opts)
- elsif install_dependency(core, install_opts)
+ if install_dependency_from_source(core)
+ elsif install_dependency(core)
info "Installed #{core.name} from rubygems..."
installed_from_rubygems << core
end
end
end
@@ -1055,12 +1069,12 @@
deps.each do |dependency|
next if dependency.name == 'merb-core'
if dry_run?
note "Installing #{dependency.name}..."
else
- if install_dependency_from_source(dependency, install_opts)
- elsif install_dependency(dependency, install_opts)
+ if install_dependency_from_source(dependency)
+ elsif install_dependency(dependency)
info "Installed #{dependency.name} from rubygems..."
installed_from_rubygems << dependency
end
end
end
@@ -1077,28 +1091,35 @@
instance.options = options
instance.list(filter, comp)
end
# Extract application dependencies by querying the app directly.
- def self.extract_dependencies(merb_root, env = 'production')
+ def self.extract_dependencies(merb_root)
require 'merb-core'
if !@_merb_loaded || Merb.root != merb_root
Merb.start_environment(
+ :log_level => :fatal,
:testing => true,
:adapter => 'runner',
- :environment => env,
+ :environment => ENV['MERB_ENV'] || 'development',
:merb_root => merb_root
)
@_merb_loaded = true
end
Merb::BootLoader::Dependencies.dependencies
- rescue => e
+ rescue StandardError => e
error "Couldn't extract dependencies from application!"
error e.message
puts "Make sure you're executing the task from your app (--merb-root), or"
puts "specify a config option (--config or --config-file=YAML_FILE)"
return []
+ rescue SystemExit
+ error "Couldn't extract dependencies from application!"
+ error "application failed to run"
+ puts "Please check if your application runs using 'merb'; for example,"
+ puts "look for any gem version mismatches in dependencies.rb"
+ return []
end
# Parse the basic YAML config data, and process Gem::Dependency output.
# Formatting example: merb_helpers (>= 0.9.8, runtime)
def self.parse_dependencies_yaml(yaml)
@@ -1122,16 +1143,18 @@
# The Stack tasks will install dependencies based on known sets of gems,
# regardless of actual application dependency settings.
DM_STACK = %w[
extlib
+ data_objects
dm-core
dm-aggregates
dm-migrations
dm-timestamps
dm-types
dm-validations
+ merb_datamapper
]
MERB_STACK = %w[
extlib
merb-core
@@ -1140,10 +1163,15 @@
merb-cache
merb-helpers
merb-mailer
merb-slices
merb-auth
+ merb-auth-core
+ merb-auth-more
+ merb-auth-slice-password
+ merb-param-protection
+ merb-exceptions
] + DM_STACK
MERB_BASICS = %w[
extlib
merb-core
@@ -1216,10 +1244,19 @@
dm-couchdb-adapter
dm-ferret-adapter
dm-rest-adapter
]
+ DATA_OBJECTS = %w[
+ data_objects
+ do_derby do_hsqldb
+ do_jdbc
+ do_mysql
+ do_postgres
+ do_sqlite3
+ ]
+
attr_accessor :system, :local, :missing
include MerbThorHelper
global_method_options = {
@@ -1386,10 +1423,11 @@
# git repository based component sets
comps["merb"] = ["merb-core"] + MERB_MORE
comps["merb-more"] = MERB_MORE.sort
comps["merb-plugins"] = MERB_PLUGINS.sort
comps["dm-more"] = DM_MORE.sort
+ comps["do"] = DATA_OBJECTS.sort
comps
end
end
@@ -1411,11 +1449,11 @@
comps
end
end
def self.framework_components
- %w[merb-core merb-more merb-plugins].inject([]) do |all, comp|
+ %w[merb-core merb-more].inject([]) do |all, comp|
all + components(comp)
end
end
def self.components(comp = nil)
@@ -1433,11 +1471,11 @@
comps = components(comp) || []
dependencies.select { |dep| comps.include?(dep.name) }
end
def self.base_components
- %w[thor rake]
+ %w[thor rake extlib]
end
def self.all_components
base_components + framework_components
end
@@ -1445,10 +1483,11 @@
# Find the latest merb-core and gather its dependencies.
# We check for 0.9.8 as a minimum release version.
def self.core_dependencies(gem_dir = nil, ignore_deps = false)
@_core_dependencies ||= begin
if gem_dir # add local gems to index
+ orig_gem_path = ::Gem.path
::Gem.clear_paths; ::Gem.path.unshift(gem_dir)
end
deps = []
merb_core = ::Gem::Dependency.new('merb-core', '>= 0.9.8')
if gemspec = ::Gem.source_index.search(merb_core).last
@@ -1459,11 +1498,11 @@
end
else
deps += gemspec.dependencies
end
end
- ::Gem.clear_paths if gem_dir # reset
+ ::Gem.path.replace(orig_gem_path) if gem_dir # reset
deps
end
end
def self.lookup_repository_name(item)
@@ -1816,9 +1855,11 @@
note "Installing #{current_gem} from source..."
else
message "Installing #{current_gem} from source..."
if install_dependency_from_source(dependency)
ensure_bin_wrapper_for(dependency.name) if options[:binaries]
+ else
+ raise "gem source not found"
end
end
end
rescue => e
error "Failed to install #{current_gem ? current_gem : 'gem'} (#{e.message})"
\ No newline at end of file