buildrizpack 0.2-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'buildrizpack/package'
@@ -0,0 +1,224 @@
1
+ # encoding: UTF-8
2
+ # :include:../../README.rdoc
3
+ # Licensed to the Apache Software Foundation (ASF) under one or more
4
+ # contributor license agreements. See the NOTICE file distributed with this
5
+ # work for additional information regarding copyright ownership. The ASF
6
+ # licenses this file to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations under
16
+ # the License.
17
+
18
+ require "rexml/document"
19
+ include REXML
20
+
21
+ module BuildrIzPack
22
+
23
+ # A simple helper class to create a single pack
24
+ #
25
+ class Pack
26
+ # The path to be used by the IzPack-installer for this pack. Defaults to
27
+ attr_reader :defaultPath
28
+ # A hast of the files to be packed (src => installpath)
29
+ attr_reader :files
30
+ # A more elaborate description of the pack
31
+ attr_reader :description
32
+ # Attributes of the pack. a hash of name => value, eg. 'require' => 'yes'
33
+ attr_reader :attributes
34
+ # Initialize an IzPack-Pack by name, description.
35
+ # :attributes: Attributes of the pack, a Hash, eg. { 'required' => 'yes' }
36
+ def initialize(name, description, attributes = {}, defaultPath = '$INSTALL_PATH/plugins')
37
+ @description = description
38
+ @attributes = attributes
39
+ @attributes['name'] = name
40
+ @files = Hash.new
41
+ @defaultPath = defaultPath
42
+ @attributes['required'] = 'no' if !@attributes['required']
43
+ end
44
+
45
+ # Add a single file to the pack
46
+ def addFile(src, dest=nil)
47
+ orig = dest
48
+ dest = File.join(@defaultPath, File.basename(src)) if !dest
49
+ @files[src] = dest
50
+ end
51
+
52
+ # collect the XML representation for the pack using an XMLMarkup object
53
+ def emitIzPackXML(xm)
54
+ # raise "xm must be an Builder::XmlMarkup object, but is #{xm.class}" if xm.class != Builder::XmlMarkup
55
+ xm.pack(@attributes) {
56
+ xm.description(@description)
57
+ @files.each{ |src, dest| xm.singlefile('src'=> src, 'target' =>dest) }
58
+ }
59
+ end
60
+ end
61
+
62
+ class IzPackTask < Buildr::ArchiveTask
63
+
64
+ # a hash of name => value to be passed when calling the izpack installer
65
+ # See also IzPackTask.html[http://www.jarvana.com/jarvana/view/org/codehaus/izpack/izpack-standalone-compiler/4.0.1/izpack-standalone-compiler-4.0.1-javadoc.jar!/com/izforge/izpack/ant/IzPackTask.html]
66
+ attr_accessor :properties
67
+ # "IzPack"[http://izpack.org/documentation/installation-files.html] to be used as starting point for calling the izpack installer
68
+ # some or all of its content may be overwritten, if you specify other attributes, e.g.
69
+ # if you want to specify one or mor pack bundles with a file list maintained by buildr.
70
+ # If not specified BuildrIzPack will create one at File.join(project.path_to(:target, 'install.xml'))
71
+ attr_accessor :input
72
+ # ther version of the izpack installer to be used. Defaults to 4.3.5
73
+ attr_accessor :izpackVersion
74
+ # Application name used by the IzPack installer. Defaults to the current project
75
+ attr_accessor :appName
76
+ # The installer output directory and filename (defaults to <project>-<version>.izpack)
77
+ attr_accessor :output
78
+ # The base directory of compilation process (defaults project.path_to(:target))
79
+ attr_accessor :basedir
80
+ # The installer type (defaults to standard). You can select between standard and web.
81
+ attr_accessor :installerType
82
+ # It seems that in order to propagate all project properties to the the izpack compiler you need to set the inheritAll attribute to "true".
83
+ # Therefore it defaults to true
84
+ attr_accessor :inheritAll
85
+ # defaults to deflate. You can select between default, deflate and raw.
86
+ attr_accessor :compression
87
+ # defaults to 9. The compression level of the installation (defaults to -1 for no compression). Valid values are -1 to 9.
88
+ attr_accessor :compressionLevel
89
+ # the packs (including attributes, fileset, os-dependencies etc). Must be an array of XmlMarkup object.
90
+ attr_accessor :packs
91
+
92
+ # The supported locale's for the installer. Must be an array of XmlMarkup object. Defaults to ['eng']
93
+ # For details look at IzPacks installation.dtd (Distributed with this gem)
94
+ attr_accessor :locales
95
+ # IzPacks panels's. Must be an array of XmlMarkup object. Defaults to ['TargetPanel', 'InstallPack']
96
+ attr_accessor :panels
97
+ # the supported locale's. Must be an array of XmlMarkup object. Defaults to 680 x 520
98
+ attr_accessor :guiprefs
99
+
100
+ attr_accessor :packaging, :properties, :variables, :dynamicvariables, :conditions, :installerrequirements,:resources,
101
+ :listeners, :jar, :native
102
+
103
+ # The ArchiveTask class delegates this method
104
+ # so we can create the archive.
105
+ # the file_map is the result of the computations of the include and exclude filters.
106
+ #
107
+ def create_from(file_map)
108
+ @izpackVersion ||= '4.3.5'
109
+ @appName ||= project.id
110
+ @izpackBaseDir = File.dirname(@output) if !@izpackBaseDir
111
+ @installerType ||= 'standard'
112
+ @inheritAll ||= 'true'
113
+ @compression ||= 'deflate'
114
+ @compressionLevel ||= '9'
115
+ @locales ||= ['eng']
116
+ @panels ||= ['TargetPanel', 'InstallPanel']
117
+ @packs ||=
118
+ raise "You must include at least one file to create an izPack installer" if file_map.size == 0 and !File.exists?(@input)
119
+ izPackArtifact = Buildr.artifact( "org.codehaus.izpack:izpack-standalone-compiler:jar:#{@izpackVersion}")
120
+ doc = nil
121
+ if !File.exists?(@input)
122
+ genInstaller(Builder::XmlMarkup.new(:target=>File.open(@input, 'w+'), :indent => 2), file_map)
123
+ # genInstaller(Builder::XmlMarkup.new(:target=>$stdout, :indent => 2), file_map)
124
+ # genInstaller(Builder::XmlMarkup.new(:target=>File.open('/home/niklaus/tmp2.xml', 'w+'), :indent => 2), file_map)
125
+ end
126
+ Buildr.ant('izpack-ant') do |x|
127
+ izPackArtifact.invoke
128
+ msg = "Generating izpack aus #{File.expand_path(@input)}"
129
+ trace msg
130
+ if properties
131
+ properties.each{ |name, value|
132
+ puts "Need added property #{name} with value #{value}"
133
+ x.property(:name => name, :value => value)
134
+ }
135
+ end
136
+ x.echo(:message =>msg)
137
+ x.taskdef :name=>'izpack',
138
+ :classname=>'com.izforge.izpack.ant.IzPackTask',
139
+ :classpath=>izPackArtifact.to_s
140
+ x.izpack :input=> @input,
141
+ :output => @output,
142
+ :basedir => @izpackBaseDir,
143
+ :installerType=> @installerType,
144
+ :inheritAll=> @inheritAll,
145
+ :compression => @compression,
146
+ :compressionLevel => @compressionLevel do
147
+ end
148
+ end
149
+ end
150
+
151
+ private
152
+ def genInstaller(xm, file_map)
153
+ xm.instruct!
154
+ xm.installation('version'=>'1.0') {
155
+ xm.tag!('info') { xm.appname(@appName); xm.appversion(@version)}
156
+ if @guiprefs then xm << @guiprefs
157
+ else
158
+ xm.guiprefs('width' => '680', 'height' => '520', 'resizable' => 'yes')
159
+ end
160
+ if @panels.class == String then xm << @panels
161
+ else
162
+ xm.panels {
163
+ @panels.each{ |x| xm.panel('classname' => x) }
164
+ }
165
+ end
166
+ if @panels.class == String then xm << @panels
167
+ else
168
+ xm.locale {
169
+ @locales.each{ |x| xm.langpack('iso3'=>x) }
170
+ }
171
+ end
172
+ if @packs then xm << @packs
173
+ else
174
+ #default definiton of packs
175
+ xm.packs {
176
+ xm.pack('name' => 'main', 'required' => 'yes') {
177
+ xm.description("Main pack of #{@appName}")
178
+ file_map.each{ |src,aJar|
179
+ xm.file('src'=> aJar, 'targetdir' =>'$INSTALL_PATH')
180
+ }
181
+ }
182
+ }
183
+ end
184
+ [@packaging, @properties, @variables, @dynamicvariables, @conditions, @installerrequirements,@resources,@listeners, @jar, @native].each do
185
+ |element|
186
+ xm << element if element
187
+ end
188
+
189
+ }
190
+ # Don't close $stdout
191
+ xm.target!().close if xm.target!.class == File
192
+ end
193
+
194
+ end
195
+
196
+ module ActAsIzPackPackager
197
+ include Extension
198
+
199
+ def package_as_izpack(file_name)
200
+ izpack = IzPackTask.define_task(file_name)
201
+ izpack.enhance do |task|
202
+ task.enhance do
203
+ package ||= project.id
204
+ version ||= project.version
205
+ end
206
+ task.input ||= File.join(project.path_to(:target, 'install.xml'))
207
+ task.appName ||= project.id
208
+ task.output ||= file_name
209
+ task.basedir ||= project.path_to(:target)
210
+ task.installerType ||= 'standard'
211
+ task.inheritAll ||= 'true'
212
+ task.compression ||= 'deflate'
213
+ task.compressionLevel ||= '9'
214
+ end
215
+ return izpack
216
+ end
217
+ end
218
+ end
219
+
220
+ module Buildr
221
+ class Project
222
+ include BuildrIzPack::ActAsIzPackPackager
223
+ end
224
+ end
@@ -0,0 +1,224 @@
1
+ # encoding: UTF-8
2
+ # :include:../../README.rdoc
3
+ # Licensed to the Apache Software Foundation (ASF) under one or more
4
+ # contributor license agreements. See the NOTICE file distributed with this
5
+ # work for additional information regarding copyright ownership. The ASF
6
+ # licenses this file to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations under
16
+ # the License.
17
+
18
+ require "rexml/document"
19
+ include REXML
20
+
21
+ module BuildrIzPack
22
+
23
+ # A simple helper class to create a single pack
24
+ #
25
+ class Pack
26
+ # The path to be used by the IzPack-installer for this pack. Defaults to
27
+ attr_reader :defaultPath
28
+ # A hast of the files to be packed (src => installpath)
29
+ attr_reader :files
30
+ # A more elaborate description of the pack
31
+ attr_reader :description
32
+ # Attributes of the pack. a hash of name => value, eg. 'require' => 'yes'
33
+ attr_reader :attributes
34
+ # Initialize an IzPack-Pack by name, description.
35
+ # :attributes: Attributes of the pack, a Hash, eg. { 'required' => 'yes' }
36
+ def initialize(name, description, attributes = {}, defaultPath = '$INSTALL_PATH/plugins')
37
+ @description = description
38
+ @attributes = attributes
39
+ @attributes['name'] = name
40
+ @files = Hash.new
41
+ @defaultPath = defaultPath
42
+ @attributes['required'] = 'no' if !@attributes['required']
43
+ end
44
+
45
+ # Add a single file to the pack
46
+ def addFile(src, dest=nil)
47
+ orig = dest
48
+ dest = File.join(@defaultPath, File.basename(src)) if !dest
49
+ @files[src] = dest
50
+ end
51
+
52
+ # collect the XML representation for the pack using an XMLMarkup object
53
+ def emitIzPackXML(xm)
54
+ # raise "xm must be an Builder::XmlMarkup object, but is #{xm.class}" if xm.class != Builder::XmlMarkup
55
+ xm.pack(@attributes) {
56
+ xm.description(@description)
57
+ @files.each{ |src, dest| xm.singlefile('src'=> src, 'target' =>dest) }
58
+ }
59
+ end
60
+ end
61
+
62
+ class IzPackTask < Buildr::ArchiveTask
63
+
64
+ # a hash of name => value to be passed when calling the izpack installer
65
+ # See also IzPackTask.html[http://www.jarvana.com/jarvana/view/org/codehaus/izpack/izpack-standalone-compiler/4.0.1/izpack-standalone-compiler-4.0.1-javadoc.jar!/com/izforge/izpack/ant/IzPackTask.html]
66
+ attr_accessor :properties
67
+ # "IzPack"[http://izpack.org/documentation/installation-files.html] to be used as starting point for calling the izpack installer
68
+ # some or all of its content may be overwritten, if you specify other attributes, e.g.
69
+ # if you want to specify one or mor pack bundles with a file list maintained by buildr.
70
+ # If not specified BuildrIzPack will create one at File.join(project.path_to(:target, 'install.xml'))
71
+ attr_accessor :input
72
+ # ther version of the izpack installer to be used. Defaults to 4.3.5
73
+ attr_accessor :izpackVersion
74
+ # Application name used by the IzPack installer. Defaults to the current project
75
+ attr_accessor :appName
76
+ # The installer output directory and filename (defaults to <project>-<version>.izpack)
77
+ attr_accessor :output
78
+ # The base directory of compilation process (defaults project.path_to(:target))
79
+ attr_accessor :basedir
80
+ # The installer type (defaults to standard). You can select between standard and web.
81
+ attr_accessor :installerType
82
+ # It seems that in order to propagate all project properties to the the izpack compiler you need to set the inheritAll attribute to "true".
83
+ # Therefore it defaults to true
84
+ attr_accessor :inheritAll
85
+ # defaults to deflate. You can select between default, deflate and raw.
86
+ attr_accessor :compression
87
+ # defaults to 9. The compression level of the installation (defaults to -1 for no compression). Valid values are -1 to 9.
88
+ attr_accessor :compressionLevel
89
+ # the packs (including attributes, fileset, os-dependencies etc). Must be an array of XmlMarkup object.
90
+ attr_accessor :packs
91
+
92
+ # The supported locale's for the installer. Must be an array of XmlMarkup object. Defaults to ['eng']
93
+ # For details look at IzPacks installation.dtd (Distributed with this gem)
94
+ attr_accessor :locales
95
+ # IzPacks panels's. Must be an array of XmlMarkup object. Defaults to ['TargetPanel', 'InstallPack']
96
+ attr_accessor :panels
97
+ # the supported locale's. Must be an array of XmlMarkup object. Defaults to 680 x 520
98
+ attr_accessor :guiprefs
99
+
100
+ attr_accessor :packaging, :properties, :variables, :dynamicvariables, :conditions, :installerrequirements,:resources,
101
+ :listeners, :jar, :native
102
+
103
+ # The ArchiveTask class delegates this method
104
+ # so we can create the archive.
105
+ # the file_map is the result of the computations of the include and exclude filters.
106
+ #
107
+ def create_from(file_map)
108
+ @izpackVersion ||= '4.3.5'
109
+ @appName ||= project.id
110
+ @izpackBaseDir = File.dirname(@output) if !@izpackBaseDir
111
+ @installerType ||= 'standard'
112
+ @inheritAll ||= 'true'
113
+ @compression ||= 'deflate'
114
+ @compressionLevel ||= '9'
115
+ @locales ||= ['eng']
116
+ @panels ||= ['TargetPanel', 'InstallPanel']
117
+ @packs ||=
118
+ raise "You must include at least one file to create an izPack installer" if file_map.size == 0 and !File.exists?(@input)
119
+ izPackArtifact = Buildr.artifact( "org.codehaus.izpack:izpack-standalone-compiler:jar:#{@izpackVersion}")
120
+ doc = nil
121
+ if !File.exists?(@input)
122
+ genInstaller(Builder::XmlMarkup.new(:target=>File.open(@input, 'w+'), :indent => 2), file_map)
123
+ # genInstaller(Builder::XmlMarkup.new(:target=>$stdout, :indent => 2), file_map)
124
+ # genInstaller(Builder::XmlMarkup.new(:target=>File.open('/home/niklaus/tmp2.xml', 'w+'), :indent => 2), file_map)
125
+ end
126
+ Buildr.ant('izpack-ant') do |x|
127
+ izPackArtifact.invoke
128
+ msg = "Generating izpack aus #{File.expand_path(@input)} #{File.size(@input)}"
129
+ trace msg
130
+ if properties
131
+ properties.each{ |name, value|
132
+ puts "Need added property #{name} with value #{value}"
133
+ x.property(:name => name, :value => value)
134
+ }
135
+ end
136
+ x.echo(:message =>msg)
137
+ x.taskdef :name=>'izpack',
138
+ :classname=>'com.izforge.izpack.ant.IzPackTask',
139
+ :classpath=>izPackArtifact.to_s
140
+ x.izpack :input=> @input,
141
+ :output => @output,
142
+ :basedir => @izpackBaseDir,
143
+ :installerType=> @installerType,
144
+ :inheritAll=> @inheritAll,
145
+ :compression => @compression,
146
+ :compressionLevel => @compressionLevel do
147
+ end
148
+ end
149
+ end
150
+
151
+ private
152
+ def genInstaller(xm, file_map)
153
+ xm.instruct!
154
+ xm.installation('version'=>'1.0') {
155
+ xm.tag!('info') { xm.appname(@appName); xm.appversion(@version)}
156
+ if @guiprefs then xm << @guiprefs
157
+ else
158
+ xm.guiprefs('width' => '680', 'height' => '520', 'resizable' => 'yes')
159
+ end
160
+ if @panels.class == String then xm << @panels
161
+ else
162
+ xm.panels {
163
+ @panels.each{ |x| xm.panel('classname' => x) }
164
+ }
165
+ end
166
+ if @panels.class == String then xm << @panels
167
+ else
168
+ xm.locale {
169
+ @locales.each{ |x| xm.langpack('iso3'=>x) }
170
+ }
171
+ end
172
+ if @packs then xm << @packs
173
+ else
174
+ #default definiton of packs
175
+ xm.packs {
176
+ xm.pack('name' => 'main', 'required' => 'yes') {
177
+ xm.description("Main pack of #{@appName}")
178
+ file_map.each{ |src,aJar|
179
+ xm.file('src'=> aJar, 'targetdir' =>'$INSTALL_PATH')
180
+ }
181
+ }
182
+ }
183
+ end
184
+ [@packaging, @properties, @variables, @dynamicvariables, @conditions, @installerrequirements,@resources,@listeners, @jar, @native].each do
185
+ |element|
186
+ xm << element if element
187
+ end
188
+
189
+ }
190
+ # Don't close $stdout
191
+ xm.target!().close if xm.target!.class == File
192
+ end
193
+
194
+ end
195
+
196
+ module ActAsIzPackPackager
197
+ include Extension
198
+
199
+ def package_as_izpack(file_name)
200
+ izpack = IzPackTask.define_task(file_name)
201
+ izpack.enhance do |task|
202
+ task.enhance do
203
+ package ||= project.id
204
+ version ||= project.version
205
+ end
206
+ task.input ||= File.join(project.path_to(:target, 'install.xml'))
207
+ task.appName ||= project.id
208
+ task.output ||= file_name
209
+ task.basedir ||= project.path_to(:target)
210
+ task.installerType ||= 'standard'
211
+ task.inheritAll ||= 'true'
212
+ task.compression ||= 'deflate'
213
+ task.compressionLevel ||= '9'
214
+ end
215
+ return izpack
216
+ end
217
+ end
218
+ end
219
+
220
+ module Buildr
221
+ class Project
222
+ include BuildrIzPack::ActAsIzPackPackager
223
+ end
224
+ end