mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Download starter.zip from home page
This commit is contained in:
parent
a7433b094c
commit
9d4a6bf6c5
14
.cfignore
Normal file
14
.cfignore
Normal file
@ -0,0 +1,14 @@
|
||||
.gradle
|
||||
*.sw?
|
||||
.#*
|
||||
*#
|
||||
*~
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
bin
|
||||
build
|
||||
target
|
||||
.springBeans
|
||||
tmp*
|
||||
spring.zip
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@ bin
|
||||
build
|
||||
target
|
||||
.springBeans
|
||||
tmp*
|
||||
spring
|
||||
grapes
|
||||
spring.zip
|
||||
|
41
app.groovy
41
app.groovy
@ -50,14 +50,42 @@ class MainController {
|
||||
new ResponseEntity<byte[]>(download.bytes, ["Content-Type":"application/zip"] as HttpHeaders, HttpStatus.OK)
|
||||
}
|
||||
|
||||
@RequestMapping("/starter")
|
||||
@ResponseBody
|
||||
ResponseEntity<byte[]> spring(PomRequest request) {
|
||||
|
||||
def model = [:]
|
||||
String pom = new String(pom(request, model).body)
|
||||
File dir = File.createTempFile("tmp","",new File(tmpdir));
|
||||
dir.delete()
|
||||
dir.mkdirs()
|
||||
new File(dir, "pom.xml").write(pom)
|
||||
|
||||
File src = new File(new File(dir, "src/main/java"),request.packageName.replace(".", "/"))
|
||||
src.mkdirs()
|
||||
|
||||
def body = template "Application.java", model
|
||||
log.info("Creating: " + src + "Application.java")
|
||||
new File(src, "Application.java").write(body)
|
||||
|
||||
File download = new File(tmpdir, dir.name + ".zip")
|
||||
log.info("Creating: " + download)
|
||||
|
||||
new AntBuilder().zip(destfile: download) {
|
||||
zipfileset(dir:dir, includes:"**")
|
||||
}
|
||||
log.info("Downloading: " + download)
|
||||
new ResponseEntity<byte[]>(download.bytes, ["Content-Type":"application/zip"] as HttpHeaders, HttpStatus.OK)
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/pom")
|
||||
@ResponseBody
|
||||
ResponseEntity<byte[]> pom(PomRequest request) {
|
||||
ResponseEntity<byte[]> pom(PomRequest request, Map model) {
|
||||
|
||||
def style = request.style
|
||||
log.info("Styles requested: " + style)
|
||||
|
||||
def model = [:]
|
||||
model.groupId = request.groupId
|
||||
model.artifactId = request.artifactId
|
||||
model.version = request.version
|
||||
@ -68,7 +96,7 @@ class MainController {
|
||||
if (style==null || style.size()==0) {
|
||||
style = [""]
|
||||
}
|
||||
model["styles"] = style.collect{ it=="" ? "" : it + "-" }
|
||||
model["styles"] = style.collect{ it=="" ? "" : "-" + it }
|
||||
|
||||
log.info("Model: " + model)
|
||||
|
||||
@ -107,13 +135,8 @@ class MainController {
|
||||
|
||||
}
|
||||
|
||||
@Grab("org.springframework.security:spring-security-config:3.2.0.M2")
|
||||
@Grab(value="org.springframework.security:spring-security-web:3.2.0.M2", transitive=false)
|
||||
import org.springframework.security.config.annotation.web.*
|
||||
import org.springframework.security.authentication.*
|
||||
import org.springframework.security.core.Authentication
|
||||
import org.springframework.security.core.authority.AuthorityUtils
|
||||
import org.springframework.actuate.properties.SecurityProperties
|
||||
@EnableWebSecurity
|
||||
@Configuration
|
||||
@Log
|
||||
class SecurityConfiguration {
|
||||
|
@ -6,4 +6,4 @@ applications:
|
||||
url: initializr.cfapps.io
|
||||
path: .
|
||||
command: java -jar ./spring/lib/*.jar run --local app.groovy -- --server.port=$PORT
|
||||
buildpack: https://github.com/cloudfoundry/cloudfoundry-buildpack-java
|
||||
# buildpack: https://github.com/dsyer/cloudfoundry-buildpack-java
|
||||
|
1
system.properties
Normal file
1
system.properties
Normal file
@ -0,0 +1 @@
|
||||
java.runtime.version=1.6
|
14
templates/Application.java
Normal file
14
templates/Application.java
Normal file
@ -0,0 +1,14 @@
|
||||
package ${packageName};
|
||||
|
||||
import org.springframework.bootstrap.SpringApplication;
|
||||
import org.springframework.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@
|
||||
</div>
|
||||
<h1>Spring Initializr</h1>
|
||||
<div>
|
||||
<form action="/pom" method="get">
|
||||
<form action="/starter.zip" 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"/>
|
||||
|
@ -19,19 +19,19 @@
|
||||
<dependencies><% styles.each { %>
|
||||
<dependency>
|
||||
<groupId>org.springframework.zero</groupId>
|
||||
<artifactId>spring-starter-${it}</artifactId>
|
||||
<artifactId>spring-starter${it}</artifactId>
|
||||
</dependency><% } %>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<start-class>${packageName}.ApplicationConfiguration</start-class>
|
||||
<start-class>${packageName}.Application</start-class>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<groupId>org.springframework.zero</groupId>
|
||||
<artifactId>spring-package-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
Loading…
Reference in New Issue
Block a user