Skip to content

Commit e852f51

Browse files
committed
App: add getBaseDirectory() API
Now you can ask an app for its base directory, as well as the name of the system property which overrides that directory.
1 parent 479826b commit e852f51

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/org/scijava/app/AbstractApp.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131

3232
package org.scijava.app;
3333

34+
import java.io.File;
35+
3436
import org.scijava.plugin.AbstractRichPlugin;
37+
import org.scijava.util.AppUtils;
3538
import org.scijava.util.Manifest;
3639
import org.scijava.util.POM;
3740

@@ -95,4 +98,14 @@ public String getInfo(boolean mem) {
9598
return sb.toString();
9699
}
97100

101+
@Override
102+
public String getSystemProperty() {
103+
return getInfo().getName().toLowerCase() + ".dir";
104+
}
105+
106+
@Override
107+
public File getBaseDirectory() {
108+
return AppUtils.getBaseDirectory(getSystemProperty(), getClass(), null);
109+
}
110+
98111
}

src/main/java/org/scijava/app/App.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
package org.scijava.app;
3333

34+
import java.io.File;
35+
3436
import org.scijava.plugin.Plugin;
3537
import org.scijava.plugin.RichPlugin;
3638
import org.scijava.plugin.SingletonPlugin;
@@ -91,4 +93,17 @@ public interface App extends RichPlugin, SingletonPlugin {
9193
*/
9294
String getInfo(boolean mem);
9395

96+
/**
97+
* A system property which, if set, overrides the base directory of the
98+
* application.
99+
*/
100+
String getSystemProperty();
101+
102+
/**
103+
* Gets the application's root directory. If the application's system property
104+
* is set, it is used. Otherwise, we scan up the tree from this class for a
105+
* suitable directory.
106+
*/
107+
File getBaseDirectory();
108+
94109
}

0 commit comments

Comments
 (0)