fcsh 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jaap van der Meer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = fcsh
2
+
3
+ Wrapper for FCSH.
4
+
5
+ == Usage
6
+
7
+ @fcsh = Fcsh.new
8
+ target_id = @fcsh.mxmlc "main.mxml"
9
+ @fcsh.errors.each do |error|
10
+ if error.level == "warn"
11
+ puts "WARNING"
12
+ elsif error.level == "error"
13
+ puts "ERROR"
14
+ end
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+ == Note on Patches/Pull Requests
22
+
23
+ * Fork the project.
24
+ * Make your feature addition or bug fix.
25
+ * Add tests for it. This is important so I don't break it in a
26
+ future version unintentionally.
27
+ * Commit, do not mess with rakefile, version, or history.
28
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
29
+ * Send me a pull request. Bonus points for topic branches.
30
+
31
+ == Copyright
32
+
33
+ Copyright (c) 2010 Jaap van der Meer. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "fcsh"
8
+ gem.summary = %Q{Wrapper for flex fcsh command}
9
+ gem.description = %Q{}
10
+ gem.email = "jaapvandermeer@gmail.com"
11
+ gem.homepage = "http://github.com/japetheape/fcsh"
12
+ gem.authors = ["Jaap van der Meer"]
13
+ gem.add_development_dependency "rspec", ">= 2"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+
22
+
23
+
24
+ require "rspec/core/rake_task"
25
+ require "rspec/core/version"
26
+
27
+
28
+ RSpec::Core::RakeTask.new(:spec)
29
+
30
+ task :default => :spec
31
+
32
+ require 'rake/rdoctask'
33
+ Rake::RDocTask.new do |rdoc|
34
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
35
+
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = "fcsh #{version}"
38
+ rdoc.rdoc_files.include('README*')
39
+ rdoc.rdoc_files.include('lib/**/*.rb')
40
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/fcsh.rb ADDED
@@ -0,0 +1,154 @@
1
+ require 'open3'
2
+ require File.join(File.dirname(__FILE__), 'mxmlc_output/mxmlc_output_reader')
3
+
4
+ # Abstraction of flex fcsh command
5
+ class Fcsh
6
+ # Run the flex command.
7
+ # Make sure fcsh is in the path, else set Fcsh.BIN_FILE = '/path/to/fcsh'
8
+ def initialize
9
+ fcsh_command = defined?(self.location) ? location : 'fcsh'
10
+ @stdin, @stdout, @stderr = Open3.popen3(fcsh_command)
11
+ wait_for_on_stdout(/^\(fcsh\)/)
12
+ end
13
+
14
+ # run mxmlc with a command, returns the id of the assigned target
15
+ # e.g. fcsh.new.mxmlc(""
16
+ # can run an CompileError when compile errors are found
17
+ def mxmlc(command)
18
+ puts "mxmlc %s" % command if $DEBUG
19
+ @stdin.puts "mxmlc %s" % command
20
+ target_id = nil
21
+ @stdout.each_line do |line|
22
+ if line =~ /fcsh: Assigned (\d) as the compile target id/
23
+ target_id = $1
24
+ end
25
+ break
26
+ end
27
+
28
+ @errors_last_run = capture_error_output
29
+ return target_id
30
+ end
31
+
32
+
33
+ def compile(target_id)
34
+ puts "Compiling target: " + target_id if $DEBUG
35
+ @stdout.flush
36
+ @stderr.flush
37
+ @stdin.puts "compile %d" % target_id.to_i
38
+ @errors_last_run = capture_error_output
39
+ end
40
+
41
+
42
+ def clear(target_id)
43
+ puts "Clearing target id" if $DEBUG
44
+ @stdin.puts "clear %d" % target_id.to_i
45
+ end
46
+
47
+
48
+ def errors
49
+ return MxmlcOutputReader.new(@errors_last_run)
50
+ end
51
+
52
+
53
+ private
54
+
55
+ # Currently there is no way of knowing when error output has finished,
56
+ # so now we capture errors from start of receiving first line is 1 second
57
+ # ago or we started capturing error output is 4 seconds ago. Hope this
58
+ # will be enough.
59
+ def capture_error_output
60
+ puts "Capturing error output..."
61
+ out = ""
62
+ @stderr.flush
63
+ error_catching_thread = Thread.new {
64
+ @out = ""
65
+ thread = Thread.start do
66
+ @stderr.each_line do |line|
67
+ @out << line
68
+ end
69
+ end
70
+ }
71
+ @stderr.sync = false
72
+
73
+ line = ""
74
+ while c = @stdout.read(1)
75
+ line += c
76
+ if line =~ /\(fcsh\)/
77
+ puts "Done...."
78
+ return @out
79
+ end
80
+ next if c != "/n"
81
+
82
+ puts "(out) " + line.inspect if $DEBUG
83
+ if line =~ /Nothing has changed/
84
+ puts "Nothing has changed" if $DEBUG
85
+ return @out
86
+ end
87
+
88
+ if line =~ /Files changed:/
89
+ puts "Filed changed:" if $DEBUG
90
+ return @out
91
+ end
92
+
93
+ if line =~ /Error: (.*)/
94
+ raise CompileError.new(line)
95
+ end
96
+
97
+ if line =~ /.+\.swf/
98
+ puts "" if $DEBUG
99
+ return @out
100
+ end
101
+
102
+ line = ""
103
+ end
104
+ end
105
+
106
+
107
+
108
+
109
+
110
+
111
+ def watch_std_out_for_errors
112
+ # watch std out till files changed
113
+ @stdout.each_line do |line|
114
+ puts "FCSH OUT: " + line.inspect if $DEBUG
115
+
116
+ if /.+\.swf/.match(line)
117
+ puts ""
118
+ break
119
+ end
120
+
121
+ if /Nothing has changed/.match(line)
122
+ puts "Nothing has changed"
123
+ break
124
+ end
125
+
126
+ if /Files changed/.match(line)
127
+ capture_error_output
128
+ break
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+
135
+ # Wait on stdout for pattern
136
+ def wait_for_on_stdout(pattern)
137
+ out = ''
138
+ # read everything in out and stop when pattern is matched
139
+ {} while !((out << @stdout.read(1)) =~ pattern)
140
+ end
141
+
142
+
143
+ class << self
144
+ attr_accessor :location
145
+ end
146
+
147
+
148
+ class CompileError < RuntimeError
149
+ def initialize(message)
150
+ super(message)
151
+ end
152
+ end
153
+
154
+ end
@@ -0,0 +1,21 @@
1
+ class MxmlcError
2
+ attr_reader :filename, :line, :column, :level, :message, :content
3
+
4
+ LEVEL_WARN = :warn
5
+ LEVEL_ERROR = :error
6
+
7
+
8
+
9
+ def initialize(filename, line, column, level, message)
10
+ @filename = filename
11
+ @line = line
12
+ @column = column
13
+ @level = level
14
+ @message = message
15
+ @content = ''
16
+ end
17
+
18
+
19
+
20
+
21
+ end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), 'mxmlc_error')
2
+
3
+
4
+ # Formats the mxmlc to errors
5
+ class MxmlcOutputReader
6
+ attr_reader :errors
7
+ ERROR_LINE = /^((\/([\w\.]+))+)(\((-?\d+)\))?:\s*(col: (\d+))?:?\s*(Error|Warning+): (.+)$/
8
+
9
+ def initialize(output)
10
+ @output = output
11
+ @messages = []
12
+ parse!
13
+ end
14
+
15
+
16
+ def warnings
17
+ out = []
18
+ @messages.each do |e|
19
+ out << e if e.level == "Warning"
20
+ end
21
+ out
22
+ end
23
+
24
+ def errors
25
+ out = []
26
+ @messages.each do |e|
27
+ out << e if e.level == "Error"
28
+ end
29
+ out
30
+ end
31
+
32
+ # example: /Users/japetheape/Projects/tunedustry/editor/src/com/tunedustry/editor/view/Controls.as(43): col: 32 Warning: return value for function 'setPositions' has no type declaration.
33
+ def parse!
34
+ @output.each_line do |l|
35
+ matches = ERROR_LINE.match(l)
36
+ if !matches.nil?
37
+ @messages << MxmlcError.new(matches[1], matches[5], matches[7], matches[8], matches[9])
38
+ elsif !@messages.empty?
39
+ @messages.last.content << l
40
+ end
41
+ end
42
+ end
43
+
44
+ end
data/spec/fcsh_spec.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'fcsh'
3
+
4
+ describe Fcsh do
5
+ before(:each) do
6
+ @fcsh = Fcsh.new
7
+ end
8
+
9
+
10
+ it "uses the constant location if that's set" do
11
+ Fcsh.should_receive(:location=).with("test").once
12
+ Fcsh.location = 'test'
13
+ end
14
+
15
+
16
+ it "should compile a basic file" do
17
+ lambda {@fcsh.mxmlc("test.as") }.should raise_error
18
+ end
19
+
20
+ it "should compile and after that continue" do
21
+ target_id = @fcsh.mxmlc("fixtures/main.mxml")
22
+ target_id.should == 1
23
+ @fcsh.compile(target_id)
24
+ end
25
+
26
+
27
+
28
+
29
+
30
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ # optionally add autorun support
3
+ require 'rspec/autorun'
4
+
5
+ Rspec.configure do |c|
6
+ c.mock_with :rspec
7
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fcsh
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jaap van der Meer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ version: "2"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: ""
34
+ email: jaapvandermeer@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.rdoc
42
+ files:
43
+ - .document
44
+ - .gitignore
45
+ - LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - VERSION
49
+ - lib/fcsh.rb
50
+ - lib/mxmlc_output/mxmlc_error.rb
51
+ - lib/mxmlc_output/mxmlc_output_reader.rb
52
+ - spec/fcsh_spec.rb
53
+ - spec/spec_helper.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/japetheape/fcsh
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Wrapper for flex fcsh command
86
+ test_files:
87
+ - spec/fcsh_spec.rb
88
+ - spec/spec_helper.rb