Method: Bee::Task::Java#jar
- Defined in:
- lib/bee_task_java.rb
#jar(params) ⇒ Object
Generate Jar file.
-
src: directory or list of directories to include to the archive.
-
includes: glob or list of globs for files to include in the Jar file.
-
excludes: glob or list of globs for files to exclude from the Jar file.
-
manifest: manifest file to include in generated Jar file (optional).
-
dest: the Jar file to generate.
-
options: custom options to use on command line (optional).
Example
- java.jar:
src: "#{build_dir}/classes"
dest: "#{build_dir}/myjar.jar"
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/bee_task_java.rb', line 137 def jar(params) # check parameters params_desc = { :src => { :mandatory => false, :type => :string_or_array }, :includes => { :mandatory => false, :type => :string_or_array }, :excludes => { :mandatory => false, :type => :string_or_array }, :manifest => { :mandatory => false, :type => :string }, :dest => { :mandatory => true, :type => :string }, :options => { :mandatory => false, :type => :string } } check_parameters(params, params_desc) src = params[:src] includes = params[:includes] excludes = params[:excludes] manifest = params[:manifest] dest = params[:dest] = params[:options] error "jar 'src' or 'includes' parameter must be specified" unless src or includes error "jar 'manifest' parameter must be an existing file" unless not manifest or File.exists?(manifest) # select directories to include in the Jar file directories = [] if src dirs = Array(src) for dir in dirs directories += Dir.glob(dir) end end # select files to include in the Jar file files = [] if includes files = filter_files(nil, includes, excludes) files.map! { |file| "\"#{file}\"" } end # run command line puts "Processing Jar archive '#{dest}'" command = "jar c" command += "v" if @verbose command += "m" if manifest command +="f " command += "\"#{manifest}\" " if manifest command += "\"#{dest}\" " command += "#{} " if if directories.length > 0 for dir in directories command += "-C \"#{dir}\" ." end end if files.length > 0 command += "#{files.join(' ')}" end puts "Running command '#{command}'" if @verbose ok = system(command) error "Error generating Jar archive" unless ok end |