diff --git a/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java b/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java index 5f98eae3a9..12326a12a5 100644 --- a/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java +++ b/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue; * Integration test for {@link JarCommand}. * * @author Andy Wilkinson + * @author Stephane Nicoll */ public class JarCommandIT { @@ -98,12 +99,16 @@ public class JarCommandIT { assertThat(invocation.getErrorOutput(), equalTo("")); assertThat(invocation.getStandardOutput(), containsString("Hello World!")); - assertThat(invocation.getStandardOutput(), containsString("/public/public.txt")); assertThat(invocation.getStandardOutput(), - containsString("/resources/resource.txt")); - assertThat(invocation.getStandardOutput(), containsString("/static/static.txt")); + containsString("/BOOT-INF/classes!/public/public.txt")); assertThat(invocation.getStandardOutput(), - containsString("/templates/template.txt")); + containsString("/BOOT-INF/classes!/resources/resource.txt")); + assertThat(invocation.getStandardOutput(), + containsString("/BOOT-INF/classes!/static/static.txt")); + assertThat(invocation.getStandardOutput(), + containsString("/BOOT-INF/classes!/templates/template.txt")); + assertThat(invocation.getStandardOutput(), + containsString("/BOOT-INF/classes!/root.properties")); assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama")); } diff --git a/spring-boot-cli/src/it/java/org/springframework/boot/cli/WarCommandIT.java b/spring-boot-cli/src/it/java/org/springframework/boot/cli/WarCommandIT.java index ca6c87d17f..6d5856df01 100644 --- a/spring-boot-cli/src/it/java/org/springframework/boot/cli/WarCommandIT.java +++ b/spring-boot-cli/src/it/java/org/springframework/boot/cli/WarCommandIT.java @@ -26,14 +26,13 @@ import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation import org.springframework.boot.loader.tools.JavaExecutable; import org.springframework.util.SocketUtils; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration test for {@link WarCommand}. * * @author Andrey Stolyarov + * @author Henri Kerola */ public class WarCommandIT { @@ -47,18 +46,18 @@ public class WarCommandIT { Invocation invocation = this.cli.invoke("war", war.getAbsolutePath(), "war.groovy"); invocation.await(); - assertTrue(war.exists()); + assertThat(war.exists()).isTrue(); Process process = new JavaExecutable() .processBuilder("-jar", war.getAbsolutePath(), "--server.port=" + port) .start(); invocation = new Invocation(process); invocation.await(); - assertThat(invocation.getOutput(), containsString("onStart error")); - assertThat(invocation.getOutput(), containsString("Tomcat started")); - assertThat(invocation.getOutput(), - containsString("/WEB-INF/lib-provided/tomcat-embed-core")); - assertThat(invocation.getOutput(), - containsString("/WEB-INF/lib-provided/tomcat-embed-core")); + assertThat(invocation.getOutput()).contains("onStart error"); + assertThat(invocation.getOutput()).contains("Tomcat started"); + assertThat(invocation.getOutput()) + .contains("/WEB-INF/lib-provided/tomcat-embed-core"); + assertThat(invocation.getOutput()) + .contains("WEB-INF/classes!/root.properties"); process.destroy(); } diff --git a/spring-boot-cli/src/it/resources/jar-command/jar.groovy b/spring-boot-cli/src/it/resources/jar-command/jar.groovy index ee912748d0..1f385b4f33 100644 --- a/spring-boot-cli/src/it/resources/jar-command/jar.groovy +++ b/spring-boot-cli/src/it/resources/jar-command/jar.groovy @@ -13,6 +13,7 @@ class Example implements CommandLineRunner { println getClass().getResource('/resources/resource.txt') println getClass().getResource('/static/static.txt') println getClass().getResource('/templates/template.txt') + println getClass().getResource('/root.properties') println template('template.txt', [world:'Mama']) } } diff --git a/spring-boot-cli/src/it/resources/jar-command/root.properties b/spring-boot-cli/src/it/resources/jar-command/root.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-boot-cli/src/it/resources/war-command/root.properties b/spring-boot-cli/src/it/resources/war-command/root.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-boot-cli/src/it/resources/war-command/war.groovy b/spring-boot-cli/src/it/resources/war-command/war.groovy index 1a8ca70eca..b1a4c75cf2 100644 --- a/spring-boot-cli/src/it/resources/war-command/war.groovy +++ b/spring-boot-cli/src/it/resources/war-command/war.groovy @@ -10,6 +10,7 @@ class WarExample implements CommandLineRunner { void run(String... args) { println getClass().getResource('/org/apache/tomcat/InstanceManager.class') + println getClass().getResource('/root.properties') throw new RuntimeException("onStart error") } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/ArchiveCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/ArchiveCommand.java index 2986ae4b37..45e2b5bd33 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/ArchiveCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/ArchiveCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -73,6 +73,7 @@ import org.springframework.util.Assert; * @author Andy Wilkinson * @author Phillip Webb * @author Andrey Stolyarov + * @author Henri Kerola */ abstract class ArchiveCommand extends OptionParsingCommand { @@ -104,6 +105,10 @@ abstract class ArchiveCommand extends OptionParsingCommand { this.layout = layout; } + protected Layout getLayout() { + return this.layout; + } + @Override protected void doOptions() { this.includeOption = option("include", @@ -278,13 +283,18 @@ abstract class ArchiveCommand extends OptionParsingCommand { libraries.add(new Library(entry.getFile(), LibraryScope.COMPILE)); } else { - writer.writeEntry(entry.getName(), - new FileInputStream(entry.getFile())); + writeClasspathEntry(writer, entry); } } return libraries; } + protected void writeClasspathEntry(JarWriter writer, + MatchedResource entry) throws IOException { + writer.writeEntry(entry.getName(), + new FileInputStream(entry.getFile())); + } + protected abstract LibraryScope getLibraryScope(File file); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/WarCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/WarCommand.java index 80f0de42d6..08ae910302 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/WarCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/archive/WarCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -17,6 +17,7 @@ package org.springframework.boot.cli.command.archive; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import org.springframework.boot.cli.command.Command; @@ -29,6 +30,7 @@ import org.springframework.boot.loader.tools.LibraryScope; * * @author Andrey Stolyarov * @author Phillip Webb + * @author Henri Kerola * @since 1.3.0 */ public class WarCommand extends ArchiveCommand { @@ -61,6 +63,13 @@ public class WarCommand extends ArchiveCommand { super.addCliClasses(writer); } + @Override + protected void writeClasspathEntry(JarWriter writer, + ResourceMatcher.MatchedResource entry) throws IOException { + writer.writeEntry(getLayout().getClassesLocation() + entry.getName(), + new FileInputStream(entry.getFile())); + } + } }