ext 0.0.10 → 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.
- data/README +11 -10
- data/Rakefile +2 -2
- data/lib/{ext → extensions}/string.rb +0 -0
- data/lib/{ext → extensions}/symbol.rb +0 -0
- data/lib/externals/configuration/configuration.rb +112 -77
- data/lib/externals/configuration/old_configuration.rb +166 -0
- data/lib/externals/ext.rb +181 -48
- data/lib/externals/old_project.rb +114 -0
- data/lib/externals/old_scms/old_git_project.rb +116 -0
- data/lib/externals/old_scms/old_svn_project.rb +98 -0
- data/lib/externals/project.rb +59 -52
- data/lib/externals/project_types/rails.rb +18 -6
- data/lib/externals/scms/git_project.rb +6 -0
- data/lib/externals/scms/svn_project.rb +5 -0
- data/test/test_checkout_git.rb +4 -0
- data/test/test_checkout_with_subprojects_git.rb +10 -1
- data/test/test_checkout_with_subprojects_svn.rb +26 -12
- data/test/test_upgrade_externals_file.rb +84 -0
- metadata +9 -4
@@ -0,0 +1,116 @@
|
|
1
|
+
module Externals
|
2
|
+
class OldGitProject < OldProject
|
3
|
+
def co *args
|
4
|
+
puts "path is #{path} repository is #{repository}"
|
5
|
+
if path != '.'
|
6
|
+
(rmdircmd = "rmdir #{path}")
|
7
|
+
`#{rmdircmd}` if File.exists?(path)
|
8
|
+
end
|
9
|
+
|
10
|
+
dest = path
|
11
|
+
dest = '' if dest == '.'
|
12
|
+
dest = "\"#{dest}\"" if dest && !dest.empty?
|
13
|
+
|
14
|
+
puts(gitclonecmd = "git clone \"#{repository}\" #{dest}")
|
15
|
+
puts `#{gitclonecmd}`
|
16
|
+
if branch
|
17
|
+
Dir.chdir path do
|
18
|
+
puts `git checkout --track -b #{branch} origin/#{branch}`
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def ex *args
|
24
|
+
if path != '.'
|
25
|
+
(rmdircmd = "rmdir #{path}")
|
26
|
+
`#{rmdircmd}` if File.exists? path
|
27
|
+
end
|
28
|
+
|
29
|
+
dest = path
|
30
|
+
|
31
|
+
dest = '' if dest == '.'
|
32
|
+
|
33
|
+
dest = "\"#{dest}\"" if dest && !dest.empty?
|
34
|
+
|
35
|
+
puts(gitclonecmd = "git clone --depth 1 \"#{repository}\" #{dest}")
|
36
|
+
|
37
|
+
puts `#{gitclonecmd}`
|
38
|
+
if branch
|
39
|
+
puts `cd #{path}; git checkout --track -b #{branch} origin/#{branch}`
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def up *args
|
44
|
+
puts "updating #{path}:"
|
45
|
+
Dir.chdir path do
|
46
|
+
puts `git pull`
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def st *args
|
51
|
+
puts "\nstatus for #{path}:"
|
52
|
+
Dir.chdir path do
|
53
|
+
puts `git status`
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.scm_path? path
|
58
|
+
path =~ /^git:/ || path =~ /.git$/
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.fill_in_opts opts, main_options, sub_options
|
62
|
+
opts.on("--git", "-g", "same as '--scm git' Uses git to checkout/export the main project",
|
63
|
+
Integer) {sub_options[:scm] = main_options[:scm] = 'git'}
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def self.scm
|
68
|
+
"git"
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.detected?
|
72
|
+
File.exists? ".git"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.add_all
|
76
|
+
puts `git add .`
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
protected
|
81
|
+
def ignore_contains? path
|
82
|
+
text = ignore_text
|
83
|
+
text.split(/\n/).detect {|r| r.strip == path.strip}
|
84
|
+
end
|
85
|
+
|
86
|
+
def ignore_text
|
87
|
+
return '' unless File.exists? '.gitignore'
|
88
|
+
retval = ''
|
89
|
+
open('.gitignore') do |f|
|
90
|
+
retval = f.read
|
91
|
+
end
|
92
|
+
retval
|
93
|
+
end
|
94
|
+
|
95
|
+
def append_ignore path
|
96
|
+
rows = ignore_text || ''
|
97
|
+
return if rows.index path.strip
|
98
|
+
|
99
|
+
rows = rows.split(/\n/)
|
100
|
+
rows << path.strip
|
101
|
+
|
102
|
+
rows.delete_if {|row| row =~ /^\s*$/}
|
103
|
+
|
104
|
+
|
105
|
+
open('.gitignore', 'w') do |f|
|
106
|
+
f.write "#{rows.compact.join("\n")}\n"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def extract_name s
|
111
|
+
if s =~ /\/([\w_-]+)(?:\.git)?$/
|
112
|
+
$1
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Externals
|
2
|
+
class OldSvnProject < OldProject
|
3
|
+
def co *args
|
4
|
+
(rmdircmd = "rmdir #{path}")
|
5
|
+
|
6
|
+
`#{rmdircmd}` if File.exists? path
|
7
|
+
puts(svncocmd = "svn co #{repository} #{path}")
|
8
|
+
puts `#{svncocmd}`
|
9
|
+
end
|
10
|
+
|
11
|
+
def ex *args
|
12
|
+
(rmdircmd = "rmdir #{path}")
|
13
|
+
|
14
|
+
`#{rmdircmd}` if File.exists? path
|
15
|
+
puts(svncocmd = "svn export #{repository} #{path}")
|
16
|
+
puts `#{svncocmd}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def up *args
|
20
|
+
puts "updating #{path}:"
|
21
|
+
Dir.chdir path do
|
22
|
+
puts `svn up .`
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def st *args
|
27
|
+
puts "\nstatus for #{path}:"
|
28
|
+
Dir.chdir path do
|
29
|
+
puts `svn status`
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.scm_path? path
|
34
|
+
return true if path =~ /^svn(\+ssh)?:/
|
35
|
+
if path =~ /^https?:\/\/([\w+\-_]+)\.(?:[\w+\-_]+\.)*[\w\-_]+(?:\/|$)/
|
36
|
+
return true if $1.downcase == "svn"
|
37
|
+
|
38
|
+
if path =~ /^https?:\/\/(?:[\w_\-]+\.)*[\w\-_]+\/(\w+)\//
|
39
|
+
return true if $1.downcase == "svn"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.fill_in_opts opts, main_options, sub_options
|
47
|
+
opts.on("--svn", "--subversion","-s", "same as '--scm svn' Uses subversion to checkout/export the main project",
|
48
|
+
Integer) {sub_options[:scm] = main_options[:scm] = 'svn'}
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.scm
|
52
|
+
"svn"
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.detected?
|
56
|
+
File.exists? ".svn"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.add_all
|
60
|
+
status = `svn st`
|
61
|
+
|
62
|
+
status.split("\n").grep(/^\?/).each do |to_add|
|
63
|
+
puts `svn add #{to_add.gsub(/^\?\s*/,"")}`
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
protected
|
69
|
+
def ignore_contains? path
|
70
|
+
ignore_text(path) =~ Regexp.new("^\\s*#{File.basename(path)}\\s*$")
|
71
|
+
end
|
72
|
+
|
73
|
+
def append_ignore path
|
74
|
+
parent = File.dirname(path)
|
75
|
+
child = File.basename(path)
|
76
|
+
|
77
|
+
rows = ignore_text(path).split(/\n/)
|
78
|
+
|
79
|
+
return if rows.detect {|row| row.strip == child.strip}
|
80
|
+
|
81
|
+
rows << child.strip
|
82
|
+
|
83
|
+
rows.delete_if {|row| row =~ /^\s*$/}
|
84
|
+
|
85
|
+
Dir.chdir(parent) do
|
86
|
+
puts `svn propset svn:ignore "#{rows.compact.join("\n")}\n" .`
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def ignore_text(path)
|
91
|
+
ignore_text = ''
|
92
|
+
Dir.chdir File.dirname(path) do
|
93
|
+
puts(ignore_text = `svn propget svn:ignore`)
|
94
|
+
end
|
95
|
+
ignore_text
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/externals/project.rb
CHANGED
@@ -1,103 +1,110 @@
|
|
1
|
-
|
2
|
-
# this regular expression will match a quoted string
|
3
|
-
# it will allow for " to be escaped with "" within the string
|
4
|
-
quoted = '(?:"(?:(?:[^"]*(?:"")?)*)")'
|
5
|
-
|
6
|
-
# this regular expression will match strings of text that are not quoted. They must appear at the start of a line or after a ,
|
7
|
-
# it will also match empty strings like ,,
|
8
|
-
unquoted = '(?:[^"\\s][^\\s$]*)'
|
9
|
-
|
10
|
-
column = "(#{quoted}|#{unquoted})"
|
11
|
-
PROJECT_LINE_REGEX = Regexp.new("^\\s*#{column}(?:\\s+#{column})?\\s*$")
|
1
|
+
require 'extensions/symbol'
|
12
2
|
|
3
|
+
module Externals
|
13
4
|
class Project
|
14
|
-
|
15
|
-
|
5
|
+
def self.attr_attr_accessor *names
|
6
|
+
names = [names].flatten
|
7
|
+
names.each do |name|
|
8
|
+
define_method name do
|
9
|
+
attributes[name.to_sym]
|
10
|
+
end
|
11
|
+
define_method "#{name}=" do |value|
|
12
|
+
attributes[name.to_sym] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
VALID_ATTRIBUTES = [:name, :path, :repository, :branch, :type, :scm].map(&:to_s)
|
16
18
|
|
19
|
+
attr_attr_accessor VALID_ATTRIBUTES
|
20
|
+
def attributes
|
21
|
+
@attributes ||= {}
|
22
|
+
end
|
17
23
|
def name
|
18
|
-
|
24
|
+
attributes[:name] || extract_name(repository)
|
19
25
|
end
|
20
|
-
|
21
|
-
|
22
|
-
@is_main
|
26
|
+
def main_project?
|
27
|
+
path == '.'
|
23
28
|
end
|
24
29
|
|
25
30
|
def self.scm
|
26
31
|
raise "subclass responsibility"
|
27
32
|
end
|
28
|
-
|
29
|
-
|
30
33
|
def scm
|
31
34
|
self.class.scm
|
32
35
|
end
|
36
|
+
def self.default_branch
|
37
|
+
raise "subclass responsibility"
|
38
|
+
end
|
39
|
+
def default_branch
|
40
|
+
self.class.default_branch
|
41
|
+
end
|
33
42
|
|
34
|
-
|
35
|
-
def initialize row_string, is_main = false
|
43
|
+
def initialize hash
|
36
44
|
raise "Abstract class" if self.class == Project
|
45
|
+
raise "expected hash" unless hash.is_a? Hash
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
hash = hash.keys.inject({}) do |new_hash, key|
|
48
|
+
new_hash[key.to_s] = hash[key]
|
49
|
+
new_hash
|
50
|
+
end
|
51
|
+
|
52
|
+
invalid_attributes = hash.keys - VALID_ATTRIBUTES
|
53
|
+
|
54
|
+
if !invalid_attributes.empty?
|
55
|
+
raise "invalid attribute(s): #{invalid_attributes.join(', ')}"
|
56
|
+
end
|
47
57
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
path = hash.delete('path')
|
59
|
+
|
60
|
+
hash.keys.each do |key|
|
61
|
+
send("#{key}=", hash[key])
|
62
|
+
end
|
63
|
+
|
64
|
+
if path && !path.is_a?(String)
|
65
|
+
path = path.default_path(name)
|
56
66
|
end
|
67
|
+
self.path = path
|
57
68
|
end
|
58
|
-
|
69
|
+
|
59
70
|
[:co, :ex].each do |method_name|
|
60
|
-
define_method method_name do |args|
|
71
|
+
define_method method_name do |args|
|
61
72
|
raise "subclass responsibility"
|
62
73
|
end
|
63
74
|
end
|
64
|
-
|
75
|
+
|
65
76
|
def update_ignore path
|
66
77
|
if !ignore_contains?(path)
|
67
78
|
append_ignore path
|
68
79
|
end
|
69
80
|
end
|
70
|
-
|
81
|
+
|
71
82
|
def checkout *args
|
72
83
|
co(*args)
|
73
84
|
end
|
74
|
-
|
85
|
+
|
75
86
|
def export *args
|
76
87
|
ex(*args)
|
77
88
|
end
|
78
|
-
|
89
|
+
|
79
90
|
def extract_name repository
|
80
91
|
if repository =~ /\/([\w_-]+)(?:\.git)?$/
|
81
92
|
$1
|
82
93
|
end
|
83
94
|
end
|
84
|
-
|
85
|
-
def path
|
86
|
-
@path || default_path(self)
|
87
|
-
end
|
88
95
|
|
89
96
|
def parent_path
|
90
97
|
File.dirname path
|
91
98
|
end
|
92
|
-
|
99
|
+
|
93
100
|
def self.project_line? line
|
94
101
|
#Make sure it's not a comment
|
95
102
|
return false if line =~ /^\s*#/
|
96
|
-
|
103
|
+
|
97
104
|
line =~ PROJECT_LINE_REGEX
|
98
105
|
end
|
99
|
-
|
100
|
-
|
106
|
+
|
107
|
+
|
101
108
|
|
102
109
|
protected
|
103
110
|
def trim_quotes value
|
@@ -1,17 +1,29 @@
|
|
1
1
|
module Externals
|
2
2
|
module RailsProjectType
|
3
3
|
def self.install
|
4
|
-
|
4
|
+
#obj.send(:extend, Externals::RailsProjectType::Project)
|
5
|
+
Externals::OldProject.send(:include, Externals::RailsProjectType::Project)
|
5
6
|
end
|
6
|
-
|
7
|
-
|
8
|
-
def default_path
|
9
|
-
if
|
10
|
-
(
|
7
|
+
|
8
|
+
class DefaultPathCalculator
|
9
|
+
def default_path name
|
10
|
+
if name
|
11
|
+
(name == 'rails') ? File.join("vendor","rails") : File.join("vendor","plugins", name)
|
12
|
+
else
|
13
|
+
raise "couldn't figure out project name..."
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
18
|
+
module Project
|
19
|
+
def default_path
|
20
|
+
if name
|
21
|
+
(name == 'rails') ? File.join("vendor","rails") : File.join("vendor","plugins", name)
|
22
|
+
else
|
23
|
+
raise "couldn't figure out project name..."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
16
28
|
|
17
29
|
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Externals
|
2
2
|
class GitProject < Project
|
3
|
+
|
4
|
+
def default_branch
|
5
|
+
'master'
|
6
|
+
end
|
7
|
+
|
3
8
|
def co *args
|
4
9
|
puts "path is #{path} repository is #{repository}"
|
5
10
|
if path != '.'
|
@@ -112,5 +117,6 @@ module Externals
|
|
112
117
|
$1
|
113
118
|
end
|
114
119
|
end
|
120
|
+
|
115
121
|
end
|
116
122
|
end
|