@@ -79,6 +79,9 @@ class PackageTask < TaskLib
79
79
# Zip command for zipped archives. The default is 'zip'.
80
80
attr_accessor :zip_command
81
81
82
+ # True if parent directory should be omited (default is false)
83
+ attr_accessor :without_parent_dir
84
+
82
85
# Create a Package Task with the given name and version. Use +:noversion+
83
86
# as the version to build a package without a version or to provide a
84
87
# fully-versioned package name.
@@ -102,6 +105,7 @@ def init(name, version)
102
105
@need_zip = false
103
106
@tar_command = "tar"
104
107
@zip_command = "zip"
108
+ @without_parent_dir = false
105
109
end
106
110
107
111
# Create the tasks defined by this task library.
@@ -132,7 +136,8 @@ def define
132
136
task package : [ "#{ package_dir } /#{ file } " ]
133
137
file "#{ package_dir } /#{ file } " =>
134
138
[ package_dir_path ] + package_files do
135
- chdir ( package_dir ) { sh @tar_command , "#{ flag } cvf" , file , package_name }
139
+ chdir ( working_dir ) { sh @tar_command , "#{ flag } cvf" , file , target_dir }
140
+ mv "#{ package_dir_path } /#{ target_dir } " , package_dir if without_parent_dir
136
141
end
137
142
end
138
143
end
@@ -141,7 +146,8 @@ def define
141
146
task package : [ "#{ package_dir } /#{ zip_file } " ]
142
147
file "#{ package_dir } /#{ zip_file } " =>
143
148
[ package_dir_path ] + package_files do
144
- chdir ( package_dir ) { sh @zip_command , "-r" , zip_file , package_name }
149
+ chdir ( working_dir ) { sh @zip_command , "-r" , zip_file , target_dir }
150
+ mv "#{ package_dir_path } /#{ zip_file } " , package_dir if without_parent_dir
145
151
end
146
152
end
147
153
@@ -202,6 +208,15 @@ def tar_xz_file
202
208
def zip_file
203
209
"#{ package_name } .zip"
204
210
end
211
+
212
+ def working_dir
213
+ without_parent_dir ? package_dir_path : package_dir
214
+ end
215
+
216
+ # target directory relative to working_dir
217
+ def target_dir
218
+ without_parent_dir ? "." : package_name
219
+ end
205
220
end
206
221
207
222
end
0 commit comments