From 2595a41da2d05866118cdf11374bc377587ff81d Mon Sep 17 00:00:00 2001 From: jonx8 Date: Sat, 9 Sep 2023 22:18:08 +0300 Subject: [PATCH] Delete unnecessary IOException and JOBS_SETTINGS_FILE --- src/main/java/ru/etu/petci/Main.java | 1 - .../java/ru/etu/petci/configuration/Configurator.java | 5 ++--- .../java/ru/etu/petci/handlers/AddCommandHandler.java | 9 +-------- .../ru/etu/petci/handlers/ContinueCommandHandler.java | 3 +-- .../java/ru/etu/petci/handlers/InitCommandHandler.java | 4 ---- 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/java/ru/etu/petci/Main.java b/src/main/java/ru/etu/petci/Main.java index 080162d..8973689 100644 --- a/src/main/java/ru/etu/petci/Main.java +++ b/src/main/java/ru/etu/petci/Main.java @@ -9,7 +9,6 @@ import java.util.logging.Logger; public class Main { - public static final String JOBS_SETTINGS_FILE = "jobs.properties"; private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); static { diff --git a/src/main/java/ru/etu/petci/configuration/Configurator.java b/src/main/java/ru/etu/petci/configuration/Configurator.java index e622e46..e12e882 100644 --- a/src/main/java/ru/etu/petci/configuration/Configurator.java +++ b/src/main/java/ru/etu/petci/configuration/Configurator.java @@ -4,7 +4,6 @@ import ru.etu.petci.jobs.Job; import ru.etu.petci.observers.RepositoryObserver; -import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -37,7 +36,7 @@ public void saveRepositoryConfig(String repoPath, String branchName) { } - public List readJobsConfig() throws IOException, BackingStoreException { + public List readJobsConfig() throws BackingStoreException { List jobsList = new ArrayList<>(); var jobsPreferences = Preferences.userRoot().node(JOBS_PREFERENCES); for (String jobName : jobsPreferences.keys()) { @@ -48,7 +47,7 @@ public List readJobsConfig() throws IOException, BackingStoreException { } - public void saveJobsConfig(String jobName, String scriptPath) throws IOException { + public void saveJobsConfig(String jobName, String scriptPath) { var jobsPreferences = Preferences.userRoot().node(JOBS_PREFERENCES); if (jobsPreferences.get(jobName, null) == null) { diff --git a/src/main/java/ru/etu/petci/handlers/AddCommandHandler.java b/src/main/java/ru/etu/petci/handlers/AddCommandHandler.java index 505152a..6a3c290 100644 --- a/src/main/java/ru/etu/petci/handlers/AddCommandHandler.java +++ b/src/main/java/ru/etu/petci/handlers/AddCommandHandler.java @@ -2,7 +2,6 @@ import ru.etu.petci.configuration.Configurator; -import java.io.IOException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; @@ -35,14 +34,8 @@ public int handle(String arg) { return 1; } + configurator.saveJobsConfig(jobName, scriptPath); scanner.close(); - - try { - configurator.saveJobsConfig(jobName, scriptPath); - } catch (IOException e) { - LOGGER.severe(e.getMessage()); - return 1; - } return 0; } } diff --git a/src/main/java/ru/etu/petci/handlers/ContinueCommandHandler.java b/src/main/java/ru/etu/petci/handlers/ContinueCommandHandler.java index 060f521..42ac818 100644 --- a/src/main/java/ru/etu/petci/handlers/ContinueCommandHandler.java +++ b/src/main/java/ru/etu/petci/handlers/ContinueCommandHandler.java @@ -7,7 +7,6 @@ import ru.etu.petci.jobs.JobsExecutor; import ru.etu.petci.observers.RepositoryObserver; -import java.io.IOException; import java.util.List; import java.util.Objects; import java.util.logging.Level; @@ -35,7 +34,7 @@ public int handle(String arg) { } catch (InterruptedException e) { LOGGER.log(Level.SEVERE, "The program was interrupted"); Thread.currentThread().interrupt(); - } catch (RepositoryNotFoundException | BackingStoreException | IOException e) { + } catch (RepositoryNotFoundException | BackingStoreException e) { LOGGER.log(Level.SEVERE, e.getMessage()); } return 1; diff --git a/src/main/java/ru/etu/petci/handlers/InitCommandHandler.java b/src/main/java/ru/etu/petci/handlers/InitCommandHandler.java index 344dea5..1580ecc 100644 --- a/src/main/java/ru/etu/petci/handlers/InitCommandHandler.java +++ b/src/main/java/ru/etu/petci/handlers/InitCommandHandler.java @@ -2,15 +2,11 @@ import ru.etu.petci.configuration.Configurator; -import java.io.IOException; -import java.nio.file.Path; import java.util.Objects; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; -import static ru.etu.petci.Main.JOBS_SETTINGS_FILE; - public class InitCommandHandler implements CommandHandler { private static final Logger LOGGER = Logger.getLogger(InitCommandHandler.class.getName());