Commit c3ec3168 authored by Phillip Webb's avatar Phillip Webb

Move Application* and *FileWriter classes

Move `ApplicationHome`, `ApplicationPid` and `ApplicationTemp` to the
`system` package. Since `system` package is now much lower level, the
existing `FileWriter` implementations also needed to move to prevent
package tangles.

Fixes gh-8614
parent 3ff77295
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -28,7 +28,6 @@ import com.atomikos.icatch.config.UserTransactionServiceImp;
import com.atomikos.icatch.jta.UserTransactionManager;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.ApplicationHome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
......@@ -39,6 +38,7 @@ import org.springframework.boot.jta.atomikos.AtomikosDependsOnBeanFactoryPostPro
import org.springframework.boot.jta.atomikos.AtomikosProperties;
import org.springframework.boot.jta.atomikos.AtomikosXAConnectionFactoryWrapper;
import org.springframework.boot.jta.atomikos.AtomikosXADataSourceWrapper;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -26,7 +26,6 @@ import bitronix.tm.TransactionManagerServices;
import bitronix.tm.jndi.BitronixContext;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.ApplicationHome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
......@@ -37,6 +36,7 @@ import org.springframework.boot.jta.XADataSourceWrapper;
import org.springframework.boot.jta.bitronix.BitronixDependentBeanFactoryPostProcessor;
import org.springframework.boot.jta.bitronix.BitronixXAConnectionFactoryWrapper;
import org.springframework.boot.jta.bitronix.BitronixXADataSourceWrapper;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -28,7 +28,6 @@ import org.jboss.narayana.jta.jms.TransactionHelper;
import org.jboss.tm.XAResourceRecoveryRegistry;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.ApplicationHome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
......@@ -41,6 +40,7 @@ import org.springframework.boot.jta.narayana.NarayanaProperties;
import org.springframework.boot.jta.narayana.NarayanaRecoveryManagerBean;
import org.springframework.boot.jta.narayana.NarayanaXAConnectionFactoryWrapper;
import org.springframework.boot.jta.narayana.NarayanaXADataSourceWrapper;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -17,7 +17,7 @@
package org.springframework.boot.cli;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.system.EmbeddedServerPortFileWriter;
import org.springframework.boot.web.context.WebServerPortFileWriter;
import org.springframework.context.ConfigurableApplicationContext;
/**
......@@ -33,7 +33,7 @@ public class CliTesterSpringApplication extends SpringApplication {
@Override
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
context.addApplicationListener(new EmbeddedServerPortFileWriter());
context.addApplicationListener(new WebServerPortFileWriter());
}
}
......@@ -1337,8 +1337,8 @@ useful for process monitoring:
* `ApplicationPidFileWriter` creates a file containing the application PID (by default,
in the application directory with a file name of `application.pid`).
* `EmbeddedServerPortFileWriter` creates a file (or files) containing the ports of the
embedded server (by default, in the application directory with a file name of
* `WebServerPortFileWriter` creates a file (or files) containing the ports of the
running web server (by default, in the application directory with a file name of
`application.port`).
By default, these writers are not activated, but you can enable:
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -22,6 +22,8 @@ import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.system;
package org.springframework.boot.context;
import java.io.File;
import java.io.IOException;
......@@ -26,11 +26,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.ApplicationPid;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.boot.system.SystemProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
......@@ -58,7 +58,7 @@ import org.springframework.util.Assert;
* @author Phillip Webb
* @author Tomasz Przybyla
* @author Madhura Bhave
* @since 1.4.0
* @since 2.0.0
*/
public class ApplicationPidFileWriter
implements ApplicationListener<SpringApplicationEvent>, Ordered {
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -16,7 +16,7 @@
package org.springframework.boot.logging;
import org.springframework.boot.ApplicationPid;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertyResolver;
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.system;
import java.io.File;
import java.io.IOException;
......@@ -37,7 +37,7 @@ import org.springframework.util.StringUtils;
*
* @author Phillip Webb
* @author Raja Kolli
* @since 1.2.0
* @since 2.0.0
*/
public class ApplicationHome {
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.system;
import java.io.File;
import java.io.FileNotFoundException;
......@@ -32,6 +32,7 @@ import org.springframework.util.ObjectUtils;
* An application process ID.
*
* @author Phillip Webb
* @since 2.0.0
*/
public class ApplicationPid {
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.system;
import java.io.File;
import java.security.MessageDigest;
......@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
* restarting an application will give the same location.
*
* @author Phillip Webb
* @since 1.3.0
* @since 2.0.0
*/
public class ApplicationTemp {
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -20,8 +20,9 @@ package org.springframework.boot.system;
* Access to system properties.
*
* @author Phillip Webb
* @since 2.0.0
*/
final class SystemProperties {
public final class SystemProperties {
private SystemProperties() {
}
......
......@@ -14,15 +14,14 @@
* limitations under the License.
*/
package org.springframework.boot.system;
package org.springframework.boot.web.context;
import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.boot.system.SystemProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.util.Assert;
......@@ -38,42 +37,40 @@ import org.springframework.util.StringUtils;
* @author David Liu
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.4.0
* @since 2.0.0
*/
public class EmbeddedServerPortFileWriter
public class WebServerPortFileWriter
implements ApplicationListener<WebServerInitializedEvent> {
private static final String DEFAULT_FILE_NAME = "application.port";
private static final String[] PROPERTY_VARIABLES = { "PORTFILE", "portfile" };
private static final Log logger = LogFactory
.getLog(EmbeddedServerPortFileWriter.class);
private static final Log logger = LogFactory.getLog(WebServerPortFileWriter.class);
private final File file;
/**
* Create a new {@link EmbeddedServerPortFileWriter} instance using the filename
* Create a new {@link WebServerPortFileWriter} instance using the filename
* 'application.port'.
*/
public EmbeddedServerPortFileWriter() {
public WebServerPortFileWriter() {
this(new File(DEFAULT_FILE_NAME));
}
/**
* Create a new {@link EmbeddedServerPortFileWriter} instance with a specified
* filename.
* Create a new {@link WebServerPortFileWriter} instance with a specified filename.
* @param filename the name of file containing port
*/
public EmbeddedServerPortFileWriter(String filename) {
public WebServerPortFileWriter(String filename) {
this(new File(filename));
}
/**
* Create a new {@link EmbeddedServerPortFileWriter} instance with a specified file.
* Create a new {@link WebServerPortFileWriter} instance with a specified file.
* @param file the file containing port
*/
public EmbeddedServerPortFileWriter(File file) {
public WebServerPortFileWriter(File file) {
Assert.notNull(file, "File must not be null");
String override = SystemProperties.get(PROPERTY_VARIABLES);
if (override != null) {
......
......@@ -18,8 +18,8 @@ package org.springframework.boot.web.servlet.server;
import java.io.File;
import org.springframework.boot.ApplicationHome;
import org.springframework.boot.ApplicationTemp;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.boot.system.ApplicationTemp;
import org.springframework.util.Assert;
/**
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.system;
package org.springframework.boot.context;
import java.io.File;
import java.io.FileReader;
......
......@@ -38,7 +38,6 @@ import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.springframework.boot.ApplicationPid;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent;
......@@ -51,6 +50,7 @@ import org.springframework.boot.logging.LoggingInitializationContext;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.logging.LoggingSystemProperties;
import org.springframework.boot.logging.java.JavaLoggingSystem;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.boot.testsupport.rule.OutputCapture;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.system;
import java.io.File;
import java.io.FileReader;
......@@ -24,7 +24,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.ApplicationPid;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.system;
import java.io.File;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.system;
package org.springframework.boot.web.context;
import java.io.File;
import java.io.FileReader;
......@@ -27,8 +27,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.boot.web.server.WebServer;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
......@@ -38,13 +36,13 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Tests {@link EmbeddedServerPortFileWriter}.
* Tests {@link WebServerPortFileWriter}.
*
* @author David Liu
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class EmbeddedServerPortFileWriterTests {
public class WebServerPortFileWriterTest {
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
......@@ -58,7 +56,7 @@ public class EmbeddedServerPortFileWriterTests {
@Test
public void createPortFile() throws Exception {
File file = this.temporaryFolder.newFile();
EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file);
WebServerPortFileWriter listener = new WebServerPortFileWriter(file);
listener.onApplicationEvent(mockEvent("", 8080));
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEqualTo("8080");
}
......@@ -66,7 +64,7 @@ public class EmbeddedServerPortFileWriterTests {
@Test
public void overridePortFileWithDefault() throws Exception {
System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath());
EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter();
WebServerPortFileWriter listener = new WebServerPortFileWriter();
listener.onApplicationEvent(mockEvent("", 8080));
FileReader reader = new FileReader(System.getProperty("PORTFILE"));
assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080");
......@@ -76,7 +74,7 @@ public class EmbeddedServerPortFileWriterTests {
public void overridePortFileWithExplicitFile() throws Exception {
File file = this.temporaryFolder.newFile();
System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath());
EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file);
WebServerPortFileWriter listener = new WebServerPortFileWriter(file);
listener.onApplicationEvent(mockEvent("", 8080));
FileReader reader = new FileReader(System.getProperty("PORTFILE"));
assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080");
......@@ -85,7 +83,7 @@ public class EmbeddedServerPortFileWriterTests {
@Test
public void createManagementPortFile() throws Exception {
File file = this.temporaryFolder.newFile();
EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file);
WebServerPortFileWriter listener = new WebServerPortFileWriter(file);
listener.onApplicationEvent(mockEvent("", 8080));
listener.onApplicationEvent(mockEvent("management", 9090));
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEqualTo("8080");
......@@ -104,7 +102,7 @@ public class EmbeddedServerPortFileWriterTests {
public void createUpperCaseManagementPortFile() throws Exception {
File file = this.temporaryFolder.newFile();
file = new File(file.getParentFile(), file.getName().toUpperCase());
EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file);
WebServerPortFileWriter listener = new WebServerPortFileWriter(file);
listener.onApplicationEvent(mockEvent("management", 9090));
String managementFile = file.getName();
managementFile = managementFile.substring(0, managementFile.length()
......
......@@ -86,8 +86,8 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.mockito.InOrder;
import org.springframework.boot.ApplicationHome;
import org.springframework.boot.ApplicationTemp;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.boot.system.ApplicationTemp;
import org.springframework.boot.testsupport.rule.OutputCapture;
import org.springframework.boot.testsupport.web.servlet.ExampleFilter;
import org.springframework.boot.testsupport.web.servlet.ExampleServlet;
......
......@@ -18,14 +18,14 @@ package com.example;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.context.EmbeddedServerPortFileWriter;
import org.springframework.boot.web.context.WebServerPortFileWriter;
@SpringBootApplication
public class DevToolsTestApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(DevToolsTestApplication.class)
.listeners(new EmbeddedServerPortFileWriter("target/server.port"))
.listeners(new WebServerPortFileWriter("target/server.port"))
.run(args);
}
......
......@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.context.EmbeddedServerPortFileWriter;
import org.springframework.boot.web.context.WebServerPortFileWriter;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
......@@ -41,7 +41,7 @@ public class ResourceHandlingApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ResourceHandlingApplication.class)
.properties("server.port:0")
.listeners(new EmbeddedServerPortFileWriter("target/server.port"))
.listeners(new WebServerPortFileWriter("target/server.port"))
.run(args);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment