csproj 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +44 -0
- data/lib/csproj.rb +25 -0
- data/lib/csproj/detect_values.rb +162 -0
- data/lib/csproj/msbuild/project.rb +43 -0
- data/lib/csproj/msbuild/solution.rb +19 -0
- data/lib/csproj/msbuild/solution_parser.rb +36 -0
- data/lib/csproj/platform.rb +13 -0
- data/lib/csproj/version.rb +3 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9b51606e022b0c08f21b2c07f60aa9d6862c75bd01f84417ddced763ca117271
|
4
|
+
data.tar.gz: fa9e7f6425ccaa4b48afe3d77461fbb32bcaef9e1ab843bf4b0f1f598ae58f4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: acd8730f0ff2616cf9f7c7f578da59acb4afb18e51a4ae39913bfd92a96172ec5523597797021d96144b88ca73877d0bb1ec0b4d0831d0c744fe59fa4a5fb045
|
7
|
+
data.tar.gz: 317f7c8266f767e0b9a6e07ab48a4afa0d3dc2764d31bfb2527f535eef416e923e7b7ec5706fb0ef99b05d82f20cd4a939e178f274271a125cd8df2116a238dc
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jake Barnby
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# CsProj
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/csproj`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'csproj'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install csproj
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csproj. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/csproj/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the CsProj project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/csproj/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/csproj.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "csproj/version"
|
2
|
+
require "csproj/detect_values"
|
3
|
+
|
4
|
+
module CsProj
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
def self.read_project(values)
|
8
|
+
::CsProj.config = values
|
9
|
+
CsProj
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :config
|
14
|
+
|
15
|
+
attr_accessor :project
|
16
|
+
|
17
|
+
attr_accessor :cache
|
18
|
+
|
19
|
+
def config=(value)
|
20
|
+
@config = value
|
21
|
+
DetectValues.set_additional_default_values
|
22
|
+
@cache = {}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "csproj/msbuild/project"
|
3
|
+
require "csproj/msbuild/solution_parser"
|
4
|
+
|
5
|
+
module CsProj
|
6
|
+
class DetectValues
|
7
|
+
def self.set_additional_default_values
|
8
|
+
config = CsProj.config
|
9
|
+
|
10
|
+
if config[:platform] == Platform::ANDROID
|
11
|
+
config[:build_platform] = "AnyCPU"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Detect the project
|
15
|
+
CsProj.project = Msbuild::Project.new(config)
|
16
|
+
detect_solution
|
17
|
+
detect_project
|
18
|
+
|
19
|
+
doc_csproj = get_parser_handle config[:project_path]
|
20
|
+
|
21
|
+
detect_output_path doc_csproj
|
22
|
+
detect_manifest doc_csproj
|
23
|
+
detect_info_plist
|
24
|
+
detect_assembly_name doc_csproj
|
25
|
+
|
26
|
+
config
|
27
|
+
end
|
28
|
+
|
29
|
+
# Helper Methods
|
30
|
+
|
31
|
+
def self.detect_solution
|
32
|
+
return if CsProj.config[:solution_path]
|
33
|
+
|
34
|
+
sln = find_file("*.sln", 3)
|
35
|
+
|
36
|
+
unless sln
|
37
|
+
puts "Not able to find solution file automatically, try to specify it via `solution_path` parameter."
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
|
41
|
+
CsProj.config[:solution_path] = abs_path sln
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.detect_project
|
45
|
+
return if CsProj.config[:project_path]
|
46
|
+
|
47
|
+
path = CsProj.config[:solution_path]
|
48
|
+
projects = Msbuild::SolutionParser
|
49
|
+
.parse(path)
|
50
|
+
.get_platform(CsProj.config[:platform])
|
51
|
+
|
52
|
+
unless projects.any?
|
53
|
+
puts "Not able to find any project in solution, that matches the platform `#{CsProj.config[:platform]}`."
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
project = projects.first
|
58
|
+
csproj = fix_path_relative project.project_path
|
59
|
+
|
60
|
+
unless csproj
|
61
|
+
puts "Not able to find project file automatically, try to specify it via `project_path` parameter."
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
|
65
|
+
CsProj.config[:project_name] = project.project_name
|
66
|
+
CsProj.config[:project_path] = abs_path csproj
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.detect_output_path(doc_csproj)
|
70
|
+
return if CsProj.config[:output_path] ||
|
71
|
+
!CsProj.config[:build_configuration]
|
72
|
+
|
73
|
+
configuration = CsProj.config[:build_configuration]
|
74
|
+
platform = CsProj.config[:build_platform]
|
75
|
+
|
76
|
+
doc_node = doc_csproj.xpath("/*[local-name()='Project']/*[local-name()='PropertyGroup'][translate(@*[local-name() = 'Condition'],'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = \" '$(configuration)|$(platform)' == '#{configuration.downcase}|#{platform.downcase}' \"]/*[local-name()='OutputPath']/text()")
|
77
|
+
output_path = doc_node.text
|
78
|
+
|
79
|
+
unless output_path
|
80
|
+
puts "Not able to find output path automatically, try to specify it via `output_path` parameter."
|
81
|
+
exit
|
82
|
+
end
|
83
|
+
|
84
|
+
CsProj.config[:output_path] = abs_project_path output_path
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.detect_manifest(doc_csproj)
|
88
|
+
return if CsProj.config[:manifest_path] || (CsProj.config[:platform] != Platform::ANDROID)
|
89
|
+
|
90
|
+
doc_node = doc_csproj.css("AndroidManifest").first
|
91
|
+
|
92
|
+
CsProj.config[:manifest_path] = abs_project_path doc_node.text
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.detect_info_plist
|
96
|
+
return if CsProj.config[:plist_path] || (CsProj.config[:platform] != Platform::IOS)
|
97
|
+
|
98
|
+
plist_path = find_file("*/Info.plist", 1)
|
99
|
+
|
100
|
+
unless plist_path
|
101
|
+
puts "Not able to find Info.plist automatically, try to specify it via `plist_path` parameter."
|
102
|
+
exit
|
103
|
+
end
|
104
|
+
|
105
|
+
CsProj.config[:plist_path] = abs_project_path plist_path
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.detect_assembly_name(doc_csproj)
|
109
|
+
return if CsProj.config[:assembly_name]
|
110
|
+
|
111
|
+
if [Platform::IOS, Platform::OSX].include? CsProj.config[:platform]
|
112
|
+
CsProj.config[:assembly_name] = doc_csproj.css("PropertyGroup > AssemblyName").text
|
113
|
+
elsif CsProj.config[:platform] == Platform::ANDROID
|
114
|
+
doc = get_parser_handle CsProj.config[:manifest_path]
|
115
|
+
CsProj.config[:assembly_name] = doc.xpath("string(//manifest/@package)")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private_class_method
|
120
|
+
|
121
|
+
def self.find_file(query, depth)
|
122
|
+
itr = 0
|
123
|
+
files = []
|
124
|
+
|
125
|
+
loop do
|
126
|
+
files = Dir.glob(query)
|
127
|
+
query = "../#{query}"
|
128
|
+
itr += 1
|
129
|
+
break if files.any? || (itr > depth)
|
130
|
+
end
|
131
|
+
|
132
|
+
files.first
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.get_parser_handle(filename)
|
136
|
+
f = File.open(filename)
|
137
|
+
doc = Nokogiri::XML(f)
|
138
|
+
f.close
|
139
|
+
|
140
|
+
doc
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.fix_path_relative(path)
|
144
|
+
root = File.dirname CsProj.config[:solution_path]
|
145
|
+
path = "#{root}/#{path}"
|
146
|
+
path
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.abs_project_path(path)
|
150
|
+
path = path.tr('\\', "/")
|
151
|
+
platform_path = CsProj.config[:project_path]
|
152
|
+
path = "#{File.dirname platform_path}/#{path}"
|
153
|
+
path
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.abs_path(path)
|
157
|
+
path = path.tr('\\', "/")
|
158
|
+
path = File.expand_path(path)
|
159
|
+
path
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module CsProj
|
2
|
+
module Msbuild
|
3
|
+
class Project
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def project_name
|
11
|
+
@options[:project_name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def project_path
|
15
|
+
@options[:project_path]
|
16
|
+
end
|
17
|
+
|
18
|
+
def ios?
|
19
|
+
is_platform? CsProj::Platform::IOS
|
20
|
+
end
|
21
|
+
|
22
|
+
def osx?
|
23
|
+
is_platform? CsProj::Platform::OSX
|
24
|
+
end
|
25
|
+
|
26
|
+
def android?
|
27
|
+
is_platform? CsProj::Platform::ANDROID
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_platform?(platform)
|
31
|
+
case platform
|
32
|
+
when CsProj::Platform::IOS
|
33
|
+
then project_name.downcase.include? "ios"
|
34
|
+
when CsProj::Platform::OSX
|
35
|
+
then project_name.downcase.include? "mac"
|
36
|
+
when CsProj::Platform::ANDROID
|
37
|
+
then project_name.downcase.include? "droid"
|
38
|
+
else false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CsProj
|
2
|
+
module Msbuild
|
3
|
+
class Solution
|
4
|
+
attr_accessor :projects
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@projects = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_project(project)
|
11
|
+
@projects << project
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_platform(platform)
|
15
|
+
@projects.select { |p| p.is_platform? platform }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "csproj/msbuild/solution"
|
2
|
+
|
3
|
+
module CsProj
|
4
|
+
module Msbuild
|
5
|
+
class SolutionParser
|
6
|
+
def self.parse(filename)
|
7
|
+
solution = Solution.new
|
8
|
+
|
9
|
+
File.open(filename) do |f|
|
10
|
+
f.read.split("\n").each do |line|
|
11
|
+
if line.start_with? "Project"
|
12
|
+
options = parse_line line
|
13
|
+
solution.add_project Project.new(options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
solution
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_line(line)
|
22
|
+
name = get_project_name line
|
23
|
+
project_file = get_project_file line
|
24
|
+
{project_name: name, project_path: project_file}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_project_name(project_line)
|
28
|
+
project_line.split("\"")[3]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_project_file(project_line)
|
32
|
+
project_line.split("\"")[5].tr('\\', "/")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csproj
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jake Barnby
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
description: Load and manipulate C# solutions and projects
|
28
|
+
email:
|
29
|
+
- jakeb994@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/csproj.rb
|
37
|
+
- lib/csproj/detect_values.rb
|
38
|
+
- lib/csproj/msbuild/project.rb
|
39
|
+
- lib/csproj/msbuild/solution.rb
|
40
|
+
- lib/csproj/msbuild/solution_parser.rb
|
41
|
+
- lib/csproj/platform.rb
|
42
|
+
- lib/csproj/version.rb
|
43
|
+
homepage: https://github.com/abnegate/ruby-csproj
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
allowed_push_host: https://rubygems.org
|
48
|
+
homepage_uri: https://github.com/abnegate/ruby-csproj
|
49
|
+
source_code_uri: https://github.com/abnegate/ruby-csproj
|
50
|
+
changelog_uri: https://github.com/abnegate/ruby-csproj/blob/main/CHANGELOG.md
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.1.4
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Load and manipulate C# solutions and projects
|
70
|
+
test_files: []
|