fims pom파일 생성 메소드 추가

main
이범준 1 year ago
parent d9d3c4768f
commit 3cafe1b9e2

@ -1,11 +1,21 @@
package cokr.xit;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.function.Consumer;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import cokr.xit.foundation.Downloadable;
import cokr.xit.foundation.web.AbstractController;
@Controller
@ -20,4 +30,180 @@ public class MainController extends AbstractController {
@RequestMapping(name="fims pom파일 작성", value={"/createFimsPOM.do"})
public ModelAndView createFimsPOM(HttpServletRequest req) {
ModelAndView mav = new ModelAndView("downloadView");
String project = req.getParameter("project");
String description = req.getParameter("description");
String[] serviceSelection = req.getParameterValues("serviceSelection");
String[] dbSelection = req.getParameterValues("dbSelection");
TextFileMaker pom = new TextFileMaker();
//xml
pom.addLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//pom
pom.addLine("<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 https://maven.apache.org/xsd/maven-4.0.0.xsd\">");
pom.addLine("<modelVersion>4.0.0</modelVersion>");
pom.addLine("<groupId>xit-app</groupId>");
pom.addLine("<artifactId>"+project+"</artifactId>");
pom.addLine("<version>1.0.0-SNAPSHOT</version>");
pom.addLine("<name>"+project+"</name>");
pom.addLine("<description>"+description+"</description>");
pom.addLine("<packaging>war</packaging>");
//부모프로젝트
String parent = """
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<relativePath/>
</parent>
""";
pom.addLine(parent);
//프로퍼티
String encodingAndJava = """
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
</properties>
""";
pom.addLine(encodingAndJava);
//저장소
String repo = """
<repositories>
<repository>
<id>maven-public</id>
<url>https://nas.xit.co.kr:8888/repository/maven-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>https://nas.xit.co.kr:8888/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
""";
pom.addLine(repo);
//의존 라이브러리
pom.addLine("<dependencies>");
if(serviceSelection != null) {
for(String item : serviceSelection) {
pom.addLine(dependencyFims("java", item));
}
}
if(dbSelection != null) {
for(String item : dbSelection) {
switch(item){
case "mariadb":
case "mysql":
//nothing
case "oracle":
//nothing?
break;
case "PostgreSQL":
case "CUBRID":
case "MSSQL":
case "TIBERO":
case "ALTIBASE":
break;
}
}
}
if(serviceSelection != null) {
for(String item : serviceSelection) {
pom.addLine(dependencyFims("web", item));
break;
}
}
pom.addLine("</dependencies>");
//빌드
String build = """
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
""";
pom.addLine(build);
pom.addLine("</project>");
pom.makeTxtFile("C:\\Temp", "pom.xml", pom.getFileCn());
File file = new File("C:\\Temp"+File.separator+"pom.xml");
try {
byte[] bytes = Files.readAllBytes(file.toPath());
Consumer<OutputStream> writer = new Consumer<OutputStream>() {
@Override
public void accept(OutputStream os) {
try {
os.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
};
mav.addObject("download",
new Downloadable()
.setContentType("application/xml")
.setWriter(writer)
.setFilename("pom.xml")
);
} catch (IOException e) {
e.printStackTrace();
}
return mav;
}
public String dependencyFims(String lang, String service) {
String d = "";
d += "<dependency>\r\n";
d += "<groupId>cokr.xit.app</groupId>\r\n";
d += "<artifactId>fims-"+lang+"-"+service+"</artifactId>\r\n";
d += "<version>1.0.0-SNAPSHOT</version>\r\n";
d += "</dependency>\r\n";
return d;
}
}

@ -0,0 +1,53 @@
package cokr.xit;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class TextFileMaker {
private String fileCn = "";
private String lineChange = "\r\n";
public void setLineChange(String str) {
this.lineChange = str;
}
public void addLine(String lines) {
this.fileCn += lines + this.lineChange;
}
public void REM(String line) {
this.fileCn += "REM " + line + this.lineChange;
}
public void SET(String line) {
this.fileCn += "SET " + line + this.lineChange;
}
public void ECHO(String line) {
this.fileCn += "ECHO " + line + this.lineChange;
}
public String getFileCn() {
return this.fileCn;
}
public void makeTxtFile(String filePath, String fileName, String fileContents) {
File folder = new File(filePath);
if (!folder.exists()) {
folder.mkdirs();
}
File file = new File(filePath+File.separator+fileName);
try {
FileWriter fw = new FileWriter(file, false);
fw.write(fileContents);
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -19,6 +19,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import cokr.xit.foundation.web.AccessInitializer;
import cokr.xit.foundation.web.DownloadView;
@Configuration
@ -87,6 +88,11 @@ public class MvcConfig implements WebMvcConfigurer {
return bean;
}
@Bean
public DownloadView downloadView() {
return new DownloadView();
}
/**CommonsMultipartResolver .
* @return CommonsMultipartResolver
*/

Loading…
Cancel
Save