From 1f36d4657f6bc248b018542b9864fe1e5d396af6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 25 Jun 2014 14:31:41 -0700 Subject: [PATCH] Fix various Windows related issues Fixes gh-1168 --- spring-boot-actuator/pom.xml | 10 ++++++++++ .../boot/cli/command/jar/ResourceMatcher.java | 5 +++-- .../compiler/ExtendedGroovyClassLoader.java | 2 ++ .../grape/DetailedProgressReporterTests.java | 20 +++++++++++++------ .../logging/LoggingApplicationListener.java | 11 ++++++++++ .../boot/logging/logback/base.xml | 2 +- .../LoggingApplicationListenerTests.java | 7 ++++++- .../logback/LogbackLoggingSystemTests.java | 6 +++++- .../src/test/resources/logback-nondefault.xml | 2 +- 9 files changed, 53 insertions(+), 12 deletions(-) diff --git a/spring-boot-actuator/pom.xml b/spring-boot-actuator/pom.xml index eb0fd8f7eaf..7a62f8d8f22 100644 --- a/spring-boot-actuator/pom.xml +++ b/spring-boot-actuator/pom.xml @@ -101,6 +101,16 @@ tomcat-embed-core true + + org.crashub + crash.shell + true + + + org.crashub + crash.cli + true + org.crashub crash.embed.spring diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/ResourceMatcher.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/ResourceMatcher.java index a6ff6b44632..f69672abe8b 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/ResourceMatcher.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/ResourceMatcher.java @@ -33,6 +33,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.util.AntPathMatcher; +import org.springframework.util.StringUtils; /** * Used to match resources for inclusion in a CLI application's jar file @@ -186,8 +187,8 @@ class ResourceMatcher { } private MatchedResource(File rootFolder, File file) { - this.name = file.getAbsolutePath().substring( - rootFolder.getAbsolutePath().length() + 1); + this.name = StringUtils.cleanPath(file.getAbsolutePath().substring( + rootFolder.getAbsolutePath().length() + 1)); this.file = file; this.root = false; } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java index b67ef2bdcdd..01a2620e3f0 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java @@ -38,6 +38,7 @@ import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.SourceUnit; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; +import org.springframework.util.StringUtils; /** * Extension of the {@link GroovyClassLoader} with support for obtaining '.class' files as @@ -222,6 +223,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader { } private boolean isGroovyJar(String entry) { + entry = StringUtils.cleanPath(entry); for (String jarPrefix : GROOVY_JARS_PREFIXES) { if (entry.contains("/" + jarPrefix + "-")) { return true; diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/DetailedProgressReporterTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/DetailedProgressReporterTests.java index 18883df0300..36d3e6daa51 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/DetailedProgressReporterTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/DetailedProgressReporterTests.java @@ -26,9 +26,17 @@ import org.eclipse.aether.transfer.TransferResource; import org.junit.Before; import org.junit.Test; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThat; +/** + * Tests for {@link DetailedProgressReporter}. + * + * @author Andy Wilkinson + */ public final class DetailedProgressReporterTests { private static final String REPOSITORY = "http://my.repository.com/"; @@ -63,13 +71,13 @@ public final class DetailedProgressReporterTests { public void downloaded() throws InterruptedException { // Ensure some transfer time Thread.sleep(100); - TransferEvent completedEvent = new TransferEvent.Builder(this.session, this.resource).addTransferredBytes(4096).build(); this.session.getTransferListener().transferSucceeded(completedEvent); - - assertTrue(new String(this.baos.toByteArray()).matches(String.format( - "Downloaded: %s%s \\(4KB at [0-9]+(\\.|,)[0-9]KB/sec\\)\\n", REPOSITORY, - ARTIFACT))); + String message = new String(this.baos.toByteArray()).replace("\\", "/"); + assertThat(message, startsWith("Downloaded: " + REPOSITORY + ARTIFACT)); + assertThat(message, containsString("4KB at")); + assertThat(message, containsString("KB/sec")); + assertThat(message, endsWith("\n")); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index 64b05be1929..454c540a6fa 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -36,6 +36,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ResourceUtils; +import org.springframework.util.StringUtils; /** * An {@link ApplicationListener} that configures a logging framework depending on what it @@ -147,6 +148,16 @@ public class LoggingApplicationListener implements SmartApplicationListener { } } + // Logback won't read backslashes so add a clean path for it to use + if (!StringUtils.hasLength(System.getProperty("LOG_TEMP"))) { + String path = System.getProperty("java.io.tmpdir"); + path = StringUtils.cleanPath(path); + if(path.endsWith("/")) { + path = path.substring(0,path.length()-1); + } + System.setProperty("LOG_TEMP", path); + } + boolean environmentChanged = false; for (Map.Entry mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING .entrySet()) { diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml index 3298ff9b943..67958866ec1 100644 --- a/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml @@ -3,7 +3,7 @@ - + - + ${LOG_FILE} [%t] ${PID:-????} %c{1}: %m%n