From 496b3a8d75e535b40d9edf914c2342f892e92670 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 25 Jul 2016 13:44:10 -0700 Subject: [PATCH] Relocate FileWriters to `spring-boot` Move ApplicationPidFileWriter and EmbeddedServerPortFileWriter to the core spring-boot project since they're not really tied to the actuator. Fixes gh-6398 --- .../system/ApplicationPidFileWriter.java | 194 +------------ .../system/EmbeddedServerPortFileWriter.java | 94 +------ .../boot/system/ApplicationPidFileWriter.java | 257 ++++++++++++++++++ .../system/EmbeddedServerPortFileWriter.java | 144 ++++++++++ .../boot}/system/SystemProperties.java | 2 +- .../boot/system/package-info.java | 20 ++ .../system/ApplicationPidFileWriterTests.java | 2 +- .../EmbeddedServerPortFileWriterTests.java | 2 +- 8 files changed, 438 insertions(+), 277 deletions(-) create mode 100644 spring-boot/src/main/java/org/springframework/boot/system/ApplicationPidFileWriter.java create mode 100644 spring-boot/src/main/java/org/springframework/boot/system/EmbeddedServerPortFileWriter.java rename {spring-boot-actuator/src/main/java/org/springframework/boot/actuate => spring-boot/src/main/java/org/springframework/boot}/system/SystemProperties.java (96%) create mode 100644 spring-boot/src/main/java/org/springframework/boot/system/package-info.java rename {spring-boot-actuator/src/test/java/org/springframework/boot/actuate => spring-boot/src/test/java/org/springframework/boot}/system/ApplicationPidFileWriterTests.java (99%) rename {spring-boot-actuator/src/test/java/org/springframework/boot/actuate => spring-boot/src/test/java/org/springframework/boot}/system/EmbeddedServerPortFileWriterTests.java (99%) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/ApplicationPidFileWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/ApplicationPidFileWriter.java index 3a4ced986b..e1fff597b4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/ApplicationPidFileWriter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/ApplicationPidFileWriter.java @@ -17,24 +17,11 @@ package org.springframework.boot.actuate.system; import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -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.bind.RelaxedPropertyResolver; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent; -import org.springframework.boot.context.event.SpringApplicationEvent; import org.springframework.context.ApplicationListener; -import org.springframework.core.Ordered; import org.springframework.core.env.Environment; -import org.springframework.util.Assert; /** * An {@link ApplicationListener} that saves application PID into file. This application @@ -56,47 +43,19 @@ import org.springframework.util.Assert; * @author Phillip Webb * @author Tomasz Przybyla * @since 1.2.0 + * @deprecated as of 1.4 in favor of + * {@link org.springframework.boot.system.ApplicationPidFileWriter} */ +@Deprecated public class ApplicationPidFileWriter - implements ApplicationListener, Ordered { - - private static final Log logger = LogFactory.getLog(ApplicationPidFileWriter.class); - - private static final String DEFAULT_FILE_NAME = "application.pid"; - - private static final List FILE_PROPERTIES; - - static { - List properties = new ArrayList(); - properties.add(new SpringProperty("spring.pid.", "file")); - properties.add(new SpringProperty("spring.", "pidfile")); - properties.add(new SystemProperty("PIDFILE")); - FILE_PROPERTIES = Collections.unmodifiableList(properties); - } - - private static final List FAIL_ON_WRITE_ERROR_PROPERTIES; - - static { - List properties = new ArrayList(); - properties.add(new SpringProperty("spring.pid.", "fail-on-write-error")); - properties.add(new SystemProperty("PID_FAIL_ON_WRITE_ERROR")); - FAIL_ON_WRITE_ERROR_PROPERTIES = Collections.unmodifiableList(properties); - } - - private static final AtomicBoolean created = new AtomicBoolean(false); - - private int order = Ordered.HIGHEST_PRECEDENCE + 13; - - private final File file; - - private Class triggerEventType = ApplicationPreparedEvent.class; + extends org.springframework.boot.system.ApplicationPidFileWriter { /** * Create a new {@link ApplicationPidFileWriter} instance using the filename * 'application.pid'. */ public ApplicationPidFileWriter() { - this(new File(DEFAULT_FILE_NAME)); + super(); } /** @@ -104,7 +63,7 @@ public class ApplicationPidFileWriter * @param filename the name of file containing pid */ public ApplicationPidFileWriter(String filename) { - this(new File(filename)); + super(filename); } /** @@ -112,146 +71,7 @@ public class ApplicationPidFileWriter * @param file the file containing pid */ public ApplicationPidFileWriter(File file) { - Assert.notNull(file, "File must not be null"); - this.file = file; - } - - /** - * Sets the type of application event that will trigger writing of the PID file. - * Defaults to {@link ApplicationPreparedEvent}. NOTE: If you use the - * {@link org.springframework.boot.context.event.ApplicationStartedEvent} to trigger - * the write, you will not be able to specify the PID filename in the Spring - * {@link Environment}. - * @param triggerEventType the trigger event type - */ - public void setTriggerEventType( - Class triggerEventType) { - Assert.notNull(triggerEventType, "Trigger event type must not be null"); - this.triggerEventType = triggerEventType; - } - - @Override - public void onApplicationEvent(SpringApplicationEvent event) { - if (this.triggerEventType.isInstance(event)) { - if (created.compareAndSet(false, true)) { - try { - writePidFile(event); - } - catch (Exception ex) { - String message = String.format("Cannot create pid file %s", - this.file); - if (failOnWriteError(event)) { - throw new IllegalStateException(message, ex); - } - logger.warn(message, ex); - } - } - } - } - - private void writePidFile(SpringApplicationEvent event) throws IOException { - File pidFile = this.file; - String override = getProperty(event, FILE_PROPERTIES); - if (override != null) { - pidFile = new File(override); - } - new ApplicationPid().write(pidFile); - pidFile.deleteOnExit(); - } - - private boolean failOnWriteError(SpringApplicationEvent event) { - String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES); - return (value == null ? false : Boolean.parseBoolean(value)); - } - - private String getProperty(SpringApplicationEvent event, List candidates) { - for (Property candidate : candidates) { - String value = candidate.getValue(event); - if (value != null) { - return value; - } - } - return null; - } - - public void setOrder(int order) { - this.order = order; - } - - @Override - public int getOrder() { - return this.order; - } - - /** - * Reset the created flag for testing purposes. - */ - static void reset() { - created.set(false); - } - - /** - * Provides access to a property value. - */ - private interface Property { - - String getValue(SpringApplicationEvent event); - - } - - /** - * {@link Property} obtained from Spring's {@link Environment}. - */ - private static class SpringProperty implements Property { - - private final String prefix; - - private final String key; - - SpringProperty(String prefix, String key) { - this.prefix = prefix; - this.key = key; - } - - @Override - public String getValue(SpringApplicationEvent event) { - Environment environment = getEnvironment(event); - if (environment == null) { - return null; - } - return new RelaxedPropertyResolver(environment, this.prefix) - .getProperty(this.key); - } - - private Environment getEnvironment(SpringApplicationEvent event) { - if (event instanceof ApplicationEnvironmentPreparedEvent) { - return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment(); - } - if (event instanceof ApplicationPreparedEvent) { - return ((ApplicationPreparedEvent) event).getApplicationContext() - .getEnvironment(); - } - return null; - } - - } - - /** - * {@link Property} obtained from {@link SystemProperties}. - */ - private static class SystemProperty implements Property { - - private final String[] properties; - - SystemProperty(String name) { - this.properties = new String[] { name.toUpperCase(), name.toLowerCase() }; - } - - @Override - public String getValue(SpringApplicationEvent event) { - return SystemProperties.get(this.properties); - } - + super(file); } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriter.java index b687750803..44657c0138 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriter.java @@ -18,15 +18,7 @@ package org.springframework.boot.actuate.system; import java.io.File; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.context.ApplicationListener; -import org.springframework.util.Assert; -import org.springframework.util.FileCopyUtils; -import org.springframework.util.StringUtils; /** * An {@link ApplicationListener} that saves embedded server port and management port into @@ -37,27 +29,20 @@ import org.springframework.util.StringUtils; * @author David Liu * @author Phillip Webb * @author Andy Wilkinson - * * @since 1.2.0 + * @deprecated as of 1.4 in favor of + * {@link org.springframework.boot.system.EmbeddedServerPortFileWriter} */ +@Deprecated public class EmbeddedServerPortFileWriter - implements ApplicationListener { - - 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 final File file; + extends org.springframework.boot.system.EmbeddedServerPortFileWriter { /** * Create a new {@link EmbeddedServerPortFileWriter} instance using the filename * 'application.port'. */ public EmbeddedServerPortFileWriter() { - this(new File(DEFAULT_FILE_NAME)); + super(); } /** @@ -66,7 +51,7 @@ public class EmbeddedServerPortFileWriter * @param filename the name of file containing port */ public EmbeddedServerPortFileWriter(String filename) { - this(new File(filename)); + super(filename); } /** @@ -74,72 +59,7 @@ public class EmbeddedServerPortFileWriter * @param file the file containing port */ public EmbeddedServerPortFileWriter(File file) { - Assert.notNull(file, "File must not be null"); - String override = SystemProperties.get(PROPERTY_VARIABLES); - if (override != null) { - this.file = new File(override); - } - else { - this.file = file; - } - } - - @Override - public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { - File portFile = getPortFile(event.getApplicationContext()); - try { - String port = String.valueOf(event.getEmbeddedServletContainer().getPort()); - createParentFolder(portFile); - FileCopyUtils.copy(port.getBytes(), portFile); - portFile.deleteOnExit(); - } - catch (Exception ex) { - logger.warn(String.format("Cannot create port file %s", this.file)); - } - } - - /** - * Return the actual port file that should be written for the given application - * context. The default implementation builds a file from the source file and the - * application context namespace. - * @param applicationContext the source application context - * @return the file that should be written - */ - protected File getPortFile(EmbeddedWebApplicationContext applicationContext) { - String contextName = applicationContext.getNamespace(); - if (StringUtils.isEmpty(contextName)) { - return this.file; - } - String name = this.file.getName(); - String extension = StringUtils.getFilenameExtension(this.file.getName()); - name = name.substring(0, name.length() - extension.length() - 1); - if (isUpperCase(name)) { - name = name + "-" + contextName.toUpperCase(); - } - else { - name = name + "-" + contextName.toLowerCase(); - } - if (StringUtils.hasLength(extension)) { - name = name + "." + extension; - } - return new File(this.file.getParentFile(), name); - } - - private boolean isUpperCase(String name) { - for (int i = 0; i < name.length(); i++) { - if (Character.isLetter(name.charAt(i)) - && !Character.isUpperCase(name.charAt(i))) { - return false; - } - } - return true; - } - - private void createParentFolder(File file) { - File parent = file.getParentFile(); - if (parent != null) { - parent.mkdirs(); - } + super(file); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPidFileWriter.java b/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPidFileWriter.java new file mode 100644 index 0000000000..94965061e5 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPidFileWriter.java @@ -0,0 +1,257 @@ +/* + * Copyright 2012-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.system; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +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.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; +import org.springframework.boot.context.event.ApplicationPreparedEvent; +import org.springframework.boot.context.event.SpringApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.core.Ordered; +import org.springframework.core.env.Environment; +import org.springframework.util.Assert; + +/** + * An {@link ApplicationListener} that saves application PID into file. This application + * listener will be triggered exactly once per JVM, and the file name can be overridden at + * runtime with a System property or environment variable named "PIDFILE" (or "pidfile") + * or using a {@code spring.pid.file} property in the Spring {@link Environment}. + *

+ * If PID file can not be created no exception is reported. This behavior can be changed + * by assigning {@code true} to System property or environment variable named + * {@code PID_FAIL_ON_WRITE_ERROR} (or "pid_fail_on_write_error") or to + * {@code spring.pid.fail-on-write-error} property in the Spring {@link Environment}. + *

+ * Note: access to the Spring {@link Environment} is only possible when the + * {@link #setTriggerEventType(Class) triggerEventType} is set to + * {@link ApplicationEnvironmentPreparedEvent} or {@link ApplicationPreparedEvent}. + * + * @author Jakub Kubrynski + * @author Dave Syer + * @author Phillip Webb + * @author Tomasz Przybyla + * @since 1.4.0 + */ +public class ApplicationPidFileWriter + implements ApplicationListener, Ordered { + + private static final Log logger = LogFactory.getLog(ApplicationPidFileWriter.class); + + private static final String DEFAULT_FILE_NAME = "application.pid"; + + private static final List FILE_PROPERTIES; + + static { + List properties = new ArrayList(); + properties.add(new SpringProperty("spring.pid.", "file")); + properties.add(new SpringProperty("spring.", "pidfile")); + properties.add(new SystemProperty("PIDFILE")); + FILE_PROPERTIES = Collections.unmodifiableList(properties); + } + + private static final List FAIL_ON_WRITE_ERROR_PROPERTIES; + + static { + List properties = new ArrayList(); + properties.add(new SpringProperty("spring.pid.", "fail-on-write-error")); + properties.add(new SystemProperty("PID_FAIL_ON_WRITE_ERROR")); + FAIL_ON_WRITE_ERROR_PROPERTIES = Collections.unmodifiableList(properties); + } + + private static final AtomicBoolean created = new AtomicBoolean(false); + + private int order = Ordered.HIGHEST_PRECEDENCE + 13; + + private final File file; + + private Class triggerEventType = ApplicationPreparedEvent.class; + + /** + * Create a new {@link ApplicationPidFileWriter} instance using the filename + * 'application.pid'. + */ + public ApplicationPidFileWriter() { + this(new File(DEFAULT_FILE_NAME)); + } + + /** + * Create a new {@link ApplicationPidFileWriter} instance with a specified filename. + * @param filename the name of file containing pid + */ + public ApplicationPidFileWriter(String filename) { + this(new File(filename)); + } + + /** + * Create a new {@link ApplicationPidFileWriter} instance with a specified file. + * @param file the file containing pid + */ + public ApplicationPidFileWriter(File file) { + Assert.notNull(file, "File must not be null"); + this.file = file; + } + + /** + * Sets the type of application event that will trigger writing of the PID file. + * Defaults to {@link ApplicationPreparedEvent}. NOTE: If you use the + * {@link org.springframework.boot.context.event.ApplicationStartedEvent} to trigger + * the write, you will not be able to specify the PID filename in the Spring + * {@link Environment}. + * @param triggerEventType the trigger event type + */ + public void setTriggerEventType( + Class triggerEventType) { + Assert.notNull(triggerEventType, "Trigger event type must not be null"); + this.triggerEventType = triggerEventType; + } + + @Override + public void onApplicationEvent(SpringApplicationEvent event) { + if (this.triggerEventType.isInstance(event)) { + if (created.compareAndSet(false, true)) { + try { + writePidFile(event); + } + catch (Exception ex) { + String message = String.format("Cannot create pid file %s", + this.file); + if (failOnWriteError(event)) { + throw new IllegalStateException(message, ex); + } + logger.warn(message, ex); + } + } + } + } + + private void writePidFile(SpringApplicationEvent event) throws IOException { + File pidFile = this.file; + String override = getProperty(event, FILE_PROPERTIES); + if (override != null) { + pidFile = new File(override); + } + new ApplicationPid().write(pidFile); + pidFile.deleteOnExit(); + } + + private boolean failOnWriteError(SpringApplicationEvent event) { + String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES); + return (value == null ? false : Boolean.parseBoolean(value)); + } + + private String getProperty(SpringApplicationEvent event, List candidates) { + for (Property candidate : candidates) { + String value = candidate.getValue(event); + if (value != null) { + return value; + } + } + return null; + } + + public void setOrder(int order) { + this.order = order; + } + + @Override + public int getOrder() { + return this.order; + } + + /** + * Reset the created flag for testing purposes. + */ + protected static void reset() { + created.set(false); + } + + /** + * Provides access to a property value. + */ + private interface Property { + + String getValue(SpringApplicationEvent event); + + } + + /** + * {@link Property} obtained from Spring's {@link Environment}. + */ + private static class SpringProperty implements Property { + + private final String prefix; + + private final String key; + + SpringProperty(String prefix, String key) { + this.prefix = prefix; + this.key = key; + } + + @Override + public String getValue(SpringApplicationEvent event) { + Environment environment = getEnvironment(event); + if (environment == null) { + return null; + } + return new RelaxedPropertyResolver(environment, this.prefix) + .getProperty(this.key); + } + + private Environment getEnvironment(SpringApplicationEvent event) { + if (event instanceof ApplicationEnvironmentPreparedEvent) { + return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment(); + } + if (event instanceof ApplicationPreparedEvent) { + return ((ApplicationPreparedEvent) event).getApplicationContext() + .getEnvironment(); + } + return null; + } + + } + + /** + * {@link Property} obtained from {@link SystemProperties}. + */ + private static class SystemProperty implements Property { + + private final String[] properties; + + SystemProperty(String name) { + this.properties = new String[] { name.toUpperCase(), name.toLowerCase() }; + } + + @Override + public String getValue(SpringApplicationEvent event) { + return SystemProperties.get(this.properties); + } + + } + +} diff --git a/spring-boot/src/main/java/org/springframework/boot/system/EmbeddedServerPortFileWriter.java b/spring-boot/src/main/java/org/springframework/boot/system/EmbeddedServerPortFileWriter.java new file mode 100644 index 0000000000..fc19d85594 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/system/EmbeddedServerPortFileWriter.java @@ -0,0 +1,144 @@ +/* + * Copyright 2012-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.system; + +import java.io.File; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; +import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.util.Assert; +import org.springframework.util.FileCopyUtils; +import org.springframework.util.StringUtils; + +/** + * An {@link ApplicationListener} that saves embedded server port and management port into + * file. This application listener will be triggered whenever the servlet container + * starts, and the file name can be overridden at runtime with a System property or + * environment variable named "PORTFILE" or "portfile". + * + * @author David Liu + * @author Phillip Webb + * @author Andy Wilkinson + * @since 1.4.0 + */ +public class EmbeddedServerPortFileWriter + implements ApplicationListener { + + 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 final File file; + + /** + * Create a new {@link EmbeddedServerPortFileWriter} instance using the filename + * 'application.port'. + */ + public EmbeddedServerPortFileWriter() { + this(new File(DEFAULT_FILE_NAME)); + } + + /** + * Create a new {@link EmbeddedServerPortFileWriter} instance with a specified + * filename. + * @param filename the name of file containing port + */ + public EmbeddedServerPortFileWriter(String filename) { + this(new File(filename)); + } + + /** + * Create a new {@link EmbeddedServerPortFileWriter} instance with a specified file. + * @param file the file containing port + */ + public EmbeddedServerPortFileWriter(File file) { + Assert.notNull(file, "File must not be null"); + String override = SystemProperties.get(PROPERTY_VARIABLES); + if (override != null) { + this.file = new File(override); + } + else { + this.file = file; + } + } + + @Override + public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { + File portFile = getPortFile(event.getApplicationContext()); + try { + String port = String.valueOf(event.getEmbeddedServletContainer().getPort()); + createParentFolder(portFile); + FileCopyUtils.copy(port.getBytes(), portFile); + portFile.deleteOnExit(); + } + catch (Exception ex) { + logger.warn(String.format("Cannot create port file %s", this.file)); + } + } + + /** + * Return the actual port file that should be written for the given application + * context. The default implementation builds a file from the source file and the + * application context namespace. + * @param applicationContext the source application context + * @return the file that should be written + */ + protected File getPortFile(EmbeddedWebApplicationContext applicationContext) { + String contextName = applicationContext.getNamespace(); + if (StringUtils.isEmpty(contextName)) { + return this.file; + } + String name = this.file.getName(); + String extension = StringUtils.getFilenameExtension(this.file.getName()); + name = name.substring(0, name.length() - extension.length() - 1); + if (isUpperCase(name)) { + name = name + "-" + contextName.toUpperCase(); + } + else { + name = name + "-" + contextName.toLowerCase(); + } + if (StringUtils.hasLength(extension)) { + name = name + "." + extension; + } + return new File(this.file.getParentFile(), name); + } + + private boolean isUpperCase(String name) { + for (int i = 0; i < name.length(); i++) { + if (Character.isLetter(name.charAt(i)) + && !Character.isUpperCase(name.charAt(i))) { + return false; + } + } + return true; + } + + private void createParentFolder(File file) { + File parent = file.getParentFile(); + if (parent != null) { + parent.mkdirs(); + } + } + +} diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java b/spring-boot/src/main/java/org/springframework/boot/system/SystemProperties.java similarity index 96% rename from spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java rename to spring-boot/src/main/java/org/springframework/boot/system/SystemProperties.java index 68f66bfaeb..f6541551bb 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java +++ b/spring-boot/src/main/java/org/springframework/boot/system/SystemProperties.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.actuate.system; +package org.springframework.boot.system; /** * Access to system properties. diff --git a/spring-boot/src/main/java/org/springframework/boot/system/package-info.java b/spring-boot/src/main/java/org/springframework/boot/system/package-info.java new file mode 100644 index 0000000000..738b496a6c --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/system/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * General actuator system support classes. + */ +package org.springframework.boot.system; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java b/spring-boot/src/test/java/org/springframework/boot/system/ApplicationPidFileWriterTests.java similarity index 99% rename from spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java rename to spring-boot/src/test/java/org/springframework/boot/system/ApplicationPidFileWriterTests.java index 07fae4c134..1e4d0af805 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/system/ApplicationPidFileWriterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.actuate.system; +package org.springframework.boot.system; import java.io.File; import java.io.FileReader; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java b/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java similarity index 99% rename from spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java rename to spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java index b8bfd26576..4b20f7da43 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.actuate.system; +package org.springframework.boot.system; import java.io.File; import java.io.FileReader;