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

When binary is found on system path, hardcoded "phantomjs" is returned, instead of the full path to the binary #10

Closed
sipersso opened this issue Jan 23, 2014 · 2 comments
Assignees
Milestone

Comments

@sipersso
Copy link

When checkSystemPath is set to true and phantomjs is found, the phantomjs-maven-plugin sets the phantomjs.binary to "phantomjs" and not the actual path where phantomjs is located. This causes a problem when used with the Jasmine-Maven-Plugin and PhantomJsDriver. When PhantomJsDriver tries to locate the phantom binaries it tries new File("phantomjs"), and thus looking in the current directory, which will fail.

The following code can be used to retrieve the correct location on OSX/Linux:

private String getAbsolutePhantomPath() throws MojoExecutionException{
  Commandline commandline = new Commandline("which");
  commandline.createArg().setValue(PHANTOMJS);
  try {
    String path = extractString(commandline);
    getLog().info("Phantomjs is installed in location"+path);
    return path;
  } catch (IOException e) {
    throw new MojoExecutionException("Failed to locate phantom",e);
  } catch (InterruptedException e) {
    throw new MojoExecutionException("Failed to locate phantom", e);
  }
}

private String extractString(Commandline commandline) throws IOException, InterruptedException{
  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){
    return null;
  }
  return versionString;
}

On windows, the "where" command could possibly be used instead of "which", but I haven't verified this.

@klieber
Copy link
Owner

klieber commented Jan 23, 2014

Good catch! Another way to tackle this would be to just implement it in java completely by just iterating through all the paths in the system PATH variable until we find one that has phantomjs binary in it. Not sure which way would be better. Definitely will get this fixed in the next release. Thanks.

@ghost ghost assigned klieber Jan 23, 2014
@sipersso
Copy link
Author

Great job! Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants