Skip to content

Commit

Permalink
Merge pull request #19 from jenkinsci/fixUrlUriPathConversions
Browse files Browse the repository at this point in the history
Safely convert URI to File
  • Loading branch information
olivierdagenais committed Nov 21, 2013
2 parents f61f3fc + 8c0dca3 commit 84b4346
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/main/java/hudson/plugins/tfs/model/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,25 @@ static synchronized void ensureNativeLibrariesConfigured() {
final Class<TFSTeamProjectCollection> metaclass = TFSTeamProjectCollection.class;
final ProtectionDomain protectionDomain = metaclass.getProtectionDomain();
final CodeSource codeSource = protectionDomain.getCodeSource();
// TODO: codeSource could be null; what should we do, then?
if (codeSource == null) {
// TODO: log that we were unable to determine the codeSource
return;
}
final URL location = codeSource.getLocation();
URI locationUri = null;
try {
locationUri = location.toURI();
} catch (URISyntaxException e) {
// this shouldn't happen
// TODO: consider logging this situation if it ever happens
// inspired by http://hg.netbeans.org/main/file/default/openide.filesystems/src/org/openide/filesystems/FileUtil.java#l1992
final String u = location.toString();
URI locationUri;
if (u.startsWith("jar:file:") && u.endsWith("!/")) {
locationUri = URI.create(u.substring(4, u.length() - 2));
}
else if (u.startsWith("file:")) {
locationUri = URI.create(u);
}
else {
// TODO: log that we were unable to determine location from codeSource
return;
}
final String stringPathToJar = locationUri.getPath();
final File pathToJar = new File(stringPathToJar);
final File pathToJar = new File(locationUri);
final File pathToLibFolder = pathToJar.getParentFile();
final File pathToNativeFolder = new File(pathToLibFolder, "native");
System.setProperty(nativeFolderPropertyName, pathToNativeFolder.toString());
Expand Down

0 comments on commit 84b4346

Please sign in to comment.