Ruby Patch to Zip: Difference between revisions
(New page: I needed to take a patch file, which contained patches from more than one Eclipse project, and create a zip file with each file contained within. The Eclipse patch file basically looks ...) |
mNo edit summary |
||
Line 50: | Line 50: | ||
./patchToFiles.rb patches/mypatch.patch | xargs zip mypatch.zip | ./patchToFiles.rb patches/mypatch.patch | xargs zip mypatch.zip | ||
</geshi> | </geshi> | ||
[[Category:Ruby|Patch to Zip]] |
Latest revision as of 00:40, 31 July 2008
I needed to take a patch file, which contained patches from more than one Eclipse project, and create a zip file with each file contained within.
The Eclipse patch file basically looks like:
<geshi lang="patch">
- Eclipse Workspace Patch 1.0
- P My Little Project
Index: src/com/MyClass.java
=======================================================
RCS file: /usr/dev/cvs/cvsroot/My Little Project/src/com/MyClass.java,v retrieving revision 1.11.2.2.8.3 diff -u -r1.11.2.2.8.3 MyClass.java --- src/com/MyClass.java 24 May 2007 01:20:56 -0000 1.11.2.2.8.3 +++ src/com/MyClass.java 5 Sep 2007 01:00:23 -0000 @@ -338,8 +338,6 @@
private void setupCustomers( StringBuffer errorBuf_ ) {
- // a comment I removed -
System.out.println("Hello customer");
</geshi>
You have a project definition, followed by files in that project. You can have multiple project definitions. I created a Ruby script to parse the file and keep track of the project name. The script then outputs the qualified path to each file it encounters. Sure, I could have done this with awk, but Ruby is more enjoyable and readable.
<geshi lang="ruby">
- !/bin/env ruby
ARGV.each do |arg|
if !File.exists?(arg) then raise(RuntimeError,"#{arg} does not exist!") end File.open(arg, 'r') do |infile| while(line = infile.gets) if line =~ /^#P ([^\r]*)/ then # ignore any new line characters
project = $1
end if line =~ /^Index: ([^\r]*)/ then
puts '"' + project + '/' + $1 + '"'
end end end
end </geshi>
Lastly, to zip up these files, I used bash/Cygwin.
<geshi lang="bash"> ./patchToFiles.rb patches/mypatch.patch | xargs zip mypatch.zip </geshi>