-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathSetupBuilder.java
375 lines (326 loc) · 10.7 KB
/
SetupBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* Copyright 2015 - 2021 i-net software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.inet.gradle.setup;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.util.ConfigureUtil;
import com.inet.gradle.setup.abstracts.AbstractSetupBuilder;
import com.inet.gradle.setup.abstracts.DesktopStarter;
import com.inet.gradle.setup.abstracts.LocalizedResource;
import com.inet.gradle.setup.abstracts.Service;
import com.inet.gradle.setup.abstracts.SetupSources;
import groovy.lang.Closure;
/**
* The Gradle extension for all setup tasks.
*
* @author Volker Berlin
*/
public class SetupBuilder extends AbstractSetupBuilder implements SetupSources {
private List<LocalizedResource> licenseFiles = new ArrayList<>();
private List<LocalizedResource> longDescription = new ArrayList<>();
private String defaultResourceLanguage = "en";
private DesktopStarter runAfter, runBeforeUninstall;
private List<Service> services = new ArrayList<>();
private final List<DesktopStarter> desktopStarters = new ArrayList<>();
private List<String> deleteFiles = new ArrayList<>();
private List<String> deleteFolders = new ArrayList<>();
private String minUpdateVersion;
private String minUpdateMessage;
/**
* Create a new instance.
*
* @param project current project
*/
public SetupBuilder( Project project ) {
super( project );
}
/**
* Return the license files
*
* @return licenseFiles list of license files
*/
public List<LocalizedResource> getLicenseFiles() {
return licenseFiles;
}
/**
* Return the license file for a specific locale
*
* @param locale for which to get the file
* @return license file
*/
public File getLicenseFile( String locale ) {
return LocalizedResource.getLocalizedResourceFile( licenseFiles, locale );
}
/**
* Set the license file
*
* @param license license file or closure
*/
public void setLicenseFile( Object license ) {
licenseFiles.clear();
licenseFile( license );
}
/**
* Add a license file
*
* @param license license file or closure
*/
public void licenseFile( Object license ) {
LocalizedResource.addLocalizedResource( this, licenseFiles, license );
}
/**
* A command that run after the installer.
*
* @return the command or null
*/
public DesktopStarter getRunAfter() {
return runAfter;
}
/**
* Set a command that run after the installer.
*
* @param runAfter the command
*/
public void setRunAfter( String runAfter ) {
this.runAfter = new DesktopStarter( this );
this.runAfter.setExecutable( runAfter );
}
/**
* Set a command that run after the installer.
*
* @param closure the command
*/
public void runAfter( Closure<?> closure ) {
runAfter = ConfigureUtil.configure( closure, new DesktopStarter( this ) );
}
/**
* Set a command that run after the installer.
*
* @param action the command
*/
public void runAfter( Action<? super DesktopStarter> action ) {
runAfter = new DesktopStarter( this );
action.execute(runAfter);
}
/**
* A command that run before the uninstaller.
*
* @return the command or null
*/
public DesktopStarter getRunBeforeUninstall() {
return runBeforeUninstall;
}
/**
* Set a command that run before the uninstaller.
*
* @param runAfter the command
*/
public void setRunBeforeUninstall( String runAfter ) {
this.runBeforeUninstall = new DesktopStarter( this );
this.runBeforeUninstall.setExecutable( runAfter );
}
/**
* Set a command that run run before the uninstaller.
*
* @param closue the command
*/
public void runBeforeUninstall( Closure<DesktopStarter> closue ) {
runBeforeUninstall = ConfigureUtil.configure( closue, new DesktopStarter( this ) );
}
/**
* Set a command that run run before the uninstaller.
*
* @param action the command
*/
public void runBeforeUninstall( Action<? super DesktopStarter> action ) {
runBeforeUninstall = new DesktopStarter( this );
action.execute(runBeforeUninstall);
}
/**
* Register a service.
*
* @param closue the closure of the service definition
*/
public void service( Closure<Service> closue ) {
Service service = ConfigureUtil.configure( closue, new Service( this ) );
services.add( service );
}
/**
* Register a service.
*
* @param action the closure of the service definition
*/
public void service( Action<? super Service> action ) {
Service service = new Service( this );
action.execute(service);
services.add( service );
}
/**
* Returns the registered services.
*
* @return the registered services
*/
public List<Service> getServices() {
return services;
}
/**
* Register a desktop starter.
*
* @param closue the closure of the desktop starter's definition
*/
public void desktopStarter( Closure<?> closue ) {
DesktopStarter service = ConfigureUtil.configure( closue, new DesktopStarter( this ) );
desktopStarters.add( service );
}
/**
* Register a desktop starter.
*
* @param action the closure of the desktop starter's definition
*/
public void desktopStarter( Action<? super DesktopStarter> action ) {
DesktopStarter service = new DesktopStarter( this );
action.execute(service);
desktopStarters.add( service );
}
/**
* Returns the registered desktop starters.
*
* @return the registered desktop starters, never null, can be empty.
*/
public List<DesktopStarter> getDesktopStarters() {
return desktopStarters;
}
/**
* Get the list pattern for files that should be deleted.
*
* @return the list
*/
public List<String> getDeleteFiles() {
return deleteFiles;
}
/**
* Add a file pattern to delete files before install and after uninstall.
*
* @param pattern the patter. Can contains * and ? characters
*/
public void deleteFiles( String pattern ) {
if( pattern.isEmpty() ) {
return;
}
deleteFiles.add( pattern );
}
/**
* Get the list of folders to delete.
*
* @return the list
*/
public List<String> getDeleteFolders() {
return deleteFolders;
}
/**
* Add a folder to delete before install and after uninstall. It delete the folder with all sub directories.
*
* @param folder the folder
*/
public void deleteFolder( String folder ) {
this.deleteFolders.add( folder );
}
/**
* @return the defaultResourceLanguage
*/
public String getDefaultResourceLanguage() {
return defaultResourceLanguage;
}
/**
* @param defaultResourceLanguage the defaultResourceLanguage to set
*/
public void setDefaultResourceLanguage( String defaultResourceLanguage ) {
this.defaultResourceLanguage = defaultResourceLanguage;
}
/**
* Return the description files
*
* @return licenseFiles list of license files
*/
public List<LocalizedResource> getLongDescriptions() {
return longDescription;
}
/**
* Return the description file for a specific locale
*
* @param locale for which to get the file
* @return license file
*/
public File getLongDescription( String locale ) {
return LocalizedResource.getLocalizedResourceFile( longDescription, locale );
}
/**
* Set the description file
*
* @param description file or closure
*/
public void longDescription( Object description ) {
LocalizedResource.addLocalizedResource( this, longDescription, description );
}
/**
* Return the minimum supported version for an update.
*
* @return the version or null
*/
public String getMinimumUpdateVersion() {
return minUpdateVersion;
}
/**
* Return the minimum supported version error message.
*
* @return the message or null
*/
public String getMinimumUpdateMessage() {
return minUpdateMessage;
}
/**
* Set the oldest version which will be updated. If an already installed version is older then the update will be cancel.
* A default error message is used.
* @param version the version
*/
public void setMinimumUpdateMessage( String version ) {
minimumUpdateVersion( version, null );
}
/**
* Set the oldest version which will be updated. If an already installed version is older then the update will be cancel.
* A default error message is used.
* @param version the version
*/
public void minimumUpdateVersion( String version ) {
minimumUpdateVersion( version, null );
}
/**
* Set the oldest version which will be updated. If an already installed version is older then the update will be cancel.
* If no message is set a default error message is used.
* @param version the version
* @param message the error message for the user
*/
public void minimumUpdateVersion( String version, String message ) {
if( version != null && message == null ) {
message = "Updates are only supported from version " + version + " or later.";
}
minUpdateVersion = version;
minUpdateMessage = message;
}
}