pull/498/merge
Phillip Webb 11 years ago
parent f55ca99214
commit ca0a12cedb

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,10 +58,21 @@ public class ExplodedArchive extends Archive {
private boolean recursive = true; private boolean recursive = true;
/**
* Create a new {@link ExplodedArchive} instance.
* @param root the root folder
*/
public ExplodedArchive(File root) { public ExplodedArchive(File root) {
this(root, true); 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) { public ExplodedArchive(File root, boolean recursive) {
if (!root.exists() || !root.isDirectory()) { if (!root.exists() || !root.isDirectory()) {
throw new IllegalArgumentException("Invalid source folder " + root); throw new IllegalArgumentException("Invalid source folder " + root);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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;
import org.springframework.boot.loader.util.AsciiBytes; import org.springframework.boot.loader.util.AsciiBytes;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ExplodedArchive}. * Tests for {@link ExplodedArchive}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Dave Syer
*/ */
public class ExplodedArchiveTests { public class ExplodedArchiveTests {
@ -145,6 +148,30 @@ public class ExplodedArchiveTests {
assertThat(classLoader.getResourceAsStream("2.dat"), nullValue()); 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) { private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>(); Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>();
for (Archive.Entry entry : archive.getEntries()) { for (Archive.Entry entry : archive.getEntries()) {

@ -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;
}
}

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

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

@ -88,14 +88,13 @@ class StartupInfoLogger {
message.append(getApplicationName()); message.append(getApplicationName());
message.append(" in "); message.append(" in ");
message.append(stopWatch.getTotalTimeSeconds()); message.append(stopWatch.getTotalTimeSeconds());
message.append(" seconds (JVM running for ");
try { 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) { catch (Throwable ex) {
message.append("?"); // No JVM time available
} }
message.append(")");
return message; return message;
} }

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

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -79,7 +79,7 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
SLF4JBridgeHandler.install(); SLF4JBridgeHandler.install();
} }
} }
catch (Throwable e) { catch (Throwable ex) {
// Ignore. No java.util.logging bridge is installed. // Ignore. No java.util.logging bridge is installed.
} }
} }

Loading…
Cancel
Save