From e4a82c56b42a6e5ca2d83add37ba6f34caff7f3f Mon Sep 17 00:00:00 2001 From: Greg Jastrab Date: Fri, 5 Dec 2008 13:46:20 -0500 Subject: [PATCH] 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 --- Manifest.txt | 6 ++ Rakefile | 1 + bin/puremvc-gen | 57 ++++++------ conf/build.xml | 10 ++- lib/pure_m_v_c_gen/ant_checker.rb | 34 ++++++++ lib/pure_m_v_c_gen/commands/check_command.rb | 16 ++++ .../commands/command_extensions.rb | 14 +++ .../commands/initialize_command.rb | 16 ++++ lib/pure_m_v_c_gen/commands/new_command.rb | 86 +++++++++++++++++++ puremvc-gen.gemspec | 7 +- 10 files changed, 213 insertions(+), 34 deletions(-) create mode 100644 lib/pure_m_v_c_gen/ant_checker.rb create mode 100644 lib/pure_m_v_c_gen/commands/check_command.rb create mode 100644 lib/pure_m_v_c_gen/commands/command_extensions.rb create mode 100644 lib/pure_m_v_c_gen/commands/initialize_command.rb create mode 100644 lib/pure_m_v_c_gen/commands/new_command.rb diff --git a/Manifest.txt b/Manifest.txt index 96fb52e..9728226 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -17,5 +17,11 @@ 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 diff --git a/Rakefile b/Rakefile index 386d6df..ee2bb52 100644 --- a/Rakefile +++ b/Rakefile @@ -25,6 +25,7 @@ Hoe.new(PKG_NAME, PKG_VERSION) do |p| p.summary = p.description # More details later?? p.remote_rdoc_dir = PKG_NAME # Release to /PKG_NAME # p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n") + p.extra_deps << ["cmdparse", ">= 2.0.2"] p.need_zip = true p.need_tar = false end diff --git a/bin/puremvc-gen b/bin/puremvc-gen index e2b613e..fe83d84 100644 --- a/bin/puremvc-gen +++ b/bin/puremvc-gen @@ -2,45 +2,44 @@ require 'rubygems' 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='') - system "ant -f #{BUILDFILE} -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 - + system "ant -f #{BUILDFILE} -Dpmvcgen.dir=#{PMVC_GEN_HOME} -Dbasedir=#{Dir.pwd} #{args}" end cmd = CmdParse::CommandParser.new(true, true) -cmd.program_name = "puremvc-gen" -cmd.version = [0, 0, 1] +cmd.program_name = "puremvc-gen " +cmd.program_version = [0, 0, 1] cmd.add_command(CmdParse::HelpCommand.new) cmd.add_command(CmdParse::VersionCommand.new) cmd.add_command(CheckCommand.new) cmd.add_command(InitializeCommand.new) +cmd.add_command(NewCommand.new) cmd.parse diff --git a/conf/build.xml b/conf/build.xml index 5feff05..160186d 100644 --- a/conf/build.xml +++ b/conf/build.xml @@ -233,7 +233,7 @@ - ${log.gen.macro.command} - ${log.gen.simple.command} + + + - + diff --git a/lib/pure_m_v_c_gen/ant_checker.rb b/lib/pure_m_v_c_gen/ant_checker.rb new file mode 100644 index 0000000..9861001 --- /dev/null +++ b/lib/pure_m_v_c_gen/ant_checker.rb @@ -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 \ No newline at end of file diff --git a/lib/pure_m_v_c_gen/commands/check_command.rb b/lib/pure_m_v_c_gen/commands/check_command.rb new file mode 100644 index 0000000..ebe27f8 --- /dev/null +++ b/lib/pure_m_v_c_gen/commands/check_command.rb @@ -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 \ No newline at end of file diff --git a/lib/pure_m_v_c_gen/commands/command_extensions.rb b/lib/pure_m_v_c_gen/commands/command_extensions.rb new file mode 100644 index 0000000..998ef7b --- /dev/null +++ b/lib/pure_m_v_c_gen/commands/command_extensions.rb @@ -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 \ No newline at end of file diff --git a/lib/pure_m_v_c_gen/commands/initialize_command.rb b/lib/pure_m_v_c_gen/commands/initialize_command.rb new file mode 100644 index 0000000..8767ced --- /dev/null +++ b/lib/pure_m_v_c_gen/commands/initialize_command.rb @@ -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 \ No newline at end of file diff --git a/lib/pure_m_v_c_gen/commands/new_command.rb b/lib/pure_m_v_c_gen/commands/new_command.rb new file mode 100644 index 0000000..b0ea661 --- /dev/null +++ b/lib/pure_m_v_c_gen/commands/new_command.rb @@ -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 \ No newline at end of file diff --git a/puremvc-gen.gemspec b/puremvc-gen.gemspec index 174c411..45fb460 100644 --- a/puremvc-gen.gemspec +++ b/puremvc-gen.gemspec @@ -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.authors = ["Greg Jastrab"] - s.date = %q{2008-12-02} + s.date = %q{2008-12-05} s.default_executable = %q{puremvc-gen} s.description = %q{An ANT-based PureMVC generator.} s.email = %q{gjastrab.dev@gmail.com} s.executables = ["puremvc-gen"] 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.homepage = %q{FIX (url)} s.rdoc_options = ["--main", "README.txt"] @@ -27,11 +27,14 @@ Gem::Specification.new do |s| s.specification_version = 2 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 2.0.2"]) s.add_development_dependency(%q, [">= 1.8.2"]) else + s.add_dependency(%q, [">= 2.0.2"]) s.add_dependency(%q, [">= 1.8.2"]) end else + s.add_dependency(%q, [">= 2.0.2"]) s.add_dependency(%q, [">= 1.8.2"]) end end