21
21
import org .junit .jupiter .api .Test ;
22
22
23
23
import 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 ;
24
28
25
29
/**
26
30
* Tests for adding custom resources to the image/package.
@@ -97,23 +101,31 @@ void can_add_resources_for_jpackage() {
97
101
// Use 'src/main/resourcesPackage', which is the convention
98
102
99
103
// 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 ("" );
102
104
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 ("" );
103
107
104
108
// 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 ();
106
110
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 ();
108
112
109
113
build .build (":app:jpackage" );
110
114
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" ;
114
118
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 );
117
129
}
118
130
119
131
@ Test
@@ -130,8 +142,7 @@ void can_add_resources_for_app_folder() {
130
142
131
143
build .build (":app:jpackage" );
132
144
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 ();
135
146
}
136
147
137
148
@ Test
@@ -152,7 +163,6 @@ void can_add_resources_to_image_root() {
152
163
153
164
build .build (":app:jpackage" );
154
165
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 ();
157
167
}
158
168
}
0 commit comments