|
12 | 12 | *******************************************************************************/ |
13 | 13 | package org.eclipse.tycho.model.project; |
14 | 14 |
|
| 15 | +import static org.eclipse.tycho.model.project.ProjectParser.resolveLinks; |
15 | 16 | import static org.junit.jupiter.api.Assertions.assertEquals; |
16 | 17 | import static org.junit.jupiter.api.Assertions.assertNull; |
17 | 18 |
|
18 | 19 | import java.net.URI; |
19 | 20 | import java.nio.file.Path; |
| 21 | +import java.util.List; |
20 | 22 | import java.util.Map; |
21 | 23 |
|
22 | 24 | import org.eclipse.tycho.model.project.ProjectParser.LinkDescription; |
@@ -46,109 +48,172 @@ public class ProjectParserTest { |
46 | 48 | @Test |
47 | 49 | void testLinkNoLocationOrUri() throws Exception { |
48 | 50 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, null); |
49 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 51 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
50 | 52 | assertNull(result); |
51 | 53 | } |
52 | 54 |
|
53 | 55 | @Test |
54 | 56 | void testLinkDirSimpleCase() throws Exception { |
55 | 57 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
56 | 58 | URI.create("foo/bar")); |
57 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 59 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
58 | 60 | assertEquals(Path.of("/path/to/project/foo/bar/subdir"), result); |
59 | 61 | } |
60 | 62 |
|
61 | 63 | @Test |
62 | 64 | void testLinkDirProjectLoc() throws Exception { |
63 | 65 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
64 | 66 | URI.create("PROJECT_LOC/bar")); |
65 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 67 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
66 | 68 | assertEquals(Path.of("/path/to/project/bar/subdir"), result); |
67 | 69 | } |
68 | 70 |
|
69 | 71 | @Test |
70 | 72 | void testLinkDirParent1ProjectLoc() throws Exception { |
71 | 73 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
72 | 74 | URI.create("PARENT-1-PROJECT_LOC/otherproject")); |
73 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 75 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
74 | 76 | assertEquals(Path.of("/path/to/otherproject/subdir"), result); |
75 | 77 | } |
76 | 78 |
|
77 | 79 | @Test |
78 | 80 | void testLinkDirParent2ProjectLoc() throws Exception { |
79 | 81 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
80 | 82 | URI.create("PARENT-2-PROJECT_LOC/anotherdir")); |
81 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 83 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
82 | 84 | assertEquals(Path.of("/path/anotherdir/subdir"), result); |
83 | 85 | } |
84 | 86 |
|
85 | 87 | @Test |
86 | 88 | void testLinkDirVarExpandEndingInProjectLoc() throws Exception { |
87 | 89 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, URI.create("FOO1/x")); |
88 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 90 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
89 | 91 | assertEquals(Path.of("/path/to/project/other/dir/bar/foo/x/subdir"), result); |
90 | 92 | } |
91 | 93 |
|
92 | 94 | @Test |
93 | 95 | void testLinkDirVarExpandEndingInParent1ProjectLoc() throws Exception { |
94 | 96 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, URI.create("FOO2/x")); |
95 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 97 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
96 | 98 | assertEquals(Path.of("/path/to/otherproject/dir/bar/foo/x/subdir"), result); |
97 | 99 | } |
98 | 100 |
|
99 | 101 | @Test |
100 | 102 | void testLinkDirRecursion() throws Exception { |
101 | 103 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
102 | 104 | URI.create("RECURSION1/x")); |
103 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 105 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
104 | 106 | assertNull(result); |
105 | 107 | } |
106 | 108 |
|
107 | 109 | @Test |
108 | 110 | void testLinkDirVarExpandLiteral() throws Exception { |
109 | 111 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
110 | 112 | URI.create("LITERAL/x")); |
111 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 113 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
112 | 114 | assertEquals(Path.of("/path/to/project/value/x/subdir"), result); |
113 | 115 | } |
114 | 116 |
|
115 | 117 | @Test |
116 | 118 | void testLinkDirVarExpandFailingKeepDollarVariable() throws Exception { |
117 | 119 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, null, |
118 | 120 | URI.create("UNKNOWN/x")); |
119 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 121 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
120 | 122 | assertEquals(Path.of("/path/to/project/${DONTKNOW}/foo/x/subdir"), result); |
121 | 123 | } |
122 | 124 |
|
123 | 125 | @Test |
124 | 126 | void testLinkDirAbsolutePathInsteadOfUri() throws Exception { |
125 | 127 | LinkDescription link = new LinkDescription(Path.of("link"), LinkDescription.FOLDER, Path.of("/absolute/path"), |
126 | 128 | null); |
127 | | - Path result = ProjectParser.resolvePath(link, Path.of("link/subdir"), PROJECT_PATH, VARS); |
| 129 | + Path result = resolveLinks(List.of(link), Path.of("link/subdir"), PROJECT_PATH, VARS); |
128 | 130 | assertEquals(Path.of("/absolute/path/subdir"), result); |
129 | 131 | } |
130 | 132 |
|
131 | 133 | @Test |
132 | 134 | void testLinkFileSimpleCase() throws Exception { |
133 | 135 | LinkDescription link = new LinkDescription(Path.of("link.txt"), LinkDescription.FILE, null, |
134 | 136 | URI.create("linktarget.txt")); |
135 | | - Path result = ProjectParser.resolvePath(link, Path.of("link.txt"), PROJECT_PATH, VARS); |
| 137 | + Path result = resolveLinks(List.of(link), Path.of("link.txt"), PROJECT_PATH, VARS); |
136 | 138 | assertEquals(Path.of("/path/to/project/linktarget.txt"), result); |
137 | 139 | } |
138 | 140 |
|
| 141 | + @Test |
| 142 | + void testLinkFileInDirSimpleCase() throws Exception { |
| 143 | + LinkDescription link = new LinkDescription(Path.of("folder/link.txt"), LinkDescription.FILE, null, |
| 144 | + URI.create("linktarget.txt")); |
| 145 | + Path result = resolveLinks(List.of(link), Path.of("folder/link.txt"), PROJECT_PATH, VARS); |
| 146 | + assertEquals(Path.of("/path/to/project/linktarget.txt"), result); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + void testLinkedFileInDirSimpleCase() throws Exception { |
| 151 | + LinkDescription link = new LinkDescription(Path.of("link.txt"), LinkDescription.FILE, null, |
| 152 | + URI.create("folder/linktarget.txt")); |
| 153 | + Path result = resolveLinks(List.of(link), Path.of("link.txt"), PROJECT_PATH, VARS); |
| 154 | + assertEquals(Path.of("/path/to/project/folder/linktarget.txt"), result); |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + void testLinkFileFromDirToDirSimpleCase() throws Exception { |
| 159 | + LinkDescription link = new LinkDescription(Path.of("folder/link.txt"), LinkDescription.FILE, null, |
| 160 | + URI.create("folder/linktarget.txt")); |
| 161 | + Path result = resolveLinks(List.of(link), Path.of("folder/link.txt"), PROJECT_PATH, VARS); |
| 162 | + assertEquals(Path.of("/path/to/project/folder/linktarget.txt"), result); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + void testLinkedFileInLinkedDir() throws Exception { |
| 167 | + LinkDescription fileLink = new LinkDescription(Path.of("folder/link.txt"), LinkDescription.FILE, null, |
| 168 | + URI.create("folder/linktarget.txt")); |
| 169 | + LinkDescription folderLink = new LinkDescription(Path.of("folder"), LinkDescription.FOLDER, null, |
| 170 | + URI.create("foldertarget")); |
| 171 | + |
| 172 | + List<LinkDescription> links = List.of(fileLink, folderLink); // expect file to be resolved |
| 173 | + assertEquals(Path.of("/path/to/project/folder/linktarget.txt"), |
| 174 | + resolveLinks(links, Path.of("folder/link.txt"), PROJECT_PATH, VARS)); |
| 175 | + links = List.of(folderLink, fileLink); // expect folder to be resolved |
| 176 | + assertEquals(Path.of("/path/to/project/foldertarget/link.txt"), |
| 177 | + resolveLinks(List.of(folderLink, fileLink), Path.of("folder/link.txt"), PROJECT_PATH, VARS)); |
| 178 | + } |
| 179 | + |
| 180 | + @Test |
| 181 | + void testLinkedNestedDirSimpleCase() throws Exception { |
| 182 | + LinkDescription link = new LinkDescription(Path.of("folder"), LinkDescription.FOLDER, null, |
| 183 | + URI.create("folder/foldertarget2")); |
| 184 | + Path result = resolveLinks(List.of(link), Path.of("folder/link.txt"), PROJECT_PATH, VARS); |
| 185 | + assertEquals(Path.of("/path/to/project/folder/foldertarget2/link.txt"), result); |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + void testLinkToNestedDirSimpleCase() throws Exception { |
| 190 | + LinkDescription link = new LinkDescription(Path.of("folder/folder2"), LinkDescription.FOLDER, null, |
| 191 | + URI.create("foldertarget")); |
| 192 | + Path result = resolveLinks(List.of(link), Path.of("folder/folder2/link.txt"), PROJECT_PATH, VARS); |
| 193 | + assertEquals(Path.of("/path/to/project/foldertarget/link.txt"), result); |
| 194 | + } |
| 195 | + |
| 196 | + @Test |
| 197 | + void testLinkDirFromDirToDirSimpleCase() throws Exception { |
| 198 | + LinkDescription link = new LinkDescription(Path.of("folder/folder2"), LinkDescription.FOLDER, null, |
| 199 | + URI.create("folder/foldertarget2")); |
| 200 | + Path result = resolveLinks(List.of(link), Path.of("folder/folder2/link.txt"), PROJECT_PATH, VARS); |
| 201 | + assertEquals(Path.of("/path/to/project/folder/foldertarget2/link.txt"), result); |
| 202 | + } |
| 203 | + |
139 | 204 | @Test |
140 | 205 | void testLinkFileAbsolutePathInsteadOfUri() throws Exception { |
141 | 206 | LinkDescription link = new LinkDescription(Path.of("link.txt"), LinkDescription.FILE, |
142 | 207 | Path.of("/path/to/some/txtfile.txt"), null); |
143 | | - Path result = ProjectParser.resolvePath(link, Path.of("link.txt"), PROJECT_PATH, VARS); |
| 208 | + Path result = resolveLinks(List.of(link), Path.of("link.txt"), PROJECT_PATH, VARS); |
144 | 209 | assertEquals(Path.of("/path/to/some/txtfile.txt"), result); |
145 | 210 | } |
146 | 211 |
|
147 | 212 | @Test |
148 | 213 | void testLinkFileIllegalSegmentAfterFile() throws Exception { |
149 | 214 | LinkDescription link = new LinkDescription(Path.of("link.txt"), LinkDescription.FILE, |
150 | 215 | Path.of("/path/to/some/txtfile.txt"), null); |
151 | | - Path result = ProjectParser.resolvePath(link, Path.of("link.txt/thisisinvalid"), PROJECT_PATH, VARS); |
| 216 | + Path result = resolveLinks(List.of(link), Path.of("link.txt/thisisinvalid"), PROJECT_PATH, VARS); |
152 | 217 | assertNull(result); |
153 | 218 | } |
154 | 219 |
|
|
0 commit comments