This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return absolute path when checking system path; fixes #10
- Loading branch information
Showing
1 changed file
with
23 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,23 +128,41 @@ public void run() throws MojoExecutionException { | |
} | ||
|
||
private String findBinaryOnSystemPath() throws MojoExecutionException { | ||
Commandline commandline = new Commandline(PHANTOMJS); | ||
String systemPath = System.getenv("PATH"); | ||
String pathSeparator = System.getProperty("path.separator",":"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
String fileSeparator = System.getProperty("file.separator","/"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
String binary = null; | ||
for (String path : systemPath.split(pathSeparator)) { | ||
String absolutePath = path + fileSeparator + PHANTOMJS; | ||
if (FileUtils.fileExists(absolutePath)) { | ||
This comment has been minimized.
Sorry, something went wrong.
bentmann
Contributor
|
||
binary = absolutePath; | ||
String versionString = getVersion(binary); | ||
if (!enforceVersion || this.version.equals(versionString)) { | ||
getLog().info("Found phantomjs "+versionString+" at "+binary); | ||
return binary; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private String getVersion(String binary) throws MojoExecutionException { | ||
Commandline commandline = new Commandline(binary); | ||
commandline.createArg().setValue("-v"); | ||
try { | ||
Process process = new ProcessBuilder(commandline.getShellCommandline()).start(); | ||
BufferedReader standardOut = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
String versionString = StringUtils.trim(standardOut.readLine()); | ||
int exitCode = process.waitFor(); | ||
if (exitCode == 0 && (!enforceVersion || this.version.equals(versionString))) { | ||
getLog().info("Found phantomjs "+versionString+" on the system path."); | ||
return PHANTOMJS; | ||
if (exitCode != 0) { | ||
throw new MojoExecutionException("Failed to check system path"); | ||
} | ||
return versionString; | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Failed to check system path",e); | ||
} catch (InterruptedException e) { | ||
throw new MojoExecutionException("Failed to check system path", e); | ||
} | ||
return null; | ||
} | ||
|
||
private String installBinaryFromWeb() throws MojoExecutionException { | ||
|
You might find
File.pathSeparator
more convenient.