25
25
import java .nio .file .Files ;
26
26
import java .io .IOException ;
27
27
import java .util .List ;
28
+ import jdk .jpackage .internal .util .XmlUtils ;
28
29
import jdk .jpackage .test .AppImageFile ;
29
30
import jdk .jpackage .test .Annotations .Parameter ;
31
+ import jdk .jpackage .test .CannedFormattedString ;
30
32
import jdk .jpackage .test .TKit ;
31
33
import jdk .jpackage .test .JPackageCommand ;
34
+ import jdk .jpackage .test .JPackageStringBundle ;
32
35
import jdk .jpackage .test .PackageTest ;
33
36
import jdk .jpackage .test .RunnablePackageTest .Action ;
34
37
import jdk .jpackage .test .Annotations .Test ;
@@ -106,17 +109,16 @@ public static void testEmpty(boolean withIcon) throws IOException {
106
109
public static void testBadAppImage () throws IOException {
107
110
Path appImageDir = TKit .createTempDirectory ("appimage" );
108
111
Files .createFile (appImageDir .resolve ("foo" ));
109
- configureAppImageWithoutJPackageXMLFile (appImageDir ).addInitializer (
110
- cmd -> {
111
- cmd .removeArgumentWithValue ("--name" );
112
- }).run (Action .CREATE );
112
+ configureBadAppImage (appImageDir ).addInitializer (cmd -> {
113
+ cmd .removeArgumentWithValue ("--name" );
114
+ }).run (Action .CREATE );
113
115
}
114
116
115
117
@ Test
116
118
public static void testBadAppImage2 () throws IOException {
117
119
Path appImageDir = TKit .createTempDirectory ("appimage" );
118
120
Files .createFile (appImageDir .resolve ("foo" ));
119
- configureAppImageWithoutJPackageXMLFile (appImageDir ).run (Action .CREATE );
121
+ configureBadAppImage (appImageDir ).run (Action .CREATE );
120
122
}
121
123
122
124
@ Test
@@ -126,29 +128,45 @@ public static void testBadAppImage3() throws IOException {
126
128
JPackageCommand appImageCmd = JPackageCommand .helloAppImage ().
127
129
setFakeRuntime ().setArgumentValue ("--dest" , appImageDir );
128
130
129
- configureAppImageWithoutJPackageXMLFile (appImageCmd .outputBundle ()).
130
- addRunOnceInitializer (() -> {
131
- appImageCmd .execute ();
132
- Files .delete (AppImageFile .getPathInAppImage (appImageCmd .
133
- outputBundle ()));
134
- }).run (Action .CREATE );
131
+ configureBadAppImage (appImageCmd .outputBundle ()).addRunOnceInitializer (() -> {
132
+ appImageCmd .execute ();
133
+ Files .delete (AppImageFile .getPathInAppImage (appImageCmd .outputBundle ()));
134
+ }).run (Action .CREATE );
135
135
}
136
136
137
- private static PackageTest configureAppImageWithoutJPackageXMLFile (
138
- Path appImageDir ) {
139
- return new PackageTest ()
140
- .addInitializer (cmd -> {
141
- cmd .saveConsoleOutput (true );
142
- cmd .addArguments ("--app-image" , appImageDir );
143
- cmd .removeArgumentWithValue ("--input" );
144
- cmd .ignoreDefaultVerbose (true ); // no "--verbose" option
145
- })
146
- .addBundleVerifier ((cmd , result ) -> {
147
- TKit .assertTextStream (
148
- "Error: Missing .jpackage.xml file in app-image dir" ).apply (
149
- result .getOutput ().stream ());
150
- })
151
- .setExpectedExitCode (1 );
137
+ @ Test
138
+ public static void testBadAppImageFile () throws IOException {
139
+ final var appImageRoot = TKit .createTempDirectory ("appimage" );
140
+
141
+ final var appImageCmd = JPackageCommand .helloAppImage ().
142
+ setFakeRuntime ().setArgumentValue ("--dest" , appImageRoot );
143
+
144
+ final var appImageDir = appImageCmd .outputBundle ();
145
+
146
+ final var expectedError = JPackageStringBundle .MAIN .cannedFormattedString (
147
+ "error.invalid-app-image" , appImageDir , AppImageFile .getPathInAppImage (appImageDir ));
148
+
149
+ configureBadAppImage (appImageDir , expectedError ).addRunOnceInitializer (() -> {
150
+ appImageCmd .execute ();
151
+ XmlUtils .createXml (AppImageFile .getPathInAppImage (appImageDir ), xml -> {
152
+ xml .writeStartElement ("jpackage-state" );
153
+ xml .writeEndElement ();
154
+ });
155
+ }).run (Action .CREATE );
156
+ }
157
+
158
+ private static PackageTest configureBadAppImage (Path appImageDir ) {
159
+ return configureBadAppImage (appImageDir ,
160
+ JPackageStringBundle .MAIN .cannedFormattedString ("error.foreign-app-image" , appImageDir ));
161
+ }
162
+
163
+ private static PackageTest configureBadAppImage (Path appImageDir , CannedFormattedString expectedError ) {
164
+ return new PackageTest ().addInitializer (cmd -> {
165
+ cmd .addArguments ("--app-image" , appImageDir );
166
+ cmd .removeArgumentWithValue ("--input" );
167
+ cmd .ignoreDefaultVerbose (true ); // no "--verbose" option
168
+ cmd .validateOutput (expectedError );
169
+ }).setExpectedExitCode (1 );
152
170
}
153
171
154
172
private static Path iconPath (String name ) {
0 commit comments