Skip to content

Commit 086ee9b

Browse files
committed
Remove the UserDir discovery provider in favour of new AppDir provider
The intention for the user dir provider was always to return the same directory that the application was installed in - in almost all cases this would be expected to be the "current" directory as obtained from the user.dir system property. However, the current directory is not necessarily the same as the installation directory. So instead, remove that provider and replace it with one that uses class loader protection domain and code source to find the file location containing the vlcj class files and return this as the application directory.
1 parent 0e2b6fb commit 086ee9b

4 files changed

Lines changed: 65 additions & 49 deletions

File tree

src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@
7474

7575
// Standard implementations of native library discovery directory providers
7676
provides uk.co.caprica.vlcj.factory.discovery.provider.DiscoveryDirectoryProvider with
77+
uk.co.caprica.vlcj.factory.discovery.provider.AppDirDirectoryProvider,
7778
uk.co.caprica.vlcj.factory.discovery.provider.ConfigDirConfigFileDiscoveryDirectoryProvider,
7879
uk.co.caprica.vlcj.factory.discovery.provider.JnaLibraryPathDirectoryProvider,
7980
uk.co.caprica.vlcj.factory.discovery.provider.LinuxWellKnownDirectoryProvider,
8081
uk.co.caprica.vlcj.factory.discovery.provider.MacOsWellKnownDirectoryProvider,
8182
uk.co.caprica.vlcj.factory.discovery.provider.SystemPathDirectoryProvider,
8283
uk.co.caprica.vlcj.factory.discovery.provider.UserDirConfigFileDiscoveryDirectoryProvider,
83-
uk.co.caprica.vlcj.factory.discovery.provider.UserDirDirectoryProvider,
8484
uk.co.caprica.vlcj.factory.discovery.provider.WindowsInstallDirectoryProvider;
8585

8686
// Standard implementations of native library discovery strategy providers
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is part of VLCJ.
3+
*
4+
* VLCJ is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* VLCJ is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with VLCJ. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Copyright 2009-2025 Caprica Software Limited.
18+
*/
19+
20+
package uk.co.caprica.vlcj.factory.discovery.provider;
21+
22+
import java.io.File;
23+
import java.net.URL;
24+
import java.security.CodeSource;
25+
import java.security.ProtectionDomain;
26+
27+
/**
28+
* Implementation of a directory provider that returns the directory the application is installed in.
29+
*/
30+
public class AppDirDirectoryProvider implements DiscoveryDirectoryProvider {
31+
32+
@Override
33+
public int priority() {
34+
return DiscoveryProviderPriority.APP_DIR;
35+
}
36+
37+
@Override
38+
public String[] directories() {
39+
try {
40+
Class<?> clazz = DiscoveryDirectoryProvider.class;
41+
ProtectionDomain protectionDomain = clazz.getProtectionDomain();
42+
CodeSource codeSource = protectionDomain.getCodeSource();
43+
if (codeSource != null) {
44+
URL location = codeSource.getLocation();
45+
if (location != null) {
46+
File file = new File(location.toURI());
47+
if (!file.isDirectory()) {
48+
file = file.getParentFile();
49+
}
50+
return new String[] { file.getAbsolutePath() };
51+
}
52+
}
53+
return new String[0];
54+
} catch (Exception e) {
55+
return new String[0];
56+
}
57+
}
58+
59+
@Override
60+
public boolean supported() {
61+
return true;
62+
}
63+
}

src/main/java/uk/co/caprica/vlcj/factory/discovery/provider/DiscoveryProviderPriority.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface DiscoveryProviderPriority {
2828

2929
int JNA_LIBRARY_PATH = -1;
3030

31-
int USER_DIR = -2;
31+
int APP_DIR = -2;
3232

3333
int INSTALL_DIR = -3;
3434

src/main/java/uk/co/caprica/vlcj/factory/discovery/provider/UserDirDirectoryProvider.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)