From 323f5bf370ee2f13a18a5808956500be8d72fd22 Mon Sep 17 00:00:00 2001 From: Adam InTae Gerard Date: Sat, 31 Mar 2018 11:45:58 -0700 Subject: [PATCH] BAEL-1635: Spring Boot CLI (#3886) * BAEL-1635: Spring Boot CLI * Modified packages for consistent naming --- spring-boot-cli/README.md | 6 +++ spring-boot-cli/bash/groovy.sh | 17 +++++++++ spring-boot-cli/bash/setup.sh | 22 +++++++++++ spring-boot-cli/groovy/data/DataConfig.groovy | 23 +++++++++++ .../groovy/security/Security.groovy | 12 ++++++ spring-boot-cli/groovy/test/Test.groovy | 12 ++++++ spring-boot-cli/groovy/yml/Application.groovy | 17 +++++++++ .../groovy/yml/config/application.yml | 2 + spring-cloud-cli/install.sh | 38 ++++++------------- 9 files changed, 122 insertions(+), 27 deletions(-) create mode 100644 spring-boot-cli/README.md create mode 100644 spring-boot-cli/bash/groovy.sh create mode 100644 spring-boot-cli/bash/setup.sh create mode 100644 spring-boot-cli/groovy/data/DataConfig.groovy create mode 100644 spring-boot-cli/groovy/security/Security.groovy create mode 100644 spring-boot-cli/groovy/test/Test.groovy create mode 100644 spring-boot-cli/groovy/yml/Application.groovy create mode 100644 spring-boot-cli/groovy/yml/config/application.yml diff --git a/spring-boot-cli/README.md b/spring-boot-cli/README.md new file mode 100644 index 0000000000..4185415b39 --- /dev/null +++ b/spring-boot-cli/README.md @@ -0,0 +1,6 @@ +========= + +## Spring Boot CLI + +### Relevant Articles: +- [Introduction to Spring Boot CLI](http://www.baeldung.com/) diff --git a/spring-boot-cli/bash/groovy.sh b/spring-boot-cli/bash/groovy.sh new file mode 100644 index 0000000000..f8fc52bc7c --- /dev/null +++ b/spring-boot-cli/bash/groovy.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +echo "Run Groovy Service or Script" +echo "spring run app.groovy" +spring run app.groovy +echo + +echo "Watch Groovy Service or Script" +echo "spring run app.groovy --watch" +spring run app.groovy --watch +echo + +echo "Spring Shell" +echo "spring shell" +spring shell +echo "now enter a spring command..." +echo \ No newline at end of file diff --git a/spring-boot-cli/bash/setup.sh b/spring-boot-cli/bash/setup.sh new file mode 100644 index 0000000000..2cb3c89fd0 --- /dev/null +++ b/spring-boot-cli/bash/setup.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +echo "Install SDKMan" +sudo apt-get update +sudo apt-get install unzip zip -y +sudo curl -s get.sdkman.io | bash +sudo source "$HOME/.sdkman/bin/sdkman-init.sh" +sdk version + +echo "Install Spring Dependencies" +sudo sdk install groovy +sudo sdk install java +sudo sdk install maven + +echo "Install Spring Boot" +sudo sdk install springboot +spring --version + +# Spring Boot CLI Proper +# sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.0.0.RELEASE-bin/spring-2.0.0.RELEASE/ +# sdk default springboot dev +# spring --version diff --git a/spring-boot-cli/groovy/data/DataConfig.groovy b/spring-boot-cli/groovy/data/DataConfig.groovy new file mode 100644 index 0000000000..962b992b3d --- /dev/null +++ b/spring-boot-cli/groovy/data/DataConfig.groovy @@ -0,0 +1,23 @@ +package bael.data + +@Grab('h2') + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType +import org.springframework.web.servlet.config.annotation.EnableWebMvc +import javax.sql.DataSource + +@Configuration +@EnableWebMvc +@ComponentScan('bael.data') +class DataConfig { + + @Bean + DataSource dataSource() { + return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build(); + } + +} diff --git a/spring-boot-cli/groovy/security/Security.groovy b/spring-boot-cli/groovy/security/Security.groovy new file mode 100644 index 0000000000..a02fe1c343 --- /dev/null +++ b/spring-boot-cli/groovy/security/Security.groovy @@ -0,0 +1,12 @@ +package bael.security + +@Grab("spring-boot-starter-security") + +@RestController +class SampleController { + + @RequestMapping("/") + public def example() { + [message: "Hello World!"] + } +} diff --git a/spring-boot-cli/groovy/test/Test.groovy b/spring-boot-cli/groovy/test/Test.groovy new file mode 100644 index 0000000000..836ef80e2b --- /dev/null +++ b/spring-boot-cli/groovy/test/Test.groovy @@ -0,0 +1,12 @@ +package bael.test + +@Grab('junit') +@Log + +class Test { + + static void main(String[] args) { + log.info "Test..." + } + +} \ No newline at end of file diff --git a/spring-boot-cli/groovy/yml/Application.groovy b/spring-boot-cli/groovy/yml/Application.groovy new file mode 100644 index 0000000000..a62f7a5179 --- /dev/null +++ b/spring-boot-cli/groovy/yml/Application.groovy @@ -0,0 +1,17 @@ +package bael.yml + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.builder.SpringApplicationBuilder +import org.springframework.context.annotation.ComponentScan + +@EnableAutoConfiguration +@ComponentScan('bael.yml') +class App { + + static void main(String[] args) { + new SpringApplicationBuilder() + .sources(App) + .run(args) + } + +} \ No newline at end of file diff --git a/spring-boot-cli/groovy/yml/config/application.yml b/spring-boot-cli/groovy/yml/config/application.yml new file mode 100644 index 0000000000..06de93e3a9 --- /dev/null +++ b/spring-boot-cli/groovy/yml/config/application.yml @@ -0,0 +1,2 @@ +spring: + port: 8081 \ No newline at end of file diff --git a/spring-cloud-cli/install.sh b/spring-cloud-cli/install.sh index e01a8fc22e..334b4d77f9 100644 --- a/spring-cloud-cli/install.sh +++ b/spring-cloud-cli/install.sh @@ -1,33 +1,20 @@ #!/usr/bin/env bash -echo See: https://howtoprogram.xyz/2016/08/28/install-spring-boot-command-line-interface-on-linux/ -echo -echo "Setting up Java JDK 8" -echo See: http://tipsonubuntu.com/2016/07/31/install-oracle-java-8-9-ubuntu-16-04-linux-mint-18/ -sudo add-apt-repository ppa:webupd8team/java +echo "Install SDKMan" sudo apt-get update -sudo apt-get install oracle-java8-set-default -echo +sudo apt-get install unzip zip -y +sudo curl -s get.sdkman.io | bash +sudo source "$HOME/.sdkman/bin/sdkman-init.sh" +sdk version -echo "Downloading Spring Boot CLI 1.5.7" -wget http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.5.7.RELEASE/spring-boot-cli-1.5.7.RELEASE-bin.tar.gz -echo +echo "Install Spring Dependencies" +sudo sdk install groovy +sudo sdk install java +sudo sdk install maven -echo "Extracting and Installing" -sudo mkdir /opt/spring-boot -sudo tar xzf spring-boot-cli-1.5.7.RELEASE-bin.tar.gz -C /opt/spring-boot -export SPRING_HOME=/opt/spring-boot/spring-1.5.7.RELEASE -export PATH=$SPRING_HOME/bin:$PATH -source /etc/profile -echo - -echo "Verifying Install of Spring CLI" +echo "Install Spring Boot" +sudo sdk install springboot spring --version -echo - -echo "Maven Install" -sudo apt-get install maven -echo echo "Installing JCE" sudo apt-get install p7zip-full @@ -41,9 +28,6 @@ sudo mv UnlimitedJCEPolicyJDK8/*.jar /usr/lib/jvm/java-8-oracle/jre/lib/security echo echo "Installing Spring Cloud CLI" -sudo mkdir /opt/spring-boot/spring-1.5.7.RELEASE/lib/ext -sudo chown -R $USER:$USER /opt/spring-boot/spring-1.5.7.RELEASE/lib/ext -echo see: https://repo.spring.io/snapshot/org/springframework/cloud/spring-cloud-cli/ if manual install required spring install org.springframework.cloud:spring-cloud-cli:1.3.2.RELEASE echo