Skip to content

Commit a9b2244

Browse files
committed
Improve printing of values for options.
1 parent 604ede8 commit a9b2244

File tree

11 files changed

+54
-36
lines changed

11 files changed

+54
-36
lines changed

substratevm/src/com.oracle.svm.common/src/com/oracle/svm/common/option/CommonOptionParser.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,8 @@ public static OptionParseResult parseOption(EconomicMap<String, OptionDescriptor
276276
selectedOptionTypes.add(OptionType.valueOf(enumString));
277277
}
278278
} catch (IllegalArgumentException e) {
279-
StringBuilder sb = new StringBuilder();
280-
boolean firstValue = true;
281-
for (OptionType ot : OptionType.values()) {
282-
if (firstValue) {
283-
firstValue = false;
284-
} else {
285-
sb.append(", ");
286-
}
287-
sb.append(ot.name());
288-
}
289-
String possibleValues = sb.toString();
290-
return OptionParseResult.error("Invalid value for option " + current + ". '" + enumString + "' is not one of: " + possibleValues);
279+
String possibleValues = StringUtil.joinSingleQuoted(OptionType.values());
280+
return OptionParseResult.error("Invalid value for option " + current + ". '" + enumString + "' is not one of " + possibleValues + ".");
291281
}
292282
}
293283
return OptionParseResult.printFlags(selectedOptionTypes);

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/APIOptionHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ boolean consume(ArgumentQueue args) {
319319
if (headArg.startsWith(groupNameAndSeparator)) {
320320
GroupInfo groupInfo = entry.getValue();
321321
String groupName = APIOption.Utils.optionName(groupInfo.group.name());
322-
String supportedValues = "'" + String.join("', '", groupInfo.supportedValues) + "'";
323322
NativeImage.showError("In " + args.argumentOrigin + " '" + headArg.substring(groupNameAndSeparator.length()) + "' is not a valid value for the option " + groupName +
324-
". Supported values are " + supportedValues);
323+
". Supported values are " + StringUtil.joinSingleQuoted(groupInfo.supportedValues) + ".");
325324
}
326325
}
327326
}

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/BundleSupport.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import java.util.jar.JarFile;
5959
import java.util.jar.JarOutputStream;
6060
import java.util.jar.Manifest;
61-
import java.util.stream.Collectors;
6261
import java.util.stream.Stream;
6362

6463
import org.graalvm.util.json.JSONParserException;
@@ -71,6 +70,7 @@
7170
import com.oracle.svm.core.util.json.JsonWriter;
7271
import com.oracle.svm.util.ClassUtil;
7372
import com.oracle.svm.util.LogUtils;
73+
import com.oracle.svm.util.StringUtil;
7474

7575
final class BundleSupport {
7676

@@ -176,10 +176,8 @@ static BundleSupport create(NativeImage nativeImage, String bundleArg, NativeIma
176176
return bundleSupport;
177177

178178
} catch (StringIndexOutOfBoundsException | IllegalArgumentException e) {
179-
String suggestedVariants = Arrays.stream(BundleOptionVariants.values())
180-
.map(v -> BUNDLE_OPTION + "-" + v)
181-
.collect(Collectors.joining(", "));
182-
throw NativeImage.showError("Unknown option " + bundleArg + ". Valid variants are: " + suggestedVariants + ".");
179+
String suggestedVariants = StringUtil.joinSingleQuoted(Arrays.stream(BundleOptionVariants.values()).map(v -> BUNDLE_OPTION + "-" + v).toList());
180+
throw NativeImage.showError("Unknown option '" + bundleArg + "'. Valid variants are " + suggestedVariants + ".");
183181
}
184182
}
185183

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import com.oracle.svm.util.LogUtils;
9595
import com.oracle.svm.util.ModuleSupport;
9696
import com.oracle.svm.util.ReflectionUtil;
97+
import com.oracle.svm.util.StringUtil;
9798

9899
public class NativeImage {
99100

@@ -1102,8 +1103,7 @@ private int completeImageBuild() {
11021103
}
11031104

11041105
if (!extraImageArgs.isEmpty()) {
1105-
String prefix = "Unknown argument" + (extraImageArgs.size() == 1 ? ": " : "s: ");
1106-
showError(extraImageArgs.stream().collect(Collectors.joining(", ", prefix, "")));
1106+
showError("Unknown argument(s): " + StringUtil.joinSingleQuoted(extraImageArgs));
11071107
}
11081108
}
11091109

@@ -1147,8 +1147,7 @@ private int completeImageBuild() {
11471147
}
11481148

11491149
if (!leftoverArgs.isEmpty()) {
1150-
String prefix = "Unrecognized option" + (leftoverArgs.size() == 1 ? ": " : "s: ");
1151-
showError(leftoverArgs.stream().collect(Collectors.joining(", ", prefix, "")));
1150+
showError("Unrecognized option(s): " + StringUtil.joinSingleQuoted(leftoverArgs));
11521151
}
11531152

11541153
LinkedHashSet<Path> finalImageModulePath = new LinkedHashSet<>(imageModulePath);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
import com.oracle.svm.util.ImageBuildStatistics;
307307
import com.oracle.svm.util.ReflectionUtil;
308308
import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError;
309+
import com.oracle.svm.util.StringUtil;
309310

310311
import jdk.vm.ci.aarch64.AArch64;
311312
import jdk.vm.ci.amd64.AMD64;
@@ -1890,7 +1891,7 @@ private static <T extends Enum<T>> Set<T> parseCSVtoEnum(Class<T> enumType, List
18901891
try {
18911892
result.add(Enum.valueOf(enumType, enumValue));
18921893
} catch (IllegalArgumentException iae) {
1893-
throw VMError.shouldNotReachHere("Value '" + enumValue + "' does not exist. Available values are:\n" + Arrays.toString(availValues));
1894+
throw VMError.shouldNotReachHere("Value '" + enumValue + "' does not exist. Available values are " + StringUtil.joinSingleQuoted(availValues) + ".");
18941895
}
18951896
}
18961897
return result;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.nio.file.Path;
3131
import java.nio.file.Paths;
3232
import java.text.SimpleDateFormat;
33-
import java.util.Arrays;
3433
import java.util.Date;
3534

3635
import org.graalvm.collections.EconomicMap;
@@ -51,6 +50,7 @@
5150
import com.oracle.svm.core.util.UserError;
5251
import com.oracle.svm.hosted.classinitialization.ClassInitializationOptions;
5352
import com.oracle.svm.hosted.util.CPUType;
53+
import com.oracle.svm.util.StringUtil;
5454

5555
public class NativeImageOptions {
5656

@@ -171,14 +171,14 @@ public boolean compatibleWith(CStandards standard) {
171171
}
172172
}
173173

174-
@Option(help = "C standard to use in header files. Possible values are: [C89, C99, C11]", type = User)//
174+
@Option(help = "C standard to use in header files. Possible values are 'C89', 'C99', and 'C11'.", type = User)//
175175
public static final HostedOptionKey<String> CStandard = new HostedOptionKey<>("C89");
176176

177177
public static CStandards getCStandard() {
178178
try {
179179
return CStandards.valueOf(CStandard.getValue());
180180
} catch (IllegalArgumentException e) {
181-
throw UserError.abort("C standard %s is not supported. Supported standards are: %s", CStandard.getValue(), Arrays.toString(CStandards.values()));
181+
throw UserError.abort("C standard '%s' is not supported. Supported standards are %s.", CStandard.getValue(), StringUtil.joinSingleQuoted(CStandards.values()));
182182
}
183183
}
184184

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/diagnostic/HostedHeapDumpFeature.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.svm.core.option.SubstrateOptionsParser;
4747
import com.oracle.svm.core.util.UserError;
4848
import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl;
49+
import com.oracle.svm.util.StringUtil;
4950

5051
@AutomaticallyRegisteredFeature
5152
public class HostedHeapDumpFeature implements InternalFeature {
@@ -84,8 +85,8 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
8485
if (validPhases.contains(value)) {
8586
phases.add(value);
8687
} else {
87-
throw UserError.abort("Invalid value %s given for %s. Valid values are: %s.", value,
88-
SubstrateOptionsParser.commandArgument(Options.DumpHeap, ""), String.join(", ", validPhases));
88+
throw UserError.abort("Invalid value %s given for %s. Valid values are %s.",
89+
value, SubstrateOptionsParser.commandArgument(Options.DumpHeap, ""), StringUtil.joinSingleQuoted(validPhases));
8990
}
9091
}
9192
return !phases.isEmpty();

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAArch64.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.svm.core.option.SubstrateOptionsParser;
4646
import com.oracle.svm.core.util.UserError;
4747
import com.oracle.svm.hosted.NativeImageOptions;
48+
import com.oracle.svm.util.StringUtil;
4849

4950
import jdk.vm.ci.aarch64.AArch64;
5051
import jdk.vm.ci.aarch64.AArch64.CPUFeature;
@@ -63,7 +64,7 @@ public enum CPUTypeAArch64 implements CPUType {
6364
COMPATIBILITY(NativeImageOptions.MICRO_ARCHITECTURE_COMPATIBILITY, ARMV8_A),
6465
NATIVE(NativeImageOptions.MICRO_ARCHITECTURE_NATIVE, getNativeOrEmpty());
6566

66-
private static final String AVAILABLE_FEATURE_MODIFIERS = String.join(", ", new String[]{"aes", "lse", "fp", "simd"});
67+
private static final String AVAILABLE_FEATURE_MODIFIERS = StringUtil.joinSingleQuoted("aes", "lse", "fp", "simd");
6768

6869
private static CPUFeature[] getNativeOrEmpty() {
6970
CPUFeature[] empty = new CPUFeature[0];
@@ -132,7 +133,7 @@ public static EnumSet<CPUFeature> getCPUFeaturesForArch(String marchValue) {
132133
throw UserError.abort("Unsupported architecture '%s'. Please adjust '%s'. On AArch64, only %s are available.",
133134
marchValue,
134135
SubstrateOptionsParser.commandArgument(NativeImageOptions.MicroArchitecture, marchValue),
135-
List.of(values()).stream().map(v -> v.name).collect(Collectors.joining(", ")));
136+
StringUtil.joinSingleQuoted(values()));
136137
}
137138
List<CPUFeature> features = new ArrayList<>(value.getFeatures());
138139
processFeatureModifiers(features, archParts);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.oracle.svm.core.util.UserError;
6868
import com.oracle.svm.hosted.NativeImageOptions;
6969
import com.oracle.svm.util.LogUtils;
70+
import com.oracle.svm.util.StringUtil;
7071

7172
import jdk.vm.ci.amd64.AMD64;
7273
import jdk.vm.ci.amd64.AMD64.CPUFeature;
@@ -184,7 +185,7 @@ public static EnumSet<CPUFeature> getCPUFeaturesForArch(String marchValue) {
184185
throw UserError.abort("Unsupported architecture '%s'. Please adjust '%s'. On AMD64, only %s are available.",
185186
marchValue,
186187
SubstrateOptionsParser.commandArgument(NativeImageOptions.MicroArchitecture, marchValue),
187-
List.of(values()).stream().map(v -> v.name).collect(Collectors.joining(", ")));
188+
StringUtil.joinSingleQuoted(values()));
188189
}
189190
return value.getFeatures();
190191
}

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
import java.util.function.ToLongBiFunction;
9999
import java.util.function.ToLongFunction;
100100
import java.util.function.UnaryOperator;
101-
import java.util.stream.Collectors;
102101

103102
import org.graalvm.collections.Pair;
104103
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
@@ -163,6 +162,7 @@
163162
import com.oracle.svm.truffle.api.SubstrateTruffleRuntime;
164163
import com.oracle.svm.truffle.api.SubstrateTruffleUniverseFactory;
165164
import com.oracle.svm.util.LogUtils;
165+
import com.oracle.svm.util.StringUtil;
166166
import com.oracle.truffle.api.CompilerAsserts;
167167
import com.oracle.truffle.api.CompilerDirectives;
168168
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -870,9 +870,9 @@ public void beforeCompilation(BeforeCompilationAccess config) {
870870

871871
if (implementations.size() > 1) {
872872
throw UserError.abort("More than one implementation of %s found. For performance reasons, Truffle languages must not provide new implementations, " +
873-
"and instead only use the single implementation provided by the Truffle runtime. To disable this check, add %s to the native-image command line. Found classes: %s",
873+
"and instead only use the single implementation provided by the Truffle runtime. To disable this check, add %s to the native-image command line. Classes found are %s.",
874874
Frame.class.getTypeName(), SubstrateOptionsParser.commandArgument(Options.TruffleCheckFrameImplementation, "-"),
875-
implementations.stream().map(m -> m.toJavaName(true)).collect(Collectors.joining(", ")));
875+
StringUtil.joinSingleQuoted(implementations.stream().map(m -> m.toJavaName(true)).toArray(String[]::new)));
876876
} else {
877877
assert implementations.size() == 0 || implementations.iterator().next().equals(frameType.getSingleImplementor());
878878
}

0 commit comments

Comments
 (0)