Release quality functionality in place.

Command line parsing in place and complete for initial version.
Will look next into reading command name and constant as arguments instead of options.

Script determines whether ant is found on the path, and complains if it is not.

TODO: Fix log messages to be read in appropriately
This commit is contained in:
Greg Jastrab 2008-12-05 13:46:20 -05:00
parent 33bab6c024
commit e4a82c56b4
10 changed files with 213 additions and 34 deletions

View File

@ -17,5 +17,11 @@ conf/templates/standard/Mediator.tpl
conf/templates/standard/Proxy.tpl conf/templates/standard/Proxy.tpl
conf/templates/standard/SimpleCommand.tpl conf/templates/standard/SimpleCommand.tpl
lib/pure_m_v_c_gen.rb lib/pure_m_v_c_gen.rb
lib/pure_m_v_c_gen/ant_checker.rb
lib/pure_m_v_c_gen/commands/check_command.rb
lib/pure_m_v_c_gen/commands/command_extensions.rb
lib/pure_m_v_c_gen/commands/initialize_command.rb
lib/pure_m_v_c_gen/commands/new_command.rb
lib/pure_m_v_c_gen/version.rb lib/pure_m_v_c_gen/version.rb
puremvc-gen.gemspec
test/test_pure_m_v_c_gen.rb test/test_pure_m_v_c_gen.rb

View File

@ -25,6 +25,7 @@ Hoe.new(PKG_NAME, PKG_VERSION) do |p|
p.summary = p.description # More details later?? p.summary = p.description # More details later??
p.remote_rdoc_dir = PKG_NAME # Release to /PKG_NAME p.remote_rdoc_dir = PKG_NAME # Release to /PKG_NAME
# p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n") # p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
p.extra_deps << ["cmdparse", ">= 2.0.2"]
p.need_zip = true p.need_zip = true
p.need_tar = false p.need_tar = false
end end

View File

@ -2,45 +2,44 @@
require 'rubygems' require 'rubygems'
require 'cmdparse' require 'cmdparse'
BUILDFILE = File.join(File.dirname(__FILE__), '..', 'conf', 'build.xml') PMVC_GEN_LIB = File.join(File.dirname(__FILE__), '..', 'lib', 'pure_m_v_c_gen')
require File.join(PMVC_GEN_LIB, 'ant_checker')
unless PureMVCGen::AntChecker.has_ant_installed?
err = <<-EOL
You must have ANT installed to run puremvc-gen.
Install it! ==> http://ant.apache.org
If you have it installed, ensure it is on your path.
EOL
puts err
exit 1
end
CMD_PATH = File.join(PMVC_GEN_LIB, 'commands')
require File.join(CMD_PATH, 'command_extensions')
require File.join(CMD_PATH, 'check_command')
require File.join(CMD_PATH, 'initialize_command')
require File.join(CMD_PATH, 'new_command')
include PureMVCGen::Commands
PMVC_GEN_HOME = File.join(File.dirname(__FILE__), '..', 'conf')
BUILDFILE = File.join(PMVC_GEN_HOME, 'build.xml')
def call_ant(args='') def call_ant(args='')
system "ant -f #{BUILDFILE} -Dbasedir=#{Dir.pwd} #{args}" system "ant -f #{BUILDFILE} -Dpmvcgen.dir=#{PMVC_GEN_HOME} -Dbasedir=#{Dir.pwd} #{args}"
end
class CheckCommand < CmdParse::Command
def initialize
super('check', false)
self.short_desc = "Validates that all required property settings are current detected"
end
def execute(args)
call_ant "validate-properties"
end
end
class InitializeCommand < CmdParse::Command
def initialize
super('init', false)
self.short_desc = "Initializes the current working directory with a new PureMVC project"
end
def execute(args)
call_ant "new-pmvc"
end
end end
cmd = CmdParse::CommandParser.new(true, true) cmd = CmdParse::CommandParser.new(true, true)
cmd.program_name = "puremvc-gen" cmd.program_name = "puremvc-gen "
cmd.version = [0, 0, 1] cmd.program_version = [0, 0, 1]
cmd.add_command(CmdParse::HelpCommand.new) cmd.add_command(CmdParse::HelpCommand.new)
cmd.add_command(CmdParse::VersionCommand.new) cmd.add_command(CmdParse::VersionCommand.new)
cmd.add_command(CheckCommand.new) cmd.add_command(CheckCommand.new)
cmd.add_command(InitializeCommand.new) cmd.add_command(InitializeCommand.new)
cmd.add_command(NewCommand.new)
cmd.parse cmd.parse

View File

@ -233,7 +233,7 @@
</copy> </copy>
</target> </target>
<target name="create-macro-command" depends="init,prompt-command-name,set-filters" <target name="create-macro-command" depends="init,prompt-command-name,prompt-command-const,set-filters"
description="Creates a MacroCommand"> description="Creates a MacroCommand">
<echo>${log.gen.macro.command}</echo> <echo>${log.gen.macro.command}</echo>
<copy file="${macro.template}" <copy file="${macro.template}"
@ -252,7 +252,7 @@
</replace> </replace>
</target> </target>
<target name="create-simple-command" depends="init,prompt-command-name,set-filters" <target name="create-simple-command" depends="init,prompt-command-name,prompt-command-const,set-filters"
description="Creates a SimpleCommand"> description="Creates a SimpleCommand">
<echo>${log.gen.simple.command}</echo> <echo>${log.gen.simple.command}</echo>
<copy file="${simple.template}" <copy file="${simple.template}"
@ -341,6 +341,10 @@
<length string="${cmd.name}" length="0" /> <length string="${cmd.name}" length="0" />
</condition> </condition>
<fail message="${log.fail.command.name}" if="do.abort" /> <fail message="${log.fail.command.name}" if="do.abort" />
</target>
<target name="prompt-command-const" unless="cmd.const"
description="Prompts the user to enter a command constant, unless cmd.const is already set.">
<input message="${log.prompt.command.constant}" addproperty="cmd.const" /> <input message="${log.prompt.command.constant}" addproperty="cmd.const" />
<condition property="do.abort"> <condition property="do.abort">
<length string="${cmd.const}" length="0" /> <length string="${cmd.const}" length="0" />

View File

@ -0,0 +1,34 @@
module PureMVCGen
class AntChecker
# Determines if ANT is installed on the system
def self.has_ant_installed?
AntChecker.find_in_path("ant")
end
# Searches the path, looking for the given utility. If an executable
# file is found that matches the parameter, this returns true.
def self.find_in_path(utility)
path = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
suffixes = self.on_windows? ? self.windows_executable_extensions : [""]
path.each do |dir|
suffixes.each do |sfx|
file = File.join(dir, utility + sfx)
return true if File.executable?(file)
end
end
false
end
def self.on_windows?
RUBY_PLATFORM =~ /mswin|mingw/
end
def self.windows_executable_extensions
%w(.exe .bat .com .cmd)
end
end
end

View File

@ -0,0 +1,16 @@
module PureMVCGen
module Commands
class CheckCommand < CmdParse::Command
def initialize
super('check', false)
self.short_desc = "Validates that all required property settings are current detected"
end
def execute(args)
call_ant "validate-properties"
end
end
end
end

View File

@ -0,0 +1,14 @@
module CmdParse
class Command
# injects our common options
def default_options(&block)
CmdParse::OptionParserWrapper.new do |opt|
opt.on("-h", "--help") do
self.show_help
exit
end
yield(opt)
end
end
end
end

View File

@ -0,0 +1,16 @@
module PureMVCGen
module Commands
class InitializeCommand < CmdParse::Command
def initialize
super('init', false)
self.short_desc = "Initializes the current working directory with a new PureMVC project"
end
def execute(args)
call_ant "new-pmvc"
end
end
end
end

View File

@ -0,0 +1,86 @@
module PureMVCGen
module Commands
class NewCommand < CmdParse::Command
def initialize
super('new', true)
self.short_desc = "Command to generate PureMVC classes"
# add sub commands
self.add_command(CreateCommand.new)
self.add_command(CreateMediator.new)
self.add_command(CreateProxy.new)
end
class CreateCommand < CmdParse::Command
def initialize
super('command', false)
@type = :simple
self.short_desc = "Creates a simple or macro command (defaults to simple)."
self.description = <<-EOL
Generates a simple or macro command.
Generating a simple command is the default behavior, unless the macro switch is passed:
-m or --macro
If no other switches are passed, the ANT script will prompt for a command name and constant,
however these may be passed on the command line with the -n (or --name) and -c (or --const) switches.
EOL
self.options = default_options do |opt|
opt.on("-m", "--macro", "Specifies the command is a MacroCommand") { @type = :macro }
opt.on("-n", "--name COMMAND_NAME", "Specifies the name for the command") { |name| @command_name = name }
opt.on("-c", "--const COMMAND_CONSTANT", "Specifies the constant to use for the command") { |const| @command_const = const }
end
end
def execute(args)
cmd = ""
cmd << "-Dcmd.name=#{@command_name} " unless @command_name.nil?
cmd << "-Dcmd.const=#{@command_const} " unless @command_const.nil?
cmd << "#{@type == :simple ? "create-simple-command" : "create-macro-command"}"
call_ant cmd
end
end
class CreateMediator < CmdParse::Command
def initialize
super('mediator', false)
self.short_desc = "Creates a new mediator."
self.options = default_options do |opt|
opt.on("-n", "--name MEDIATOR_NAME", "Specifies the name for the mediator") { |name| @mediator_name = name }
end
end
def execute(args)
cmd = ""
cmd << "-Dmediator.name=#{@mediator_name} " unless @mediator_name.nil?
cmd << "create-mediator"
call_ant cmd
end
end
class CreateProxy < CmdParse::Command
def initialize
super('proxy', false)
self.short_desc = "Creates a new proxy."
self.options = default_options do |opt|
opt.on("-n", "--name PROXY_NAME", "Specifies the name for the proxy") { |name| @proxy_name = name }
end
end
def execute(args)
cmd = ""
cmd << "-Dproxy.name=#{@proxy_name} " unless @proxy_name.nil?
cmd << "create-proxy"
call_ant cmd
end
end
end
end
end

View File

@ -6,13 +6,13 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Greg Jastrab"] s.authors = ["Greg Jastrab"]
s.date = %q{2008-12-02} s.date = %q{2008-12-05}
s.default_executable = %q{puremvc-gen} s.default_executable = %q{puremvc-gen}
s.description = %q{An ANT-based PureMVC generator.} s.description = %q{An ANT-based PureMVC generator.}
s.email = %q{gjastrab.dev@gmail.com} s.email = %q{gjastrab.dev@gmail.com}
s.executables = ["puremvc-gen"] s.executables = ["puremvc-gen"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"] s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/puremvc-gen", "conf/build.xml", "conf/config/pmvcgen.log.properties", "conf/config/pmvcgen.properties", "conf/example/author.properties", "conf/example/proj.properties", "conf/templates/.DS_Store", "conf/templates/Event.tpl", "conf/templates/standard/Application.tpl", "conf/templates/standard/Facade.tpl", "conf/templates/standard/MacroCommand.tpl", "conf/templates/standard/Mediator.tpl", "conf/templates/standard/Proxy.tpl", "conf/templates/standard/SimpleCommand.tpl", "lib/pure_m_v_c_gen.rb", "lib/pure_m_v_c_gen/version.rb", "test/test_pure_m_v_c_gen.rb"] s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/puremvc-gen", "conf/build.xml", "conf/config/pmvcgen.log.properties", "conf/config/pmvcgen.properties", "conf/example/author.properties", "conf/example/proj.properties", "conf/templates/.DS_Store", "conf/templates/Event.tpl", "conf/templates/standard/Application.tpl", "conf/templates/standard/Facade.tpl", "conf/templates/standard/MacroCommand.tpl", "conf/templates/standard/Mediator.tpl", "conf/templates/standard/Proxy.tpl", "conf/templates/standard/SimpleCommand.tpl", "lib/pure_m_v_c_gen.rb", "lib/pure_m_v_c_gen/ant_checker.rb", "lib/pure_m_v_c_gen/commands/check_command.rb", "lib/pure_m_v_c_gen/commands/command_extensions.rb", "lib/pure_m_v_c_gen/commands/initialize_command.rb", "lib/pure_m_v_c_gen/commands/new_command.rb", "lib/pure_m_v_c_gen/version.rb", "puremvc-gen.gemspec", "test/test_pure_m_v_c_gen.rb"]
s.has_rdoc = true s.has_rdoc = true
s.homepage = %q{FIX (url)} s.homepage = %q{FIX (url)}
s.rdoc_options = ["--main", "README.txt"] s.rdoc_options = ["--main", "README.txt"]
@ -27,11 +27,14 @@ Gem::Specification.new do |s|
s.specification_version = 2 s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<cmdparse>, [">= 2.0.2"])
s.add_development_dependency(%q<hoe>, [">= 1.8.2"]) s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
else else
s.add_dependency(%q<cmdparse>, [">= 2.0.2"])
s.add_dependency(%q<hoe>, [">= 1.8.2"]) s.add_dependency(%q<hoe>, [">= 1.8.2"])
end end
else else
s.add_dependency(%q<cmdparse>, [">= 2.0.2"])
s.add_dependency(%q<hoe>, [">= 1.8.2"]) s.add_dependency(%q<hoe>, [">= 1.8.2"])
end end
end end