2121import org .junit .jupiter .api .Test ;
2222
2323import static org .assertj .core .api .Assertions .assertThat ;
24+ import static org .gradlex .javamodule .packaging .test .fixture .GradleBuild .currentTarget ;
25+ import static org .gradlex .javamodule .packaging .test .fixture .GradleBuild .runsOnLinux ;
26+ import static org .gradlex .javamodule .packaging .test .fixture .GradleBuild .runsOnMacos ;
27+ import static org .gradlex .javamodule .packaging .test .fixture .GradleBuild .runsOnWindows ;
2428
2529/**
2630 * Tests for adding custom resources to the image/package.
@@ -97,23 +101,31 @@ void can_add_resources_for_jpackage() {
97101 // Use 'src/main/resourcesPackage', which is the convention
98102
99103 // resources that are not known - will be ignored
100- build .projectDir .file ("app/src/main/resourcesPackage/windows/dummy.txt" ).writeText ("" );
101- build .projectDir .file ("app/src/main/resourcesPackage/macos/dummy.txt" ).writeText ("" );
102104 build .projectDir .file ("app/src/main/resourcesPackage/linux/dummy.txt" ).writeText ("" );
105+ build .projectDir .file ("app/src/main/resourcesPackage/macos/dummy.txt" ).writeText ("" );
106+ build .projectDir .file ("app/src/main/resourcesPackage/windows/dummy.txt" ).writeText ("" );
103107
104108 // icons will be used
105- build .projectDir .file ("app/src/main/resourcesPackage/windows /icon.png" ).create ();
109+ build .projectDir .file ("app/src/main/resourcesPackage/linux /icon.png" ).create ();
106110 build .projectDir .file ("app/src/main/resourcesPackage/macos/icon.icns" ).create ();
107- build .projectDir .file ("app/src/main/resourcesPackage/linux /icon.ico" ).create ();
111+ build .projectDir .file ("app/src/main/resourcesPackage/windows /icon.ico" ).create ();
108112
109113 build .build (":app:jpackage" );
110114
111- // Intermediate location to collect files
112- assertThat ( build . file ( "app/build/tmp/jpackage/macos/jpackage-resources/dummy.txt" ). getAsPath ()). exists () ;
113- assertThat ( build . file ( "app/build/tmp/jpackage/macos/jpackage-resources/app.icns" ). getAsPath ()). exists () ;
115+ String icon = "app.icns" ;
116+ if ( runsOnLinux ()) icon = "app.png" ;
117+ if ( runsOnWindows ()) icon = "app.ico" ;
114118
115- // Icons end up in Resources
116- assertThat (build .file ("app/build/packages/macos/app.app/Contents/Resources/app.icns" ).getAsPath ()).hasSize (0 );
119+ // Intermediate location to collect files
120+ assertThat (build .file ("app/build/tmp/jpackage/%s/jpackage-resources/dummy.txt" .formatted (currentTarget ()))
121+ .getAsPath ()).exists ();
122+ assertThat (build .file ("app/build/tmp/jpackage/%s/jpackage-resources/%s" .formatted (currentTarget (), icon ))
123+ .getAsPath ()).exists ();
124+
125+ // icons end up in Resources
126+ String resourcesFolder = "" ;
127+ if (runsOnMacos ()) resourcesFolder = "Resources/" ;
128+ assertThat (build .appContentsFolder ().file (resourcesFolder + icon ).getAsPath ()).hasSize (0 );
117129 }
118130
119131 @ Test
@@ -130,8 +142,7 @@ void can_add_resources_for_app_folder() {
130142
131143 build .build (":app:jpackage" );
132144
133- // Icons end up in Resources
134- assertThat (build .file ("app/build/packages/macos/app.app/Contents/app/dummy.txt" ).getAsPath ()).exists ();
145+ assertThat (build .appContentsFolder ().file ("app/dummy.txt" ).getAsPath ()).exists ();
135146 }
136147
137148 @ Test
@@ -152,7 +163,6 @@ void can_add_resources_to_image_root() {
152163
153164 build .build (":app:jpackage" );
154165
155- // Icons end up in Resources
156- assertThat (build .file ("app/build/packages/macos/app.app/Contents/customFolder/dummy.txt" ).getAsPath ()).exists ();
166+ assertThat (build .appContentsFolder ().file ("customFolder/dummy.txt" ).getAsPath ()).exists ();
157167 }
158168}
0 commit comments