|
11 | 11 | import java.io.FileInputStream; |
12 | 12 | import java.io.IOException; |
13 | 13 | import java.io.InputStream; |
| 14 | +import java.net.URL; |
14 | 15 | import java.nio.file.Files; |
15 | 16 | import java.nio.file.Path; |
16 | 17 | import java.util.List; |
@@ -150,48 +151,20 @@ public static String readExternalClasspathRef(String file, RefFormat refFormat, |
150 | 151 | } |
151 | 152 |
|
152 | 153 | public static String buildUrl(String rootPath, String relativePath) { |
153 | | - String[] rootPathParts = rootPath.split("/"); |
154 | | - String [] relPathParts = relativePath.split("/"); |
155 | | - |
156 | | - if(rootPath == null || relativePath == null) { |
157 | | - return null; |
158 | | - } |
159 | | - |
160 | | - int trimRoot = 0; |
161 | | - int trimRel = 0; |
162 | | - |
163 | | - if(!"".equals(rootPathParts[rootPathParts.length - 1])) { |
164 | | - trimRoot = 1; |
165 | | - } |
166 | | - if("".equals(relPathParts[0])) { |
167 | | - trimRel = 1; trimRoot = rootPathParts.length-3; |
168 | | - } |
169 | | - for(int i = 0; i < rootPathParts.length; i++) { |
170 | | - if("".equals(rootPathParts[i])) { |
171 | | - trimRel += 1; |
172 | | - } |
173 | | - else { |
174 | | - break; |
175 | | - } |
176 | | - } |
177 | | - for(int i = 0; i < relPathParts.length; i ++) { |
178 | | - if(".".equals(relPathParts[i])) { |
179 | | - trimRel += 1; |
180 | | - } |
181 | | - else if ("..".equals(relPathParts[i])) { |
182 | | - trimRel += 1; trimRoot += 1; |
183 | | - } |
184 | | - } |
185 | | - |
186 | | - String [] outputParts = new String[rootPathParts.length + relPathParts.length - trimRoot - trimRel]; |
187 | | - System.arraycopy(rootPathParts, 0, outputParts, 0, rootPathParts.length - trimRoot); |
188 | | - System.arraycopy(relPathParts, |
189 | | - trimRel, |
190 | | - outputParts, |
191 | | - rootPathParts.length - trimRoot, |
192 | | - relPathParts.length - trimRel); |
193 | | - |
194 | | - return StringUtils.join(outputParts, "/"); |
| 154 | + if(rootPath == null || relativePath == null) { |
| 155 | + return null; |
| 156 | + } |
| 157 | + |
| 158 | + try { |
| 159 | + int until = rootPath.lastIndexOf("/")+1; |
| 160 | + String root = rootPath.substring(0, until); |
| 161 | + URL rootUrl = new URL(root); |
| 162 | + URL finalUrl = new URL(rootUrl, relativePath); |
| 163 | + return finalUrl.toString(); |
| 164 | + } |
| 165 | + catch(Exception e) { |
| 166 | + throw new RuntimeException(e); |
| 167 | + } |
195 | 168 | } |
196 | 169 |
|
197 | 170 | public static String readExternalRef(String file, RefFormat refFormat, List<AuthorizationValue> auths, |
|
0 commit comments