Enhance JarCommand to support lists of includes and excludes
The lists are comma separated. In addition, user can add prefixes "+" or "-", to signal that those values should be removed from the default list, not added to a fresh one. E.g. $ spring jar app.jar --include lib/*.jar,-static/** --exclude -**/*.jar to include a jar file specifically, and make sure it is not excluded, and additionally not include the static/** resources that would otherwise be included in the defaults. As soon as "+" or "-" prefixes are detected the default entries are all added (except the ones exlcuded with "-"). Fixes gh-1090
This commit is contained in:
@@ -26,6 +26,7 @@ import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -80,7 +81,32 @@ public class JarCommandIT {
|
||||
assertThat(invocation.getStandardOutput(), containsString("/static/static.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/templates/template.txt"));
|
||||
assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarCreationWithIncludes() throws Exception {
|
||||
File jar = new File("target/test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
|
||||
"--include", "-public/**,-resources/**", "jar.groovy");
|
||||
invocation.await();
|
||||
assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
|
||||
assertTrue(jar.exists());
|
||||
|
||||
Process process = new JavaExecutable().processBuilder("-jar",
|
||||
jar.getAbsolutePath()).start();
|
||||
invocation = new Invocation(process);
|
||||
invocation.await();
|
||||
|
||||
assertThat(invocation.getErrorOutput(), equalTo(""));
|
||||
assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("Goodbye Mama"));
|
||||
not(containsString("/public/public.txt")));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
not(containsString("/resources/resource.txt")));
|
||||
assertThat(invocation.getStandardOutput(), containsString("/static/static.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/templates/template.txt"));
|
||||
assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user