gem-patch 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Josef Strzibny.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -6,13 +6,24 @@ A RubyGems plugin that patches gems.
6
6
 
7
7
  `gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them. It opens a given .gem file, extracts it, patches it with system `patch` command, clones its spec, updates the file list and builds the patched gem.
8
8
 
9
+ ## Installation
10
+
11
+ Run:
12
+ `gem install gem-patch`
13
+
9
14
  ## Usage
10
15
 
11
16
  `gem patch [options] name-version.gem PATCH [PATCH ...]`
12
17
 
13
- Optionally with `-pNUMBER` or `--strip=NUMBER` option that sets the file name strip count to NUMBER
14
- (same options as for `patch` command on Linux machines).
18
+ Options:
19
+
20
+ `-pNUMBER` or `--strip=NUMBER` sets the file name strip count to NUMBER (same options as for `patch` command on Linux machines).
21
+ `--verbose` prints additional info and STDOUT from `patch` command
15
22
 
16
23
  ## Requirements
17
24
 
18
25
  This version is build for both RubyGems 1.8 and RubyGems 2.0.
26
+
27
+ ## Copyright
28
+
29
+ See LICENCE
@@ -6,13 +6,20 @@ A RubyGems plugin that patches gems.
6
6
 
7
7
  `gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them. It opens a given .gem file, extracts it, patches it with system `patch` command, clones its spec, updates the file list and builds the patched gem.
8
8
 
9
+ == Installation
10
+
11
+ Run:
12
+ `gem install gem-patch`
13
+
9
14
  == Usage
10
15
 
11
16
  `gem patch [options] name-version.gem PATCH [PATCH ...]`
12
17
 
13
- Optionally with `-pNUMBER` or `--strip=NUMBER` option that sets the file name strip count to NUMBER
14
- (same options as for `patch` command on Linux machines).
18
+ Options:
19
+
20
+ `-pNUMBER` or `--strip=NUMBER` sets the file name strip count to NUMBER (same options as for `patch` command on Linux machines).
21
+ `--verbose` prints additional info and STDOUT from `patch` command
15
22
 
16
23
  == Requirements
17
24
 
18
- This version is build for RubyGems 2.0.a, a branch for RubyGems 1.8 is also available.
25
+ This version is build for RubyGems 2.0.a, a branch for RubyGems 1.8 is also available.
@@ -50,5 +50,6 @@ class Gem::Commands::PatchCommand < Gem::Command
50
50
 
51
51
  patcher = Gem::Patcher.new(gemfile, options[:output])
52
52
  patcher.patch_with(patches, options[:strip])
53
+ patcher.print_results
53
54
  end
54
55
  end
@@ -25,6 +25,8 @@ class Gem::Patcher
25
25
  # Patch the gem, move the new patched gem to the working directory and return the path
26
26
 
27
27
  def patch_with(patches, strip_number)
28
+ @output = []
29
+
28
30
  check_patch_command_is_installed
29
31
  extract_gem
30
32
 
@@ -36,15 +38,11 @@ class Gem::Patcher
36
38
 
37
39
  build_patched_gem
38
40
 
39
- # Move the newly generated gem to the working directory
40
- gem_file = IO.read(File.join @target_dir, @package.spec.file_name)
41
-
42
- File.open(File.join(@output_dir, @package.spec.file_name), 'w') do |f|
43
- f.write gem_file
44
- end
41
+ new_gem_path = File.join(@output_dir, @package.spec.file_name)
42
+ FileUtils.mv((File.join @target_dir, @package.spec.file_name), new_gem_path)
45
43
 
46
44
  # Return the path to the patched gem
47
- File.join @output_dir, "#{@package.spec.file_name}"
45
+ new_gem_path
48
46
  end
49
47
 
50
48
  def apply_patch(patch, strip_number)
@@ -53,14 +51,32 @@ class Gem::Patcher
53
51
 
54
52
  # Apply the patch by calling 'patch -pNUMBER < patch'
55
53
  Dir.chdir @target_dir do
56
- if system("patch --verbose -p#{strip_number} < #{patch_path}")
57
- info 'Succesfully patched by ' + patch
58
- else
59
- info 'Error: Unable to patch with ' + patch
54
+ IO.popen("patch --verbose -p#{strip_number} < #{patch_path} 2>&1") do |out|
55
+ std = out.readlines
56
+ out.close
57
+ info std
58
+
59
+ unless $?.nil?
60
+ if $?.exitstatus == 0
61
+ @output << "Succesfully patched with #{patch}"
62
+ else
63
+ @output << "Error: Unable to patch with #{patch}."
64
+
65
+ unless Gem.configuration.really_verbose
66
+ @output << "Run gem patch with --verbose option to swich to verbose mode."
67
+ end
68
+ end
69
+ end
60
70
  end
61
71
  end
62
72
  end
63
73
 
74
+ def print_results
75
+ @output.each do |msg|
76
+ say msg
77
+ end
78
+ end
79
+
64
80
  private
65
81
 
66
82
  def extract_gem
@@ -83,7 +99,7 @@ class Gem::Patcher
83
99
  end
84
100
 
85
101
  def info(msg)
86
- say msg if Gem.configuration.verbose
102
+ say msg if Gem.configuration.really_verbose
87
103
  end
88
104
 
89
105
  def files_in_gem
@@ -121,7 +137,9 @@ class Gem::Patcher
121
137
  end
122
138
 
123
139
  def check_patch_command_is_installed
124
- unless system("patch --version")
140
+ result = IO.popen('patch --version')
141
+
142
+ unless /^patch\s\d\.\d\./.match result.readlines[0]
125
143
  raise PatchCommandMissing, 'Calling `patch` command failed. Do you have it installed?'
126
144
  end
127
145
  end
@@ -4,7 +4,7 @@ require 'rdoc/task'
4
4
 
5
5
  gemspec = Gem::Specification.new do |s|
6
6
  s.name = "gem-patch"
7
- s.version = "0.1.1"
7
+ s.version = "0.1.2"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.summary = "RubyGems plugin for patching gems."
10
10
  s.description = <<-EOF
@@ -12,12 +12,13 @@ gemspec = Gem::Specification.new do |s|
12
12
  It opens a given .gem file, extracts it, patches it with system `patch` command,
13
13
  clones its spec, updates the file list and builds the patched gem.
14
14
  EOF
15
+ s.homepage = "http://github.com/strzibny/gem-patch"
15
16
  s.licenses = ["MIT"]
16
17
  s.author = "Josef Stribny"
17
18
  s.email = "jstribny@redhat.com"
18
19
  s.required_ruby_version = ">= 1.8.7"
19
20
  s.required_rubygems_version = ">= 1.8.0"
20
- s.files = FileList["README.md", "README.rdoc", "rakefile.rb",
21
+ s.files = FileList["README.md", "README.rdoc", "LICENCE", "rakefile.rb",
21
22
  "lib/**/*.rb", "test/**/test*.rb"]
22
23
  end
23
24
 
@@ -35,4 +36,4 @@ Rake::TestTask.new('test') do |t|
35
36
  t.verbose = true
36
37
  end
37
38
 
38
- task :default => [:test]
39
+ task :default => [:test]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-02 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! " `gem-patch` is a RubyGems plugin that helps to
15
15
  patch gems without manually opening and rebuilding them.\n It
@@ -23,6 +23,7 @@ extra_rdoc_files: []
23
23
  files:
24
24
  - README.md
25
25
  - README.rdoc
26
+ - LICENCE
26
27
  - rakefile.rb
27
28
  - lib/rubygems_plugin.rb
28
29
  - lib/rubygems/package-1.8.rb
@@ -30,7 +31,7 @@ files:
30
31
  - lib/rubygems/commands/patch_command.rb
31
32
  - test/rubygems/test_gem_patch.rb
32
33
  - test/rubygems/test_gem_commands_patch_command.rb
33
- homepage:
34
+ homepage: http://github.com/strzibny/gem-patch
34
35
  licenses:
35
36
  - MIT
36
37
  post_install_message: