iron-spect 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
19
+ *.iml
20
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iron-spect-spect.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+
2
+ Copyright 2013 Nicholas Terry
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Iron::Spect
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'iron-spect'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install iron-spect
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'bundler/setup'
3
+ require 'bundler'
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ Bundler.setup(:default, :test)
8
+
9
+ desc 'Run the default which is to run the tests'
10
+ task :default => :test
11
+
12
+ desc 'Run the specs'
13
+ RSpec::Core::RakeTask.new(:test) do |t|
14
+ t.pattern = %w(specs/**/*spec.rb)
15
+ end
16
+
17
+ desc 'Update the gem version by one value'
18
+ task :update_version, :new_version do |t, args|
19
+ abort('No version specified') if not args[:new_version]
20
+
21
+ VERSION = /VERSION\s=\s'(?<major>\d*)\.(?<minor>\d*)\.(?<build>\d*)'/
22
+ puts "Updating application to build #{args[:new_version]}"
23
+
24
+ version_file = File.dirname(__FILE__) + '/lib/iron-spect/version.rb'
25
+ version_contents = File.read(version_file)
26
+
27
+ match = VERSION.match(version_contents)
28
+ return if not match
29
+
30
+ new_version = "#{match[:major]}.#{match[:minor]}.#{args[:new_version]}"
31
+ puts "Updating the version to #{new_version}"
32
+
33
+ replace = "VERSION = '#{new_version}'"
34
+ new_contents = version_contents.gsub(VERSION, replace)
35
+
36
+ File.open(version_file, 'w') do |data|
37
+ data << new_contents
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iron-spect/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'iron-spect'
8
+ gem.version = IronSpect::VERSION
9
+ gem.authors = ['Nicholas Terry']
10
+ gem.email = %w(Nicholas Terry)
11
+ gem.description = %q{C# project file parser and inspector}
12
+ gem.summary = %q{C# project file parser and inspector}
13
+ gem.homepage = ''
14
+ gem.license = 'Apache2'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = %w(lib)
20
+
21
+ gem.add_dependency 'xml-simple'
22
+
23
+ gem.add_development_dependency 'bundler', '~> 1.3'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rspec'
26
+ gem.add_development_dependency 'ruby-debug19'
27
+ gem.add_development_dependency 'rspec-mocks'
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'xmlsimple'
2
+
3
+ module IronSpect
4
+ module Parsers
5
+ class ProjectFileParser
6
+
7
+ def initialize(csproj_file_path)
8
+ raise "#{csproj_file_path} doesn't exist." if not File.exist?(csproj_file_path)
9
+ @csproj_file_path = csproj_file_path
10
+ end
11
+
12
+ def parse
13
+ XmlSimple.xml_in(@csproj_file_path)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,66 @@
1
+ module IronSpect
2
+ module Parsers
3
+ class SolutionFileParser
4
+ attr_reader :solution_file
5
+
6
+ def initialize(solution_file_path)
7
+ @solution = {}
8
+ if File.directory?(solution_file_path)
9
+ sln_file = Dir["#{solution_file_path}/*.sln"]
10
+ raise "Solution file not present in directory #{solution_file_path}" if sln_file.nil?
11
+ puts "Multiple solution files found in directory #{solution_file_path}. Accepting the first." if sln_file.count > 1
12
+ @solution_file = File.open(sln_file[0], 'r+')
13
+ elsif File.file?(solution_file_path)
14
+ @solution_file = solution_file_path
15
+ else
16
+ raise "Didn't understand being called with #{solution_file_path}"
17
+ end
18
+ end
19
+
20
+ def parse
21
+ @solution[:projects] = []
22
+ @solution[:global] = []
23
+ run_parse(@solution_file.read)
24
+ @solution
25
+ end
26
+
27
+
28
+ private
29
+
30
+ def run_parse(sln_contents)
31
+ version_info = sln_contents.scan(/^(.*)Solution\sFile,\sFormat\sVersion\s(\d+\.\d+)/)
32
+ @solution[:version_info] = { :sln_type => version_info[0][0].strip, :sln_version => version_info[0][1].strip }
33
+ projects = sln_contents.scan(/(^Project.*)/)
34
+ projects.each do |project|
35
+ @solution[:projects] << parse_project(project[0])
36
+ end
37
+ global_sections = sln_contents.scan(/(GlobalSection.*?EndGlobalSection)/m)
38
+ global_sections.each do |global_section|
39
+ @solution[:global] << parse_global_section(global_section)
40
+ end
41
+ end
42
+
43
+ def parse_project(project)
44
+ first_split = project.split('=').each { |x| x.strip }
45
+ guid = first_split[0].scan(/.*(\"\{.*\}\").*/)[0][0]
46
+ pre_value = first_split[1].split(',').each { |x| x.strip }
47
+ value = {:name => pre_value[0].strip, :path => pre_value[1].strip, :guid => pre_value[2].strip }
48
+ { :guid => guid.strip, :assembly_info => value }
49
+ end
50
+
51
+ def parse_global_section(global_section)
52
+ global_hash = {}
53
+ global_hash[:properties] = []
54
+ tmp = global_section.first.scan(/^GlobalSection\((.*?)\)\s=\s(preSolution|postSolution)(.*)(EndGlobalSection)/m)
55
+ global_hash[:property_tag] = tmp[0][0]
56
+ global_hash[:property_step] = tmp[0][1]
57
+ tmp[0][2].gsub("\t", '').strip.split("\n").each do |property|
58
+ kv_prop = property.split('=')
59
+ global_hash[:properties] << { :key => kv_prop[0].strip, :value => kv_prop[1].strip }
60
+ end
61
+ global_hash
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,3 @@
1
+ module IronSpect
2
+ VERSION = '0.0.1'
3
+ end
data/lib/iron-spect.rb ADDED
@@ -0,0 +1,68 @@
1
+ require_relative 'iron-spect/version'
2
+ require_relative '../lib/iron-spect/parsers/solution_file_parser'
3
+ require_relative '../lib/iron-spect/parsers/project_file_parser'
4
+
5
+ module IronSpect
6
+ class Inspecter
7
+
8
+ def initialize(repo_dir=Dir.getwd)
9
+ @sln_file_manager = Parsers::SolutionFileParser.new(repo_dir)
10
+ @sln_file = @sln_file_manager.parse
11
+ @repo_dir = repo_dir
12
+ @startup_csproj_file = get_global_property('MonoDevelopProperties', 'StartupItem')
13
+ end
14
+
15
+ def get_executable_path(type)
16
+ raise "You must provide either 'Release' or 'Debug'" if not(type =~ /^(Debug|Release)$/)
17
+
18
+
19
+ @csproj_file_manager = Parsers::ProjectFileParser.new("#{@repo_dir}/#{@startup_csproj_file}")
20
+ startup_csproj = @csproj_file_manager.parse
21
+
22
+ startup_csproj['PropertyGroup'].each do |property|
23
+ if property.include?('Condition')
24
+ if property['Condition'] === "'$(Configuration)|$(Platform)' == '#{type}|AnyCPU'"
25
+ @out_path = property['OutputPath'][0].gsub(/\\/, '/').strip
26
+ end
27
+ end
28
+
29
+ if property.include?('AssemblyName')
30
+ @assembly_name = property['AssemblyName'][0].strip
31
+ end
32
+
33
+ if property.include?('OutputType')
34
+ @out_type = property['OutputType'][0].strip.downcase
35
+ end
36
+
37
+ next
38
+ end
39
+ raise "Didn't find any Release executable paths" if (@out_path.nil? || @assembly_name.nil? || @out_type.nil?)
40
+ "#{@repo_dir}/#{strip_csproj}/#{@out_path}#{@assembly_name}.#{@out_type}"
41
+ end
42
+
43
+ def get_global_property(property_tag, property)
44
+ @sln_file[:global].each do |prop|
45
+ prop_set = prop[:properties] if (prop[:property_tag] === property_tag)
46
+ next if prop_set.nil?
47
+ prop_set.each do |p|
48
+ return p[:value].gsub(/\\/, '/') if p[:key] === property
49
+ end
50
+ raise "Property '#{property}' not found for property tag '#{property_tag}'"
51
+ end
52
+ end
53
+
54
+ def get_project_property(project_name, property)
55
+ @sln_file[:projects].each do |project|
56
+ if project[:assembly_info][:name] =~ /("?)#{project_name}("?)/
57
+ return project[:assembly_info][property.to_sym].gsub(/\\/, '/') if (property != 'guid' && project[:assembly_info][property.to_sym])
58
+ return project[:guid].gsub(/\\/, '/') if property === 'guid'
59
+ end
60
+ end
61
+ raise "Property '#{property}' not found for project '#{project_name}'"
62
+ end
63
+
64
+ def strip_csproj
65
+ @startup_csproj_file.match(/(^.*)\/.*\.csproj$/).captures[0].strip
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iron-spect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nicholas Terry
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xml-simple
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: ruby-debug19
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-mocks
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: C# project file parser and inspector
111
+ email:
112
+ - Nicholas
113
+ - Terry
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - iron-spect.gemspec
124
+ - lib/iron-spect.rb
125
+ - lib/iron-spect/parsers/project_file_parser.rb
126
+ - lib/iron-spect/parsers/solution_file_parser.rb
127
+ - lib/iron-spect/version.rb
128
+ homepage: ''
129
+ licenses:
130
+ - Apache2
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ hash: -716888684592551723
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ segments:
151
+ - 0
152
+ hash: -716888684592551723
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.25
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: C# project file parser and inspector
159
+ test_files: []