diff --git a/objectmorph-app/pom.xml b/objectmorph-app/pom.xml index 73b39dd..0595adf 100644 --- a/objectmorph-app/pom.xml +++ b/objectmorph-app/pom.xml @@ -39,25 +39,35 @@ org.springframework.boot spring-boot-devtools + + + org.projectlombok + lombok + provided + - org.springframework.boot spring-boot-maven-plugin + 3.3.5 + + objectmorph-app-image:${project.parent.version} + - + - org.springframework.boot - spring-boot-dependencies - 3.3.5 - pom - import + org.springframework.boot + spring-boot-dependencies + 3.3.5 + pom + import diff --git a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/ObjectmorphApplication.java b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/ObjectmorphApplication.java similarity index 83% rename from objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/ObjectmorphApplication.java rename to objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/ObjectmorphApplication.java index 093e1e3..35dbe2d 100644 --- a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/ObjectmorphApplication.java +++ b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/ObjectmorphApplication.java @@ -1,4 +1,4 @@ -package com.github.mohamedennahdi.objectmorph.objectmorph; +package com.github.mohamedennahdi.objectmorph.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/controller/ObjectmorphController.java b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/controller/ObjectmorphController.java similarity index 70% rename from objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/controller/ObjectmorphController.java rename to objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/controller/ObjectmorphController.java index 527af3e..872e335 100644 --- a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/controller/ObjectmorphController.java +++ b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/controller/ObjectmorphController.java @@ -1,8 +1,5 @@ -package com.github.mohamedennahdi.objectmorph.objectmorph.controller; +package com.github.mohamedennahdi.objectmorph.app.controller; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URISyntaxException; import java.util.List; import org.springframework.http.HttpStatus; @@ -11,9 +8,10 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.github.mohamedennahdi.objectmorph.objectmorph.service.ObjectmorphService; +import com.github.mohamedennahdi.objectmorph.app.service.ObjectmorphService; import io.swagger.v3.oas.annotations.Parameter; @@ -38,20 +36,16 @@ public ResponseEntity test(List files) { } @GetMapping( value = "/html" ) - public ResponseEntity html(@Parameter(name = "sourceCode", description = "Source Code", example = "class SourceCode { int attribute1; int attribute2; SourceCode(){} public int getAttribute1() { return attribute1;}}") String[] sourceCode) { - String html = ""; + public ResponseEntity html(@Parameter(name = "sourceCode", description = "Source Code", example = "class SourceCode { int attribute1; int attribute2; SourceCode(){} public int getAttribute1() { return attribute1;}}") + @RequestParam("sourceCode") String[] sourceCode) { try { + String html = ""; html = objectmorphService.generateHTML(sourceCode); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { + return new ResponseEntity<>(html, HttpStatus.OK); + } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); + return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } - return new ResponseEntity<>(html, HttpStatus.OK); } } diff --git a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/logic/ObjectmorphSingleton.java b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/logic/ObjectmorphSingleton.java similarity index 86% rename from objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/logic/ObjectmorphSingleton.java rename to objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/logic/ObjectmorphSingleton.java index 396c516..8a442ad 100644 --- a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/logic/ObjectmorphSingleton.java +++ b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/logic/ObjectmorphSingleton.java @@ -1,4 +1,4 @@ -package com.github.mohamedennahdi.objectmorph.objectmorph.logic; +package com.github.mohamedennahdi.objectmorph.app.logic; import java.io.File; diff --git a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/service/ObjectmorphService.java b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/service/ObjectmorphService.java similarity index 69% rename from objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/service/ObjectmorphService.java rename to objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/service/ObjectmorphService.java index f839271..52a7548 100644 --- a/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/objectmorph/service/ObjectmorphService.java +++ b/objectmorph-app/src/main/java/com/github/mohamedennahdi/objectmorph/app/service/ObjectmorphService.java @@ -1,4 +1,4 @@ -package com.github.mohamedennahdi.objectmorph.objectmorph.service; +package com.github.mohamedennahdi.objectmorph.app.service; import java.io.File; import java.io.FileNotFoundException; @@ -15,8 +15,11 @@ import org.apache.commons.io.FileUtils; import org.springframework.stereotype.Service; -import com.github.mohamedennahdi.objectmorph.objectmorph.logic.ObjectmorphSingleton; +import com.github.mohamedennahdi.objectmorph.app.logic.ObjectmorphSingleton; +import lombok.extern.slf4j.Slf4j; + +@Slf4j @Service public class ObjectmorphService { ObjectmorphSingleton objectmorphLogic; @@ -31,22 +34,20 @@ public String generateHTML(String[] sourceCodes) throws IOException, URISyntaxEx String patternString = "(?<=class ).*?(?=\\s)"; Pattern pattern = Pattern.compile(patternString); + String path = System.getProperty("user.home"); for (String sourceCode: sourceCodes) { Matcher matcher = pattern.matcher(sourceCode); if (matcher.find()) { - System.out.println(matcher.group()); + String fileName = matcher.group() + ".java"; + log.info("Filename: " + fileName); + File file = Files.createFile(Paths.get(path + File.separator + fileName)).toFile(); + FileUtils.writeStringToFile(file, sourceCode, StandardCharsets.UTF_8); + files.add(file); } - - File file = Files.createFile(Paths.get(matcher.group() + ".java")).toFile(); - FileUtils.writeStringToFile(file, sourceCode, StandardCharsets.UTF_8); - files.add(file); } - return objectmorphLogic.getHtmlGenerator(files.toArray(new File[0])).generateFullHTML(); - } catch (FileNotFoundException e) { - throw e; - } catch (URISyntaxException e) { + } catch (Exception e) { throw e; } finally { for (File file : files) { diff --git a/objectmorph-app/src/main/resources/applications.yml b/objectmorph-app/src/main/resources/applications.yml index 9dfa991..7e9c389 100644 --- a/objectmorph-app/src/main/resources/applications.yml +++ b/objectmorph-app/src/main/resources/applications.yml @@ -1,3 +1,13 @@ spring: application: - name: "objectmorph-app" \ No newline at end of file + name: "objectmorph-app" +logging: + level: + root: DEBUG + com: + github: + objectmorph: WARN + file.name: logs/objectmorph-app.log + pattern: + console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" + file: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" \ No newline at end of file