-
Notifications
You must be signed in to change notification settings - Fork 21
/
Dmg.java
588 lines (523 loc) · 17.9 KB
/
Dmg.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*
* Copyright 2015 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.dmg;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.tools.ant.types.FileSet;
import org.gradle.api.Action;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Optional;
import org.gradle.util.ConfigureUtil;
import com.inet.gradle.appbundler.OSXCodeSign;
import com.inet.gradle.setup.SetupBuilder;
import com.inet.gradle.setup.abstracts.AbstractUnixSetupTask;
import com.inet.gradle.setup.abstracts.LocalizedResource;
import com.inet.gradle.setup.abstracts.Service;
import com.inet.gradle.setup.util.GradleUtils;
import com.oracle.appbundler.Architecture;
import groovy.lang.Closure;
/**
* The dmg Gradle task. It build a dmg package for Mac.
*
* @author Volker Berlin
*/
public class Dmg extends AbstractUnixSetupTask {
private Object backgroundImage, setupDarkBackground, setupBackground, setupIcon;
private int windowWidth = 400, windowHeight = 300, iconSize = 128, fontSize = 14, windowWidthCorrection = 0, windowHeightCorrection = 22;
private Color backgroundColor;
private String applicationIdentifier;
private boolean aquaSystemAppearanceRequired = false;
private OSXCodeSign<Dmg, SetupBuilder> codeSign;
private List<LocalizedResource> welcomePages = new ArrayList<>();
private List<LocalizedResource> conclusionPages = new ArrayList<>();
private List<PreferencesLink> preferencesLink = new ArrayList<>();
private List<String> architecture = Arrays.asList( "x86_64", "arm64" );
final List<OSXApplicationBuilder> appBuilders = new ArrayList<>();
private List<String> jreIncludes = Arrays.asList( new String[] {
"bin/java",
"lib/",
"COPYRIGHT",
"LICENSE",
"README",
"THIRDPARTYLICENSEREADME-JAVAFX.txt",
"THIRDPARTYLICENSEREADME.txt",
"Welcome.html"
} );
private List<String> jreExcludes = Arrays.asList( new String[] {
"lib/deploy/",
"lib/deploy.jar",
"lib/javaws.jar",
"lib/libdeploy.dylib",
"lib/libnpjp2.dylib",
"lib/plugin.jar",
"lib/security/javaws.policy"
} );
private List<Object> nativeLibraries = new ArrayList<>();
/**
* Create the task.
*/
public Dmg() {
super( "dmg" );
getProject().getLogger().lifecycle( "\tCreating afterEvaluate task." );
getProject().afterEvaluate( ( project ) -> {
// if the "dmg" task should be executed then create some possible extra tasks on the end of the configuration phase
boolean isExecute = GradleUtils.isTaskExecute( Dmg.this, project );
if( isExecute ) {
SetupBuilder setup = getSetupBuilder();
project.getLogger().lifecycle( "\tPreparing " + setup.getServices().size() + " appBuilders." );
for( Service service : setup.getServices() ) {
ProjectInternal projInternal = (ProjectInternal)project;
OSXApplicationBuilder builder = new OSXApplicationBuilder( Dmg.this, setup, projInternal.getFileResolver() );
builder.configSubTasks( service );
appBuilders.add( builder );
}
} else {
project.getLogger().lifecycle( "\tDMG is not marked for task execution." );
}
} );
}
/**
* {@inheritDoc}
*/
@Override
public void build() {
ProjectInternal project = (ProjectInternal)getProject();
getProject().getLogger().lifecycle( "\tStarting the build." );
new DmgBuilder( this, getSetupBuilder(), project.getFileResolver() ).build();
}
/**
* Return width of Finder view INCLUDING the correction settings
*
* @return width of Finder view
*/
@Input
public int getWindowWidth() {
return windowWidth + windowWidthCorrection;
}
/**
* Set width of Finder view
*
* @param windowWidth width of Finder view
*/
public void setWindowWidth( int windowWidth ) {
this.windowWidth = windowWidth;
}
/**
* Return correction width of Finder view
* This may be needed if there is a background-image
* set which does not take the borders of the window into account
*
* @return width correction of Finder view
*/
@Input
public int getWindowWidthCorrection() {
return windowWidthCorrection;
}
/**
* Set correction width of Finder view
* This may be needed if there is a background-image
* set which does not take the borders of the window into account
*
* @param windowWidthCorrection width of Finder view
*/
public void setWindowWidthCorrection( int windowWidthCorrection ) {
this.windowWidthCorrection = windowWidthCorrection;
}
/**
* Return height of Finder view INCLUDING the correction settings
*
* @return height of Finder view
*/
@Input
public int getWindowHeight() {
return windowHeight + windowHeightCorrection;
}
/**
* Set height of Finder view
*
* @param windowHeight of Finder view
*/
public void setWindowHeight( int windowHeight ) {
this.windowHeight = windowHeight;
}
/**
* Return correction height of Finder view
* This may be needed if there is a background-image
* set which does not take the borders of the window into account
*
* @return width correction of Finder view
*/
@Input
public int getWindowHeightCorrection() {
return windowHeightCorrection;
}
/**
* Set correction height of Finder view
* This may be needed if there is a background-image
* set which does not take the borders of the window into account
*
* @param windowHeightCorrection height of Finder view
*/
public void setWindowHeightCorrection( int windowHeightCorrection ) {
this.windowHeightCorrection = windowHeightCorrection;
}
/**
* Return size of icons in Finder view
*
* @return size of icons in Finder view
*/
@Input
public int getIconSize() {
return iconSize;
}
/**
* Set size of icons in Finder view
*
* @param iconSize of icons in Finder view
*/
public void setIconSize( int iconSize ) {
this.iconSize = iconSize;
}
/**
* Return background Image for Finder View
*
* @return background Image for Finder View
*/
@InputFile
@Optional
public File getBackgroundImage() {
if( backgroundImage != null ) {
return getProject().file( backgroundImage );
}
return null;
}
/**
* Set background Image for Finder View
*
* @param backgroundFile Image for Finder View
*/
public void setBackgroundImage( File backgroundFile ) {
this.backgroundImage = backgroundFile;
}
/**
* Return font size for Finder View
*
* @return font size for Finder View
*/
@Input
public int getFontSize() {
return fontSize;
}
/**
* Set font size for Finder View
*
* @param fontSize size for Finder View
*/
public void setFontSize( int fontSize ) {
this.fontSize = fontSize;
}
/**
* Set the needed information for signing the setup.
*
* @param closure the data for signing
*/
public void setCodeSign( Closure<OSXCodeSign<Dmg, SetupBuilder>> closure ) {
ProjectInternal project = (ProjectInternal)getProject();
codeSign = ConfigureUtil.configure( closure, new OSXCodeSign<Dmg, SetupBuilder>( this, project.getFileResolver() ) );
}
/**
* Set the needed information for signing the setup.
*
* @param action the data for signing
*/
public void setCodeSign( Action<? super OSXCodeSign<? super Dmg,? super SetupBuilder>> action ) {
ProjectInternal project = (ProjectInternal)getProject();
codeSign = new OSXCodeSign<>(this, project.getFileResolver());
action.execute(codeSign);
}
/**
* Get the SignTool configuration if set
*
* @return the settings or null
*/
@Input
@Optional
public OSXCodeSign<Dmg, SetupBuilder> getCodeSign() {
return codeSign;
}
/**
* Return the welcome page list
* Allowed Format: rtf, rtfd, txt, html
*
* @return welcome page
*/
@Input
@Optional
public List<LocalizedResource> getConclusionPages() {
return conclusionPages;
}
/**
* Set the welcome page
* Allowed Format: rtf, rtfd, txt, html
*
* @param conclusionPage which is shown at the end
*/
public void conclusionPage( Object conclusionPage ) {
LocalizedResource.addLocalizedResource( getSetupBuilder(), conclusionPages, conclusionPage );
}
/**
* Return the welcome page list
* Allowed Format: rtf, rtfd, txt, html
*
* @return welcome page
*/
@Input
@Optional
public List<LocalizedResource> getWelcomePages() {
return welcomePages.size() > 0 ? welcomePages : getSetupBuilder().getLongDescriptions();
}
/**
* Set the welcome page
* Allowed Format: rtf, rtfd, txt, html
*
* @param welcomePage welcome page file
*/
public void welcomePage( Object welcomePage ) {
LocalizedResource.addLocalizedResource( getSetupBuilder(), welcomePages, welcomePage );
}
/**
* Return the background image for the setup
*
* @return background image
*/
@InputFile
@Optional
public File getSetupBackgroundImage() {
if( setupBackground != null ) {
return getProject().file( setupBackground );
}
return null;
}
/**
* Set the background image for the setup
*
* @param setupBackground to set
*/
public void setSetupBackgroundImage( Object setupBackground ) {
this.setupBackground = setupBackground;
}
/**
* Returns a dark background image for the package installer
*
* @return a dark background image for the package installer
*/
@InputFile
@Optional
public File getSetupDarkBackgroundImage() {
if( setupDarkBackground != null ) {
return getProject().file( setupDarkBackground );
}
return null;
}
/**
* Set the dark background image for the package installer
*
* @param setupDarkBackground to set
*/
public void setSetupDarkBackgroundImage( Object setupDarkBackground ) {
this.setupDarkBackground = setupDarkBackground;
}
/**
* Returns the setup icon
*
* @return the setupIcon
*/
@Input
@Optional
public Object getSetupIcon() {
if( setupIcon == null ) {
return getSetupBuilder().getIcons();
}
return setupIcon;
}
/**
* Set up the setup icon
*
* @param setupIcon the setupIcon to set
*/
public void setSetupIcon( Object setupIcon ) {
this.setupIcon = setupIcon;
}
/**
* Return the list of preferences links
*
* @return preferences links
*/
@Input
@Optional
public List<PreferencesLink> getPreferencesLinks() {
return preferencesLink;
}
/**
* Set a preferences link
*
* @param action the link
*/
public void preferencesLink( Action<? super PreferencesLink> action ) {
final PreferencesLink link = new PreferencesLink();
action.execute(link);
preferencesLink.add(link);
}
/**
* Get a list of string - defining files - that should be included in the bundled JRE
*
* @return the jreIncludes
*/
@Input
@Optional
public List<String> getJreIncludes() {
return jreIncludes;
}
/**
* Set a list of string - defining files - that should be included in the bundled JRE
*
* @param jreIncludes the jreIncludes to set
*/
public void setJreIncludes( List<String> jreIncludes ) {
this.jreIncludes = jreIncludes;
}
/**
* Get a list of string - defining files - that should be excluded from the bundled JRE
*
* @return the jreExclude
*/
@Input
@Optional
public List<String> getJreExcludes() {
return jreExcludes;
}
/**
* Set a list of string - defining files - that should be excluded from the bundled JRE
*
* @param jreExclude the jreExclude to set
*/
public void setJreExcludes( List<String> jreExclude ) {
this.jreExcludes = jreExclude;
}
/**
* Get a list of supported architectures that will be added to the Info.plist file
* @return the list of architectures
*/
@Input
@Optional
public List<String> getArchitecture() {
return architecture;
}
/**
* Create a list of architectures from the given input list of strings.
* @param architecture the list of supported architectures
*/
public void setArchitecture( List<String> architecture ) {
this.architecture = architecture;
}
/**
* Returns the converted background color as apple script string
*
* @return the backgroundColor as dmgbuild color string
*/
@Input
public String getBackgroundColor() {
if( backgroundColor == null ) {
// Fallback
backgroundColor = new Color( 255, 255, 255 );
}
float base = 1.0f / 255.0f;
return "rgb(" + String.join( ", ", Arrays.asList( String.valueOf( backgroundColor.getRed() * base ), String.valueOf( backgroundColor.getGreen() * base ), String.valueOf( backgroundColor.getBlue() * base ) ) ) + ")";
}
/**
* @param backgroundColor the backgroundColor to set
*/
public void setBackgroundColor( Color backgroundColor ) {
this.backgroundColor = backgroundColor;
}
/**
* Returns an application identifier set for the DMG builder.
* It is being used as ID in the Info.plist
*
* @param setup the SetupBuilder instance for a fallback
* @return the application identifier for macOS
*/
public String getApplicationIdentifier( SetupBuilder setup ) {
if( applicationIdentifier == null || applicationIdentifier.isEmpty() ) {
if( setup.getMainClass() == null || setup.getMainClass().isEmpty() ) {
return setup.getAppIdentifier();
}
return setup.getMainClass();
}
return applicationIdentifier;
}
/**
* Sets an application identifier for the DMG builder.
* It is being used as ID in the Info.plist
*
* @param applicationIdentifier the application identifier for macOS
*/
public void setApplicationIdentifier( String applicationIdentifier ) {
this.applicationIdentifier = applicationIdentifier;
}
/**
* Returns true, if the application requires the aqua system appearance. False by default
*
* @return true, if the application requires the aqua system appearance.
*/
@Input
public boolean isAquaSystemAppearanceRequired() {
return aquaSystemAppearanceRequired;
}
/**
* Define, that the application requires the system appearance. False by default
*
* @param aquaSystemAppearanceRequired true, if the system appearance is required.
*/
public void setAquaSystemAppearanceRequired( boolean aquaSystemAppearanceRequired ) {
this.aquaSystemAppearanceRequired = aquaSystemAppearanceRequired;
}
/**
* add a native library using any gradle compatible file syntax
* @param library a native library to add
*/
public void nativeLibraries( Object library ) {
nativeLibraries.add( library );
}
/**
* Returns the list of native libraries set for the current project
* @return the list of native libraries set for the current project
*/
@Input
public List<FileSet> getNativeLibraries() {
return nativeLibraries.stream().map( e -> {
FileSet set = new FileSet();
set.setDir( getProject().file( e ) );
return set;
} ).collect( Collectors.toList() );
}
}