Merge pull request #6367 from henrikerola:gh-6351

* pr/6367:
  Polish contribution
  "spring war" should copy resources to WEB-INF/classes
pull/7164/head
Stephane Nicoll 8 years ago
commit 0b9283c3cd

@ -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"); * 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.
@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue;
* Integration test for {@link JarCommand}. * Integration test for {@link JarCommand}.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Nicoll
*/ */
public class JarCommandIT { public class JarCommandIT {
@ -98,12 +99,16 @@ public class JarCommandIT {
assertThat(invocation.getErrorOutput(), equalTo("")); assertThat(invocation.getErrorOutput(), equalTo(""));
assertThat(invocation.getStandardOutput(), containsString("Hello World!")); assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
assertThat(invocation.getStandardOutput(), containsString("/public/public.txt"));
assertThat(invocation.getStandardOutput(), assertThat(invocation.getStandardOutput(),
containsString("/resources/resource.txt")); containsString("/BOOT-INF/classes!/public/public.txt"));
assertThat(invocation.getStandardOutput(), containsString("/static/static.txt"));
assertThat(invocation.getStandardOutput(), 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")); assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
} }

@ -26,14 +26,13 @@ import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation
import org.springframework.boot.loader.tools.JavaExecutable; import org.springframework.boot.loader.tools.JavaExecutable;
import org.springframework.util.SocketUtils; import org.springframework.util.SocketUtils;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration test for {@link WarCommand}. * Integration test for {@link WarCommand}.
* *
* @author Andrey Stolyarov * @author Andrey Stolyarov
* @author Henri Kerola
*/ */
public class WarCommandIT { public class WarCommandIT {
@ -47,18 +46,18 @@ public class WarCommandIT {
Invocation invocation = this.cli.invoke("war", war.getAbsolutePath(), Invocation invocation = this.cli.invoke("war", war.getAbsolutePath(),
"war.groovy"); "war.groovy");
invocation.await(); invocation.await();
assertTrue(war.exists()); assertThat(war.exists()).isTrue();
Process process = new JavaExecutable() Process process = new JavaExecutable()
.processBuilder("-jar", war.getAbsolutePath(), "--server.port=" + port) .processBuilder("-jar", war.getAbsolutePath(), "--server.port=" + port)
.start(); .start();
invocation = new Invocation(process); invocation = new Invocation(process);
invocation.await(); invocation.await();
assertThat(invocation.getOutput(), containsString("onStart error")); assertThat(invocation.getOutput()).contains("onStart error");
assertThat(invocation.getOutput(), containsString("Tomcat started")); assertThat(invocation.getOutput()).contains("Tomcat started");
assertThat(invocation.getOutput(), assertThat(invocation.getOutput())
containsString("/WEB-INF/lib-provided/tomcat-embed-core")); .contains("/WEB-INF/lib-provided/tomcat-embed-core");
assertThat(invocation.getOutput(), assertThat(invocation.getOutput())
containsString("/WEB-INF/lib-provided/tomcat-embed-core")); .contains("WEB-INF/classes!/root.properties");
process.destroy(); process.destroy();
} }

@ -13,6 +13,7 @@ class Example implements CommandLineRunner {
println getClass().getResource('/resources/resource.txt') println getClass().getResource('/resources/resource.txt')
println getClass().getResource('/static/static.txt') println getClass().getResource('/static/static.txt')
println getClass().getResource('/templates/template.txt') println getClass().getResource('/templates/template.txt')
println getClass().getResource('/root.properties')
println template('template.txt', [world:'Mama']) println template('template.txt', [world:'Mama'])
} }
} }

@ -10,6 +10,7 @@ class WarExample implements CommandLineRunner {
void run(String... args) { void run(String... args) {
println getClass().getResource('/org/apache/tomcat/InstanceManager.class') println getClass().getResource('/org/apache/tomcat/InstanceManager.class')
println getClass().getResource('/root.properties')
throw new RuntimeException("onStart error") throw new RuntimeException("onStart error")
} }

@ -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"); * 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.
@ -73,6 +73,7 @@ import org.springframework.util.Assert;
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Phillip Webb * @author Phillip Webb
* @author Andrey Stolyarov * @author Andrey Stolyarov
* @author Henri Kerola
*/ */
abstract class ArchiveCommand extends OptionParsingCommand { abstract class ArchiveCommand extends OptionParsingCommand {
@ -104,6 +105,10 @@ abstract class ArchiveCommand extends OptionParsingCommand {
this.layout = layout; this.layout = layout;
} }
protected Layout getLayout() {
return this.layout;
}
@Override @Override
protected void doOptions() { protected void doOptions() {
this.includeOption = option("include", this.includeOption = option("include",
@ -278,13 +283,18 @@ abstract class ArchiveCommand extends OptionParsingCommand {
libraries.add(new Library(entry.getFile(), LibraryScope.COMPILE)); libraries.add(new Library(entry.getFile(), LibraryScope.COMPILE));
} }
else { else {
writer.writeEntry(entry.getName(), writeClasspathEntry(writer, entry);
new FileInputStream(entry.getFile()));
} }
} }
return libraries; 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); protected abstract LibraryScope getLibraryScope(File file);
} }

@ -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"); * 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.
@ -17,6 +17,7 @@
package org.springframework.boot.cli.command.archive; package org.springframework.boot.cli.command.archive;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import org.springframework.boot.cli.command.Command; import org.springframework.boot.cli.command.Command;
@ -29,6 +30,7 @@ import org.springframework.boot.loader.tools.LibraryScope;
* *
* @author Andrey Stolyarov * @author Andrey Stolyarov
* @author Phillip Webb * @author Phillip Webb
* @author Henri Kerola
* @since 1.3.0 * @since 1.3.0
*/ */
public class WarCommand extends ArchiveCommand { public class WarCommand extends ArchiveCommand {
@ -61,6 +63,13 @@ public class WarCommand extends ArchiveCommand {
super.addCliClasses(writer); super.addCliClasses(writer);
} }
@Override
protected void writeClasspathEntry(JarWriter writer,
ResourceMatcher.MatchedResource entry) throws IOException {
writer.writeEntry(getLayout().getClassesLocation() + entry.getName(),
new FileInputStream(entry.getFile()));
}
} }
} }

Loading…
Cancel
Save