Skip to content

Commit c64d37a

Browse files
committed
improved base folder detection if started through CLI
1 parent 1b38d0d commit c64d37a

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

jcp/src/main/java/com/igormaznitsa/jcp/JcpPreprocessor.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@
7777
* The main class implements the Java Comment Preprocessor, it has the main
7878
* method and can be started from a command string
7979
* Base directory for preprocessing can be provided through System property 'jcp.base.dir'
80+
* if it is not provided then current work directory will be recognized as base one.
8081
*/
8182
public final class JcpPreprocessor {
8283

84+
private static final String PROPERTY_JCP_BASE_DIR = "jcp.base.dir";
85+
8386
static final CommandLineHandler[] COMMAND_LINE_HANDLERS = new CommandLineHandler[] {
8487
new HelpHandler(),
8588
new InCharsetHandler(),
@@ -147,20 +150,11 @@ public static void main(final String... args) {
147150

148151

149152
private static File getBaseDir() {
150-
String baseDirInProperties = System.getProperty("jcp.base.dir");
151-
if (baseDirInProperties == null) {
152-
File result;
153-
try {
154-
final File jarFile = new File(
155-
JcpPreprocessor.class.getProtectionDomain().getCodeSource().getLocation().toURI());
156-
result = jarFile.isDirectory() ? jarFile : jarFile.getParentFile();
157-
} catch (Exception ex) {
158-
result = new File("");
159-
}
160-
return result;
161-
} else {
162-
return new File(baseDirInProperties);
163-
}
153+
final String baseDirInProperties = System
154+
.getProperty(PROPERTY_JCP_BASE_DIR,
155+
System.getProperty("user.dir", new File("").getAbsolutePath())
156+
);
157+
return new File(baseDirInProperties);
164158
}
165159

166160

0 commit comments

Comments
 (0)