Skip to content

Commit 009b362

Browse files
committed
fix Windows relative root problem
1 parent 57fe493 commit 009b362

2 files changed

Lines changed: 27 additions & 33 deletions

File tree

key.core/src/main/java/de/uka/ilkd/key/proof/io/OutputStreamProofSaver.java

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import de.uka.ilkd.key.pp.LogicPrinter;
1919
import de.uka.ilkd.key.pp.NotationInfo;
2020
import de.uka.ilkd.key.pp.PrettyPrinter;
21+
import de.uka.ilkd.key.proof.JavaModel;
2122
import de.uka.ilkd.key.proof.NameRecorder;
2223
import de.uka.ilkd.key.proof.Node;
2324
import de.uka.ilkd.key.proof.Proof;
@@ -40,8 +41,8 @@
4041
import de.uka.ilkd.key.smt.SMTRuleApp;
4142
import de.uka.ilkd.key.strategy.StrategyProperties;
4243
import de.uka.ilkd.key.util.KeYConstants;
43-
import de.uka.ilkd.key.util.MiscTools;
4444

45+
import org.jspecify.annotations.NonNull;
4546
import org.key_project.logic.Name;
4647
import org.key_project.logic.PosInTerm;
4748
import org.key_project.logic.op.Modality;
@@ -56,7 +57,7 @@
5657
import org.key_project.prover.sequent.Sequent;
5758
import org.key_project.prover.sequent.SequentFormula;
5859
import org.key_project.util.collection.ImmutableList;
59-
import org.key_project.util.java.IOUtil;
60+
import org.key_project.util.collection.ImmutableMapEntry;
6061

6162
import org.jspecify.annotations.Nullable;
6263
import org.slf4j.Logger;
@@ -144,7 +145,7 @@ public String writeSettings(ProofSettings ps) {
144145

145146
public void save(Path basePath, OutputStream out) throws IOException {
146147
CopyReferenceResolver.copyCachedGoals(proof, null, null, null);
147-
try (var ps = new PrintWriter(out, true, StandardCharsets.UTF_8)) {
148+
try (PrintWriter ps = new PrintWriter(out, true, StandardCharsets.UTF_8)) {
148149
final ProofOblInput po =
149150
proof.getServices().getSpecificationRepository().getProofOblInput(proof);
150151
LogicPrinter printer = createLogicPrinter(proof.getServices(), false);
@@ -167,14 +168,14 @@ public void save(Path basePath, OutputStream out) throws IOException {
167168
ps.println(writeSettings(proof.getSettings()));
168169

169170

170-
var header = proof.header();
171+
KeyAst.Declarations header = proof.header();
171172
String headerStr = makePathsRelative(basePath, header);
172173
ps.print(headerStr);
173174

174175
proof.printSymbols(ps);
175176

176177
// \problem or \proofObligation
177-
var hasProofObligation =
178+
boolean hasProofObligation =
178179
po instanceof IPersistablePO ppo && ppo.printProofObligation(ps, proof);
179180

180181

@@ -218,10 +219,9 @@ public void save(Path basePath, OutputStream out) throws IOException {
218219
/// Better would be to get rid of the header, and using an AST.
219220
///
220221
///
221-
/// @see KeYUserProblemFile#getProblemHeader()
222+
/// @see de.uka.ilkd.key.proof.init.KeYUserProblemFile#getProblemHeader()
222223
/// @see de.uka.ilkd.key.proof.init.InitConfig#getProblemHeader()
223-
private String makePathsRelative(Path basePath, KeyAst.@Nullable Declarations header)
224-
throws IOException {
224+
private String makePathsRelative(Path basePath, KeyAst.@Nullable Declarations header) {
225225
if (header == null) {
226226
return "";
227227
}
@@ -230,28 +230,28 @@ private String makePathsRelative(Path basePath, KeyAst.@Nullable Declarations he
230230

231231
header.printDefinitions(out);
232232

233-
var jm = proof.getServices().getJavaModel();
233+
JavaModel jm = proof.getServices().getJavaModel();
234234

235-
var bootClassPath = jm.getBootClassPath();
235+
Path bootClassPath = jm.getBootClassPath();
236236
if (bootClassPath != null) {
237-
out.printf("\\bootclasspath \"%s\";\n", IOUtil.safePath(bootClassPath));
237+
out.printf("\\bootclasspath \"%s\";\n", safePathRelativeTo(bootClassPath, basePath));
238238
}
239239

240-
var classPath = jm.getClassPath();
240+
List<Path> classPath = jm.getClassPath();
241241
if (classPath != null && !classPath.isEmpty()) {
242242
for (Path path : classPath) {
243243
out.printf("\\classpath \"%s\";\n", safePathRelativeTo(path, basePath));
244244
}
245245
}
246246

247-
var javaSource = jm.getModelDir();
247+
Path javaSource = jm.getModelDir();
248248
if (javaSource != null) {
249249
out.printf("\\javaSource \"%s\";\n", safePathRelativeTo(javaSource, basePath));
250250
}
251251

252-
var includedFiles = jm.getIncludedFiles();
252+
List<Path> includedFiles = jm.getIncludedFiles();
253253
if (includedFiles != null && !includedFiles.isEmpty()) {
254-
for (var includedFile : includedFiles) {
254+
for (Path includedFile : includedFiles) {
255255
out.printf("\\include \"%s\";\n",
256256
safePathRelativeTo(includedFile, basePath));
257257
}
@@ -260,18 +260,6 @@ private String makePathsRelative(Path basePath, KeyAst.@Nullable Declarations he
260260
return sw.toString();
261261
}
262262

263-
/**
264-
* Try to create a relative path, but return the absolute path if a relative path cannot be
265-
* found. This may happen on Windows systems (bug #1480).
266-
*/
267-
private static String tryToMakeFilenameRelative(String absPath, String basePath) {
268-
try {
269-
return MiscTools.makeFilenameRelative(absPath, basePath);
270-
} catch (final RuntimeException e) {
271-
return absPath;
272-
}
273-
}
274-
275263
private String newNames2Proof(Node n) {
276264
StringBuilder s = new StringBuilder();
277265
final NameRecorder rec = n.getNameRecorder();
@@ -369,9 +357,9 @@ private void printLatticeAbstractionForSingleMergeRuleApp(
369357
output.append(" (").append(ProofElementID.MERGE_USER_CHOICES.getRawName())
370358
.append(" \"");
371359
boolean first = true;
372-
for (var pair : userChoices.entrySet()) {
373-
final var key = pair.getKey();
374-
final var value = pair.getValue();
360+
for (Map.Entry<ProgramVariable, AbstractDomainElement> pair : userChoices.entrySet()) {
361+
final ProgramVariable key = pair.getKey();
362+
final AbstractDomainElement value = pair.getValue();
375363
if (first) {
376364
first = false;
377365
} else {
@@ -690,7 +678,7 @@ public static String posInTerm2Proof(PosInTerm pos) {
690678
public Collection<String> getInterestingInstantiations(SVInstantiations inst) {
691679
Collection<String> s = new ArrayList<>();
692680

693-
for (final var pair : inst.interesting()) {
681+
for (final ImmutableMapEntry<@NonNull SchemaVariable, @NonNull InstantiationEntry<?>> pair : inst.interesting()) {
694682
final SchemaVariable var = pair.key();
695683

696684
final Object value = pair.value().getInstantiation();

key.util/src/main/java/org/key_project/util/java/IOUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,13 @@ public static String safePath(Path path) {
831831
/// @param basePath a directory
832832
/// @return a string that is printable (escaped) for KeY files
833833
public static String safePathRelativeTo(Path source, Path basePath) {
834-
var abs = source.toAbsolutePath();
835-
return safePath(basePath.relativize(abs));
834+
if (Objects.equals(source.getRoot(), basePath.getRoot())) {
835+
// required on Windows
836+
var abs = source.toAbsolutePath();
837+
return safePath(basePath.relativize(abs));
838+
} else {
839+
// fallback: return absolute path
840+
return safePath(source.toAbsolutePath());
841+
}
836842
}
837843
}

0 commit comments

Comments
 (0)