mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Polish
This commit is contained in:
parent
1e38dd5531
commit
2c1e81adf0
@ -69,7 +69,8 @@ public abstract class OnEndpointElementCondition extends SpringBootCondition {
|
||||
}
|
||||
|
||||
protected ConditionOutcome getDefaultEndpointsOutcome(ConditionContext context) {
|
||||
boolean match = Boolean.valueOf(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
|
||||
boolean match = Boolean
|
||||
.parseBoolean(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
|
||||
return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType)
|
||||
.because(this.prefix + "defaults.enabled is considered " + match));
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
|
||||
* @param prefix the prefix
|
||||
* @return the serialized instance
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private Map<String, Object> safeSerialize(ObjectMapper mapper, Object bean, String prefix) {
|
||||
try {
|
||||
return new HashMap<>(mapper.convertValue(bean, Map.class));
|
||||
|
@ -65,13 +65,11 @@ public class PathMappedEndpoints implements Iterable<PathMappedEndpoint> {
|
||||
|
||||
private Map<EndpointId, PathMappedEndpoint> getEndpoints(Collection<EndpointsSupplier<?>> suppliers) {
|
||||
Map<EndpointId, PathMappedEndpoint> endpoints = new LinkedHashMap<>();
|
||||
suppliers.forEach((supplier) -> {
|
||||
supplier.getEndpoints().forEach((endpoint) -> {
|
||||
if (endpoint instanceof PathMappedEndpoint) {
|
||||
endpoints.put(endpoint.getEndpointId(), (PathMappedEndpoint) endpoint);
|
||||
}
|
||||
});
|
||||
});
|
||||
suppliers.forEach((supplier) -> supplier.getEndpoints().forEach((endpoint) -> {
|
||||
if (endpoint instanceof PathMappedEndpoint) {
|
||||
endpoints.put(endpoint.getEndpointId(), (PathMappedEndpoint) endpoint);
|
||||
}
|
||||
}));
|
||||
return Collections.unmodifiableMap(endpoints);
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class HealthWebEndpointResponseMapper {
|
||||
}
|
||||
|
||||
private WebEndpointResponse<Health> createWebEndpointResponse(Health health) {
|
||||
Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
|
||||
int status = this.statusHttpMapper.mapStatus(health.getStatus());
|
||||
return new WebEndpointResponse<>(health, status);
|
||||
}
|
||||
|
||||
|
@ -1059,7 +1059,7 @@ public class RabbitProperties {
|
||||
}
|
||||
else {
|
||||
this.host = input.substring(0, portIndex);
|
||||
this.port = Integer.valueOf(input.substring(portIndex + 1));
|
||||
this.port = Integer.parseInt(input.substring(portIndex + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ abstract class RedisConnectionConfiguration {
|
||||
try {
|
||||
String[] parts = StringUtils.split(node, ":");
|
||||
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
|
||||
nodes.add(new RedisNode(parts[0], Integer.valueOf(parts[1])));
|
||||
nodes.add(new RedisNode(parts[0], Integer.parseInt(parts[1])));
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new IllegalStateException("Invalid redis sentinel property '" + node + "'", ex);
|
||||
|
@ -44,8 +44,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
|
||||
* needed, otherwise default converters will be used.
|
||||
* <p>
|
||||
* NOTE: The default converters used are the same as standard Spring MVC (see
|
||||
* {@link WebMvcConfigurationSupport#getMessageConverters} with some slight re-ordering to
|
||||
* put XML converters at the back of the list.
|
||||
* {@link WebMvcConfigurationSupport}) with some slight re-ordering to put XML converters
|
||||
* at the back of the list.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
|
@ -68,10 +68,10 @@ class ArtemisConnectionFactoryFactory {
|
||||
}
|
||||
|
||||
private void startEmbeddedJms() {
|
||||
for (int i = 0; i < EMBEDDED_JMS_CLASSES.length; i++) {
|
||||
if (ClassUtils.isPresent(EMBEDDED_JMS_CLASSES[i], null)) {
|
||||
for (String embeddedJmsClass : EMBEDDED_JMS_CLASSES) {
|
||||
if (ClassUtils.isPresent(embeddedJmsClass, null)) {
|
||||
try {
|
||||
this.beanFactory.getBeansOfType(Class.forName(EMBEDDED_JMS_CLASSES[i]));
|
||||
this.beanFactory.getBeansOfType(Class.forName(embeddedJmsClass));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Ignore
|
||||
@ -103,8 +103,8 @@ class ArtemisConnectionFactoryFactory {
|
||||
}
|
||||
|
||||
private boolean isEmbeddedJmsClassPresent() {
|
||||
for (int i = 0; i < EMBEDDED_JMS_CLASSES.length; i++) {
|
||||
if (ClassUtils.isPresent(EMBEDDED_JMS_CLASSES[i], null)) {
|
||||
for (String embeddedJmsClass : EMBEDDED_JMS_CLASSES) {
|
||||
if (ClassUtils.isPresent(embeddedJmsClass, null)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class LdapProperties {
|
||||
Assert.notNull(environment, "Environment must not be null");
|
||||
String localPort = environment.getProperty("local.ldap.port");
|
||||
if (localPort != null) {
|
||||
return Integer.valueOf(localPort);
|
||||
return Integer.parseInt(localPort);
|
||||
}
|
||||
return DEFAULT_PORT;
|
||||
}
|
||||
|
@ -282,17 +282,15 @@ public class TomcatWebServerFactoryCustomizer
|
||||
|
||||
private void customizeStaticResources(ConfigurableTomcatWebServerFactory factory) {
|
||||
ServerProperties.Tomcat.Resource resource = this.serverProperties.getTomcat().getResource();
|
||||
factory.addContextCustomizers((context) -> {
|
||||
context.addLifecycleListener((event) -> {
|
||||
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
|
||||
context.getResources().setCachingAllowed(resource.isAllowCaching());
|
||||
if (resource.getCacheTtl() != null) {
|
||||
long ttl = resource.getCacheTtl().toMillis();
|
||||
context.getResources().setCacheTtl(ttl);
|
||||
}
|
||||
factory.addContextCustomizers((context) -> context.addLifecycleListener((event) -> {
|
||||
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
|
||||
context.getResources().setCachingAllowed(resource.isAllowCaching());
|
||||
if (resource.getCacheTtl() != null) {
|
||||
long ttl = resource.getCacheTtl().toMillis();
|
||||
context.getResources().setCacheTtl(ttl);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void customizeErrorReportValve(ErrorProperties error, ConfigurableTomcatWebServerFactory factory) {
|
||||
|
@ -168,16 +168,13 @@ public class UndertowWebServerFactoryCustomizer
|
||||
return (value) -> this.factory.addBuilderCustomizers((builder) -> builder.setSocketOption(option, value));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T> Consumer<Map<String, String>> forEach(Function<Option<T>, Consumer<T>> function) {
|
||||
return (map) -> {
|
||||
map.forEach((key, value) -> {
|
||||
Option<T> option = (Option<T>) NAME_LOOKUP.get(getCanonicalName(key));
|
||||
Assert.state(option != null, "Unable to find '" + key + "' in UndertowOptions");
|
||||
T parsed = option.parseValue(value, getClass().getClassLoader());
|
||||
function.apply(option).accept(parsed);
|
||||
});
|
||||
};
|
||||
return (map) -> map.forEach((key, value) -> {
|
||||
Option<T> option = (Option<T>) NAME_LOOKUP.get(getCanonicalName(key));
|
||||
Assert.state(option != null, "Unable to find '" + key + "' in UndertowOptions");
|
||||
T parsed = option.parseValue(value, getClass().getClassLoader());
|
||||
function.apply(option).accept(parsed);
|
||||
});
|
||||
}
|
||||
|
||||
private static String getCanonicalName(String name) {
|
||||
|
@ -18,7 +18,6 @@ package org.springframework.boot.cli.command.archive;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
@ -175,7 +174,7 @@ abstract class ArchiveCommand extends OptionParsingCommand {
|
||||
}
|
||||
|
||||
private void writeJar(File file, Class<?>[] compiledClasses, List<MatchedResource> classpathEntries,
|
||||
List<URL> dependencies) throws FileNotFoundException, IOException, URISyntaxException {
|
||||
List<URL> dependencies) throws IOException, URISyntaxException {
|
||||
final List<Library> libraries;
|
||||
try (JarWriter writer = new JarWriter(file)) {
|
||||
addManifest(writer, compiledClasses);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.cli.command.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -48,9 +49,7 @@ public class HintCommand extends AbstractCommand {
|
||||
try {
|
||||
int index = (args.length != 0) ? Integer.parseInt(args[0]) - 1 : 0;
|
||||
List<String> arguments = new ArrayList<>(args.length);
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
arguments.add(args[i]);
|
||||
}
|
||||
arguments.addAll(Arrays.asList(args).subList(2, args.length));
|
||||
String starting = "";
|
||||
if (index < arguments.size()) {
|
||||
starting = arguments.remove(index);
|
||||
|
@ -283,7 +283,7 @@ public class LiveReloadServer {
|
||||
}
|
||||
}
|
||||
|
||||
private void runConnection(Connection connection) throws IOException, Exception {
|
||||
private void runConnection(Connection connection) throws Exception {
|
||||
try {
|
||||
addConnection(connection);
|
||||
connection.run();
|
||||
|
@ -98,16 +98,14 @@ class PropertiesMigrationReporter {
|
||||
MultiValueMap<String, PropertyMigration> result = new LinkedMultiValueMap<>();
|
||||
List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter)
|
||||
.collect(Collectors.toList());
|
||||
getPropertySourcesAsMap().forEach((name, source) -> {
|
||||
candidates.forEach((metadata) -> {
|
||||
ConfigurationProperty configurationProperty = source
|
||||
.getConfigurationProperty(ConfigurationPropertyName.of(metadata.getId()));
|
||||
if (configurationProperty != null) {
|
||||
result.add(name, new PropertyMigration(configurationProperty, metadata,
|
||||
determineReplacementMetadata(metadata)));
|
||||
}
|
||||
});
|
||||
});
|
||||
getPropertySourcesAsMap().forEach((name, source) -> candidates.forEach((metadata) -> {
|
||||
ConfigurationProperty configurationProperty = source
|
||||
.getConfigurationProperty(ConfigurationPropertyName.of(metadata.getId()));
|
||||
if (configurationProperty != null) {
|
||||
result.add(name,
|
||||
new PropertyMigration(configurationProperty, metadata, determineReplacementMetadata(metadata)));
|
||||
}
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -351,16 +351,13 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
||||
* @param consumer the consumer of the created {@link ApplicationContext}
|
||||
* @return this instance
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public SELF run(ContextConsumer<? super A> consumer) {
|
||||
withContextClassLoader(this.classLoader, () -> {
|
||||
this.systemProperties.applyToSystemProperties(() -> {
|
||||
try (A context = createAssertableContext()) {
|
||||
accept(consumer, context);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
withContextClassLoader(this.classLoader, () -> this.systemProperties.applyToSystemProperties(() -> {
|
||||
try (A context = createAssertableContext()) {
|
||||
accept(consumer, context);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
return (SELF) this;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -307,7 +308,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
|
||||
if (primaryBeanName != null) {
|
||||
throw new NoUniqueBeanDefinitionException(type.resolve(), candidateBeanNames.size(),
|
||||
"more than one 'primary' bean found among candidates: "
|
||||
+ Arrays.asList(candidateBeanNames));
|
||||
+ Collections.singletonList(candidateBeanNames));
|
||||
}
|
||||
primaryBeanName = candidateBeanName;
|
||||
}
|
||||
|
@ -181,10 +181,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
if (annotation != null) {
|
||||
String prefix = getPrefix(annotation);
|
||||
if (element instanceof TypeElement) {
|
||||
processAnnotatedTypeElement(prefix, (TypeElement) element, new Stack<TypeElement>());
|
||||
processAnnotatedTypeElement(prefix, (TypeElement) element, new Stack<>());
|
||||
}
|
||||
else if (element instanceof ExecutableElement) {
|
||||
processExecutableElement(prefix, (ExecutableElement) element, new Stack<TypeElement>());
|
||||
processExecutableElement(prefix, (ExecutableElement) element, new Stack<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
|
||||
}
|
||||
|
||||
private Iterator<Archive> applyClassPathArchivePostProcessing(Iterator<Archive> archives) throws Exception {
|
||||
List<Archive> list = new ArrayList<Archive>();
|
||||
List<Archive> list = new ArrayList<>();
|
||||
while (archives.hasNext()) {
|
||||
list.add(archives.next());
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeProperties() throws Exception, IOException {
|
||||
private void initializeProperties() throws Exception {
|
||||
List<String> configs = new ArrayList<>();
|
||||
if (getProperty(CONFIG_LOCATION) != null) {
|
||||
configs.add(getProperty(CONFIG_LOCATION));
|
||||
@ -195,7 +195,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadResource(InputStream resource) throws IOException, Exception {
|
||||
private void loadResource(InputStream resource) throws Exception {
|
||||
this.properties.load(resource);
|
||||
for (Object key : Collections.list(this.properties.propertyNames())) {
|
||||
String text = this.properties.getProperty((String) key);
|
||||
@ -591,7 +591,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
|
||||
private List<Archive> asList(Iterator<Archive> iterator) {
|
||||
List<Archive> list = new ArrayList<Archive>();
|
||||
List<Archive> list = new ArrayList<>();
|
||||
while (iterator.hasNext()) {
|
||||
list.add(iterator.next());
|
||||
}
|
||||
|
@ -172,9 +172,8 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
|
||||
MergedAnnotations annotations = MergedAnnotations.from(testClass,
|
||||
MergedAnnotations.SearchStrategy.TYPE_HIERARCHY);
|
||||
ClassPathEntryFilter filter = new ClassPathEntryFilter(annotations.get(ClassPathExclusions.class));
|
||||
List<URL> processedUrls = new ArrayList<>();
|
||||
List<URL> additionalUrls = getAdditionalUrls(annotations.get(ClassPathOverrides.class));
|
||||
processedUrls.addAll(additionalUrls);
|
||||
List<URL> processedUrls = new ArrayList<>(additionalUrls);
|
||||
for (URL url : urls) {
|
||||
if (!filter.isExcluded(url)) {
|
||||
processedUrls.add(url);
|
||||
|
@ -81,7 +81,7 @@ class ModifiedClassPathExtension implements InvocationInterceptor {
|
||||
}
|
||||
|
||||
private void runTestWithModifiedClassPath(ReflectiveInvocationContext<Method> invocationContext,
|
||||
ExtensionContext extensionContext) throws ClassNotFoundException, Throwable {
|
||||
ExtensionContext extensionContext) throws Throwable {
|
||||
Class<?> testClass = extensionContext.getRequiredTestClass();
|
||||
Method testMethod = invocationContext.getExecutable();
|
||||
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
@ -95,8 +95,7 @@ class ModifiedClassPathExtension implements InvocationInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
private void runTest(ClassLoader classLoader, String testClassName, String testMethodName)
|
||||
throws ClassNotFoundException, Throwable {
|
||||
private void runTest(ClassLoader classLoader, String testClassName, String testMethodName) throws Throwable {
|
||||
Class<?> testClass = classLoader.loadClass(testClassName);
|
||||
Method testMethod = findMethod(testClass, testMethodName);
|
||||
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
|
||||
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.annotation.processing.Processor;
|
||||
import javax.tools.JavaCompiler;
|
||||
@ -59,7 +60,7 @@ public class TestCompiler {
|
||||
this.fileManager = compiler.getStandardFileManager(null, null, null);
|
||||
this.outputLocation = outputLocation;
|
||||
this.outputLocation.mkdirs();
|
||||
Iterable<? extends File> temp = Arrays.asList(this.outputLocation);
|
||||
Iterable<? extends File> temp = Collections.singletonList(this.outputLocation);
|
||||
this.fileManager.setLocation(StandardLocation.CLASS_OUTPUT, temp);
|
||||
this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, temp);
|
||||
}
|
||||
|
@ -521,7 +521,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource addPath(String path) throws IOException, MalformedURLException {
|
||||
public Resource addPath(String path) throws IOException {
|
||||
if (path.startsWith("/org/springframework/boot")) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user