Skip to content

Commit 127087b

Browse files
committed
Make jre Include / Exclude configurable
This will allow OSX users to change the included and excluded files of a java runtime if needed.
1 parent 625f312 commit 127087b

File tree

3 files changed

+131
-43
lines changed

3 files changed

+131
-43
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,16 @@ protected void bundleJre() {
187187
}
188188
task.getProject().getLogger().lifecycle( "\tbundle JRE: " + jreDir );
189189

190-
Runtime runtime = new Runtime();
191-
runtime.appendIncludes( new String[] { "jre/bin/java" } );
192-
runtime.setDir( jreDir );
190+
Runtime runtime = new Runtime( jreDir );
191+
if ( task instanceof Dmg ) {
192+
List<String> include = ((Dmg)task).getJreIncludes();
193+
List<String> exclude = ((Dmg)task).getJreExclude();
194+
195+
runtime.appendIncludes( include.toArray( new String[include.size()] ) );
196+
runtime.appendExcludes( exclude.toArray( new String[exclude.size()] ) );
197+
} else {
198+
runtime.appendIncludes( new String[] { "jre/bin/java" } );
199+
}
193200

194201
appBundler.addConfiguredRuntime( runtime );
195202
}

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

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.List;
2122

2223
import org.gradle.api.internal.project.ProjectInternal;
@@ -31,7 +32,7 @@
3132

3233
/**
3334
* The dmg Gradle task. It build a dmg package for Mac.
34-
*
35+
*
3536
* @author Volker Berlin
3637
*/
3738
public class Dmg extends AbstractUnixSetupTask {
@@ -48,6 +49,10 @@ public class Dmg extends AbstractUnixSetupTask {
4849

4950
private List<PreferencesLink> preferencesLink = new ArrayList<>();
5051

52+
private List<String> jreIncludes = Arrays.asList( "bin/java" );
53+
54+
private List<String> jreExclude = new ArrayList<>();
55+
5156
/**
5257
* Create the task.
5358
*/
@@ -66,7 +71,7 @@ public void build() {
6671

6772
/**
6873
* Return width of Finder view
69-
*
74+
*
7075
* @return width of Finder view
7176
*/
7277
public Integer getWindowWidth() {
@@ -75,7 +80,7 @@ public Integer getWindowWidth() {
7580

7681
/**
7782
* Set width of Finder view
78-
*
83+
*
7984
* @param windowWidth width of Finder view
8085
*/
8186
public void setWindowWidth( Integer windowWidth ) {
@@ -84,7 +89,7 @@ public void setWindowWidth( Integer windowWidth ) {
8489

8590
/**
8691
* Return height of Finder view
87-
*
92+
*
8893
* @return height of Finder view
8994
*/
9095
public Integer getWindowHeight() {
@@ -93,7 +98,7 @@ public Integer getWindowHeight() {
9398

9499
/**
95100
* Set height of Finder view
96-
*
101+
*
97102
* @param windowHeight of Finder view
98103
*/
99104
public void setWindowHeight( Integer windowHeight ) {
@@ -102,7 +107,7 @@ public void setWindowHeight( Integer windowHeight ) {
102107

103108
/**
104109
* Return size of icons in Finder view
105-
*
110+
*
106111
* @return size of icons in Finder view
107112
*/
108113
public Integer getIconSize() {
@@ -111,7 +116,7 @@ public Integer getIconSize() {
111116

112117
/**
113118
* Set size of icons in Finder view
114-
*
119+
*
115120
* @param iconSize of icons in Finder view
116121
*/
117122
public void setIconSize( Integer iconSize ) {
@@ -120,7 +125,7 @@ public void setIconSize( Integer iconSize ) {
120125

121126
/**
122127
* Return background Image for Finder View
123-
*
128+
*
124129
* @return background Image for Finder View
125130
*/
126131
public File getBackgroundImage() {
@@ -132,7 +137,7 @@ public File getBackgroundImage() {
132137

133138
/**
134139
* Set background Image for Finder View
135-
*
140+
*
136141
* @param backgroundFile Image for Finder View
137142
*/
138143
public void setBackgroundImage( File backgroundFile ) {
@@ -141,7 +146,7 @@ public void setBackgroundImage( File backgroundFile ) {
141146

142147
/**
143148
* Return font size for Finder View
144-
*
149+
*
145150
* @return font size for Finder View
146151
*/
147152
public Integer getFontSize() {
@@ -150,7 +155,7 @@ public Integer getFontSize() {
150155

151156
/**
152157
* Set font size for Finder View
153-
*
158+
*
154159
* @param fontSize size for Finder View
155160
*/
156161
public void setFontSize( Integer fontSize ) {
@@ -159,7 +164,7 @@ public void setFontSize( Integer fontSize ) {
159164

160165
/**
161166
* Set the needed information for signing the setup.
162-
*
167+
*
163168
* @param closue the data for signing
164169
*/
165170
public void setCodeSign( Closure<OSXCodeSign<Dmg, SetupBuilder>> closue ) {
@@ -169,7 +174,7 @@ public void setCodeSign( Closure<OSXCodeSign<Dmg, SetupBuilder>> closue ) {
169174

170175
/**
171176
* Get the SignTool configuration if set
172-
*
177+
*
173178
* @return the settings or null
174179
*/
175180
public OSXCodeSign<Dmg, SetupBuilder> getCodeSign() {
@@ -179,7 +184,7 @@ public OSXCodeSign<Dmg, SetupBuilder> getCodeSign() {
179184
/**
180185
* Return the welcome page list
181186
* Allowed Format: rtf, rtfd, txt, html
182-
*
187+
*
183188
* @return welcome page
184189
*/
185190
public List<LocalizedResource> getConclusionPages() {
@@ -189,7 +194,7 @@ public List<LocalizedResource> getConclusionPages() {
189194
/**
190195
* Set the welcome page
191196
* Allowed Format: rtf, rtfd, txt, html
192-
*
197+
*
193198
* @param conclusionPage which is shown at the end
194199
*/
195200
public void conclusionPage( Object conclusionPage ) {
@@ -199,7 +204,7 @@ public void conclusionPage( Object conclusionPage ) {
199204
/**
200205
* Return the welcome page list
201206
* Allowed Format: rtf, rtfd, txt, html
202-
*
207+
*
203208
* @return welcome page
204209
*/
205210
public List<LocalizedResource> getWelcomePages() {
@@ -209,7 +214,7 @@ public List<LocalizedResource> getWelcomePages() {
209214
/**
210215
* Set the welcome page
211216
* Allowed Format: rtf, rtfd, txt, html
212-
*
217+
*
213218
* @param welcomePage welcome page file
214219
*/
215220
public void welcomePage( Object welcomePage ) {
@@ -218,7 +223,7 @@ public void welcomePage( Object welcomePage ) {
218223

219224
/**
220225
* Return the background image for the setup
221-
*
226+
*
222227
* @return background image
223228
*/
224229
public File getSetupBackgroundImage() {
@@ -230,7 +235,7 @@ public File getSetupBackgroundImage() {
230235

231236
/**
232237
* Set the background image for the setup
233-
*
238+
*
234239
* @param setupBackground to set
235240
*/
236241
public void setSetupBackgroundImage( Object setupBackground ) {
@@ -256,7 +261,7 @@ public void setSetupIcon( Object setupIcon ) {
256261

257262
/**
258263
* Return the list of preferences links
259-
*
264+
*
260265
* @return preferences links
261266
*/
262267
public List<PreferencesLink> getPreferencesLinks() {
@@ -265,10 +270,42 @@ public List<PreferencesLink> getPreferencesLinks() {
265270

266271
/**
267272
* Set a preferences link
268-
*
273+
*
269274
* @param link the link
270275
*/
271276
public void preferencesLink( Object link ) {
272277
preferencesLink.add( ConfigureUtil.configure( (Closure<?>)link, new PreferencesLink() ) );
273278
}
279+
280+
/**
281+
* Get a list of string - defining files - that should be included in the bundled JRE
282+
* @return the jreIncludes
283+
*/
284+
public List<String> getJreIncludes() {
285+
return jreIncludes;
286+
}
287+
288+
/**
289+
* Set a list of string - defining files - that should be included in the bundled JRE
290+
* @param jreIncludes the jreIncludes to set
291+
*/
292+
public void setJreIncludes( List<String> jreIncludes ) {
293+
this.jreIncludes = jreIncludes;
294+
}
295+
296+
/**
297+
* Get a list of string - defining files - that should be excluded from the bundled JRE
298+
* @return the jreExclude
299+
*/
300+
public List<String> getJreExclude() {
301+
return jreExclude;
302+
}
303+
304+
/**
305+
* Set a list of string - defining files - that should be excluded from the bundled JRE
306+
* @param jreExclude the jreExclude to set
307+
*/
308+
public void setJreExclude( List<String> jreExclude ) {
309+
this.jreExclude = jreExclude;
310+
}
274311
}

src/com/oracle/appbundler/Runtime.java

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535

3636
public class Runtime extends FileSet {
3737

38+
/**
39+
* Constructor with the jre directory to use
40+
* @param jreDir
41+
*/
42+
public Runtime( File jreDir ) {
43+
super();
44+
setDir( jreDir );
45+
}
46+
3847
/* Override to provide canonical path so that runtime can be specified
3948
* via a version-agnostic path (relative link, e.g. `current-jre`) while
4049
* still preserving the original runtime directory name, e.g. `jre1.8.0_45.jre`.
@@ -49,19 +58,58 @@ public File getDir() {
4958
}
5059
}
5160

61+
/**
62+
* {@inheritsDoc}
63+
*/
64+
@Override
65+
public void appendIncludes( String[] includes ) {
66+
patchIncludeExcludes( includes );
67+
super.appendIncludes( includes );
68+
}
69+
70+
/**
71+
* {@inheritsDoc}
72+
*/
73+
@Override
74+
public void appendExcludes( String[] excludes ) {
75+
patchIncludeExcludes( excludes );
76+
super.appendIncludes( excludes );
77+
}
78+
79+
/**
80+
* Patch the include and exclude directories to
81+
* provide only jre relevant entries
82+
* @param includExclude the list of includes or excludes to check
83+
*/
84+
private void patchIncludeExcludes( String[] includExclude ) {
85+
boolean isJDK = new File(getDir(), "jre").isDirectory();
86+
if ( isJDK ) {
87+
for( int i = 0; i < includExclude.length; i++ ) {
88+
if ( !includExclude[i].startsWith( "jre/" ) ) {
89+
includExclude[i] = "jre/" + includExclude[i];
90+
}
91+
}
92+
}
93+
}
94+
95+
/**
96+
* check the type of the runtime set.
97+
* If it is a JDK we want to exclude certain predefined entries
98+
*/
5299
private void detectType() {
53100
boolean isJDK = new File(getDir(), "jre").isDirectory();
54101

102+
appendIncludes(new String[] {
103+
"lib/",
104+
"COPYRIGHT",
105+
"LICENSE",
106+
"README",
107+
"THIRDPARTYLICENSEREADME-JAVAFX.txt",
108+
"THIRDPARTYLICENSEREADME.txt",
109+
"Welcome.html"
110+
});
111+
55112
if (isJDK) {
56-
appendIncludes(new String[] {
57-
"jre/lib/",
58-
"jreCOPYRIGHT",
59-
"jre/LICENSE",
60-
"jre/README",
61-
"jre/THIRDPARTYLICENSEREADME-JAVAFX.txt",
62-
"jre/THIRDPARTYLICENSEREADME.txt",
63-
"jre/Welcome.html"
64-
});
65113
appendExcludes(new String[] {
66114
"jre/lib/deploy/",
67115
"jre/lib/deploy.jar",
@@ -70,20 +118,16 @@ private void detectType() {
70118
"jre/lib/libnpjp2.dylib",
71119
"jre/lib/plugin.jar",
72120
"jre/lib/security/javaws.policy"
73-
});
74-
} else {
75-
appendIncludes(new String[] {
76-
"lib/",
77-
"COPYRIGHT",
78-
"LICENSE",
79-
"README",
80-
"THIRDPARTYLICENSEREADME-JAVAFX.txt",
81-
"THIRDPARTYLICENSEREADME.txt",
82-
"Welcome.html"
83121
});
84122
}
85123
}
86124

125+
/**
126+
* Finally copy the files of the jre
127+
* @param targetDir where to copy
128+
* @param project the project we're working on
129+
* @throws IOException in case of errors
130+
*/
87131
void copyTo(File targetDir, Project project) throws IOException {
88132
detectType();
89133

0 commit comments

Comments
 (0)