From c1f8fd2bacf27759cd8a3781c81e02fa6e8af322 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 26 Jan 2014 22:54:04 -0800 Subject: [PATCH] Fix some compile warnings --- .../boot/loader/PropertiesLauncher.java | 40 +++++++++++-------- .../loader/archive/ExplodedArchiveTests.java | 1 + .../loader/jar/RandomAccessJarFileTests.java | 1 + .../test/SpringApplicationContextLoader.java | 10 ++--- ...onfigurationDefaultConfigurationTests.java | 5 ++- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index a40b62ccbd..4a91c3849c 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -121,6 +121,8 @@ public class PropertiesLauncher extends Launcher { private static final Pattern WORD_SEPARATOR = Pattern.compile("\\W+"); + private static final URL[] EMPTY_URLS = {}; + private final File home; private List paths = new ArrayList(DEFAULT_PATHS); @@ -493,26 +495,30 @@ public class PropertiesLauncher extends Launcher { private void addParentClassLoaderEntries(List lib) throws IOException, URISyntaxException { ClassLoader parentClassLoader = getClass().getClassLoader(); - if (parentClassLoader instanceof URLClassLoader) { - URLClassLoader urlClassLoader = (URLClassLoader) parentClassLoader; - for (URL url : urlClassLoader.getURLs()) { - if (url.toString().endsWith(".jar") || url.toString().endsWith(".zip")) { - lib.add(0, new JarFileArchive(new File(url.toURI()))); - } - else if (url.toString().endsWith("/*")) { - String name = url.getFile(); - File dir = new File(name.substring(0, name.length() - 1)); - if (dir.exists()) { - lib.add(0, - new ExplodedArchive(new File(name.substring(0, - name.length() - 1)), false)); - } - } - else { - lib.add(0, new ExplodedArchive(new File(url.getFile()))); + for (URL url : getURLs(parentClassLoader)) { + if (url.toString().endsWith(".jar") || url.toString().endsWith(".zip")) { + lib.add(0, new JarFileArchive(new File(url.toURI()))); + } + else if (url.toString().endsWith("/*")) { + String name = url.getFile(); + File dir = new File(name.substring(0, name.length() - 1)); + if (dir.exists()) { + lib.add(0, + new ExplodedArchive(new File(name.substring(0, + name.length() - 1)), false)); } } + else { + lib.add(0, new ExplodedArchive(new File(url.getFile()))); + } + } + } + + private URL[] getURLs(ClassLoader classLoader) { + if (classLoader instanceof URLClassLoader) { + return ((URLClassLoader) classLoader).getURLs(); } + return EMPTY_URLS; } private String cleanupPath(String path) { diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java index 39f67b06b7..9352f0b4eb 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java @@ -126,6 +126,7 @@ public class ExplodedArchiveTests { } @Test + @SuppressWarnings("resource") public void getFilteredArchive() throws Exception { Archive filteredArchive = this.archive .getFilteredArchive(new Archive.EntryRenameFilter() { diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/RandomAccessJarFileTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/RandomAccessJarFileTests.java index 0c8233206b..679c827231 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/RandomAccessJarFileTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/RandomAccessJarFileTests.java @@ -281,6 +281,7 @@ public class RandomAccessJarFileTests { } @Test + @SuppressWarnings("resource") public void verifySignedJar() throws Exception { String classpath = System.getProperty("java.class.path"); String[] entries = classpath.split(System.getProperty("path.separator")); diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index fd6e7eca37..a37bf401b0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -46,7 +46,6 @@ import org.springframework.web.context.support.GenericWebApplicationContext; * class and only creates a web application context if it is present. Non-web features, * like a repository layer, can be tested cleanly by simply not marking the test * class @WebAppConfiguration. - * *

* If @ActiveProfiles are provided in the test class they will be used to * create the application context. @@ -92,12 +91,9 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { } /** - * Detect the default configuration classes for the supplied test class. - * - *

- * The default implementation simply delegates to - * {@link AnnotationConfigContextLoaderUtils#detectDefaultConfigurationClasses(Class)}. - * + * Detect the default configuration classes for the supplied test class. By default + * simply delegates to + * {@link AnnotationConfigContextLoaderUtils#detectDefaultConfigurationClasses} . * @param declaringClass the test class that declared {@code @ContextConfiguration} * @return an array of default configuration classes, potentially empty but never * {@code null} diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java b/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java index 6c7e48694e..8a7bafebf4 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java @@ -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. @@ -25,6 +25,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.junit.Assert.assertNotNull; /** + * Tests for + * {@link SpringApplicationContextLoader#detectDefaultConfigurationClasses(Class)} + * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class)