From da82f086927578b0938114ec360ab0fce9d1eb80 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 29 Jun 2015 22:51:27 -0700 Subject: [PATCH] Create Apache Ant sample See gh-3339 --- spring-boot-samples/pom.xml | 1 + .../spring-boot-sample-actuator/build.xml | 48 -------- .../spring-boot-sample-ant/build.xml | 50 +++++++++ .../ivy.xml | 7 +- .../ivysettings.xml | 6 +- .../spring-boot-sample-ant/pom.xml | 105 ++++++++++++++++++ .../java/sample/ant/SampleAntApplication.java | 35 ++++++ .../sample/ant/SampleAntApplicationIT.java | 58 ++++++++++ .../src/test/resources/application.properties | 1 + 9 files changed, 255 insertions(+), 56 deletions(-) delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/build.xml create mode 100644 spring-boot-samples/spring-boot-sample-ant/build.xml rename spring-boot-samples/{spring-boot-sample-actuator => spring-boot-sample-ant}/ivy.xml (51%) rename spring-boot-samples/{spring-boot-sample-actuator => spring-boot-sample-ant}/ivysettings.xml (69%) create mode 100644 spring-boot-samples/spring-boot-sample-ant/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java create mode 100644 spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 54bae28dd1c..0b4be403c99 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -20,6 +20,7 @@ ${basedir}/.. + spring-boot-sample-ant spring-boot-sample-activemq spring-boot-sample-actuator spring-boot-sample-actuator-log4j diff --git a/spring-boot-samples/spring-boot-sample-actuator/build.xml b/spring-boot-samples/spring-boot-sample-actuator/build.xml deleted file mode 100644 index 96ee6f3ce20..00000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/build.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - Sample ANT build script for a Spring Boot executable JAR project. Uses ivy for dependency management so run with - '$ ant -lib ivy-2.2.jar' (substitute the location of your actual ivy jar). Run with '$ java -jar target/*.jar'. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-ant/build.xml b/spring-boot-samples/spring-boot-sample-ant/build.xml new file mode 100644 index 00000000000..61193b938b9 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-ant/build.xml @@ -0,0 +1,50 @@ + + + + Sample ANT build script for a Spring Boot executable JAR project. Uses ivy for + dependency management and spring-boot-antlib for additional tasks. Run with + '$ ant -lib ivy-2.2.jar spring-boot-antlib.jar' (substitute the location of your + actual jars). Run with '$ java -jar target/*.jar'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-boot-samples/spring-boot-sample-actuator/ivy.xml b/spring-boot-samples/spring-boot-sample-ant/ivy.xml similarity index 51% rename from spring-boot-samples/spring-boot-sample-actuator/ivy.xml rename to spring-boot-samples/spring-boot-sample-ant/ivy.xml index 0e3da0eefc5..140d3274e5d 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/ivy.xml +++ b/spring-boot-samples/spring-boot-sample-ant/ivy.xml @@ -1,13 +1,10 @@ - + - - - - + diff --git a/spring-boot-samples/spring-boot-sample-actuator/ivysettings.xml b/spring-boot-samples/spring-boot-sample-ant/ivysettings.xml similarity index 69% rename from spring-boot-samples/spring-boot-sample-actuator/ivysettings.xml rename to spring-boot-samples/spring-boot-sample-ant/ivysettings.xml index 72631b8ba83..4127a506e8c 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/ivysettings.xml +++ b/spring-boot-samples/spring-boot-sample-ant/ivysettings.xml @@ -1,11 +1,11 @@ - + - - + + diff --git a/spring-boot-samples/spring-boot-sample-ant/pom.xml b/spring-boot-samples/spring-boot-sample-ant/pom.xml new file mode 100644 index 00000000000..11552f4798e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-ant/pom.xml @@ -0,0 +1,105 @@ + + + + 4.0.0 + + org.springframework.boot + spring-boot-samples + 1.3.0.BUILD-SNAPSHOT + + spring-boot-sample-ant + Spring Boot Ant Sample + Spring Boot Ant Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + 1.9.3 + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + + + org.springframework.boot + spring-boot-loader-tools + test + + + org.springframework.boot + spring-boot-antlib + ${spring-boot.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + none + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + antbuild + package + + + + + + + + run + + + + + + org.apache.ant + ant + ${ant.version} + + + org.apache.ivy + ivy + 2.4.0 + + + org.springframework.boot + spring-boot-antlib + ${spring-boot.version} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + diff --git a/spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java b/spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java new file mode 100644 index 00000000000..7a382f8df4d --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.ant; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleAntApplication implements CommandLineRunner { + + @Override + public void run(String... args) { + System.out.println("Spring Boot Ant Example"); + } + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleAntApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java new file mode 100644 index 00000000000..5b03436d77d --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java @@ -0,0 +1,58 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.ant; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThat; + +import java.io.File; +import java.io.FileFilter; +import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.springframework.boot.loader.tools.JavaExecutable; +import org.springframework.util.FileCopyUtils; + +/** + * Integration Tests for {@code SampleAntApplication}. + * + * @author Dave Syer + * @author Phillip Webb + */ +public class SampleAntApplicationIT { + + @Test + public void runJar() throws Exception { + File target = new File("target"); + File[] jarFiles = target.listFiles(new FileFilter() { + + @Override + public boolean accept(File file) { + return file.getName().endsWith(".jar"); + } + + }); + assertThat("Number of jars", jarFiles.length, equalTo(1)); + Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); + process.waitFor(5, TimeUnit.MINUTES); + assertThat(process.exitValue(), equalTo(0)); + String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); + assertThat(output, containsString("Spring Boot Ant Example")); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties b/spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties new file mode 100644 index 00000000000..4dfe84cedc6 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties @@ -0,0 +1 @@ +name: Phil \ No newline at end of file