code_tools 4.0.0 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e0734734f903314d2b0ac7652eca0c3a345d498
4
- data.tar.gz: 4466ac82270d0b13b24bbbacdca8744204e33743
3
+ metadata.gz: cbaf6f2122fa3302144ef27d0c5484c82a8bec52
4
+ data.tar.gz: 2b3eb698101465ed00e6b367cf55e357a1aede36
5
5
  SHA512:
6
- metadata.gz: b7d0326b92e82e509fec5dd40c4e251434165682c78191e20d2ab5535ee7912428088c184c0762393b8bc83acd4beee36906fff81f5b34d3536dd2ed0132816c
7
- data.tar.gz: 8bc0c83868759a9d0cb1e533955fcf80b0cfa7b458b05a7d3fbc968d56e6269b5ea2a301b0f2c5e74074b7db14677b55479014a28702a75c817a5b37e26fa095
6
+ metadata.gz: a24bfc3ab574bfbc0fbc38b0568919cf1cf3fabf340c270810ff4cdd8b90b9d825b55cd2f719891c6b78e3bd8a83c59723a72d7225a49cfa9148d6b93ea71dd4
7
+ data.tar.gz: ceadd6e3b9b004033420b90e6e4f0bf4d63764765b3e9a2f74efd39060ed42be21309ce6773ad49346a962baba94bd71fb94ba4eb05256296beb1564e6ec65bc
@@ -1,5 +1,13 @@
1
1
  <?xml version="1.0" encoding="UTF-8" ?>
2
2
  <VersionConfig>
3
+ <FileType>
4
+ <Name>Ruby Files</Name>
5
+ <FileSpec>*.rb</FileSpec>
6
+ <Update>
7
+ <Search>(?'Before'\$VERSION=\')([0-9]+\.[0-9]+\.[0-9]+)-[0-9]+\.[0-9]+(?'After'\')</Search>
8
+ <Replace>${Before}${Major}.${Minor}.${Patch}-${Build}.${Revision}${After}</Replace>
9
+ </Update>
10
+ </FileType>
3
11
  <FileType>
4
12
  <Name>Version-in-a-text-file</Name>
5
13
  <FileSpec>*.version.txt</FileSpec>
@@ -1,5 +1,5 @@
1
1
  require 'nokogiri'
2
- require 'core_ext.rb'
2
+ require_relative '../core_ext.rb'
3
3
 
4
4
  class VersionConfigFile
5
5
  def initialize(io, tags)
@@ -16,6 +16,7 @@ class VersionConfigFile
16
16
  }
17
17
  update_node_set = node.xpath('Update')
18
18
  if update_node_set
19
+ # Replace ${...} entries in the replace string with equivalent tags if available
19
20
  file_type.updates = update_node_set.map { |sub_node|
20
21
  s_and_r = search_replace_struct.new(
21
22
  %r(#{sub_node.at_xpath('Search').text.gsub(/\(\?'(\w+)'/, '(?<\\1>')}),
@@ -1,5 +1,5 @@
1
1
  require 'nokogiri'
2
- require 'core_ext.rb'
2
+ require_relative '../core_ext.rb'
3
3
 
4
4
  class BadVersionFile < StandardError; end
5
5
 
data/lib/vamper.rb CHANGED
@@ -1,66 +1,65 @@
1
1
  require 'tzinfo'
2
2
  require 'nokogiri'
3
- require 'vamper/version_file.rb'
4
- require 'vamper/version_config_file.rb'
5
- require 'core_ext.rb'
3
+ require 'ostruct'
4
+ require 'optparse'
5
+ require_relative './vamper/version_file.rb'
6
+ require_relative './vamper/version_config_file.rb'
7
+ require_relative './core_ext.rb'
6
8
 
7
- $VERSION='4.0.0-20150811.0'
9
+ $VERSION='4.1.0-20151225.0'
8
10
 
9
11
  class Vamper
10
12
 
11
- def initialize
12
- @do_update = false;
13
- @version_file_name = ''
14
- end
15
-
16
13
  def parse(args)
17
- args.each { |arg|
18
- case arg
19
- when '-?', '-help'
20
- print %Q(Version Stamper. Version #{$VERSION}
21
- Copyright (c) John Lyon-Smith 2015.
22
-
23
- Syntax: #{File.basename(__FILE__)} [switches] VERSION_FILE
24
-
25
- Description: Stamps versions into project files
26
-
27
- Switches:
14
+ options = OpenStruct.new
15
+ options.do_update = false
16
+ options.version_file_name = ''
17
+
18
+ opt_parser = OptionParser.new do |opts|
19
+ opts.banner = %Q(Version Stamper. Version #{$VERSION}
20
+ Copyright (c) John Lyon-Smith, 2016.
21
+ Usage: #{File.basename(__FILE__)} [options]
22
+ )
23
+ opts.separator %Q(Options:
24
+ )
28
25
 
29
- -help|-? Shows this help
30
- -u|-update Increment the build number and update all files
26
+ opts.on("-u", "--update", "Increment the build number and update all files") do |dir|
27
+ options.do_update = true
28
+ end
31
29
 
32
- )
33
- exit(0)
34
- when '-u', '-update'
35
- @do_update = true
36
- else
37
- @version_file_name = arg
30
+ opts.on_tail("-?", "--help", "Show this message") do
31
+ puts opts
32
+ exit
38
33
  end
39
- }
34
+ end
35
+
36
+ opt_parser.parse!(args)
37
+ options
40
38
  end
41
39
 
42
40
  def execute
43
- self.parse(ARGV)
41
+ options = self.parse(ARGV)
44
42
 
45
- if @version_file_name.length == 0
46
- find_version_file
43
+ if options.version_file_name.length == 0
44
+ find_version_file options
47
45
  end
48
46
 
49
- @version_file_name = File.expand_path(@version_file_name)
47
+ options.version_file_name = File.expand_path(options.version_file_name)
50
48
 
51
- project_name = File.basename(@version_file_name, '.version')
52
- version_config_file_name = "#{File.dirname(@version_file_name)}/#{project_name}.version.config"
49
+ project_name = File.basename(options.version_file_name, '.version')
50
+ version_config_file_name = "#{File.dirname(options.version_file_name)}/#{project_name}.version.config"
53
51
 
54
- puts "Version file is '#{@version_file_name}'"
52
+ puts "Version file is '#{options.version_file_name}'"
55
53
  puts "Version config is '#{version_config_file_name}'"
56
54
  puts "Project name is '#{project_name}'"
57
55
 
58
- if File.exists?(@version_file_name)
59
- version_file = VersionFile.new(File.open(@version_file_name))
56
+ if File.exists?(options.version_file_name)
57
+ version_file = VersionFile.new(File.open(options.version_file_name))
60
58
  else
61
59
  verson_file = VersionFile.new
62
60
  end
63
61
 
62
+ tags = version_file.tags
64
63
  now = TZInfo::Timezone.get(version_file.time_zone).now
65
64
 
66
65
  case version_file.build_value_type
@@ -82,18 +81,18 @@ Switches:
82
81
  else
83
82
  version_file.revision += 1
84
83
  end
84
+ tags[:DashBuild] = build[0..3] + '-' + build[4..5] + '-' + build[6..7]
85
85
  when :Incremental
86
86
  version_file.build += 1
87
87
  version_file.revision = 0
88
88
  end
89
89
 
90
90
  puts 'Version data is:'
91
- tags = version_file.tags
92
91
  tags.each { |key, value|
93
92
  puts " #{key}=#{value}"
94
93
  }
95
94
 
96
- if @do_update
95
+ if options.do_update
97
96
  puts 'Updating version information:'
98
97
  end
99
98
 
@@ -105,7 +104,7 @@ Switches:
105
104
  file_list = version_file.files.map { |file_name| file_name.replace_tags!(tags) }
106
105
 
107
106
  file_list.each do |file_name|
108
- path = File.expand_path(File.join(File.dirname(@version_file_name), file_name))
107
+ path = File.expand_path(File.join(File.dirname(options.version_file_name), file_name))
109
108
  path_file_name = File.basename(path)
110
109
  match = false
111
110
 
@@ -122,14 +121,16 @@ Switches:
122
121
  exit(1)
123
122
  end
124
123
 
125
- if @do_update
124
+ if options.do_update
126
125
  IO.write(path, file_type.write)
127
126
  end
128
127
  else # !file_type.write
129
128
  if File.exists?(path)
130
- if @do_update
129
+ if options.do_update
131
130
  file_type.updates.each do |update|
132
131
  content = IO.read(path)
132
+ # At this the only ${...} variables left in the replace strings are Before and After
133
+ # This line converts the ${...} into \k<...>
133
134
  content.gsub!(%r(#{update.search})m, update.replace.gsub(/\${(\w+)}/,'\\\\k<\\1>'))
134
135
  IO.write(path, content)
135
136
  end
@@ -150,19 +151,19 @@ Switches:
150
151
 
151
152
  puts path
152
153
 
153
- if @do_update
154
- version_file.write_to(File.open(@version_file_name, 'w'))
154
+ if options.do_update
155
+ version_file.write_to(File.open(options.version_file_name, 'w'))
155
156
  end
156
157
  end
157
158
  end
158
159
 
159
- def find_version_file
160
+ def find_version_file(options)
160
161
  dir = Dir.pwd
161
162
 
162
163
  while dir.length != 0
163
164
  files = Dir.glob('*.version')
164
165
  if files.length > 0
165
- @version_file_name = files[0]
166
+ options.version_file_name = files[0]
166
167
  break
167
168
  else
168
169
  if dir == '/'
@@ -173,18 +174,18 @@ Switches:
173
174
  end
174
175
  end
175
176
 
176
- if @version_file_name.length == 0
177
+ if options.version_file_name.length == 0
177
178
  error 'Unable to find a .version file in this or parent directories.'
178
179
  exit(1)
179
180
  end
180
181
  end
181
182
 
182
183
  def get_full_date(now)
183
- now.year * 10000 + now.month * 100 + now.mday
184
+ (now.year * 10000 + now.month * 100 + now.mday).to_s
184
185
  end
185
186
 
186
187
  def get_jdate(now, start_year)
187
- ((now.year - start_year + 1) * 10000) + (now.month * 100) + now.mday
188
+ (((now.year - start_year + 1) * 10000) + (now.month * 100) + now.mday).to_s
188
189
  end
189
190
 
190
191
  def error(msg)
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Lyon-smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  description: Tools for source code maintenance, including version stamping, line endings
@@ -47,13 +47,13 @@ executables:
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
- - lib/vamper.rb
50
+ - bin/code_tools
51
+ - bin/vamper
51
52
  - lib/core_ext.rb
53
+ - lib/vamper.rb
52
54
  - lib/vamper/default.version.config
53
55
  - lib/vamper/version_config_file.rb
54
56
  - lib/vamper/version_file.rb
55
- - bin/vamper
56
- - bin/code_tools
57
57
  homepage: http://rubygems.org/gems/code_tools
58
58
  licenses:
59
59
  - MIT
@@ -64,17 +64,17 @@ require_paths:
64
64
  - lib
65
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '2.0'
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.0.14
77
+ rubygems_version: 2.4.5
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Source code tools