提交 dbd41335 编写于 作者: 武汉红喜's avatar 武汉红喜

whatsmars-initializr

上级 bf668cfc
......@@ -44,6 +44,7 @@
<commons-collections.version>3.2.2</commons-collections.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
<commons-fileupload.version>1.3.3</commons-fileupload.version>
<commons-io.version>2.7</commons-io.version>
<commons-lang.version>2.6</commons-lang.version>
<commons-logging.version>1.2</commons-logging.version>
<curator.version>2.12.0</curator.version>
......@@ -117,6 +118,11 @@
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
......
......@@ -2,6 +2,11 @@
<archetype-descriptor name="standard">
<requiredProperties>
<requiredProperty key="groupId" />
<requiredProperty key="artifactId" />
<requiredProperty key="version">
<defaultValue>1.0.0-SNAPSHOT</defaultValue>
</requiredProperty>
<requiredProperty key="package">
<defaultValue>${groupId}</defaultValue>
</requiredProperty>
......
......@@ -15,6 +15,7 @@
<modules>
<module>web-archetype</module>
<module>dubbo-archetype</module>
<module>whatsmars-initializr</module>
</modules>
......
......@@ -2,6 +2,11 @@
<archetype-descriptor name="standard">
<requiredProperties>
<requiredProperty key="groupId" />
<requiredProperty key="artifactId" />
<requiredProperty key="version">
<defaultValue>1.0.0-SNAPSHOT</defaultValue>
</requiredProperty>
<requiredProperty key="package">
<defaultValue>${groupId}</defaultValue>
</requiredProperty>
......
<?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">
<parent>
<artifactId>whatsmars-archetypes</artifactId>
<groupId>org.hongxi</groupId>
<version>Rocket.S8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-initializr</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.hongxi.whatsmars.initializr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by shenhongxi on 2020/7/2.
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package org.hongxi.whatsmars.initializr.controller;
import org.apache.commons.io.FileUtils;
import org.hongxi.whatsmars.initializr.model.ProjectMeta;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.validation.Valid;
import java.io.File;
/**
* Created by shenhongxi on 2020/7/2.
*/
@Controller
@RequestMapping("/project")
public class InitializrController {
private static final String CMD = "sh generate.sh ";
@PostMapping
public ResponseEntity<byte[]> initialize(@Valid ProjectMeta projectMeta) throws Exception {
if (StringUtils.isEmpty(projectMeta.getPackageName())) {
projectMeta.setPackageName(projectMeta.getGroupId());
}
StringBuilder params = new StringBuilder(projectMeta.getType());
params.append(" ").append(projectMeta.getGroupId())
.append(" ").append(projectMeta.getArtifactId())
.append(" ").append(projectMeta.getPackageName())
.append(" ").append(projectMeta.isIncludeActuator());
Process process = null;
try {
process = Runtime.getRuntime().exec(CMD + params);
process.waitFor();
String dst = projectMeta.getArtifactId() + ".tar";
byte[] content = FileUtils.readFileToByteArray(new File(dst));
HttpHeaders headers = new HttpHeaders();
headers.setContentDispositionFormData("attachment", projectMeta.getArtifactId() + ".tar");
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<>(content, headers, HttpStatus.OK);
} finally {
if (process != null) {
process.destroy();
}
}
}
}
package org.hongxi.whatsmars.initializr.model;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
/**
* Created by shenhongxi on 2020/7/2.
*/
@Data
public class ProjectMeta {
@NotEmpty
private String type;
@NotEmpty
private String groupId;
@NotEmpty
private String artifactId;
private String packageName;
private boolean includeActuator;
}
......@@ -27,8 +27,8 @@ rm -f ${artifactId}.tar
mvn archetype:generate \
-DarchetypeCatalog=internal \
-DarchetypeGroupId=org.hongxi \
-DarchetypeArtifactId=${type}-archetype \
-DarchetypeGroupId=org.hongxi \
-DarchetypeArtifactId=${type}-archetype \
-DarchetypeVersion=Rocket.S8 \
-DgroupId=${groupId} \
-DartifactId=${artifactId} \
......@@ -42,5 +42,3 @@ rm -rf ${artifactId}
time=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time} create project ${artifactId} successfully" >> generate-project.log
# 可用java调用此脚本生成工程,上传至某个地方,然后下载
\ No newline at end of file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>initializr</title>
</head>
<body>
whatsmars initializr
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册