Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Commit

Permalink
return absolute path when checking system path; fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
klieber committed Jan 24, 2014
1 parent fca4513 commit c9c1bdc
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@bentmann

bentmann Jan 26, 2014

Contributor

You might find File.pathSeparator more convenient.

String fileSeparator = System.getProperty("file.separator","/");

This comment has been minimized.

Copy link
@bentmann

bentmann Jan 26, 2014

Contributor

Likewise, there's File.separator.

String binary = null;
for (String path : systemPath.split(pathSeparator)) {
String absolutePath = path + fileSeparator + PHANTOMJS;
if (FileUtils.fileExists(absolutePath)) {

This comment has been minimized.

Copy link
@bentmann

bentmann Jan 26, 2014

Contributor

On Windows, one is able to execute a command line with phantomjs but you're unlikey to find a file named like that. When searching the filesystem yourself, you likely want to search for phantomjs.exe on Windows.

This comment has been minimized.

Copy link
@klieber

klieber Jan 27, 2014

Author Owner

Yep, good point. That's what I get for not having a windows system to test this on. I'll open an issue and get it fixed before the next release. Thanks!

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 {
Expand Down

0 comments on commit c9c1bdc

Please sign in to comment.