flex-source-inspector 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  bin-debug
19
+ *sublime*
data/README.md CHANGED
@@ -5,4 +5,12 @@ given a source folder and an array of link reports, it will return a list of fil
5
5
  ### Usage
6
6
  flex-source-inpsector inspect /path/to/flex-src linkreport_one.xml [...linkreport_n.xml]
7
7
 
8
-
8
+
9
+ ### Building
10
+ read: https://github.com/radar/guides/blob/master/gem-development.md
11
+
12
+ ### Run Tests
13
+ rspec spec/flex-source-inspector_spec.rb
14
+
15
+ ### Install Gem Locally
16
+ rake install
@@ -3,10 +3,6 @@ Feature: FlexSourceInspector
3
3
  As a CLI
4
4
  I want to be as objective as possible
5
5
 
6
- Scenario: i can ping
7
- When I run "flex-source-inspector ping"
8
- Then the output should contain "pong"
9
-
10
6
  Scenario: link report one
11
7
  When I run "flex-source-inspector inspect ../../spec/data/LinkReportTestProject/flex-src ../../spec/data/ApplicationOne_link-report.xml"
12
8
  Then the output should contain "NotUsedOne.as"
@@ -10,6 +10,7 @@ module FlexSourceInspector
10
10
  desc "inspect path_to_flex_src, path_to_link_reports [, ... path_to_link_report]", "pass in the path to the flex src, and 1..* paths to link-report xml files"
11
11
  def inspect( src_folder, *link_reports)
12
12
  puts FlexSourceInspector::Inspector.inspect( src_folder, *link_reports )
13
+ puts "----"
13
14
  end
14
15
  end
15
16
  end
@@ -1,7 +1,7 @@
1
1
  module Flex
2
2
  module Source
3
3
  module Inspector
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -3,13 +3,10 @@ require "rexml/document"
3
3
 
4
4
  module FlexSourceInspector
5
5
  class Inspector
6
- def self.ping()
7
- "pong"
8
- end
9
6
 
10
7
  def self.inspect( src_folder, *link_reports)
11
8
 
12
- puts "-- inspect --"
9
+ puts ">-- inspect --"
13
10
  puts "pwd: #{Dir.pwd}"
14
11
 
15
12
  raise "FlexSourceInspector::Error source folder doesn't exist #{src_folder}" unless File.exists? src_folder
@@ -21,6 +18,7 @@ module FlexSourceInspector
21
18
 
22
19
  puts ""
23
20
  puts "src folder: #{src_folder}"
21
+ puts ""
24
22
 
25
23
  link_reports.each{|report|
26
24
  puts "reading: #{report}"
@@ -28,13 +26,14 @@ module FlexSourceInspector
28
26
 
29
27
  file = File.open( report )
30
28
  doc = REXML::Document.new file
31
-
29
+
32
30
  doc.elements.each("//script"){ |script|
33
31
  name = script.attributes["name"]
34
32
  add_to_used( used, project_files, name, src_folder )
35
33
  }
36
34
  }
37
-
35
+ puts ""
36
+ puts ""
38
37
  unused = project_files - used
39
38
  unused.join "\n"
40
39
  end
@@ -42,8 +41,44 @@ module FlexSourceInspector
42
41
  def self.add_to_used(used, project_files, class_declaration, src_folder)
43
42
  project_files.each{ |file|
44
43
  cleaned = file.gsub( src_folder, "")
45
- used << file if class_declaration.include? cleaned
44
+ used << file if is_declared?(cleaned, class_declaration)
46
45
  }
47
46
  end
47
+
48
+ ###
49
+ # A declaration can either be:
50
+ # "/Path/to/file/com/MyClass.as"
51
+ # or
52
+ # "/Path/to/My.swc(com.MyClass)"
53
+ # We check to see if either declaration matches the given file.
54
+ ###
55
+ def self.is_declared?( file_name, declaration )
56
+
57
+ # Check for a direct file declaration
58
+ if declaration.include? file_name
59
+ return true
60
+ end
61
+
62
+ # Check for a swc declaration
63
+ class_name = convert_to_class_name file_name
64
+
65
+ if declaration.include? class_name
66
+ return true
67
+ end
68
+ false
69
+ end
70
+
71
+ def self.convert_to_class_name( file_name )
72
+ out = file_name
73
+ out.gsub!("/", ".")
74
+ out.gsub!(".as", "")
75
+ out.gsub!(".mxml", "")
76
+ if out[0] == "."
77
+ out = out[1..out.length]
78
+ end
79
+ out.gsub!(/(.*)\.(.*)/, '\1:\2' )
80
+ out
81
+ end
82
+
48
83
  end
49
84
  end