Browse Source

Polish

pull/498/merge
Phillip Webb 12 years ago
parent
commit
ca0a12cedb
  1. 13
      spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java
  2. 29
      spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java
  3. 66
      spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/SpecialArchiveTests.java
  4. 1
      spring-boot-tools/spring-boot-loader/src/test/resources/root/META-INF/spring/application.xml
  5. 2
      spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
  6. 9
      spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java
  7. 3
      spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java
  8. 4
      spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java

13
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -58,10 +58,21 @@ public class ExplodedArchive extends Archive { @@ -58,10 +58,21 @@ public class ExplodedArchive extends Archive {
private boolean recursive = true;
/**
* Create a new {@link ExplodedArchive} instance.
* @param root the root folder
*/
public ExplodedArchive(File root) {
this(root, true);
}
/**
* Create a new {@link ExplodedArchive} instance.
* @param root the root folder
* @param recursive if recursive searching should be used to locate the manifest.
* Defaults to {@code true}, folders with a large tree might want to set this to {code
* false}.
*/
public ExplodedArchive(File root, boolean recursive) {
if (!root.exists() || !root.isDirectory()) {
throw new IllegalArgumentException("Invalid source folder " + root);

29
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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,13 +38,16 @@ import org.springframework.boot.loader.archive.Archive.Entry; @@ -38,13 +38,16 @@ import org.springframework.boot.loader.archive.Archive.Entry;
import org.springframework.boot.loader.util.AsciiBytes;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link ExplodedArchive}.
*
* @author Phillip Webb
* @author Dave Syer
*/
public class ExplodedArchiveTests {
@ -145,6 +148,30 @@ public class ExplodedArchiveTests { @@ -145,6 +148,30 @@ public class ExplodedArchiveTests {
assertThat(classLoader.getResourceAsStream("2.dat"), nullValue());
}
@Test
public void getNonRecursiveEntriesForRoot() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("/"), false);
Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), greaterThan(1));
}
@Test
public void getNonRecursiveManifest() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
assertNotNull(archive.getManifest());
Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(4));
}
@Test
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
ExplodedArchive archive = new ExplodedArchive(
new File("src/test/resources/root"), false);
assertNotNull(archive.getManifest());
Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(3));
}
private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>();
for (Archive.Entry entry : archive.getEntries()) {

66
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/SpecialArchiveTests.java

@ -1,66 +0,0 @@ @@ -1,66 +0,0 @@
/*
* Copyright 2012-2013 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.loader.archive;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* @author Dave Syer
*/
public class SpecialArchiveTests {
@Test
public void getEntriesForRoot() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("/"), false);
Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), greaterThan(1));
}
@Test
public void getManifest() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
assertNotNull(archive.getManifest());
Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(4));
}
@Test
public void getManifestEvenIfNonRecursive() throws Exception {
ExplodedArchive archive = new ExplodedArchive(
new File("src/test/resources/root"), false);
assertNotNull(archive.getManifest());
Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(3));
}
private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>();
for (Archive.Entry entry : archive.getEntries()) {
entries.put(entry.getName().toString(), entry);
}
return entries;
}
}

1
spring-boot-tools/spring-boot-loader/src/test/resources/root/META-INF/spring/application.xml

@ -3,5 +3,4 @@ @@ -3,5 +3,4 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

2
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

@ -285,7 +285,7 @@ public class SpringApplication { @@ -285,7 +285,7 @@ public class SpringApplication {
try {
context.registerShutdownHook();
}
catch (AccessControlException e) {
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}

9
spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java

@ -88,14 +88,13 @@ class StartupInfoLogger { @@ -88,14 +88,13 @@ class StartupInfoLogger {
message.append(getApplicationName());
message.append(" in ");
message.append(stopWatch.getTotalTimeSeconds());
message.append(" seconds (JVM running for ");
try {
message.append(ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0);
double uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0;
message.append(" seconds (JVM running for " + uptime + ")");
}
catch (Throwable e) {
message.append("?");
catch (Throwable ex) {
// No JVM time available
}
message.append(")");
return message;
}

3
spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java

@ -197,7 +197,8 @@ public class LoggingApplicationListener implements SmartApplicationListener { @@ -197,7 +197,8 @@ public class LoggingApplicationListener implements SmartApplicationListener {
return name.split("@")[0];
}
}
catch (Throwable e) {
catch (Throwable ex) {
// Ignore
}
return "????";
}

4
spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -79,7 +79,7 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem { @@ -79,7 +79,7 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
SLF4JBridgeHandler.install();
}
}
catch (Throwable e) {
catch (Throwable ex) {
// Ignore. No java.util.logging bridge is installed.
}
}

Loading…
Cancel
Save