diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 2354294..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index fdc392f..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/java-project-71.iml b/.idea/java-project-71.iml deleted file mode 100644 index eccea1f..0000000 --- a/.idea/java-project-71.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 6d0ee1c..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 6eb59c4..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index d09f4e0..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fd9faff --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +run-dist: + app/build/install/app/bin/app + +run-dist-help: + app/build/install/app/bin/app -h + +run-dist-version: + app/build/install/app/bin/app -V + +run-dist-test: + app/build/install/app/bin/app src/test/resources/test1.json src/test/resources/test2.json + +run-dist-test-yml: + app/build/install/app/bin/app src/test/resources/test1.yml src/test/resources/test2.yml + +clean: + app/gradlew clean + +build: + app/gradlew clean build + +install: + app/gradlew clean install + +run: + app/gradlew run + +test: + app/gradlew test + +report: + app/gradlew jacocoTestReport + +lint: + app/gradlew checkstyleMain + +check-deps: + app/gradlew dependencyUpdates -Drevision=release + + +build-run: build run + +.PHONY: build \ No newline at end of file diff --git a/app/.idea/.gitignore b/app/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/app/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/app/.idea/gradle.xml b/app/.idea/gradle.xml deleted file mode 100644 index c2bad94..0000000 --- a/app/.idea/gradle.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/.idea/misc.xml b/app/.idea/misc.xml deleted file mode 100644 index dba1a23..0000000 --- a/app/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/.idea/vcs.xml b/app/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/app/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/Makefile b/app/Makefile deleted file mode 100644 index 80692cf..0000000 --- a/app/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -run-dist: - ./build/install/app/bin/app - -run-dist-help: - ./build/install/app/bin/app -h - -run-dist-version: - ./build/install/app/bin/app -V - -run-dist-test: - ./build/install/app/bin/app src/test/resources/test1.json src/test/resources/test2.json - -run-dist-test-yml: - ./build/install/app/bin/app src/test/resources/test1.yml src/test/resources/test2.yml - -clean: - ./gradlew clean - -build: - ./gradlew clean build - -install: - ./gradlew clean install - -run: - ./gradlew run - -test: - ./gradlew test - -report: - ./gradlew jacocoTestReport - -lint: - ./gradlew checkstyleMain - -check-deps: - ./gradlew dependencyUpdates -Drevision=release - - -build-run: build run - -.PHONY: build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fa5d2c4..9e40851 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -16,13 +16,10 @@ dependencies { testImplementation(platform("org.junit:junit-bom:5.10.2")) testImplementation("org.junit.jupiter:junit-jupiter:5.10.3") implementation("info.picocli:picocli:4.7.6") - // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind implementation("com.fasterxml.jackson.core:jackson-databind:2.17.1") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.0-rc1") } - - tasks.withType { useJUnitPlatform() } diff --git a/app/src/main/java/hexlet/code/Differ.java b/app/src/main/java/hexlet/code/Differ.java index f76f5eb..0611ada 100644 --- a/app/src/main/java/hexlet/code/Differ.java +++ b/app/src/main/java/hexlet/code/Differ.java @@ -18,4 +18,8 @@ public static String generate(String pathToFile, String pathToFile2, String form formatter = FormatterFactory.getFormatter(format); return formatter.format(DiffBuilder.build(mapFile, mapFile2)); } + + public static String generate(String pathToFile, String pathToFile2) throws Exception { + return generate(pathToFile, pathToFile2, "stylish"); + } } diff --git a/app/src/main/java/hexlet/code/Parser.java b/app/src/main/java/hexlet/code/Parser.java index 246e3cf..ad274ae 100644 --- a/app/src/main/java/hexlet/code/Parser.java +++ b/app/src/main/java/hexlet/code/Parser.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import java.io.File; -import java.io.IOException; import java.nio.file.Path; import java.util.Map; @@ -14,15 +13,19 @@ public class Parser { public static Map parse(Path file) { Map mapFile = null; ObjectMapper mapper = null; - if (file.toString().endsWith(".yml")) { - mapper = new YAMLMapper(); - } else if (file.toString().endsWith(".json")) { - mapper = new JsonMapper(); - } + String fileExtension = file.toString().split("\\.")[1]; + mapper = switch (fileExtension) { + case "yml" -> new YAMLMapper(); + case "json" -> new JsonMapper(); + default -> mapper; + }; try { + if (mapper == null) { + throw new Exception("Unexpected file extension '%s'".formatted(fileExtension)); + } mapFile = mapper.readValue(new File(file.toString()), new TypeReference<>() { }); - } catch (IOException e) { + } catch (Exception e) { System.out.println(e.getMessage()); } return mapFile;