mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 14:04:30 +08:00
Working app with maven pom generator and installer
This commit is contained in:
commit
0e1a1d6879
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.gradle
|
||||||
|
*.sw?
|
||||||
|
.#*
|
||||||
|
*#
|
||||||
|
*~
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
bin
|
||||||
|
build
|
||||||
|
target
|
||||||
|
.springBeans
|
||||||
|
spring
|
||||||
|
spring.zip
|
32
README.md
Normal file
32
README.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Spring Initializr
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
You need Java (1.6 or better) and a bash-like shell. To get started,
|
||||||
|
some basic operating system tools (`curl` and `zip`). The `spring`
|
||||||
|
command line interface can be installed like this
|
||||||
|
|
||||||
|
$ curl spring.cfapps.io/installer | bash
|
||||||
|
|
||||||
|
After running that command you should see a `spring` directory:
|
||||||
|
|
||||||
|
$ ./spring/bin/spring --help
|
||||||
|
|
||||||
|
usage: spring [--help] [--version]
|
||||||
|
<command> [<args>]
|
||||||
|
...
|
||||||
|
|
||||||
|
You could add that `bin` directory to your `PATH` (the examples below
|
||||||
|
assume you did that).
|
||||||
|
|
||||||
|
If you don't have `curl` or `zip` you can probably get them (for
|
||||||
|
Windoze users we recommend [cygwin](http://cygwin.org)), or you can
|
||||||
|
download the [zip file](http://spring.cfapps.io/spring.zip) and unpack
|
||||||
|
it yourself.
|
||||||
|
|
||||||
|
## Running the app
|
||||||
|
|
||||||
|
Use the spring command:
|
||||||
|
|
||||||
|
$ spring run app.groovy
|
||||||
|
|
91
app.groovy
Normal file
91
app.groovy
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
@Grab("org.springframework.bootstrap:spring-bootstrap-actuator:0.5.0.BUILD-SNAPSHOT")
|
||||||
|
@Grab("org.codehaus.groovy:groovy-ant:2.1.3")
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@Log
|
||||||
|
class MainController {
|
||||||
|
|
||||||
|
@Value('${info.home:http://localhost:8080/}')
|
||||||
|
private String home
|
||||||
|
|
||||||
|
@Value('${TMPDIR:.}')
|
||||||
|
private String tmpdir
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
@ResponseBody
|
||||||
|
String home() {
|
||||||
|
def model = [:]
|
||||||
|
model["styles"] = [[name:"Standard", value:""]]
|
||||||
|
model["styles"] << [name:"Web", value:"web"]
|
||||||
|
model["styles"] << [name:"Actuator", value:"actuator"]
|
||||||
|
model["styles"] << [name:"Batch", value:"batch"]
|
||||||
|
model["styles"] << [name:"JPA", value:"jpa"]
|
||||||
|
model["types"] = [[name:"Maven POM", value:"pom", selected: true], [name:"Maven Project", value:"pomproject", selected: false]]
|
||||||
|
template "home.html", model
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/installer")
|
||||||
|
@ResponseBody
|
||||||
|
String installer(@RequestHeader(required=false) String host) {
|
||||||
|
template "installer.sh", [host: host!=null ? host : home]
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/spring")
|
||||||
|
@ResponseBody
|
||||||
|
ResponseEntity<byte[]> spring() {
|
||||||
|
File download = new File(tmpdir, "spring.zip")
|
||||||
|
if (!download.exists()) {
|
||||||
|
log.info("Creating: " + download)
|
||||||
|
new AntBuilder().zip(destfile: download) {
|
||||||
|
zipfileset(dir:".", includes:"spring/bin/**", filemode:"775")
|
||||||
|
zipfileset(dir:".", includes:"spring/**", excludes:"spring/bin/**")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("Downloading: " + download)
|
||||||
|
new ResponseEntity<byte[]>(download.bytes, ["Content-Type":"application/zip"] as HttpHeaders, HttpStatus.OK)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/pom")
|
||||||
|
@ResponseBody
|
||||||
|
ResponseEntity<String> pom(PomRequest request) {
|
||||||
|
|
||||||
|
def style = request.style
|
||||||
|
log.info("Styles requested: " + style)
|
||||||
|
|
||||||
|
def model = [:]
|
||||||
|
model.groupId = request.groupId
|
||||||
|
model.artifactId = request.artifactId
|
||||||
|
model.version = request.version
|
||||||
|
model.name = request.name
|
||||||
|
model.description = request.description
|
||||||
|
model.packageName = request.packageName
|
||||||
|
|
||||||
|
if (style==null || style.size()==0) {
|
||||||
|
style = [""]
|
||||||
|
}
|
||||||
|
model["styles"] = style.collect{ it=="" ? "" : it + "-" }
|
||||||
|
|
||||||
|
log.info("Model: " + model)
|
||||||
|
|
||||||
|
def body = template "starter-pom.xml", model
|
||||||
|
new ResponseEntity<byte[]>(body, ["Content-Type":"application/octet-stream"] as HttpHeaders, HttpStatus.OK)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class PomRequest {
|
||||||
|
def style = []
|
||||||
|
|
||||||
|
String name = "demo"
|
||||||
|
String description = "Demo project for Spring Bootstrap"
|
||||||
|
String groupId = "org.test"
|
||||||
|
String artifactId
|
||||||
|
String version = "0.0.1.SNAPSHOT"
|
||||||
|
String packageName
|
||||||
|
String getName() {
|
||||||
|
artifactId == null ? name : artifactId
|
||||||
|
}
|
||||||
|
String getPackageName() {
|
||||||
|
packageName == null ? name : packageName
|
||||||
|
}
|
||||||
|
}
|
8
manifest.yml
Normal file
8
manifest.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
applications:
|
||||||
|
- name: spring
|
||||||
|
memory: 512M
|
||||||
|
instances: 1
|
||||||
|
url: spring.cfapps.io
|
||||||
|
path: .
|
||||||
|
command: ./spring/bin/spring run app.groovy -- --server.port=$PORT
|
11
static/css/bootstrap.min.css
vendored
Normal file
11
static/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
59
templates/home.html
Normal file
59
templates/home.html
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html">
|
||||||
|
<head>
|
||||||
|
<title>Spring Initializr</title>
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="/css/bootstrap.min.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="navbar">
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<a class="brand"
|
||||||
|
href="https://www.springsource.org">
|
||||||
|
Spring
|
||||||
|
</a>
|
||||||
|
<ul class="nav">
|
||||||
|
<li>
|
||||||
|
<a href="/spring.zip">
|
||||||
|
Download
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/">
|
||||||
|
Projects
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/installer">
|
||||||
|
Installer
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h1>Spring Initializr</h1>
|
||||||
|
<div>
|
||||||
|
<form action="/pom" method="get">
|
||||||
|
<label for="groupId">Group:</label> <input id="groupId" type="text" value="org.demo" name="groupId"/>
|
||||||
|
<label for="artifactId">Artifact:</label> <input id="artifactId" type="text" value="demo" name="artifactId"/>
|
||||||
|
<label for="name">Name:</label> <input id="name" type="text" value="demo" name="name"/>
|
||||||
|
<label for="name">Description:</label> <input id="description" type="text" value="Demo project" name="description"/>
|
||||||
|
<label for="packageName">Package Name:</label> <input id="packageName" type="text" value="demo" name="packageName"/>
|
||||||
|
<label>Styles:</label>
|
||||||
|
<% styles.each { %>
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" name="style" value="${it.value}"/>
|
||||||
|
${it.name}
|
||||||
|
</label><% } %>
|
||||||
|
<label>Type:</label>
|
||||||
|
<% types.each { %>
|
||||||
|
<label class="radio">
|
||||||
|
<input type="radio" name="type" value="${it.value}"${it.selected ? ' checked="true"' : ''}/>
|
||||||
|
${it.name}
|
||||||
|
</label><% } %>
|
||||||
|
<button type="submit" class="btn">Generate</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
29
templates/installer.sh
Normal file
29
templates/installer.sh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ -e spring -a ! -d spring ]; then
|
||||||
|
echo "You already have a local file called 'spring' and it's not a directory"
|
||||||
|
echo "Remove it before trying again"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d spring ]; then
|
||||||
|
echo "You already have a local directory called 'spring'. Removing..."
|
||||||
|
rm -rf spring
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Installing Spring in local directory..."
|
||||||
|
|
||||||
|
if [ ! -e spring.zip ]; then
|
||||||
|
wget ${host}/spring.zip
|
||||||
|
else
|
||||||
|
echo "Using locally cached spring.zip"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Unpacking spring.zip"
|
||||||
|
unzip -u spring.zip
|
||||||
|
rm spring.zip
|
||||||
|
|
||||||
|
echo "To use the spring CLI:"
|
||||||
|
echo " export SPRING_HOME="`pwd`/spring
|
||||||
|
echo " export PATH="`pwd`/spring/bin':\$PATH'
|
||||||
|
echo "And (e.g.) 'spring run app.groovy'"
|
68
templates/starter-pom.xml
Normal file
68
templates/starter-pom.xml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>${groupId}</groupId>
|
||||||
|
<artifactId>${artifactId}</artifactId>
|
||||||
|
<version>${version}</version>
|
||||||
|
|
||||||
|
<name>${name}</name>
|
||||||
|
<description>${description}</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.bootstrap</groupId>
|
||||||
|
<artifactId>spring-bootstrap-starters</artifactId>
|
||||||
|
<version>0.5.0.BUILD-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies><% styles.each { %>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.bootstrap</groupId>
|
||||||
|
<artifactId>spring-bootstrap-${it}starter</artifactId>
|
||||||
|
</dependency><% } %>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<start-class>${packageName}.ApplicationConfiguration</start-class>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>http://repo.springsource.org/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>http://repo.springsource.org/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>http://repo.springsource.org/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
|
</project>
|
Loading…
Reference in New Issue
Block a user