From 4cf1755fd6588e5bd1ec4e8e435d2a3a2eb6fd30 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 8 Mar 2024 10:40:10 +0100 Subject: [PATCH] ColorSettings: drop old configuration file format Fixes #3416 --- .../uka/ilkd/key/nparser/ParsingFacade.java | 20 +++++----- .../ilkd/key/gui/colors/ColorSettings.java | 39 ++++--------------- .../key/gui/colors/ColorSettingsProvider.java | 2 +- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/key.core/src/main/java/de/uka/ilkd/key/nparser/ParsingFacade.java b/key.core/src/main/java/de/uka/ilkd/key/nparser/ParsingFacade.java index 50356a94fd..e130885505 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/nparser/ParsingFacade.java +++ b/key.core/src/main/java/de/uka/ilkd/key/nparser/ParsingFacade.java @@ -208,7 +208,7 @@ public static KeyAst.Taclet parseTaclet(CharStream source) { // region configuration /** - * Parses a the configuration determined by the given {@code file}. + * Parses the configuration determined by the given {@code file}. * A configuration corresponds to the grammar rule {@code cfile} in the {@code KeYParser.g4}. * * @param file non-null {@link Path} object @@ -221,19 +221,20 @@ public static KeyAst.ConfigurationFile parseConfigurationFile(Path file) throws } /** + * @param file non-null file to read as configuration * @see #parseConfigurationFile(Path) + * @throws IOException if the file is not found or not readable. */ public static KeyAst.ConfigurationFile parseConfigurationFile(File file) throws IOException { return parseConfigurationFile(file.toPath()); } /** - * Parses a the configuration determined by the given {@code stream}. + * Parses the configuration determined by the given {@code stream}. * A configuration corresponds to the grammar rule {@code cfile} in the {@code KeYParser.g4}. * - * @param file non-null {@link CharStream} object + * @param stream non-null {@link CharStream} object * @return monad that encapsluate the ParserRuleContext - * @throws IOException if the file is not found or not readable. * @throws BuildingException if the file is syntactical broken. */ public static KeyAst.ConfigurationFile parseConfigurationFile(CharStream stream) { @@ -244,20 +245,20 @@ public static KeyAst.ConfigurationFile parseConfigurationFile(CharStream stream) } /** - * Parses a the configuration determined by the given {@code stream}. + * Parses the configuration determined by the given {@code stream}. * A configuration corresponds to the grammar rule {@code cfile} in the {@code KeYParser.g4}. * - * @param file non-null {@link CharStream} object - * @return a configration object with the data deserialize from the given file - * @throws IOException if the file is not found or not readable. + * @param input non-null {@link CharStream} object + * @return a configuration object with the data deserialize from the given file * @throws BuildingException if the file is syntactical broken. */ - public static Configuration readConfigurationFile(CharStream input) throws IOException { + public static Configuration readConfigurationFile(CharStream input) { return parseConfigurationFile(input).asConfiguration(); } /** * @see #readConfigurationFile(CharStream) + * @throws IOException if the file is not found or not readable. */ public static Configuration readConfigurationFile(Path file) throws IOException { return readConfigurationFile(CharStreams.fromPath(file)); @@ -265,6 +266,7 @@ public static Configuration readConfigurationFile(Path file) throws IOException /** * @see #readConfigurationFile(CharStream) + * @throws IOException if the file is not found or not readable. */ public static Configuration readConfigurationFile(File file) throws IOException { return readConfigurationFile(file.toPath()); diff --git a/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettings.java b/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettings.java index e1ba497b6f..d94916bee3 100644 --- a/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettings.java +++ b/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettings.java @@ -8,14 +8,11 @@ import java.io.FileWriter; import java.io.IOException; import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Properties; import java.util.stream.Stream; -import de.uka.ilkd.key.gui.settings.SettingsManager; import de.uka.ilkd.key.settings.AbstractPropertiesSettings; import de.uka.ilkd.key.settings.Configuration; import de.uka.ilkd.key.settings.PathConfig; @@ -33,21 +30,11 @@ * @version 1 (10.05.19) */ public class ColorSettings extends AbstractPropertiesSettings { - public static final String SETTINGS_FILENAME = "colors.properties"; - public static final File SETTINGS_FILE = - new File(PathConfig.getKeyConfigDir(), SETTINGS_FILENAME); - public static final File SETTINGS_FILE_NEW = new File(PathConfig.getKeyConfigDir(), "colors.json"); private static final Logger LOGGER = LoggerFactory.getLogger(ColorSettings.class); private static ColorSettings INSTANCE; - private ColorSettings(Properties settings) { - super(""); - readSettings(settings); - Runtime.getRuntime().addShutdownHook(new Thread(this::save)); - } - public ColorSettings(Configuration load) { super(""); readSettings(load); @@ -56,15 +43,17 @@ public ColorSettings(Configuration load) { public static ColorSettings getInstance() { if (INSTANCE == null) { - if (SETTINGS_FILE.exists()) { + if (SETTINGS_FILE_NEW.exists()) { try { - LOGGER.info("Use new configuration format at {}", SETTINGS_FILE_NEW); - return INSTANCE = new ColorSettings(Configuration.load(SETTINGS_FILE_NEW)); + LOGGER.info("Load color settings from file {}", SETTINGS_FILE_NEW); + INSTANCE = new ColorSettings(Configuration.load(SETTINGS_FILE_NEW)); + return INSTANCE; } catch (IOException e) { LOGGER.error("Could not read {}", SETTINGS_FILE_NEW, e); } } - return INSTANCE = new ColorSettings(SettingsManager.loadProperties(SETTINGS_FILE)); + INSTANCE = new ColorSettings(new Configuration()); + return INSTANCE; } return INSTANCE; } @@ -94,22 +83,10 @@ public static Color invert(Color c) { /** * Writes the current settings to default location. * - * @see #SETTINGS_FILE + * @see #SETTINGS_FILE_NEW */ public void save() { - LOGGER.info("Save color settings to: " + SETTINGS_FILE.getAbsolutePath()); - try (Writer writer = new FileWriter(SETTINGS_FILE, StandardCharsets.UTF_8)) { - Properties props = new Properties(); - for (Map.Entry entry : properties.entrySet()) { - props.setProperty(entry.getKey(), entry.getValue().toString()); - } - props.store(writer, "KeY's Colors"); - writer.flush(); - } catch (IOException ex) { - ex.printStackTrace(); - } - - LOGGER.info("Save color settings to: " + SETTINGS_FILE_NEW.getAbsolutePath()); + LOGGER.info("Save color settings to: {}", SETTINGS_FILE_NEW.getAbsolutePath()); try (Writer writer = new FileWriter(SETTINGS_FILE_NEW)) { var config = new Configuration(properties); config.save(writer, "KeY's Colors"); diff --git a/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettingsProvider.java b/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettingsProvider.java index e0818cbf7e..89293e55ca 100644 --- a/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettingsProvider.java +++ b/key.ui/src/main/java/de/uka/ilkd/key/gui/colors/ColorSettingsProvider.java @@ -32,7 +32,7 @@ public ColorSettingsProvider() { super(); setHeaderText(getDescription()); setSubHeaderText( - "Color settings are stored in: " + ColorSettings.SETTINGS_FILE.getAbsolutePath()); + "Color settings are stored in: " + ColorSettings.SETTINGS_FILE_NEW.getAbsolutePath()); add(new JScrollPane(tblColors)); }