diff --git a/src/org/testKitGen/MkGen.java b/src/org/testKitGen/MkGen.java index da6de633..54ae29a5 100644 --- a/src/org/testKitGen/MkGen.java +++ b/src/org/testKitGen/MkGen.java @@ -42,7 +42,7 @@ public MkGen(Arguments arg, TestTarget tt, PlaylistInfo pli, String makeFile, Li this.pli = pli; } - public void start() throws IOException { + public void start() { writeVars(); if (pli.containsTest()) { writeTargets(); @@ -50,13 +50,8 @@ public void start() throws IOException { System.out.println("Generated " + makeFile + "\n"); } - private void writeVars() throws IOException { - if (arg.getSpec().toLowerCase().contains("zos") && (arg.getJdkVersion().equals("21"))) { - writer = new OutputStreamWriter(new FileOutputStream(makeFile), Charset.forName("IBM-1047")); - } else { - writer = new FileWriter(makeFile); - } - try (Writer f = writer) { + private void writeVars() { + try (Writer f = getWriterObject(makeFile)) { String realtiveRoot = ""; int subdirlevel = dirList.size(); if (subdirlevel == 0) { @@ -236,13 +231,8 @@ private void writeSingleTest(List testsInPlaylist, TestInfo testInfo, Wr } } - private void writeTargets() throws IOException { - if (arg.getSpec().toLowerCase().contains("zos") && arg.getJdkVersion().equals("21")) { - writer = new OutputStreamWriter(new FileOutputStream(makeFile, true), Charset.forName("IBM-1047")); - } else { - writer = new FileWriter(makeFile, true); - } - try (Writer f = writer) { + private void writeTargets() { + try (Writer f = getWriterObject(makeFile)) { if (!pli.getIncludeList().isEmpty()) { for (String include : pli.getIncludeList()) { f.write("-include " + include + "\n\n"); @@ -266,4 +256,18 @@ private void writeTargets() throws IOException { System.exit(1); } } + + private Writer getWriterObject(String filetype) { + try { + if (arg.getSpec().toLowerCase().contains("zos") && (arg.getJdkVersion().equals("21"))) { + writer = new OutputStreamWriter(new FileOutputStream(filetype, true), Charset.forName("IBM-1047")); + } else { + writer = new FileWriter(filetype, true); + } + } catch(IOException e) { + e.printStackTrace(); + System.exit(1); + } + return writer; + } } \ No newline at end of file diff --git a/src/org/testKitGen/TestGenVisitor.java b/src/org/testKitGen/TestGenVisitor.java index 05c891e5..099f4eee 100644 --- a/src/org/testKitGen/TestGenVisitor.java +++ b/src/org/testKitGen/TestGenVisitor.java @@ -15,6 +15,7 @@ package org.testKitGen; import java.io.File; +import java.io.IOException; import java.util.List; public class TestGenVisitor implements DirectoryVisitor {