Skip to content

Commit 2cabfda

Browse files
committed
Add identifer for DMG task which will be used as application id
This is optional with a few fallbacks but is required to explicitly set an application ID
1 parent 4499264 commit 2cabfda

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/com/inet/gradle/setup/dmg/Dmg.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class Dmg extends AbstractUnixSetupTask {
4444

4545
private Color backgroundColor;
4646

47+
private String applicationIdentifier;
48+
4749
private OSXCodeSign<Dmg, SetupBuilder> codeSign;
4850

4951
private List<LocalizedResource> welcomePages = new ArrayList<>();
@@ -396,4 +398,26 @@ public String getBackgroundColor() {
396398
public void setBackgroundColor( Color backgroundColor ) {
397399
this.backgroundColor = backgroundColor;
398400
}
401+
402+
/**
403+
* Returns an application identifier set for the DMG builder.
404+
* It is being used as ID in the Info.plist
405+
* @return the application identifier for macOS
406+
*/
407+
public String getApplicationIdentifier( SetupBuilder setup ) {
408+
if ( applicationIdentifier == null || applicationIdentifier.isEmpty() ) {
409+
return setup.getAppIdentifier();
410+
}
411+
return applicationIdentifier;
412+
}
413+
414+
415+
/**
416+
* Sets an application identifier for the DMG builder.
417+
* It is being used as ID in the Info.plist
418+
* @param the application identifier for macOS
419+
*/
420+
public void setApplicationIdentifier( String applicationIdentifier ) {
421+
this.applicationIdentifier = applicationIdentifier;
422+
}
399423
}

src/com/inet/gradle/setup/dmg/DmgBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.inet.gradle.setup.SetupBuilder;
3636
import com.inet.gradle.setup.Template;
3737
import com.inet.gradle.setup.abstracts.AbstractBuilder;
38-
import com.inet.gradle.setup.abstracts.Application;
3938
import com.inet.gradle.setup.abstracts.DesktopStarter;
4039
import com.inet.gradle.setup.abstracts.LocalizedResource;
4140
import com.inet.gradle.setup.abstracts.Service;
@@ -153,7 +152,8 @@ private void createBinary() throws Throwable {
153152
*/
154153
private void createServiceFiles() throws IOException {
155154

156-
Application core = new Application( setup );
155+
Service core = new Service( setup );
156+
core.setId( task.getApplicationIdentifier( setup ) );
157157

158158
// Create Pre and Post install scripts
159159
DesktopStarter runAfter = setup.getRunAfter();

src/com/inet/gradle/setup/dmg/OSXScriptBuilder.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
import com.inet.gradle.setup.Template;
1313
import com.inet.gradle.setup.abstracts.Application;
14+
import com.inet.gradle.setup.abstracts.Service;
1415

1516
/**
1617
* Create scripts from templates and replace placeholders
1718
* according to configuration/application
18-
*
19+
*
1920
* @author gamma
2021
*
2122
*/
@@ -25,7 +26,7 @@ public class OSXScriptBuilder extends Template {
2526

2627
/**
2728
* Create an OSX script using the specified template
28-
*
29+
*
2930
* @param template to create script from
3031
* @throws IOException in case of errors
3132
*/
@@ -35,7 +36,7 @@ public OSXScriptBuilder( String template ) throws IOException {
3536

3637
/**
3738
* Creates an instance and concatenates the script from the input lines
38-
*
39+
*
3940
* @param script input lines
4041
*/
4142
public OSXScriptBuilder( ArrayList<String> script ) {
@@ -44,7 +45,7 @@ public OSXScriptBuilder( ArrayList<String> script ) {
4445

4546
/**
4647
* Create an OSX script using the specified template
47-
*
48+
*
4849
* @param application to use for initial setup
4950
* @param template to create script from
5051
* @throws IOException in case of errors
@@ -61,9 +62,21 @@ public OSXScriptBuilder( Application application, String template ) throws IOExc
6162
setPlaceholder( "workingDir", application.getWorkDir() );
6263
}
6364

65+
/**
66+
* Create an OSX script using the specified template
67+
*
68+
* @param service to use for initial setup
69+
* @param template to create script from
70+
* @throws IOException in case of errors
71+
*/
72+
public OSXScriptBuilder( Service service, String template ) throws IOException {
73+
this( (Application)service, template );
74+
setPlaceholder( "serviceName", service.getId() );
75+
}
76+
6477
/**
6578
* Add another subscript. These will be inserted at the {{script}} tokens
66-
*
79+
*
6780
* @param script to add
6881
*/
6982
public void addScript( OSXScriptBuilder script ) {
@@ -72,9 +85,10 @@ public void addScript( OSXScriptBuilder script ) {
7285

7386
/**
7487
* Create a string containing all subscripts
75-
*
88+
*
7689
* @return string of all the scripts.
7790
*/
91+
@Override
7892
public String toString() {
7993

8094
StringBuilder sb = new StringBuilder();
@@ -91,10 +105,11 @@ public String toString() {
91105

92106
/**
93107
* Write file and set permissions
94-
*
108+
*
95109
* @param file to write to
96110
* @throws IOException that can occur
97111
*/
112+
@Override
98113
public void writeTo( File file ) throws IOException {
99114

100115
try (FileWriter writer = new FileWriter( file )) {

0 commit comments

Comments
 (0)