Skip to content

Commit

Permalink
fix error that key-settings folder are not created
Browse files Browse the repository at this point in the history
  • Loading branch information
wadoon committed Feb 19, 2025
1 parent 88ffb5f commit d1a22ba
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions key.core/src/main/java/de/uka/ilkd/key/settings/ProofSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* SPDX-License-Identifier: GPL-2.0-only */
package de.uka.ilkd.key.settings;

import de.uka.ilkd.key.util.KeYResourceManager;
import org.antlr.v4.runtime.CharStreams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.beans.PropertyChangeListener;
import java.io.*;
import java.net.URL;
Expand All @@ -11,12 +16,6 @@
import java.util.List;
import java.util.Properties;

import de.uka.ilkd.key.util.KeYResourceManager;

import org.antlr.v4.runtime.CharStreams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/// This class is used to load and save settings for proofs such as which data type models are used
/// to represent the java types.
/// Which heuristics have to be loaded and so on?
Expand All @@ -30,18 +29,15 @@
/// MaximumNumberOfHeuristcsApplications=400
/// number = "IntegerLDT.class"
/// boolean = "BooleanLDT.class"
/// ```
///```
///
/// @see Properties
/// @see Settings
public class ProofSettings {
private static final Logger LOGGER = LoggerFactory.getLogger(ProofSettings.class);

public static final File PROVER_CONFIG_FILE =
new File(PathConfig.getKeyConfigDir(), "proof-settings.props");

public static final File PROVER_CONFIG_FILE_NEW =
new File(PathConfig.getKeyConfigDir(), "proof-settings.json");
new File(PathConfig.getKeyConfigDir(), "proof-settings.json");

public static final URL PROVER_CONFIG_FILE_TEMPLATE = KeYResourceManager.getManager()
.getResourceFile(ProofSettings.class, "default-proof-settings.json");
Expand All @@ -68,7 +64,7 @@ private static ProofSettings loadedSettings() {
private final StrategySettings strategySettings = new StrategySettings();
private final ChoiceSettings choiceSettings = new ChoiceSettings();
private final ProofDependentSMTSettings smtSettings =
ProofDependentSMTSettings.getDefaultSettingsData();
ProofDependentSMTSettings.getDefaultSettingsData();
private final NewSMTTranslationSettings newSMTSettings = new NewSMTTranslationSettings();
private final TermLabelSettings termLabelSettings = new TermLabelSettings();

Expand Down Expand Up @@ -142,9 +138,11 @@ public void settingsToStream(Writer out) {
*/
public void saveSettings() {
try {
try (Writer out = new BufferedWriter(
new FileWriter(PROVER_CONFIG_FILE_NEW, StandardCharsets.UTF_8))) {
settingsToStream(out);
if (PROVER_CONFIG_FILE.getParentFile().mkdirs()) {
try (Writer out = new BufferedWriter(
new FileWriter(PROVER_CONFIG_FILE, StandardCharsets.UTF_8))) {
settingsToStream(out);
}
}
} catch (IOException e) {
LOGGER.warn("Could not save proof-settings.", e);
Expand All @@ -165,7 +163,7 @@ public void loadSettingsFromJSONStream(Reader in) throws IOException {
public void loadDefaultJSONSettings() {
if (PROVER_CONFIG_FILE_TEMPLATE == null) {
LOGGER.warn(
"default proof-settings file 'default-proof-settings.json' could not be found.");
"default proof-settings file 'default-proof-settings.json' could not be found.");
} else {
try (var in = new InputStreamReader(PROVER_CONFIG_FILE_TEMPLATE.openStream())) {
loadSettingsFromJSONStream(in);
Expand All @@ -182,7 +180,7 @@ public void loadSettings() {
if (Boolean.getBoolean(PathConfig.DISREGARD_SETTINGS_PROPERTY)) {
LOGGER.warn("The settings in {} are *not* read.", PROVER_CONFIG_FILE);
} else {
var fileToUse = PROVER_CONFIG_FILE_NEW;
var fileToUse = PROVER_CONFIG_FILE;
try (var in = new BufferedReader(new FileReader(fileToUse, StandardCharsets.UTF_8))) {
LOGGER.info("Load proof dependent settings from file {}", fileToUse);
loadDefaultJSONSettings();
Expand Down

0 comments on commit d1a22ba

Please sign in to comment.