diff --git a/src/main/java/cokr/xit/MainController.java b/src/main/java/cokr/xit/MainController.java index f19915bc..912e97f9 100644 --- a/src/main/java/cokr/xit/MainController.java +++ b/src/main/java/cokr/xit/MainController.java @@ -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(""); + + //pom + pom.addLine(""); + + pom.addLine("4.0.0"); + + pom.addLine("xit-app"); + pom.addLine(""+project+""); + pom.addLine("1.0.0-SNAPSHOT"); + pom.addLine(""+project+""); + pom.addLine(""+description+""); + pom.addLine("war"); + + //부모프로젝트 + String parent = """ + + org.springframework.boot + spring-boot-starter-parent + 2.7.18 + + + """; + pom.addLine(parent); + + //프로퍼티 + String encodingAndJava = """ + + UTF-8 + 17 + + """; + pom.addLine(encodingAndJava); + + //저장소 + String repo = """ + + + maven-public + https://nas.xit.co.kr:8888/repository/maven-public/ + + + + + + maven-public + https://nas.xit.co.kr:8888/repository/maven-public/ + + true + + + false + + + + """; + pom.addLine(repo); + + //의존 라이브러리 + pom.addLine(""); + + + 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(""); + + //빌드 + String build = """ + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + """; + pom.addLine(build); + + + pom.addLine(""); + + 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 writer = new Consumer() { + @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 += "\r\n"; + d += "cokr.xit.app\r\n"; + d += "fims-"+lang+"-"+service+"\r\n"; + d += "1.0.0-SNAPSHOT\r\n"; + d += "\r\n"; + + return d; + } + } \ No newline at end of file diff --git a/src/main/java/cokr/xit/TextFileMaker.java b/src/main/java/cokr/xit/TextFileMaker.java new file mode 100644 index 00000000..268366e5 --- /dev/null +++ b/src/main/java/cokr/xit/TextFileMaker.java @@ -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(); + } + + } +} diff --git a/src/main/java/cokr/xit/custom/boot/MvcConfig.java b/src/main/java/cokr/xit/custom/boot/MvcConfig.java index 6411e7c3..da5ad175 100644 --- a/src/main/java/cokr/xit/custom/boot/MvcConfig.java +++ b/src/main/java/cokr/xit/custom/boot/MvcConfig.java @@ -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 */