Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -53,8 +53,7 @@ public final class RemoteSpringApplication {
|
||||
|
||||
private void run(String[] args) {
|
||||
Restarter.initialize(args, RestartInitializer.NONE);
|
||||
SpringApplication application = new SpringApplication(
|
||||
RemoteClientConfiguration.class);
|
||||
SpringApplication application = new SpringApplication(RemoteClientConfiguration.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setBanner(getBanner());
|
||||
application.setInitializers(getInitializers());
|
||||
@@ -80,8 +79,7 @@ public final class RemoteSpringApplication {
|
||||
}
|
||||
|
||||
private Banner getBanner() {
|
||||
ClassPathResource banner = new ClassPathResource("remote-banner.txt",
|
||||
RemoteSpringApplication.class);
|
||||
ClassPathResource banner = new ClassPathResource("remote-banner.txt", RemoteSpringApplication.class);
|
||||
return new ResourceBanner(banner);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -38,8 +38,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class RemoteUrlPropertyExtractor
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||
class RemoteUrlPropertyExtractor implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||
|
||||
private static final String NON_OPTION_ARGS = CommandLinePropertySource.DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME;
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ class ConditionEvaluationDeltaLoggingListener
|
||||
|
||||
private static final ConcurrentHashMap<String, ConditionEvaluationReport> previousReports = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(ConditionEvaluationDeltaLoggingListener.class);
|
||||
private static final Log logger = LogFactory.getLog(ConditionEvaluationDeltaLoggingListener.class);
|
||||
|
||||
private volatile ApplicationContext context;
|
||||
|
||||
@@ -49,25 +48,19 @@ class ConditionEvaluationDeltaLoggingListener
|
||||
if (!event.getApplicationContext().equals(this.context)) {
|
||||
return;
|
||||
}
|
||||
ConditionEvaluationReport report = event.getApplicationContext()
|
||||
.getBean(ConditionEvaluationReport.class);
|
||||
ConditionEvaluationReport previousReport = previousReports
|
||||
.get(event.getApplicationContext().getId());
|
||||
ConditionEvaluationReport report = event.getApplicationContext().getBean(ConditionEvaluationReport.class);
|
||||
ConditionEvaluationReport previousReport = previousReports.get(event.getApplicationContext().getId());
|
||||
if (previousReport != null) {
|
||||
ConditionEvaluationReport delta = report.getDelta(previousReport);
|
||||
if (!delta.getConditionAndOutcomesBySource().isEmpty()
|
||||
|| !delta.getExclusions().isEmpty()
|
||||
if (!delta.getConditionAndOutcomesBySource().isEmpty() || !delta.getExclusions().isEmpty()
|
||||
|| !delta.getUnconditionalClasses().isEmpty()) {
|
||||
if (ConditionEvaluationDeltaLoggingListener.logger.isInfoEnabled()) {
|
||||
ConditionEvaluationDeltaLoggingListener.logger
|
||||
.info("Condition evaluation delta:"
|
||||
+ new ConditionEvaluationReportMessage(delta,
|
||||
"CONDITION EVALUATION DELTA"));
|
||||
ConditionEvaluationDeltaLoggingListener.logger.info("Condition evaluation delta:"
|
||||
+ new ConditionEvaluationReportMessage(delta, "CONDITION EVALUATION DELTA"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ConditionEvaluationDeltaLoggingListener.logger
|
||||
.info("Condition evaluation unchanged");
|
||||
ConditionEvaluationDeltaLoggingListener.logger.info("Condition evaluation unchanged");
|
||||
}
|
||||
}
|
||||
previousReports.put(event.getApplicationContext().getId(), report);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -60,10 +60,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
public class DevToolsDataSourceAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
NonEmbeddedInMemoryDatabaseShutdownExecutor inMemoryDatabaseShutdownExecutor(
|
||||
DataSource dataSource, DataSourceProperties dataSourceProperties) {
|
||||
return new NonEmbeddedInMemoryDatabaseShutdownExecutor(dataSource,
|
||||
dataSourceProperties);
|
||||
NonEmbeddedInMemoryDatabaseShutdownExecutor inMemoryDatabaseShutdownExecutor(DataSource dataSource,
|
||||
DataSourceProperties dataSourceProperties) {
|
||||
return new NonEmbeddedInMemoryDatabaseShutdownExecutor(dataSource, dataSourceProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +73,7 @@ public class DevToolsDataSourceAutoConfiguration {
|
||||
@Configuration
|
||||
@ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class)
|
||||
@ConditionalOnBean(AbstractEntityManagerFactoryBean.class)
|
||||
static class DatabaseShutdownExecutorJpaDependencyConfiguration
|
||||
extends EntityManagerFactoryDependsOnPostProcessor {
|
||||
static class DatabaseShutdownExecutorJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor {
|
||||
|
||||
DatabaseShutdownExecutorJpaDependencyConfiguration() {
|
||||
super("inMemoryDatabaseShutdownExecutor");
|
||||
@@ -83,15 +81,13 @@ public class DevToolsDataSourceAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
static final class NonEmbeddedInMemoryDatabaseShutdownExecutor
|
||||
implements DisposableBean {
|
||||
static final class NonEmbeddedInMemoryDatabaseShutdownExecutor implements DisposableBean {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final DataSourceProperties dataSourceProperties;
|
||||
|
||||
NonEmbeddedInMemoryDatabaseShutdownExecutor(DataSource dataSource,
|
||||
DataSourceProperties dataSourceProperties) {
|
||||
NonEmbeddedInMemoryDatabaseShutdownExecutor(DataSource dataSource, DataSourceProperties dataSourceProperties) {
|
||||
this.dataSource = dataSource;
|
||||
this.dataSourceProperties = dataSourceProperties;
|
||||
}
|
||||
@@ -122,8 +118,7 @@ public class DevToolsDataSourceAutoConfiguration {
|
||||
|
||||
H2("jdbc:h2:mem:", "org.h2.Driver", "org.h2.jdbcx.JdbcDataSource"),
|
||||
|
||||
HSQLDB("jdbc:hsqldb:mem:", "org.hsqldb.jdbcDriver",
|
||||
"org.hsqldb.jdbc.JDBCDriver",
|
||||
HSQLDB("jdbc:hsqldb:mem:", "org.hsqldb.jdbcDriver", "org.hsqldb.jdbc.JDBCDriver",
|
||||
"org.hsqldb.jdbc.pool.JDBCXADataSource");
|
||||
|
||||
private final String urlPrefix;
|
||||
@@ -137,18 +132,15 @@ public class DevToolsDataSourceAutoConfiguration {
|
||||
|
||||
boolean matches(DataSourceProperties properties) {
|
||||
String url = properties.getUrl();
|
||||
return (url == null || this.urlPrefix == null
|
||||
|| url.startsWith(this.urlPrefix))
|
||||
&& this.driverClassNames
|
||||
.contains(properties.determineDriverClassName());
|
||||
return (url == null || this.urlPrefix == null || url.startsWith(this.urlPrefix))
|
||||
&& this.driverClassNames.contains(properties.determineDriverClassName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class DevToolsDataSourceCondition extends SpringBootCondition
|
||||
implements ConfigurationCondition {
|
||||
static class DevToolsDataSourceCondition extends SpringBootCondition implements ConfigurationCondition {
|
||||
|
||||
@Override
|
||||
public ConfigurationPhase getConfigurationPhase() {
|
||||
@@ -156,35 +148,24 @@ public class DevToolsDataSourceAutoConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
ConditionMessage.Builder message = ConditionMessage
|
||||
.forCondition("DevTools DataSource Condition");
|
||||
String[] dataSourceBeanNames = context.getBeanFactory()
|
||||
.getBeanNamesForType(DataSource.class);
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition("DevTools DataSource Condition");
|
||||
String[] dataSourceBeanNames = context.getBeanFactory().getBeanNamesForType(DataSource.class);
|
||||
if (dataSourceBeanNames.length != 1) {
|
||||
return ConditionOutcome
|
||||
.noMatch(message.didNotFind("a single DataSource bean").atAll());
|
||||
return ConditionOutcome.noMatch(message.didNotFind("a single DataSource bean").atAll());
|
||||
}
|
||||
if (context.getBeanFactory()
|
||||
.getBeanNamesForType(DataSourceProperties.class).length != 1) {
|
||||
return ConditionOutcome.noMatch(
|
||||
message.didNotFind("a single DataSourceProperties bean").atAll());
|
||||
if (context.getBeanFactory().getBeanNamesForType(DataSourceProperties.class).length != 1) {
|
||||
return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll());
|
||||
}
|
||||
BeanDefinition dataSourceDefinition = context.getRegistry()
|
||||
.getBeanDefinition(dataSourceBeanNames[0]);
|
||||
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);
|
||||
if (dataSourceDefinition instanceof AnnotatedBeanDefinition
|
||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition)
|
||||
.getFactoryMethodMetadata() != null
|
||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition)
|
||||
.getFactoryMethodMetadata().getDeclaringClassName()
|
||||
.startsWith(DataSourceAutoConfiguration.class.getPackage()
|
||||
.getName() + ".DataSourceConfiguration$")) {
|
||||
return ConditionOutcome
|
||||
.match(message.foundExactly("auto-configured DataSource"));
|
||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata() != null
|
||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata()
|
||||
.getDeclaringClassName().startsWith(DataSourceAutoConfiguration.class.getPackage().getName()
|
||||
+ ".DataSourceConfiguration$")) {
|
||||
return ConditionOutcome.match(message.foundExactly("auto-configured DataSource"));
|
||||
}
|
||||
return ConditionOutcome
|
||||
.noMatch(message.didNotFind("an auto-configured DataSource").atAll());
|
||||
return ConditionOutcome.noMatch(message.didNotFind("an auto-configured DataSource").atAll());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -119,8 +119,7 @@ public class DevToolsProperties {
|
||||
allExclude.addAll(StringUtils.commaDelimitedListToSet(this.exclude));
|
||||
}
|
||||
if (StringUtils.hasText(this.additionalExclude)) {
|
||||
allExclude.addAll(
|
||||
StringUtils.commaDelimitedListToSet(this.additionalExclude));
|
||||
allExclude.addAll(StringUtils.commaDelimitedListToSet(this.additionalExclude));
|
||||
}
|
||||
return StringUtils.toStringArray(allExclude);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -44,8 +44,7 @@ class FileWatchingFailureHandler implements FailureHandler {
|
||||
public Outcome handle(Throwable failure) {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
FileSystemWatcher watcher = this.fileSystemWatcherFactory.getFileSystemWatcher();
|
||||
watcher.addSourceFolders(
|
||||
new ClassPathFolders(Restarter.getInstance().getInitialUrls()));
|
||||
watcher.addSourceFolders(new ClassPathFolders(Restarter.getInstance().getInitialUrls()));
|
||||
watcher.addListener(new Listener(latch));
|
||||
watcher.start();
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -36,8 +36,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
class HateoasObjenesisCacheDisabler implements InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(HateoasObjenesisCacheDisabler.class);
|
||||
private static final Log logger = LogFactory.getLog(HateoasObjenesisCacheDisabler.class);
|
||||
|
||||
private static boolean cacheDisabled;
|
||||
|
||||
@@ -55,8 +54,7 @@ class HateoasObjenesisCacheDisabler implements InitializingBean {
|
||||
|
||||
private void doDisableCaching() {
|
||||
try {
|
||||
Class<?> type = ClassUtils.forName(
|
||||
"org.springframework.hateoas.core.DummyInvocationUtils",
|
||||
Class<?> type = ClassUtils.forName("org.springframework.hateoas.core.DummyInvocationUtils",
|
||||
getClass().getClassLoader());
|
||||
removeObjenesisCache(type);
|
||||
}
|
||||
@@ -67,21 +65,17 @@ class HateoasObjenesisCacheDisabler implements InitializingBean {
|
||||
|
||||
private void removeObjenesisCache(Class<?> dummyInvocationUtils) {
|
||||
try {
|
||||
Field objenesisField = ReflectionUtils.findField(dummyInvocationUtils,
|
||||
"OBJENESIS");
|
||||
Field objenesisField = ReflectionUtils.findField(dummyInvocationUtils, "OBJENESIS");
|
||||
if (objenesisField != null) {
|
||||
ReflectionUtils.makeAccessible(objenesisField);
|
||||
Object objenesis = ReflectionUtils.getField(objenesisField, null);
|
||||
Field cacheField = ReflectionUtils.findField(objenesis.getClass(),
|
||||
"cache");
|
||||
Field cacheField = ReflectionUtils.findField(objenesis.getClass(), "cache");
|
||||
ReflectionUtils.makeAccessible(cacheField);
|
||||
ReflectionUtils.setField(cacheField, objenesis, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn(
|
||||
"Failed to disable Spring HATEOAS's Objenesis cache. ClassCastExceptions may occur",
|
||||
ex);
|
||||
logger.warn("Failed to disable Spring HATEOAS's Objenesis cache. ClassCastExceptions may occur", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,7 @@ public class LocalDevToolsAutoConfiguration {
|
||||
* Local LiveReload configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true)
|
||||
static class LiveReloadConfiguration {
|
||||
|
||||
private final DevToolsProperties properties;
|
||||
@@ -80,14 +79,12 @@ public class LocalDevToolsAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OptionalLiveReloadServer optionalLiveReloadServer(
|
||||
LiveReloadServer liveReloadServer) {
|
||||
public OptionalLiveReloadServer optionalLiveReloadServer(LiveReloadServer liveReloadServer) {
|
||||
return new OptionalLiveReloadServer(liveReloadServer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LiveReloadServerEventListener liveReloadServerEventListener(
|
||||
OptionalLiveReloadServer liveReloadServer) {
|
||||
public LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadServer liveReloadServer) {
|
||||
return new LiveReloadServerEventListener(liveReloadServer);
|
||||
}
|
||||
|
||||
@@ -97,10 +94,8 @@ public class LocalDevToolsAutoConfiguration {
|
||||
* Local Restart Configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled",
|
||||
matchIfMissing = true)
|
||||
static class RestartConfiguration
|
||||
implements ApplicationListener<ClassPathChangedEvent> {
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled", matchIfMissing = true)
|
||||
static class RestartConfiguration implements ApplicationListener<ClassPathChangedEvent> {
|
||||
|
||||
private final DevToolsProperties properties;
|
||||
|
||||
@@ -111,8 +106,7 @@ public class LocalDevToolsAutoConfiguration {
|
||||
@Override
|
||||
public void onApplicationEvent(ClassPathChangedEvent event) {
|
||||
if (event.isRestartRequired()) {
|
||||
Restarter.getInstance().restart(
|
||||
new FileWatchingFailureHandler(fileSystemWatcherFactory()));
|
||||
Restarter.getInstance().restart(new FileWatchingFailureHandler(fileSystemWatcherFactory()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +114,8 @@ public class LocalDevToolsAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public ClassPathFileSystemWatcher classPathFileSystemWatcher() {
|
||||
URL[] urls = Restarter.getInstance().getInitialUrls();
|
||||
ClassPathFileSystemWatcher watcher = new ClassPathFileSystemWatcher(
|
||||
fileSystemWatcherFactory(), classPathRestartStrategy(), urls);
|
||||
ClassPathFileSystemWatcher watcher = new ClassPathFileSystemWatcher(fileSystemWatcherFactory(),
|
||||
classPathRestartStrategy(), urls);
|
||||
watcher.setStopWatcherOnRestart(true);
|
||||
return watcher;
|
||||
}
|
||||
@@ -129,8 +123,7 @@ public class LocalDevToolsAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ClassPathRestartStrategy classPathRestartStrategy() {
|
||||
return new PatternClassPathRestartStrategy(
|
||||
this.properties.getRestart().getAllExclude());
|
||||
return new PatternClassPathRestartStrategy(this.properties.getRestart().getAllExclude());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -144,16 +137,15 @@ public class LocalDevToolsAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.restart",
|
||||
name = "log-condition-evaluation-delta", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.restart", name = "log-condition-evaluation-delta",
|
||||
matchIfMissing = true)
|
||||
public ConditionEvaluationDeltaLoggingListener conditionEvaluationDeltaLoggingListener() {
|
||||
return new ConditionEvaluationDeltaLoggingListener();
|
||||
}
|
||||
|
||||
private FileSystemWatcher newFileSystemWatcher() {
|
||||
Restart restartProperties = this.properties.getRestart();
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(true,
|
||||
restartProperties.getPollInterval(),
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(true, restartProperties.getPollInterval(),
|
||||
restartProperties.getQuietPeriod());
|
||||
String triggerFile = restartProperties.getTriggerFile();
|
||||
if (StringUtils.hasLength(triggerFile)) {
|
||||
@@ -193,9 +185,8 @@ public class LocalDevToolsAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ContextRefreshedEvent
|
||||
|| (event instanceof ClassPathChangedEvent
|
||||
&& !((ClassPathChangedEvent) event).isRestartRequired())) {
|
||||
if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent
|
||||
&& !((ClassPathChangedEvent) event).isRestartRequired())) {
|
||||
this.liveReloadServer.triggerReload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -54,8 +54,7 @@ public class OptionalLiveReloadServer implements InitializingBean {
|
||||
if (!this.server.isStarted()) {
|
||||
this.server.start();
|
||||
}
|
||||
logger.info(
|
||||
"LiveReload server is running on port " + this.server.getPort());
|
||||
logger.info("LiveReload server is running on port " + this.server.getPort());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn("Unable to start LiveReload server");
|
||||
|
||||
@@ -61,15 +61,13 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
@EnableConfigurationProperties({ ServerProperties.class, DevToolsProperties.class })
|
||||
public class RemoteDevToolsAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(RemoteDevToolsAutoConfiguration.class);
|
||||
private static final Log logger = LogFactory.getLog(RemoteDevToolsAutoConfiguration.class);
|
||||
|
||||
private final DevToolsProperties properties;
|
||||
|
||||
private final ServerProperties serverProperties;
|
||||
|
||||
public RemoteDevToolsAutoConfiguration(DevToolsProperties properties,
|
||||
ServerProperties serverProperties) {
|
||||
public RemoteDevToolsAutoConfiguration(DevToolsProperties properties, ServerProperties serverProperties) {
|
||||
this.properties = properties;
|
||||
this.serverProperties = serverProperties;
|
||||
}
|
||||
@@ -78,19 +76,15 @@ public class RemoteDevToolsAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public AccessManager remoteDevToolsAccessManager() {
|
||||
RemoteDevToolsProperties remoteProperties = this.properties.getRemote();
|
||||
return new HttpHeaderAccessManager(remoteProperties.getSecretHeaderName(),
|
||||
remoteProperties.getSecret());
|
||||
return new HttpHeaderAccessManager(remoteProperties.getSecretHeaderName(), remoteProperties.getSecret());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandlerMapper remoteDevToolsHealthCheckHandlerMapper() {
|
||||
Handler handler = new HttpStatusHandler();
|
||||
Servlet servlet = this.serverProperties.getServlet();
|
||||
String servletContextPath = (servlet.getContextPath() != null)
|
||||
? servlet.getContextPath() : "";
|
||||
return new UrlHandlerMapper(
|
||||
servletContextPath + this.properties.getRemote().getContextPath(),
|
||||
handler);
|
||||
String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : "";
|
||||
return new UrlHandlerMapper(servletContextPath + this.properties.getRemote().getContextPath(), handler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -105,8 +99,7 @@ public class RemoteDevToolsAutoConfiguration {
|
||||
* Configuration for remote update and restarts.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true)
|
||||
static class RemoteRestartConfiguration {
|
||||
|
||||
@Autowired
|
||||
@@ -123,8 +116,7 @@ public class RemoteDevToolsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HttpRestartServer remoteRestartHttpRestartServer(
|
||||
SourceFolderUrlFilter sourceFolderUrlFilter) {
|
||||
public HttpRestartServer remoteRestartHttpRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter) {
|
||||
return new HttpRestartServer(sourceFolderUrlFilter);
|
||||
}
|
||||
|
||||
@@ -133,8 +125,7 @@ public class RemoteDevToolsAutoConfiguration {
|
||||
public UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server) {
|
||||
Servlet servlet = this.serverProperties.getServlet();
|
||||
RemoteDevToolsProperties remote = this.properties.getRemote();
|
||||
String servletContextPath = (servlet.getContextPath() != null)
|
||||
? servlet.getContextPath() : "";
|
||||
String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : "";
|
||||
String url = servletContextPath + remote.getContextPath() + "/restart";
|
||||
logger.warn("Listening for remote restart updates on " + url);
|
||||
Handler handler = new HttpRestartServerHandler(server);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -41,8 +41,7 @@ public class ClassPathChangedEvent extends ApplicationEvent {
|
||||
* @param changeSet the changed files
|
||||
* @param restartRequired if a restart is required due to the change
|
||||
*/
|
||||
public ClassPathChangedEvent(Object source, Set<ChangedFiles> changeSet,
|
||||
boolean restartRequired) {
|
||||
public ClassPathChangedEvent(Object source, Set<ChangedFiles> changeSet, boolean restartRequired) {
|
||||
super(source);
|
||||
Assert.notNull(changeSet, "ChangeSet must not be null");
|
||||
this.changeSet = changeSet;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -48,8 +48,7 @@ class ClassPathFileChangeListener implements FileChangeListener {
|
||||
* @param fileSystemWatcherToStop the file system watcher to stop on a restart (or
|
||||
* {@code null})
|
||||
*/
|
||||
ClassPathFileChangeListener(ApplicationEventPublisher eventPublisher,
|
||||
ClassPathRestartStrategy restartStrategy,
|
||||
ClassPathFileChangeListener(ApplicationEventPublisher eventPublisher, ClassPathRestartStrategy restartStrategy,
|
||||
FileSystemWatcher fileSystemWatcherToStop) {
|
||||
Assert.notNull(eventPublisher, "EventPublisher must not be null");
|
||||
Assert.notNull(restartStrategy, "RestartStrategy must not be null");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -35,8 +35,7 @@ import org.springframework.util.Assert;
|
||||
* @since 1.3.0
|
||||
* @see ClassPathFileChangeListener
|
||||
*/
|
||||
public class ClassPathFileSystemWatcher
|
||||
implements InitializingBean, DisposableBean, ApplicationContextAware {
|
||||
public class ClassPathFileSystemWatcher implements InitializingBean, DisposableBean, ApplicationContextAware {
|
||||
|
||||
private final FileSystemWatcher fileSystemWatcher;
|
||||
|
||||
@@ -55,8 +54,7 @@ public class ClassPathFileSystemWatcher
|
||||
*/
|
||||
public ClassPathFileSystemWatcher(FileSystemWatcherFactory fileSystemWatcherFactory,
|
||||
ClassPathRestartStrategy restartStrategy, URL[] urls) {
|
||||
Assert.notNull(fileSystemWatcherFactory,
|
||||
"FileSystemWatcherFactory must not be null");
|
||||
Assert.notNull(fileSystemWatcherFactory, "FileSystemWatcherFactory must not be null");
|
||||
Assert.notNull(urls, "Urls must not be null");
|
||||
this.fileSystemWatcher = fileSystemWatcherFactory.getFileSystemWatcher();
|
||||
this.restartStrategy = restartStrategy;
|
||||
@@ -72,8 +70,7 @@ public class ClassPathFileSystemWatcher
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@@ -84,8 +81,8 @@ public class ClassPathFileSystemWatcher
|
||||
if (this.stopWatcherOnRestart) {
|
||||
watcherToStop = this.fileSystemWatcher;
|
||||
}
|
||||
this.fileSystemWatcher.addListener(new ClassPathFileChangeListener(
|
||||
this.applicationContext, this.restartStrategy, watcherToStop));
|
||||
this.fileSystemWatcher.addListener(
|
||||
new ClassPathFileChangeListener(this.applicationContext, this.restartStrategy, watcherToStop));
|
||||
}
|
||||
this.fileSystemWatcher.start();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -41,8 +41,7 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
|
||||
private static final String FILE_NAME = ".spring-boot-devtools.properties";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
File home = getHomeFolder();
|
||||
File propertyFile = (home != null) ? new File(home, FILE_NAME) : null;
|
||||
if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
|
||||
@@ -50,8 +49,7 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
|
||||
Properties properties;
|
||||
try {
|
||||
properties = PropertiesLoaderUtils.loadProperties(resource);
|
||||
environment.getPropertySources().addFirst(
|
||||
new PropertiesPropertySource("devtools-local", properties));
|
||||
environment.getPropertySources().addFirst(new PropertiesPropertySource("devtools-local", properties));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to load " + FILE_NAME, ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -45,8 +45,7 @@ import org.springframework.util.ClassUtils;
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
private static final Log logger = DevToolsLogFactory
|
||||
.getLog(DevToolsPropertyDefaultsPostProcessor.class);
|
||||
private static final Log logger = DevToolsLogFactory.getLog(DevToolsPropertyDefaultsPostProcessor.class);
|
||||
|
||||
private static final String ENABLED = "spring.devtools.add-properties";
|
||||
|
||||
@@ -77,19 +76,15 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
if (isLocalApplication(environment)) {
|
||||
if (canAddProperties(environment)) {
|
||||
logger.info("Devtools property defaults active! Set '" + ENABLED
|
||||
+ "' to 'false' to disable");
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource("devtools", PROPERTIES));
|
||||
logger.info("Devtools property defaults active! Set '" + ENABLED + "' to 'false' to disable");
|
||||
environment.getPropertySources().addLast(new MapPropertySource("devtools", PROPERTIES));
|
||||
}
|
||||
if (isWebApplication(environment)
|
||||
&& !environment.containsProperty(WEB_LOGGING)) {
|
||||
logger.info("For additional web related logging consider "
|
||||
+ "setting the '" + WEB_LOGGING + "' property to 'DEBUG'");
|
||||
if (isWebApplication(environment) && !environment.containsProperty(WEB_LOGGING)) {
|
||||
logger.info("For additional web related logging consider " + "setting the '" + WEB_LOGGING
|
||||
+ "' property to 'DEBUG'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,8 +116,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
|
||||
|
||||
private boolean isWebApplication(Environment environment) {
|
||||
for (String candidate : WEB_ENVIRONMENT_CLASSES) {
|
||||
Class<?> environmentClass = resolveClassName(candidate,
|
||||
environment.getClass().getClassLoader());
|
||||
Class<?> environmentClass = resolveClassName(candidate, environment.getClass().getClassLoader());
|
||||
if (environmentClass != null && environmentClass.isInstance(environment)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -76,8 +76,8 @@ public final class ChangedFile {
|
||||
File file = this.file.getAbsoluteFile();
|
||||
String folderName = StringUtils.cleanPath(folder.getPath());
|
||||
String fileName = StringUtils.cleanPath(file.getPath());
|
||||
Assert.state(fileName.startsWith(folderName), () -> "The file " + fileName
|
||||
+ " is not contained in the source folder " + folderName);
|
||||
Assert.state(fileName.startsWith(folderName),
|
||||
() -> "The file " + fileName + " is not contained in the source folder " + folderName);
|
||||
return fileName.substring(folderName.length() + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -71,8 +71,7 @@ public final class ChangedFiles implements Iterable<ChangedFile> {
|
||||
}
|
||||
if (obj instanceof ChangedFiles) {
|
||||
ChangedFiles other = (ChangedFiles) obj;
|
||||
return this.sourceFolder.equals(other.sourceFolder)
|
||||
&& this.files.equals(other.files);
|
||||
return this.sourceFolder.equals(other.sourceFolder) && this.files.equals(other.files);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -78,8 +78,7 @@ public class FileSystemWatcher {
|
||||
* @param quietPeriod the amount of time required after a change has been detected to
|
||||
* ensure that updates have completed
|
||||
*/
|
||||
public FileSystemWatcher(boolean daemon, Duration pollInterval,
|
||||
Duration quietPeriod) {
|
||||
public FileSystemWatcher(boolean daemon, Duration pollInterval, Duration quietPeriod) {
|
||||
Assert.notNull(pollInterval, "PollInterval must not be null");
|
||||
Assert.notNull(quietPeriod, "QuietPeriod must not be null");
|
||||
Assert.isTrue(pollInterval.toMillis() > 0, "PollInterval must be positive");
|
||||
@@ -157,9 +156,8 @@ public class FileSystemWatcher {
|
||||
if (this.watchThread == null) {
|
||||
Map<File, FolderSnapshot> localFolders = new HashMap<>();
|
||||
localFolders.putAll(this.folders);
|
||||
this.watchThread = new Thread(new Watcher(this.remainingScans,
|
||||
new ArrayList<>(this.listeners), this.triggerFilter,
|
||||
this.pollInterval, this.quietPeriod, localFolders));
|
||||
this.watchThread = new Thread(new Watcher(this.remainingScans, new ArrayList<>(this.listeners),
|
||||
this.triggerFilter, this.pollInterval, this.quietPeriod, localFolders));
|
||||
this.watchThread.setName("File Watcher");
|
||||
this.watchThread.setDaemon(this.daemon);
|
||||
this.watchThread.start();
|
||||
@@ -220,9 +218,8 @@ public class FileSystemWatcher {
|
||||
|
||||
private Map<File, FolderSnapshot> folders;
|
||||
|
||||
private Watcher(AtomicInteger remainingScans, List<FileChangeListener> listeners,
|
||||
FileFilter triggerFilter, long pollInterval, long quietPeriod,
|
||||
Map<File, FolderSnapshot> folders) {
|
||||
private Watcher(AtomicInteger remainingScans, List<FileChangeListener> listeners, FileFilter triggerFilter,
|
||||
long pollInterval, long quietPeriod, Map<File, FolderSnapshot> folders) {
|
||||
this.remainingScans = remainingScans;
|
||||
this.listeners = listeners;
|
||||
this.triggerFilter = triggerFilter;
|
||||
@@ -263,8 +260,7 @@ public class FileSystemWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDifferent(Map<File, FolderSnapshot> previous,
|
||||
Map<File, FolderSnapshot> current) {
|
||||
private boolean isDifferent(Map<File, FolderSnapshot> previous, Map<File, FolderSnapshot> current) {
|
||||
if (!previous.keySet().equals(current.keySet())) {
|
||||
return true;
|
||||
}
|
||||
@@ -292,8 +288,7 @@ public class FileSystemWatcher {
|
||||
for (FolderSnapshot snapshot : snapshots) {
|
||||
FolderSnapshot previous = this.folders.get(snapshot.getFolder());
|
||||
updated.put(snapshot.getFolder(), snapshot);
|
||||
ChangedFiles changedFiles = previous.getChangedFiles(snapshot,
|
||||
this.triggerFilter);
|
||||
ChangedFiles changedFiles = previous.getChangedFiles(snapshot, this.triggerFilter);
|
||||
if (!changedFiles.getFiles().isEmpty()) {
|
||||
changeSet.add(changedFiles);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -37,8 +37,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
class FolderSnapshot {
|
||||
|
||||
private static final Set<String> DOT_FOLDERS = Collections
|
||||
.unmodifiableSet(new HashSet<>(Arrays.asList(".", "..")));
|
||||
private static final Set<String> DOT_FOLDERS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(".", "..")));
|
||||
|
||||
private final File folder;
|
||||
|
||||
@@ -74,12 +73,10 @@ class FolderSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
public ChangedFiles getChangedFiles(FolderSnapshot snapshot,
|
||||
FileFilter triggerFilter) {
|
||||
public ChangedFiles getChangedFiles(FolderSnapshot snapshot, FileFilter triggerFilter) {
|
||||
Assert.notNull(snapshot, "Snapshot must not be null");
|
||||
File folder = this.folder;
|
||||
Assert.isTrue(snapshot.folder.equals(folder),
|
||||
() -> "Snapshot source folder must be '" + folder + "'");
|
||||
Assert.isTrue(snapshot.folder.equals(folder), () -> "Snapshot source folder must be '" + folder + "'");
|
||||
Set<ChangedFile> changes = new LinkedHashSet<>();
|
||||
Map<File, FileSnapshot> previousFiles = getFilesMap();
|
||||
for (FileSnapshot currentFile : snapshot.files) {
|
||||
@@ -89,8 +86,7 @@ class FolderSnapshot {
|
||||
changes.add(new ChangedFile(folder, currentFile.getFile(), Type.ADD));
|
||||
}
|
||||
else if (!previousFile.equals(currentFile)) {
|
||||
changes.add(
|
||||
new ChangedFile(folder, currentFile.getFile(), Type.MODIFY));
|
||||
changes.add(new ChangedFile(folder, currentFile.getFile(), Type.MODIFY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -40,8 +40,7 @@ class Connection {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(Connection.class);
|
||||
|
||||
private static final Pattern WEBSOCKET_KEY_PATTERN = Pattern
|
||||
.compile("^Sec-WebSocket-Key:(.*)$", Pattern.MULTILINE);
|
||||
private static final Pattern WEBSOCKET_KEY_PATTERN = Pattern.compile("^Sec-WebSocket-Key:(.*)$", Pattern.MULTILINE);
|
||||
|
||||
public static final String WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
@@ -64,8 +63,7 @@ class Connection {
|
||||
* @param outputStream the socket output stream
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
Connection(Socket socket, InputStream inputStream, OutputStream outputStream)
|
||||
throws IOException {
|
||||
Connection(Socket socket, InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||
this.socket = socket;
|
||||
this.inputStream = new ConnectionInputStream(inputStream);
|
||||
this.outputStream = new ConnectionOutputStream(outputStream);
|
||||
@@ -78,23 +76,19 @@ class Connection {
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
public void run() throws Exception {
|
||||
if (this.header.contains("Upgrade: websocket")
|
||||
&& this.header.contains("Sec-WebSocket-Version: 13")) {
|
||||
if (this.header.contains("Upgrade: websocket") && this.header.contains("Sec-WebSocket-Version: 13")) {
|
||||
runWebSocket();
|
||||
}
|
||||
if (this.header.contains("GET /livereload.js")) {
|
||||
this.outputStream.writeHttp(getClass().getResourceAsStream("livereload.js"),
|
||||
"text/javascript");
|
||||
this.outputStream.writeHttp(getClass().getResourceAsStream("livereload.js"), "text/javascript");
|
||||
}
|
||||
}
|
||||
|
||||
private void runWebSocket() throws Exception {
|
||||
String accept = getWebsocketAcceptResponse();
|
||||
this.outputStream.writeHeaders("HTTP/1.1 101 Switching Protocols",
|
||||
"Upgrade: websocket", "Connection: Upgrade",
|
||||
this.outputStream.writeHeaders("HTTP/1.1 101 Switching Protocols", "Upgrade: websocket", "Connection: Upgrade",
|
||||
"Sec-WebSocket-Accept: " + accept);
|
||||
new Frame("{\"command\":\"hello\",\"protocols\":"
|
||||
+ "[\"http://livereload.com/protocols/official-7\"],"
|
||||
new Frame("{\"command\":\"hello\",\"protocols\":" + "[\"http://livereload.com/protocols/official-7\"],"
|
||||
+ "\"serverName\":\"spring-boot\"}").write(this.outputStream);
|
||||
Thread.sleep(100);
|
||||
this.webSocket = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -41,8 +41,8 @@ class ConnectionOutputStream extends FilterOutputStream {
|
||||
|
||||
public void writeHttp(InputStream content, String contentType) throws IOException {
|
||||
byte[] bytes = FileCopyUtils.copyToByteArray(content);
|
||||
writeHeaders("HTTP/1.1 200 OK", "Content-Type: " + contentType,
|
||||
"Content-Length: " + bytes.length, "Connection: close");
|
||||
writeHeaders("HTTP/1.1 200 OK", "Content-Type: " + contentType, "Content-Length: " + bytes.length,
|
||||
"Connection: close");
|
||||
write(bytes);
|
||||
flush();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -52,8 +52,7 @@ public class LiveReloadServer {
|
||||
|
||||
private static final int READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(4);
|
||||
|
||||
private final ExecutorService executor = Executors
|
||||
.newCachedThreadPool(new WorkerThreadFactory());
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool(new WorkerThreadFactory());
|
||||
|
||||
private final List<Connection> connections = new ArrayList<>();
|
||||
|
||||
@@ -232,8 +231,8 @@ public class LiveReloadServer {
|
||||
* @return a connection
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
protected Connection createConnection(Socket socket, InputStream inputStream,
|
||||
OutputStream outputStream) throws IOException {
|
||||
protected Connection createConnection(Socket socket, InputStream inputStream, OutputStream outputStream)
|
||||
throws IOException {
|
||||
return new Connection(socket, inputStream, outputStream);
|
||||
}
|
||||
|
||||
@@ -271,8 +270,7 @@ public class LiveReloadServer {
|
||||
private void handle() throws Exception {
|
||||
try {
|
||||
try (OutputStream outputStream = this.socket.getOutputStream()) {
|
||||
Connection connection = createConnection(this.socket,
|
||||
this.inputStream, outputStream);
|
||||
Connection connection = createConnection(this.socket, this.inputStream, outputStream);
|
||||
runConnection(connection);
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -55,14 +55,12 @@ import org.springframework.util.FileCopyUtils;
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class ClassPathChangeUploader
|
||||
implements ApplicationListener<ClassPathChangedEvent> {
|
||||
public class ClassPathChangeUploader implements ApplicationListener<ClassPathChangedEvent> {
|
||||
|
||||
private static final Map<ChangedFile.Type, ClassLoaderFile.Kind> TYPE_MAPPINGS;
|
||||
|
||||
static {
|
||||
Map<ChangedFile.Type, ClassLoaderFile.Kind> map = new EnumMap<>(
|
||||
ChangedFile.Type.class);
|
||||
Map<ChangedFile.Type, ClassLoaderFile.Kind> map = new EnumMap<>(ChangedFile.Type.class);
|
||||
map.put(ChangedFile.Type.ADD, ClassLoaderFile.Kind.ADDED);
|
||||
map.put(ChangedFile.Type.DELETE, ClassLoaderFile.Kind.DELETED);
|
||||
map.put(ChangedFile.Type.MODIFY, ClassLoaderFile.Kind.MODIFIED);
|
||||
@@ -99,21 +97,19 @@ public class ClassPathChangeUploader
|
||||
}
|
||||
}
|
||||
|
||||
private void performUpload(ClassLoaderFiles classLoaderFiles, byte[] bytes)
|
||||
throws IOException {
|
||||
private void performUpload(ClassLoaderFiles classLoaderFiles, byte[] bytes) throws IOException {
|
||||
try {
|
||||
while (true) {
|
||||
try {
|
||||
ClientHttpRequest request = this.requestFactory
|
||||
.createRequest(this.uri, HttpMethod.POST);
|
||||
ClientHttpRequest request = this.requestFactory.createRequest(this.uri, HttpMethod.POST);
|
||||
HttpHeaders headers = request.getHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
headers.setContentLength(bytes.length);
|
||||
FileCopyUtils.copy(bytes, request.getBody());
|
||||
ClientHttpResponse response = request.execute();
|
||||
HttpStatus statusCode = response.getStatusCode();
|
||||
Assert.state(statusCode == HttpStatus.OK, () -> "Unexpected "
|
||||
+ statusCode + " response uploading class files");
|
||||
Assert.state(statusCode == HttpStatus.OK,
|
||||
() -> "Unexpected " + statusCode + " response uploading class files");
|
||||
logUpload(classLoaderFiles);
|
||||
return;
|
||||
}
|
||||
@@ -133,8 +129,7 @@ public class ClassPathChangeUploader
|
||||
|
||||
private void logUpload(ClassLoaderFiles classLoaderFiles) {
|
||||
int size = classLoaderFiles.size();
|
||||
logger.info("Uploaded " + size + " class "
|
||||
+ ((size != 1) ? "resources" : "resource"));
|
||||
logger.info("Uploaded " + size + " class " + ((size != 1) ? "resources" : "resource"));
|
||||
}
|
||||
|
||||
private byte[] serialize(ClassLoaderFiles classLoaderFiles) throws IOException {
|
||||
@@ -145,26 +140,21 @@ public class ClassPathChangeUploader
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
private ClassLoaderFiles getClassLoaderFiles(ClassPathChangedEvent event)
|
||||
throws IOException {
|
||||
private ClassLoaderFiles getClassLoaderFiles(ClassPathChangedEvent event) throws IOException {
|
||||
ClassLoaderFiles files = new ClassLoaderFiles();
|
||||
for (ChangedFiles changedFiles : event.getChangeSet()) {
|
||||
String sourceFolder = changedFiles.getSourceFolder().getAbsolutePath();
|
||||
for (ChangedFile changedFile : changedFiles) {
|
||||
files.addFile(sourceFolder, changedFile.getRelativeName(),
|
||||
asClassLoaderFile(changedFile));
|
||||
files.addFile(sourceFolder, changedFile.getRelativeName(), asClassLoaderFile(changedFile));
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
private ClassLoaderFile asClassLoaderFile(ChangedFile changedFile)
|
||||
throws IOException {
|
||||
private ClassLoaderFile asClassLoaderFile(ChangedFile changedFile) throws IOException {
|
||||
ClassLoaderFile.Kind kind = TYPE_MAPPINGS.get(changedFile.getType());
|
||||
byte[] bytes = (kind != Kind.DELETED)
|
||||
? FileCopyUtils.copyToByteArray(changedFile.getFile()) : null;
|
||||
long lastModified = (kind != Kind.DELETED) ? changedFile.getFile().lastModified()
|
||||
: System.currentTimeMillis();
|
||||
byte[] bytes = (kind != Kind.DELETED) ? FileCopyUtils.copyToByteArray(changedFile.getFile()) : null;
|
||||
long lastModified = (kind != Kind.DELETED) ? changedFile.getFile().lastModified() : System.currentTimeMillis();
|
||||
return new ClassLoaderFile(kind, lastModified, bytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -59,8 +59,8 @@ class DelayedLiveReloadTrigger implements Runnable {
|
||||
|
||||
private long timeout = TIMEOUT;
|
||||
|
||||
DelayedLiveReloadTrigger(OptionalLiveReloadServer liveReloadServer,
|
||||
ClientHttpRequestFactory requestFactory, String url) {
|
||||
DelayedLiveReloadTrigger(OptionalLiveReloadServer liveReloadServer, ClientHttpRequestFactory requestFactory,
|
||||
String url) {
|
||||
Assert.notNull(liveReloadServer, "LiveReloadServer must not be null");
|
||||
Assert.notNull(requestFactory, "RequestFactory must not be null");
|
||||
Assert.hasLength(url, "URL must not be empty");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -51,8 +51,8 @@ public class HttpHeaderInterceptor implements ClientHttpRequestInterceptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
||||
throws IOException {
|
||||
request.getHeaders().add(this.name, this.value);
|
||||
return execution.execute(request, body);
|
||||
}
|
||||
|
||||
@@ -89,13 +89,12 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
|
||||
@Bean
|
||||
public ClientHttpRequestFactory clientHttpRequestFactory() {
|
||||
List<ClientHttpRequestInterceptor> interceptors = Arrays
|
||||
.asList(getSecurityInterceptor());
|
||||
List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(getSecurityInterceptor());
|
||||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
||||
Proxy proxy = this.properties.getRemote().getProxy();
|
||||
if (proxy.getHost() != null && proxy.getPort() != null) {
|
||||
requestFactory.setProxy(new java.net.Proxy(Type.HTTP,
|
||||
new InetSocketAddress(proxy.getHost(), proxy.getPort())));
|
||||
requestFactory
|
||||
.setProxy(new java.net.Proxy(Type.HTTP, new InetSocketAddress(proxy.getHost(), proxy.getPort())));
|
||||
}
|
||||
return new InterceptingClientHttpRequestFactory(requestFactory, interceptors);
|
||||
}
|
||||
@@ -105,8 +104,7 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
String secretHeaderName = remoteProperties.getSecretHeaderName();
|
||||
String secret = remoteProperties.getSecret();
|
||||
Assert.state(secret != null,
|
||||
"The environment value 'spring.devtools.remote.secret' "
|
||||
+ "is required to secure your connection.");
|
||||
"The environment value 'spring.devtools.remote.secret' " + "is required to secure your connection.");
|
||||
return new HttpHeaderInterceptor(secretHeaderName, secret);
|
||||
}
|
||||
|
||||
@@ -130,10 +128,8 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
* LiveReload configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled",
|
||||
matchIfMissing = true)
|
||||
static class LiveReloadConfiguration
|
||||
implements ApplicationListener<ClassPathChangedEvent> {
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true)
|
||||
static class LiveReloadConfiguration implements ApplicationListener<ClassPathChangedEvent> {
|
||||
|
||||
@Autowired
|
||||
private DevToolsProperties properties;
|
||||
@@ -160,8 +156,8 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
@Override
|
||||
public void onApplicationEvent(ClassPathChangedEvent event) {
|
||||
String url = this.remoteUrl + this.properties.getRemote().getContextPath();
|
||||
this.executor.execute(new DelayedLiveReloadTrigger(optionalLiveReloadServer(),
|
||||
this.clientHttpRequestFactory, url));
|
||||
this.executor.execute(
|
||||
new DelayedLiveReloadTrigger(optionalLiveReloadServer(), this.clientHttpRequestFactory, url));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -179,8 +175,7 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
* Client configuration for remote update and restarts.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true)
|
||||
static class RemoteRestartClientConfiguration {
|
||||
|
||||
@Autowired
|
||||
@@ -196,8 +191,7 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
if (urls == null) {
|
||||
urls = new URL[0];
|
||||
}
|
||||
return new ClassPathFileSystemWatcher(getFileSystemWatcherFactory(),
|
||||
classPathRestartStrategy(), urls);
|
||||
return new ClassPathFileSystemWatcher(getFileSystemWatcherFactory(), classPathRestartStrategy(), urls);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -207,8 +201,7 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
|
||||
private FileSystemWatcher newFileSystemWatcher() {
|
||||
Restart restartProperties = this.properties.getRestart();
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(true,
|
||||
restartProperties.getPollInterval(),
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(true, restartProperties.getPollInterval(),
|
||||
restartProperties.getQuietPeriod());
|
||||
String triggerFile = restartProperties.getTriggerFile();
|
||||
if (StringUtils.hasLength(triggerFile)) {
|
||||
@@ -219,15 +212,12 @@ public class RemoteClientConfiguration implements InitializingBean {
|
||||
|
||||
@Bean
|
||||
public ClassPathRestartStrategy classPathRestartStrategy() {
|
||||
return new PatternClassPathRestartStrategy(
|
||||
this.properties.getRestart().getAllExclude());
|
||||
return new PatternClassPathRestartStrategy(this.properties.getRestart().getAllExclude());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClassPathChangeUploader classPathChangeUploader(
|
||||
ClientHttpRequestFactory requestFactory) {
|
||||
String url = this.remoteUrl + this.properties.getRemote().getContextPath()
|
||||
+ "/restart";
|
||||
public ClassPathChangeUploader classPathChangeUploader(ClientHttpRequestFactory requestFactory) {
|
||||
String url = this.remoteUrl + this.properties.getRemote().getContextPath() + "/restart";
|
||||
return new ClassPathChangeUploader(url, requestFactory);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -57,8 +57,7 @@ public class Dispatcher {
|
||||
* @return {@code true} if the request was dispatched
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public boolean handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException {
|
||||
public boolean handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
for (HandlerMapper mapper : this.mappers) {
|
||||
Handler handler = mapper.getHandler(request);
|
||||
if (handler != null) {
|
||||
@@ -69,8 +68,7 @@ public class Dispatcher {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handle(Handler handler, ServerHttpRequest request,
|
||||
ServerHttpResponse response) throws IOException {
|
||||
private void handle(Handler handler, ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
if (!this.accessManager.isAllowed(request)) {
|
||||
response.setStatusCode(HttpStatus.FORBIDDEN);
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -54,10 +54,9 @@ public class DispatcherFilter implements Filter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
if (request instanceof HttpServletRequest
|
||||
&& response instanceof HttpServletResponse) {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
|
||||
doFilter((HttpServletRequest) request, (HttpServletResponse) response, chain);
|
||||
}
|
||||
else {
|
||||
@@ -65,8 +64,8 @@ public class DispatcherFilter implements Filter {
|
||||
}
|
||||
}
|
||||
|
||||
private void doFilter(HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
ServerHttpRequest serverRequest = new ServletServerHttpRequest(request);
|
||||
ServerHttpResponse serverResponse = new ServletServerHttpResponse(response);
|
||||
if (!this.dispatcher.handle(serverRequest, serverResponse)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -36,7 +36,6 @@ public interface Handler {
|
||||
* @param response the response
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
void handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException;
|
||||
void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -51,8 +51,7 @@ public class HttpStatusHandler implements Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException {
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
response.setStatusCode(this.status);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -54,8 +54,7 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||
DevToolsSettings settings = DevToolsSettings.get();
|
||||
List<URL> reloadableUrls = new ArrayList<>(urls.length);
|
||||
for (URL url : urls) {
|
||||
if ((settings.isRestartInclude(url) || isFolderUrl(url.toString()))
|
||||
&& !settings.isRestartExclude(url)) {
|
||||
if ((settings.isRestartInclude(url) || isFolderUrl(url.toString())) && !settings.isRestartExclude(url)) {
|
||||
reloadableUrls.add(url);
|
||||
}
|
||||
}
|
||||
@@ -104,9 +103,7 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
return ((URLClassLoader) classLoader).getURLs();
|
||||
}
|
||||
return Stream
|
||||
.of(ManagementFactory.getRuntimeMXBean().getClassPath()
|
||||
.split(File.pathSeparator))
|
||||
return Stream.of(ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator))
|
||||
.map(ChangeableUrls::toURL).toArray(URL[]::new);
|
||||
}
|
||||
|
||||
@@ -115,8 +112,7 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||
return new File(classPathEntry).toURI().toURL();
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"URL could not be created from '" + classPathEntry + "'", ex);
|
||||
throw new IllegalArgumentException("URL could not be created from '" + classPathEntry + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,9 +125,7 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||
return getUrlsFromManifestClassPathAttribute(url, jarFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to read Class-Path attribute from manifest of jar " + url,
|
||||
ex);
|
||||
throw new IllegalStateException("Failed to read Class-Path attribute from manifest of jar " + url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,14 +142,12 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<URL> getUrlsFromManifestClassPathAttribute(URL jarUrl,
|
||||
JarFile jarFile) throws IOException {
|
||||
private static List<URL> getUrlsFromManifestClassPathAttribute(URL jarUrl, JarFile jarFile) throws IOException {
|
||||
Manifest manifest = jarFile.getManifest();
|
||||
if (manifest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String classPath = manifest.getMainAttributes()
|
||||
.getValue(Attributes.Name.CLASS_PATH);
|
||||
String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
|
||||
if (!StringUtils.hasText(classPath)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -173,8 +165,7 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Class-Path attribute contains malformed URL", ex);
|
||||
throw new IllegalStateException("Class-Path attribute contains malformed URL", ex);
|
||||
}
|
||||
}
|
||||
if (!nonExistentEntries.isEmpty()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -57,11 +57,9 @@ import org.springframework.web.context.support.ServletContextResourcePatternReso
|
||||
*/
|
||||
final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternResolver {
|
||||
|
||||
private static final String[] LOCATION_PATTERN_PREFIXES = { CLASSPATH_ALL_URL_PREFIX,
|
||||
CLASSPATH_URL_PREFIX };
|
||||
private static final String[] LOCATION_PATTERN_PREFIXES = { CLASSPATH_ALL_URL_PREFIX, CLASSPATH_URL_PREFIX };
|
||||
|
||||
private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context."
|
||||
+ "WebApplicationContext";
|
||||
private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context." + "WebApplicationContext";
|
||||
|
||||
private final ResourcePatternResolver patternResolverDelegate;
|
||||
|
||||
@@ -69,17 +67,14 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
|
||||
private final ClassLoaderFiles classLoaderFiles;
|
||||
|
||||
ClassLoaderFilesResourcePatternResolver(ApplicationContext applicationContext,
|
||||
ClassLoaderFiles classLoaderFiles) {
|
||||
ClassLoaderFilesResourcePatternResolver(ApplicationContext applicationContext, ClassLoaderFiles classLoaderFiles) {
|
||||
this.classLoaderFiles = classLoaderFiles;
|
||||
this.patternResolverDelegate = getResourcePatternResolverFactory()
|
||||
.getResourcePatternResolver(applicationContext,
|
||||
retrieveResourceLoader(applicationContext));
|
||||
.getResourcePatternResolver(applicationContext, retrieveResourceLoader(applicationContext));
|
||||
}
|
||||
|
||||
private ResourceLoader retrieveResourceLoader(ApplicationContext applicationContext) {
|
||||
Field field = ReflectionUtils.findField(applicationContext.getClass(),
|
||||
"resourceLoader", ResourceLoader.class);
|
||||
Field field = ReflectionUtils.findField(applicationContext.getClass(), "resourceLoader", ResourceLoader.class);
|
||||
if (field == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -111,8 +106,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
@Override
|
||||
public Resource[] getResources(String locationPattern) throws IOException {
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
Resource[] candidates = this.patternResolverDelegate
|
||||
.getResources(locationPattern);
|
||||
Resource[] candidates = this.patternResolverDelegate.getResources(locationPattern);
|
||||
for (Resource candidate : candidates) {
|
||||
if (!isDeleted(candidate)) {
|
||||
resources.add(candidate);
|
||||
@@ -122,18 +116,15 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
return resources.toArray(new Resource[0]);
|
||||
}
|
||||
|
||||
private List<Resource> getAdditionalResources(String locationPattern)
|
||||
throws MalformedURLException {
|
||||
private List<Resource> getAdditionalResources(String locationPattern) throws MalformedURLException {
|
||||
List<Resource> additionalResources = new ArrayList<>();
|
||||
String trimmedLocationPattern = trimLocationPattern(locationPattern);
|
||||
for (SourceFolder sourceFolder : this.classLoaderFiles.getSourceFolders()) {
|
||||
for (Entry<String, ClassLoaderFile> entry : sourceFolder.getFilesEntrySet()) {
|
||||
String name = entry.getKey();
|
||||
ClassLoaderFile file = entry.getValue();
|
||||
if (file.getKind() != Kind.DELETED
|
||||
&& this.antPathMatcher.match(trimmedLocationPattern, name)) {
|
||||
URL url = new URL("reloaded", null, -1, "/" + name,
|
||||
new ClassLoaderFileURLStreamHandler(file));
|
||||
if (file.getKind() != Kind.DELETED && this.antPathMatcher.match(trimmedLocationPattern, name)) {
|
||||
URL url = new URL("reloaded", null, -1, "/" + name, new ClassLoaderFileURLStreamHandler(file));
|
||||
UrlResource resource = new UrlResource(url);
|
||||
additionalResources.add(resource);
|
||||
}
|
||||
@@ -163,8 +154,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to retrieve URI from '" + resource + "'", ex);
|
||||
throw new IllegalStateException("Failed to retrieve URI from '" + resource + "'", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,8 +195,8 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
*/
|
||||
private static class ResourcePatternResolverFactory {
|
||||
|
||||
public ResourcePatternResolver getResourcePatternResolver(
|
||||
ApplicationContext applicationContext, ResourceLoader resourceLoader) {
|
||||
public ResourcePatternResolver getResourcePatternResolver(ApplicationContext applicationContext,
|
||||
ResourceLoader resourceLoader) {
|
||||
if (resourceLoader == null) {
|
||||
resourceLoader = new DefaultResourceLoader();
|
||||
copyProtocolResolvers(applicationContext, resourceLoader);
|
||||
@@ -223,8 +213,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
}
|
||||
}
|
||||
|
||||
protected final void copyProtocolResolvers(DefaultResourceLoader source,
|
||||
DefaultResourceLoader destination) {
|
||||
protected final void copyProtocolResolvers(DefaultResourceLoader source, DefaultResourceLoader destination) {
|
||||
for (ProtocolResolver resolver : source.getProtocolResolvers()) {
|
||||
destination.addProtocolResolver(resolver);
|
||||
}
|
||||
@@ -236,24 +225,21 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
* {@link ResourcePatternResolverFactory} to be used when the classloader can access
|
||||
* {@link WebApplicationContext}.
|
||||
*/
|
||||
private static class WebResourcePatternResolverFactory
|
||||
extends ResourcePatternResolverFactory {
|
||||
private static class WebResourcePatternResolverFactory extends ResourcePatternResolverFactory {
|
||||
|
||||
@Override
|
||||
public ResourcePatternResolver getResourcePatternResolver(
|
||||
ApplicationContext applicationContext, ResourceLoader resourceLoader) {
|
||||
public ResourcePatternResolver getResourcePatternResolver(ApplicationContext applicationContext,
|
||||
ResourceLoader resourceLoader) {
|
||||
if (applicationContext instanceof WebApplicationContext) {
|
||||
return getResourcePatternResolver(
|
||||
(WebApplicationContext) applicationContext, resourceLoader);
|
||||
return getResourcePatternResolver((WebApplicationContext) applicationContext, resourceLoader);
|
||||
}
|
||||
return super.getResourcePatternResolver(applicationContext, resourceLoader);
|
||||
}
|
||||
|
||||
private ResourcePatternResolver getResourcePatternResolver(
|
||||
WebApplicationContext applicationContext, ResourceLoader resourceLoader) {
|
||||
private ResourcePatternResolver getResourcePatternResolver(WebApplicationContext applicationContext,
|
||||
ResourceLoader resourceLoader) {
|
||||
if (resourceLoader == null) {
|
||||
resourceLoader = new WebApplicationContextResourceLoader(
|
||||
applicationContext);
|
||||
resourceLoader = new WebApplicationContextResourceLoader(applicationContext);
|
||||
copyProtocolResolvers(applicationContext, resourceLoader);
|
||||
}
|
||||
return new ServletContextResourcePatternResolver(resourceLoader);
|
||||
@@ -266,8 +252,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
* {@link ResourceLoader} that optionally supports {@link ServletContextResource
|
||||
* ServletContextResources}.
|
||||
*/
|
||||
private static class WebApplicationContextResourceLoader
|
||||
extends DefaultResourceLoader {
|
||||
private static class WebApplicationContextResourceLoader extends DefaultResourceLoader {
|
||||
|
||||
private final WebApplicationContext applicationContext;
|
||||
|
||||
@@ -278,8 +263,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
|
||||
@Override
|
||||
protected Resource getResourceByPath(String path) {
|
||||
if (this.applicationContext.getServletContext() != null) {
|
||||
return new ServletContextResource(
|
||||
this.applicationContext.getServletContext(), path);
|
||||
return new ServletContextResource(this.applicationContext.getServletContext(), path);
|
||||
}
|
||||
return super.getResourceByPath(path);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -63,8 +63,8 @@ public class DefaultRestartInitializer implements RestartInitializer {
|
||||
* @return {@code true} if the thread is a main invocation
|
||||
*/
|
||||
protected boolean isMain(Thread thread) {
|
||||
return thread.getName().equals("main") && thread.getContextClassLoader()
|
||||
.getClass().getName().contains("AppClassLoader");
|
||||
return thread.getName().equals("main")
|
||||
&& thread.getContextClassLoader().getClass().getName().contains("AppClassLoader");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -32,10 +32,8 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
class OnInitializedRestarterCondition extends SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
ConditionMessage.Builder message = ConditionMessage
|
||||
.forCondition("Initialized Restarter Condition");
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition("Initialized Restarter Condition");
|
||||
Restarter restarter = getRestarter();
|
||||
if (restarter == null) {
|
||||
return ConditionOutcome.noMatch(message.because("unavailable"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -35,8 +35,7 @@ import org.springframework.core.Ordered;
|
||||
* @since 1.3.0
|
||||
* @see Restarter
|
||||
*/
|
||||
public class RestartApplicationListener
|
||||
implements ApplicationListener<ApplicationEvent>, Ordered {
|
||||
public class RestartApplicationListener implements ApplicationListener<ApplicationEvent>, Ordered {
|
||||
|
||||
private static final String ENABLED_PROPERTY = "spring.devtools.restart.enabled";
|
||||
|
||||
@@ -52,8 +51,7 @@ public class RestartApplicationListener
|
||||
if (event instanceof ApplicationPreparedEvent) {
|
||||
onApplicationPreparedEvent((ApplicationPreparedEvent) event);
|
||||
}
|
||||
if (event instanceof ApplicationReadyEvent
|
||||
|| event instanceof ApplicationFailedEvent) {
|
||||
if (event instanceof ApplicationReadyEvent || event instanceof ApplicationFailedEvent) {
|
||||
Restarter.getInstance().finish();
|
||||
}
|
||||
if (event instanceof ApplicationFailedEvent) {
|
||||
@@ -70,14 +68,12 @@ public class RestartApplicationListener
|
||||
DefaultRestartInitializer initializer = new DefaultRestartInitializer();
|
||||
boolean restartOnInitialize = !AgentReloader.isActive();
|
||||
if (!restartOnInitialize) {
|
||||
logger.info(
|
||||
"Restart disabled due to an agent-based reloader being active");
|
||||
logger.info("Restart disabled due to an agent-based reloader being active");
|
||||
}
|
||||
Restarter.initialize(args, false, initializer, restartOnInitialize);
|
||||
}
|
||||
else {
|
||||
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY
|
||||
+ "' being set to false");
|
||||
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY + "' being set to false");
|
||||
Restarter.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -27,8 +27,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
* @author Phillip Webb
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class RestartScopeInitializer
|
||||
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
public class RestartScopeInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -129,8 +129,7 @@ public class Restarter {
|
||||
* @param initializer the restart initializer
|
||||
* @see #initialize(String[])
|
||||
*/
|
||||
protected Restarter(Thread thread, String[] args, boolean forceReferenceCleanup,
|
||||
RestartInitializer initializer) {
|
||||
protected Restarter(Thread thread, String[] args, boolean forceReferenceCleanup, RestartInitializer initializer) {
|
||||
Assert.notNull(thread, "Thread must not be null");
|
||||
Assert.notNull(args, "Args must not be null");
|
||||
Assert.notNull(initializer, "Initializer must not be null");
|
||||
@@ -277,11 +276,9 @@ public class Restarter {
|
||||
Assert.notNull(this.mainClassName, "Unable to find the main class to restart");
|
||||
URL[] urls = this.urls.toArray(new URL[0]);
|
||||
ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles);
|
||||
ClassLoader classLoader = new RestartClassLoader(this.applicationClassLoader,
|
||||
urls, updatedFiles, this.logger);
|
||||
ClassLoader classLoader = new RestartClassLoader(this.applicationClassLoader, urls, updatedFiles, this.logger);
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Starting application " + this.mainClassName + " with URLs "
|
||||
+ Arrays.asList(urls));
|
||||
this.logger.debug("Starting application " + this.mainClassName + " with URLs " + Arrays.asList(urls));
|
||||
}
|
||||
return relaunch(classLoader);
|
||||
}
|
||||
@@ -293,8 +290,8 @@ public class Restarter {
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
protected Throwable relaunch(ClassLoader classLoader) throws Exception {
|
||||
RestartLauncher launcher = new RestartLauncher(classLoader, this.mainClassName,
|
||||
this.args, this.exceptionHandler);
|
||||
RestartLauncher launcher = new RestartLauncher(classLoader, this.mainClassName, this.args,
|
||||
this.exceptionHandler);
|
||||
launcher.start();
|
||||
launcher.join();
|
||||
return launcher.getError();
|
||||
@@ -363,8 +360,7 @@ public class Restarter {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Unable to clear field " + className + " " + fieldName,
|
||||
ex);
|
||||
this.logger.debug("Unable to clear field " + className + " " + fieldName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -389,8 +385,7 @@ public class Restarter {
|
||||
}
|
||||
|
||||
private boolean isFromRestartClassLoader(Object object) {
|
||||
return (object instanceof Class
|
||||
&& ((Class<?>) object).getClassLoader() instanceof RestartClassLoader);
|
||||
return (object instanceof Class && ((Class<?>) object).getClassLoader() instanceof RestartClassLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,8 +410,7 @@ public class Restarter {
|
||||
void finish() {
|
||||
synchronized (this.monitor) {
|
||||
if (!isFinished()) {
|
||||
this.logger = DeferredLog.replay(this.logger,
|
||||
LogFactory.getLog(getClass()));
|
||||
this.logger = DeferredLog.replay(this.logger, LogFactory.getLog(getClass()));
|
||||
this.finished = true;
|
||||
}
|
||||
}
|
||||
@@ -445,8 +439,8 @@ public class Restarter {
|
||||
}
|
||||
|
||||
private void prepare(GenericApplicationContext applicationContext) {
|
||||
ResourceLoader resourceLoader = new ClassLoaderFilesResourcePatternResolver(
|
||||
applicationContext, this.classLoaderFiles);
|
||||
ResourceLoader resourceLoader = new ClassLoaderFilesResourcePatternResolver(applicationContext,
|
||||
this.classLoaderFiles);
|
||||
applicationContext.setResourceLoader(resourceLoader);
|
||||
}
|
||||
|
||||
@@ -531,8 +525,7 @@ public class Restarter {
|
||||
* @param initializer the restart initializer
|
||||
* @see #initialize(String[], boolean, RestartInitializer)
|
||||
*/
|
||||
public static void initialize(String[] args, boolean forceReferenceCleanup,
|
||||
RestartInitializer initializer) {
|
||||
public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer) {
|
||||
initialize(args, forceReferenceCleanup, initializer, true);
|
||||
}
|
||||
|
||||
@@ -548,13 +541,12 @@ public class Restarter {
|
||||
* @param restartOnInitialize if the restarter should be restarted immediately when
|
||||
* the {@link RestartInitializer} returns non {@code null} results
|
||||
*/
|
||||
public static void initialize(String[] args, boolean forceReferenceCleanup,
|
||||
RestartInitializer initializer, boolean restartOnInitialize) {
|
||||
public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer,
|
||||
boolean restartOnInitialize) {
|
||||
Restarter localInstance = null;
|
||||
synchronized (INSTANCE_MONITOR) {
|
||||
if (instance == null) {
|
||||
localInstance = new Restarter(Thread.currentThread(), args,
|
||||
forceReferenceCleanup, initializer);
|
||||
localInstance = new Restarter(Thread.currentThread(), args, forceReferenceCleanup, initializer);
|
||||
instance = localInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -56,8 +56,7 @@ public class ClassLoaderFile implements Serializable {
|
||||
public ClassLoaderFile(Kind kind, long lastModified, byte[] contents) {
|
||||
Assert.notNull(kind, "Kind must not be null");
|
||||
Assert.isTrue((kind != Kind.DELETED) ? contents != null : contents == null,
|
||||
() -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "")
|
||||
+ "be null");
|
||||
() -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "") + "be null");
|
||||
this.kind = kind;
|
||||
this.lastModified = lastModified;
|
||||
this.contents = contents;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -54,8 +54,7 @@ public class ClassLoaderFileURLStreamHandler extends URLStreamHandler {
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(
|
||||
ClassLoaderFileURLStreamHandler.this.file.getContents());
|
||||
return new ByteArrayInputStream(ClassLoaderFileURLStreamHandler.this.file.getContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -61,8 +61,7 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
* URLs were created.
|
||||
* @param urls the urls managed by the classloader
|
||||
*/
|
||||
public RestartClassLoader(ClassLoader parent, URL[] urls,
|
||||
ClassLoaderFileRepository updatedFiles) {
|
||||
public RestartClassLoader(ClassLoader parent, URL[] urls, ClassLoaderFileRepository updatedFiles) {
|
||||
this(parent, urls, updatedFiles, LogFactory.getLog(RestartClassLoader.class));
|
||||
}
|
||||
|
||||
@@ -74,8 +73,7 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
* @param urls the urls managed by the classloader
|
||||
* @param logger the logger used for messages
|
||||
*/
|
||||
public RestartClassLoader(ClassLoader parent, URL[] urls,
|
||||
ClassLoaderFileRepository updatedFiles, Log logger) {
|
||||
public RestartClassLoader(ClassLoader parent, URL[] urls, ClassLoaderFileRepository updatedFiles, Log logger) {
|
||||
super(urls, parent);
|
||||
Assert.notNull(parent, "Parent must not be null");
|
||||
Assert.notNull(updatedFiles, "UpdatedFiles must not be null");
|
||||
@@ -126,13 +124,11 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
if (file.getKind() == Kind.DELETED) {
|
||||
return null;
|
||||
}
|
||||
return AccessController
|
||||
.doPrivileged((PrivilegedAction<URL>) () -> createFileUrl(name, file));
|
||||
return AccessController.doPrivileged((PrivilegedAction<URL>) () -> createFileUrl(name, file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
String path = name.replace('.', '/').concat(".class");
|
||||
ClassLoaderFile file = this.updatedFiles.getFile(path);
|
||||
if (file != null && file.getKind() == Kind.DELETED) {
|
||||
@@ -173,8 +169,7 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
|
||||
private URL createFileUrl(String name, ClassLoaderFile file) {
|
||||
try {
|
||||
return new URL("reloaded", null, -1, "/" + name,
|
||||
new ClassLoaderFileURLStreamHandler(file));
|
||||
return new URL("reloaded", null, -1, "/" + name, new ClassLoaderFileURLStreamHandler(file));
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -38,12 +38,10 @@ public class DefaultSourceFolderUrlFilter implements SourceFolderUrlFilter {
|
||||
|
||||
private static final Pattern URL_MODULE_PATTERN = Pattern.compile(".*\\/(.+)\\.jar");
|
||||
|
||||
private static final Pattern VERSION_PATTERN = Pattern
|
||||
.compile("^-\\d+(?:\\.\\d+)*(?:[.-].+)?$");
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("^-\\d+(?:\\.\\d+)*(?:[.-].+)?$");
|
||||
|
||||
private static final Set<String> SKIPPED_PROJECTS = new HashSet<>(Arrays.asList(
|
||||
"spring-boot", "spring-boot-devtools", "spring-boot-autoconfigure",
|
||||
"spring-boot-actuator", "spring-boot-starter"));
|
||||
private static final Set<String> SKIPPED_PROJECTS = new HashSet<>(Arrays.asList("spring-boot",
|
||||
"spring-boot-devtools", "spring-boot-autoconfigure", "spring-boot-actuator", "spring-boot-starter"));
|
||||
|
||||
@Override
|
||||
public boolean isMatch(String sourceFolder, URL url) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -67,12 +67,10 @@ public class HttpRestartServer {
|
||||
* @param response the response
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException {
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
try {
|
||||
Assert.state(request.getHeaders().getContentLength() > 0, "No content");
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(
|
||||
request.getBody());
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(request.getBody());
|
||||
ClassLoaderFiles files = (ClassLoaderFiles) objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
this.server.updateAndRestart(files);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -43,8 +43,7 @@ public class HttpRestartServerHandler implements Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException {
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
this.server.handle(request, response);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -67,8 +67,7 @@ public class RestartServer {
|
||||
* local classpath
|
||||
* @param classLoader the application classloader
|
||||
*/
|
||||
public RestartServer(SourceFolderUrlFilter sourceFolderUrlFilter,
|
||||
ClassLoader classLoader) {
|
||||
public RestartServer(SourceFolderUrlFilter sourceFolderUrlFilter, ClassLoader classLoader) {
|
||||
Assert.notNull(sourceFolderUrlFilter, "SourceFolderUrlFilter must not be null");
|
||||
Assert.notNull(classLoader, "ClassLoader must not be null");
|
||||
this.sourceFolderUrlFilter = sourceFolderUrlFilter;
|
||||
@@ -97,8 +96,7 @@ public class RestartServer {
|
||||
restart(urls, files);
|
||||
}
|
||||
|
||||
private boolean updateFileSystem(URL url, String name,
|
||||
ClassLoaderFile classLoaderFile) {
|
||||
private boolean updateFileSystem(URL url, String name, ClassLoaderFile classLoaderFile) {
|
||||
if (!isFolderUrl(url.toString())) {
|
||||
return false;
|
||||
}
|
||||
@@ -128,8 +126,7 @@ public class RestartServer {
|
||||
for (URL url : urls) {
|
||||
if (this.sourceFolderUrlFilter.isMatch(sourceFolder, url)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("URL " + url + " matched against source folder "
|
||||
+ sourceFolder);
|
||||
logger.debug("URL " + url + " matched against source folder " + sourceFolder);
|
||||
}
|
||||
matchingUrls.add(url);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -104,23 +104,19 @@ public class DevToolsSettings {
|
||||
static DevToolsSettings load(String location) {
|
||||
try {
|
||||
DevToolsSettings settings = new DevToolsSettings();
|
||||
Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
|
||||
.getResources(location);
|
||||
Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(location);
|
||||
while (urls.hasMoreElements()) {
|
||||
settings.add(PropertiesLoaderUtils
|
||||
.loadProperties(new UrlResource(urls.nextElement())));
|
||||
settings.add(PropertiesLoaderUtils.loadProperties(new UrlResource(urls.nextElement())));
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Included patterns for restart : "
|
||||
+ settings.restartIncludePatterns);
|
||||
logger.debug("Excluded patterns for restart : "
|
||||
+ settings.restartExcludePatterns);
|
||||
logger.debug("Included patterns for restart : " + settings.restartIncludePatterns);
|
||||
logger.debug("Excluded patterns for restart : " + settings.restartExcludePatterns);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Unable to load devtools settings from "
|
||||
+ "location [" + location + "]", ex);
|
||||
throw new IllegalStateException("Unable to load devtools settings from " + "location [" + location + "]",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -77,8 +77,7 @@ public class HttpTunnelConnection implements TunnelConnection {
|
||||
* @param requestFactory the HTTP request factory
|
||||
* @param executor the executor used to handle connections
|
||||
*/
|
||||
protected HttpTunnelConnection(String url, ClientHttpRequestFactory requestFactory,
|
||||
Executor executor) {
|
||||
protected HttpTunnelConnection(String url, ClientHttpRequestFactory requestFactory, Executor executor) {
|
||||
Assert.hasLength(url, "URL must not be empty");
|
||||
Assert.notNull(requestFactory, "RequestFactory must not be null");
|
||||
try {
|
||||
@@ -88,19 +87,16 @@ public class HttpTunnelConnection implements TunnelConnection {
|
||||
throw new IllegalArgumentException("Malformed URL '" + url + "'");
|
||||
}
|
||||
this.requestFactory = requestFactory;
|
||||
this.executor = (executor != null) ? executor
|
||||
: Executors.newCachedThreadPool(new TunnelThreadFactory());
|
||||
this.executor = (executor != null) ? executor : Executors.newCachedThreadPool(new TunnelThreadFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunnelChannel open(WritableByteChannel incomingChannel, Closeable closeable)
|
||||
throws Exception {
|
||||
public TunnelChannel open(WritableByteChannel incomingChannel, Closeable closeable) throws Exception {
|
||||
logger.trace("Opening HTTP tunnel to " + this.uri);
|
||||
return new TunnelChannel(incomingChannel, closeable);
|
||||
}
|
||||
|
||||
protected final ClientHttpRequest createRequest(boolean hasPayload)
|
||||
throws IOException {
|
||||
protected final ClientHttpRequest createRequest(boolean hasPayload) throws IOException {
|
||||
HttpMethod method = hasPayload ? HttpMethod.POST : HttpMethod.GET;
|
||||
return this.requestFactory.createRequest(this.uri, method);
|
||||
}
|
||||
@@ -141,8 +137,7 @@ public class HttpTunnelConnection implements TunnelConnection {
|
||||
public int write(ByteBuffer src) throws IOException {
|
||||
int size = src.remaining();
|
||||
if (size > 0) {
|
||||
openNewConnection(
|
||||
new HttpTunnelPayload(this.requestSeq.incrementAndGet(), src));
|
||||
openNewConnection(new HttpTunnelPayload(this.requestSeq.incrementAndGet(), src));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
@@ -157,8 +152,7 @@ public class HttpTunnelConnection implements TunnelConnection {
|
||||
}
|
||||
catch (IOException ex) {
|
||||
if (ex instanceof ConnectException) {
|
||||
logger.warn("Failed to connect to remote application at "
|
||||
+ HttpTunnelConnection.this.uri);
|
||||
logger.warn("Failed to connect to remote application at " + HttpTunnelConnection.this.uri);
|
||||
}
|
||||
else {
|
||||
logger.trace("Unexpected connection error", ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -144,8 +144,7 @@ public class TunnelClient implements SmartInitializingSingleton {
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
logger.trace("Closing tunnel client on port "
|
||||
+ this.serverSocketChannel.socket().getLocalPort());
|
||||
logger.trace("Closing tunnel client on port " + this.serverSocketChannel.socket().getLocalPort());
|
||||
this.serverSocketChannel.close();
|
||||
this.acceptConnections = false;
|
||||
interrupt();
|
||||
@@ -171,10 +170,10 @@ public class TunnelClient implements SmartInitializingSingleton {
|
||||
private void handleConnection(SocketChannel socketChannel) throws Exception {
|
||||
Closeable closeable = new SocketCloseable(socketChannel);
|
||||
TunnelClient.this.listeners.fireOpenEvent(socketChannel);
|
||||
try (WritableByteChannel outputChannel = TunnelClient.this.tunnelConnection
|
||||
.open(socketChannel, closeable)) {
|
||||
logger.trace("Accepted connection to tunnel client from "
|
||||
+ socketChannel.socket().getRemoteSocketAddress());
|
||||
try (WritableByteChannel outputChannel = TunnelClient.this.tunnelConnection.open(socketChannel,
|
||||
closeable)) {
|
||||
logger.trace(
|
||||
"Accepted connection to tunnel client from " + socketChannel.socket().getRemoteSocketAddress());
|
||||
while (true) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
int amountRead = socketChannel.read(buffer);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -37,7 +37,6 @@ public interface TunnelConnection {
|
||||
* destined for the remote server
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
WritableByteChannel open(WritableByteChannel incomingChannel, Closeable closeable)
|
||||
throws Exception;
|
||||
WritableByteChannel open(WritableByteChannel incomingChannel, Closeable closeable) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -134,8 +134,7 @@ public class HttpTunnelPayload {
|
||||
* @return payload data or {@code null}
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public static ByteBuffer getPayloadData(ReadableByteChannel channel)
|
||||
throws IOException {
|
||||
public static ByteBuffer getPayloadData(ReadableByteChannel channel) throws IOException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
try {
|
||||
int amountRead = channel.read(buffer);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -55,8 +55,7 @@ public class HttpTunnelPayloadForwarder {
|
||||
synchronized (this.monitor) {
|
||||
long seq = payload.getSequence();
|
||||
if (this.lastRequestSeq != seq - 1) {
|
||||
Assert.state(this.queue.size() < MAXIMUM_QUEUE_SIZE,
|
||||
"Too many messages queued");
|
||||
Assert.state(this.queue.size() < MAXIMUM_QUEUE_SIZE, "Too many messages queued");
|
||||
this.queue.put(seq, payload);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -112,8 +112,7 @@ public class HttpTunnelServer {
|
||||
|
||||
private static final long DEFAULT_DISCONNECT_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
private static final MediaType DISCONNECT_MEDIA_TYPE = new MediaType("application",
|
||||
"x-disconnect");
|
||||
private static final MediaType DISCONNECT_MEDIA_TYPE = new MediaType("application", "x-disconnect");
|
||||
|
||||
private static final Log logger = LogFactory.getLog(HttpTunnelServer.class);
|
||||
|
||||
@@ -140,8 +139,7 @@ public class HttpTunnelServer {
|
||||
* @param response the HTTP response
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException {
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
handle(new HttpConnection(request, response));
|
||||
}
|
||||
|
||||
@@ -199,8 +197,7 @@ public class HttpTunnelServer {
|
||||
* @param disconnectTimeout the disconnect timeout in milliseconds
|
||||
*/
|
||||
public void setDisconnectTimeout(long disconnectTimeout) {
|
||||
Assert.isTrue(disconnectTimeout > 0,
|
||||
"DisconnectTimeout must be a positive value");
|
||||
Assert.isTrue(disconnectTimeout > 0, "DisconnectTimeout must be a positive value");
|
||||
this.disconnectTimeout = disconnectTimeout;
|
||||
}
|
||||
|
||||
@@ -252,8 +249,7 @@ public class HttpTunnelServer {
|
||||
ByteBuffer data = HttpTunnelPayload.getPayloadData(this.targetServer);
|
||||
synchronized (this.httpConnections) {
|
||||
if (data != null) {
|
||||
HttpTunnelPayload payload = new HttpTunnelPayload(
|
||||
this.responseSeq.incrementAndGet(), data);
|
||||
HttpTunnelPayload payload = new HttpTunnelPayload(this.responseSeq.incrementAndGet(), data);
|
||||
payload.logIncoming();
|
||||
HttpConnection connection = getOrWaitForHttpConnection();
|
||||
connection.respond(payload);
|
||||
@@ -285,8 +281,7 @@ public class HttpTunnelServer {
|
||||
Iterator<HttpConnection> iterator = this.httpConnections.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
HttpConnection httpConnection = iterator.next();
|
||||
if (httpConnection
|
||||
.isOlderThan(HttpTunnelServer.this.longPollTimeout)) {
|
||||
if (httpConnection.isOlderThan(HttpTunnelServer.this.longPollTimeout)) {
|
||||
httpConnection.respond(HttpStatus.NO_CONTENT);
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -298,8 +293,7 @@ public class HttpTunnelServer {
|
||||
if (this.lastHttpRequestTime > 0) {
|
||||
long timeout = HttpTunnelServer.this.disconnectTimeout;
|
||||
long duration = System.currentTimeMillis() - this.lastHttpRequestTime;
|
||||
Assert.state(duration < timeout,
|
||||
() -> "Disconnect timeout: " + timeout + " " + duration);
|
||||
Assert.state(duration < timeout, () -> "Disconnect timeout: " + timeout + " " + duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,8 +330,7 @@ public class HttpTunnelServer {
|
||||
}
|
||||
synchronized (this.httpConnections) {
|
||||
while (this.httpConnections.size() > 1) {
|
||||
this.httpConnections.removeFirst()
|
||||
.respond(HttpStatus.TOO_MANY_REQUESTS);
|
||||
this.httpConnections.removeFirst().respond(HttpStatus.TOO_MANY_REQUESTS);
|
||||
}
|
||||
this.lastHttpRequestTime = System.currentTimeMillis();
|
||||
this.httpConnections.addLast(httpConnection);
|
||||
@@ -346,8 +339,7 @@ public class HttpTunnelServer {
|
||||
forwardToTargetServer(httpConnection);
|
||||
}
|
||||
|
||||
private void forwardToTargetServer(HttpConnection httpConnection)
|
||||
throws IOException {
|
||||
private void forwardToTargetServer(HttpConnection httpConnection) throws IOException {
|
||||
if (httpConnection.isDisconnectRequest()) {
|
||||
this.targetServer.close();
|
||||
interrupt();
|
||||
@@ -391,8 +383,7 @@ public class HttpTunnelServer {
|
||||
protected ServerHttpAsyncRequestControl startAsync() {
|
||||
try {
|
||||
// Try to use async to save blocking
|
||||
ServerHttpAsyncRequestControl async = this.request
|
||||
.getAsyncRequestControl(this.response);
|
||||
ServerHttpAsyncRequestControl async = this.request.getAsyncRequestControl(this.response);
|
||||
async.start();
|
||||
return async;
|
||||
}
|
||||
@@ -451,8 +442,7 @@ public class HttpTunnelServer {
|
||||
* @return if the request is a signal to disconnect
|
||||
*/
|
||||
public boolean isDisconnectRequest() {
|
||||
return DISCONNECT_MEDIA_TYPE
|
||||
.equals(this.request.getHeaders().getContentType());
|
||||
return DISCONNECT_MEDIA_TYPE.equals(this.request.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -43,8 +43,7 @@ public class HttpTunnelServerHandler implements Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response)
|
||||
throws IOException {
|
||||
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
this.server.handle(request, response);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -38,8 +38,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class SocketTargetServerConnection implements TargetServerConnection {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(SocketTargetServerConnection.class);
|
||||
private static final Log logger = LogFactory.getLog(SocketTargetServerConnection.class);
|
||||
|
||||
private final PortProvider portProvider;
|
||||
|
||||
@@ -73,8 +72,7 @@ public class SocketTargetServerConnection implements TargetServerConnection {
|
||||
|
||||
TimeoutAwareChannel(SocketChannel socketChannel) throws IOException {
|
||||
this.socketChannel = socketChannel;
|
||||
this.readChannel = Channels
|
||||
.newChannel(socketChannel.socket().getInputStream());
|
||||
this.readChannel = Channels.newChannel(socketChannel.socket().getInputStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user