3737import org .gradle .api .tasks .TaskAction ;
3838import org .gradle .jvm .toolchain .JavaInstallationMetadata ;
3939import org .gradle .process .ExecOperations ;
40+ import org .gradle .process .ExecSpec ;
4041
4142import javax .inject .Inject ;
4243import java .io .File ;
@@ -115,6 +116,9 @@ abstract public class Jpackage extends DefaultTask {
115116 @ Input
116117 abstract public ListProperty <String > getPackageTypes ();
117118
119+ @ Input
120+ abstract public Property <Boolean > getSingleStepPackaging ();
121+
118122 @ Input
119123 abstract public Property <Boolean > getVerbose ();
120124
@@ -141,7 +145,6 @@ public void runJpackage() throws Exception {
141145 validateHostSystem (arch , os );
142146
143147 Directory resourcesDir = getTempDirectory ().get ().dir ("jpackage-resources" );
144- Directory appImageParent = getTempDirectory ().get ().dir ("app-image" );
145148 //noinspection ResultOfMethodCallIgnored
146149 resourcesDir .getAsFile ().mkdirs ();
147150
@@ -154,56 +157,22 @@ public void runJpackage() throws Exception {
154157 String executableName = WINDOWS .equals (os ) ? "jpackage.exe" : "jpackage" ;
155158 String jpackage = getJavaInstallation ().get ().getInstallationPath ().file ("bin/" + executableName ).getAsFile ().getAbsolutePath ();
156159
157- // create app image folder
158- getExec ().exec (e -> {
159- e .commandLine (
160- jpackage ,
161- "--type" ,
162- "app-image" ,
163- "--module" ,
164- getMainModule ().get (),
165- "--resource-dir" ,
166- resourcesDir .getAsFile ().getPath (),
167- "--app-version" ,
168- getVersion ().get (),
169- "--module-path" ,
170- getModulePath ().getAsPath (),
171- "--name" ,
172- getApplicationName ().get (),
173- "--dest" ,
174- appImageParent .getAsFile ().getPath ()
175- );
176- if (getApplicationDescription ().isPresent ()) {
177- e .args ("--description" , getApplicationDescription ().get ());
178- }
179- if (getVendor ().isPresent ()) {
180- e .args ("--vendor" , getVendor ().get ());
181- }
182- if (getCopyright ().isPresent ()) {
183- e .args ("--copyright" , getCopyright ().get ());
184- }
185- for (String javaOption : getJavaOptions ().get ()) {
186- e .args ("--java-options" , javaOption );
187- }
188- for (String javaOption : getJlinkOptions ().get ()) {
189- e .args ("--jlink-options" , javaOption );
190- }
191- if (!getAddModules ().get ().isEmpty ()) {
192- e .args ("--add-modules" , String .join ("," , getAddModules ().get ()));
193- }
194- if (getVerbose ().get ()) {
195- e .args ("--verbose" );
196- }
197- });
160+ Directory appImageParent = getTempDirectory ().get ().dir ("app-image" );
161+ File appImageFolder ;
162+ if (getSingleStepPackaging ().get ()) {
163+ appImageFolder = appImageParent .dir (getName ()).getAsFile ();
164+ } else {
165+ performAppImageStep (jpackage , resourcesDir , appImageParent );
166+ appImageFolder = requireNonNull (appImageParent .getAsFile ().listFiles ())[0 ];
167+ }
198168
199- File appImageFolder = requireNonNull (appImageParent .getAsFile ().listFiles ())[0 ];
200169 File appRootFolder ;
201170 if (os .contains ("macos" )) {
202- appRootFolder = new File (appImageFolder , "Contents" );
171+ appRootFolder = new File (appImageFolder , "Contents" );
203172 } else if (os .contains ("windows" )) {
204- appRootFolder = appImageFolder ;
173+ appRootFolder = appImageFolder ;
205174 } else {
206- appRootFolder = new File (appImageFolder , "lib" );
175+ appRootFolder = new File (appImageFolder , "lib" );
207176 }
208177
209178 // copy additional resource into app-image folder
@@ -220,11 +189,19 @@ public void runJpackage() throws Exception {
220189 jpackage ,
221190 "--type" ,
222191 packageType ,
223- "--app-image " ,
224- appImageFolder . getPath (),
192+ "--app-version " ,
193+ getVersion (). get (),
225194 "--dest" ,
226195 getDestination ().get ().getAsFile ().getPath ()
227196 );
197+ if (getSingleStepPackaging ().get ()) {
198+ configureJPackageArguments (e , resourcesDir );
199+ for (File appContent : requireNonNull (appRootFolder .listFiles ())) {
200+ e .args ("--app-content" , appContent .getPath ());
201+ }
202+ } else {
203+ e .args ("--app-image" , appImageFolder .getPath ());
204+ }
228205 for (String option : getOptions ().get ()) {
229206 e .args (option );
230207 }
@@ -234,6 +211,55 @@ public void runJpackage() throws Exception {
234211 generateChecksums ();
235212 }
236213
214+ private void performAppImageStep (String jpackage , Directory resourcesDir , Directory appImageParent ) {
215+ getExec ().exec (e -> {
216+ e .commandLine (
217+ jpackage ,
218+ "--type" ,
219+ "app-image" ,
220+ "--dest" ,
221+ appImageParent .getAsFile ().getPath ()
222+ );
223+ configureJPackageArguments (e , resourcesDir );
224+ });
225+ }
226+
227+ private void configureJPackageArguments (ExecSpec e , Directory resourcesDir ) {
228+ e .args (
229+ "--module" ,
230+ getMainModule ().get (),
231+ "--resource-dir" ,
232+ resourcesDir .getAsFile ().getPath (),
233+ "--app-version" ,
234+ getVersion ().get (),
235+ "--module-path" ,
236+ getModulePath ().getAsPath (),
237+ "--name" ,
238+ getApplicationName ().get ()
239+ );
240+ if (getApplicationDescription ().isPresent ()) {
241+ e .args ("--description" , getApplicationDescription ().get ());
242+ }
243+ if (getVendor ().isPresent ()) {
244+ e .args ("--vendor" , getVendor ().get ());
245+ }
246+ if (getCopyright ().isPresent ()) {
247+ e .args ("--copyright" , getCopyright ().get ());
248+ }
249+ for (String javaOption : getJavaOptions ().get ()) {
250+ e .args ("--java-options" , javaOption );
251+ }
252+ for (String javaOption : getJlinkOptions ().get ()) {
253+ e .args ("--jlink-options" , javaOption );
254+ }
255+ if (!getAddModules ().get ().isEmpty ()) {
256+ e .args ("--add-modules" , String .join ("," , getAddModules ().get ()));
257+ }
258+ if (getVerbose ().get ()) {
259+ e .args ("--verbose" );
260+ }
261+ }
262+
237263 private void generateChecksums () throws NoSuchAlgorithmException , IOException {
238264 File destination = getDestination ().get ().getAsFile ();
239265 List <File > allFiles = Arrays .stream (requireNonNull (destination .listFiles ())).filter (File ::isFile ).collect (Collectors .toList ());
0 commit comments