6161import java .util .jar .JarFile ;
6262import java .util .jar .JarOutputStream ;
6363import java .util .jar .Manifest ;
64- import java .util .stream .Collectors ;
6564import java .util .stream .Stream ;
6665
6766import com .oracle .svm .core .OS ;
@@ -116,6 +115,9 @@ final class BundleSupport {
116115 private final BundleProperties bundleProperties ;
117116
118117 static final String BUNDLE_OPTION = "--bundle" ;
118+ private static final String DRY_RUN_OPTION = "dry-run" ;
119+ private static final String CONTAINER_OPTION = "container" ;
120+ private static final String DOCKERFILE_OPTION = "dockerfile" ;
119121 static final String BUNDLE_FILE_EXTENSION = ".nib" ;
120122
121123 ContainerSupport containerSupport ;
@@ -137,21 +139,6 @@ String optionName() {
137139 }
138140 }
139141
140- enum ExtendedBundleOptions {
141- dry_run ,
142- container ,
143- dockerfile ;
144-
145- static ExtendedBundleOptions get (String name ) {
146- return ExtendedBundleOptions .valueOf (name .replace ('-' , '_' ));
147- }
148-
149- @ Override
150- public String toString () {
151- return name ().replace ('_' , '-' );
152- }
153- }
154-
155142 static BundleSupport create (NativeImage nativeImage , String bundleArg , NativeImage .ArgumentQueue args ) {
156143 try {
157144 String bundleFilename = null ;
@@ -265,9 +252,9 @@ private void parseExtendedOption(String option) {
265252 optionValue = null ;
266253 }
267254
268- switch (ExtendedBundleOptions . get ( optionKey ) ) {
269- case dry_run -> nativeImage .setDryRun (true );
270- case container -> {
255+ switch (optionKey ) {
256+ case DRY_RUN_OPTION -> nativeImage .setDryRun (true );
257+ case CONTAINER_OPTION -> {
271258 if (containerSupport != null ) {
272259 throw NativeImage .showError (String .format ("native-image bundle allows option %s to be specified only once." , optionKey ));
273260 }
@@ -280,9 +267,9 @@ private void parseExtendedOption(String option) {
280267 containerSupport .tool = optionValue ;
281268 }
282269 }
283- case dockerfile -> {
270+ case DOCKERFILE_OPTION -> {
284271 if (containerSupport == null ) {
285- throw NativeImage .showError (String .format ("native-image bundle option %s is only allowed to be used after option %s." , optionKey , ExtendedBundleOptions . container ));
272+ throw NativeImage .showError (String .format ("native-image bundle option %s is only allowed to be used after option %s." , optionKey , CONTAINER_OPTION ));
286273 }
287274 if (optionValue != null ) {
288275 containerSupport .dockerfile = Path .of (optionValue );
@@ -293,12 +280,7 @@ private void parseExtendedOption(String option) {
293280 throw NativeImage .showError (String .format ("native-image option %s requires a dockerfile argument. E.g. %s=path/to/Dockerfile." , optionKey , optionKey ));
294281 }
295282 }
296- default -> {
297- String suggestedOptions = Arrays .stream (ExtendedBundleOptions .values ())
298- .map (Enum ::toString )
299- .collect (Collectors .joining (", " ));
300- throw NativeImage .showError (String .format ("Unknown option %s. Valid options are: %s." , optionKey , suggestedOptions ));
301- }
283+ default -> throw NativeImage .showError (String .format ("Unknown option %s. Use --help-extra for usage instructions." , optionKey ));
302284 }
303285 }
304286
0 commit comments