diff --git a/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java b/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java index 1488614a6a..f5a87f5b42 100644 --- a/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java +++ b/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import org.springframework.util.FileCopyUtils; import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; @@ -52,7 +53,9 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher { deleteLauncherClasses(); File targetClasses = populateTargetClasses(archive); File dependencies = populateDependencies(archive); - populateSrcMainWebapp(); + if (archive.getName().endsWith(".war")) { + populateSrcMainWebapp(); + } List classpath = new ArrayList(); classpath.add(targetClasses.getAbsolutePath()); for (File dependency : dependencies.listFiles()) { @@ -72,30 +75,35 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher { FileSystemUtils.deleteRecursively(new File(this.exploded, "org")); } - private File populateTargetClasses(File archive) { + private File populateTargetClasses(File archive) throws IOException { File targetClasses = new File(this.exploded, "target/classes"); targetClasses.mkdirs(); - new File(this.exploded, getClassesPath(archive)).renameTo(targetClasses); + File source = new File(this.exploded, getClassesPath(archive)); + FileSystemUtils.copyRecursively(source, targetClasses); + FileSystemUtils.deleteRecursively(source); return targetClasses; } - private File populateDependencies(File archive) { + private File populateDependencies(File archive) throws IOException { File dependencies = new File(this.exploded, "dependencies"); dependencies.mkdirs(); List libPaths = getLibPaths(archive); for (String libPath : libPaths) { - for (File jar : new File(this.exploded, libPath).listFiles()) { - jar.renameTo(new File(dependencies, jar.getName())); + File libDirectory = new File(this.exploded, libPath); + for (File jar : libDirectory.listFiles()) { + FileCopyUtils.copy(jar, new File(dependencies, jar.getName())); } + FileSystemUtils.deleteRecursively(libDirectory); } return dependencies; } - private void populateSrcMainWebapp() { + private void populateSrcMainWebapp() throws IOException { File srcMainWebapp = new File(this.exploded, "src/main/webapp"); srcMainWebapp.mkdirs(); - new File(this.exploded, "webapp-resource.txt") - .renameTo(new File(srcMainWebapp, "webapp-resource.txt")); + File source = new File(this.exploded, "webapp-resource.txt"); + FileCopyUtils.copy(source, new File(srcMainWebapp, "webapp-resource.txt")); + source.delete(); } private String getClassesPath(File archive) { diff --git a/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java b/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java index 1dc5ac3033..4bb6485572 100644 --- a/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java +++ b/spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import org.springframework.util.FileCopyUtils; import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; @@ -63,7 +64,9 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { File targetClasses = populateTargetClasses(archive); File dependencies = populateDependencies(archive); File resourcesProject = explodedResourcesProject(dependencies); - populateSrcMainWebapp(); + if (archive.getName().endsWith(".war")) { + populateSrcMainWebapp(); + } List classpath = new ArrayList(); classpath.add(targetClasses.getAbsolutePath()); for (File dependency : dependencies.listFiles()) { @@ -80,21 +83,25 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { } } - private File populateTargetClasses(File archive) { + private File populateTargetClasses(File archive) throws IOException { File targetClasses = new File(this.exploded, "target/classes"); targetClasses.mkdirs(); - new File(this.exploded, getClassesPath(archive)).renameTo(targetClasses); + File source = new File(this.exploded, getClassesPath(archive)); + FileSystemUtils.copyRecursively(source, targetClasses); + FileSystemUtils.deleteRecursively(source); return targetClasses; } - private File populateDependencies(File archive) { + private File populateDependencies(File archive) throws IOException { File dependencies = new File(this.exploded, "dependencies"); dependencies.mkdirs(); List libPaths = getLibPaths(archive); for (String libPath : libPaths) { - for (File jar : new File(this.exploded, libPath).listFiles()) { - jar.renameTo(new File(dependencies, jar.getName())); + File libDirectory = new File(this.exploded, libPath); + for (File jar : libDirectory.listFiles()) { + FileCopyUtils.copy(jar, new File(dependencies, jar.getName())); } + FileSystemUtils.deleteRecursively(libDirectory); } return dependencies; } @@ -108,11 +115,12 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { return resourcesProject; } - private void populateSrcMainWebapp() { + private void populateSrcMainWebapp() throws IOException { File srcMainWebapp = new File(this.exploded, "src/main/webapp"); srcMainWebapp.mkdirs(); - new File(this.exploded, "webapp-resource.txt") - .renameTo(new File(srcMainWebapp, "webapp-resource.txt")); + File source = new File(this.exploded, "webapp-resource.txt"); + FileCopyUtils.copy(source, new File(srcMainWebapp, "webapp-resource.txt")); + source.delete(); } private void deleteLauncherClasses() {