14
14
package org .eclipse .esmf .aspectmodel .resolver .fs ;
15
15
16
16
import java .io .File ;
17
+ import java .io .IOException ;
17
18
import java .net .URI ;
18
19
import java .nio .file .Path ;
19
20
import java .nio .file .Paths ;
21
+ import java .util .Objects ;
20
22
import java .util .stream .Stream ;
21
23
22
24
import org .eclipse .esmf .aspectmodel .urn .AspectModelUrn ;
23
25
26
+ import org .slf4j .Logger ;
27
+ import org .slf4j .LoggerFactory ;
28
+
29
+
24
30
public abstract class ModelsRoot {
31
+
32
+ private static final Logger LOG = LoggerFactory .getLogger ( ModelsRoot .class );
33
+ private static final File EMPTY_FILE = new File ( "" );
25
34
private final Path root ;
26
35
27
36
protected ModelsRoot ( final Path root ) {
@@ -43,6 +52,19 @@ public Stream<Path> paths() {
43
52
public abstract Path directoryForNamespace ( final AspectModelUrn urn );
44
53
45
54
public File determineAspectModelFile ( final AspectModelUrn urn ) {
46
- return directoryForNamespace ( urn ).resolve ( urn .getName () + ".ttl" ).toFile ();
55
+ Path path = directoryForNamespace ( urn ).resolve ( urn .getName () + ".ttl" );
56
+ return resolveByCanonicalPath ( path );
57
+ }
58
+
59
+ private static File resolveByCanonicalPath ( Path path ) {
60
+ File file = path .toFile ();
61
+ try {
62
+ if ( Objects .equals ( path .toString (), file .getCanonicalPath () ) ) {
63
+ return file ;
64
+ }
65
+ } catch ( IOException exception ) {
66
+ LOG .error ( "Error resolving canonical path for file: {}" , file .getPath (), exception );
67
+ }
68
+ return EMPTY_FILE ;
47
69
}
48
70
}
0 commit comments