Browse Source

Merge branch '6.0.x'

pull/31113/head
Stephane Nicoll 2 years ago
parent
commit
bf2cdcb1f2
  1. 10
      spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java

10
spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -46,7 +46,11 @@ import org.springframework.util.StringUtils; @@ -46,7 +46,11 @@ import org.springframework.util.StringUtils;
* // ...
* }</pre>
*
* See {@link CommandLinePropertySource} for complete general usage examples.
* <p>If an option has several representations, the most descriptive is expected
* to be set last, and is used as the property name of the associated
* {@link EnumerablePropertySource#getPropertyNames()}.
*
* <p>See {@link CommandLinePropertySource} for complete general usage examples.
*
* <p>Requires JOpt Simple version 4.3 or higher. Tested against JOpt up until 5.0.
*
@ -88,9 +92,9 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt @@ -88,9 +92,9 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
public String[] getPropertyNames() {
List<String> names = new ArrayList<>();
for (OptionSpec<?> spec : this.source.specs()) {
// Last option is expected to be the most descriptive.
String lastOption = CollectionUtils.lastElement(spec.options());
if (lastOption != null) {
// Only the longest name is used for enumerating
names.add(lastOption);
}
}

Loading…
Cancel
Save