0

I've looked at both these posts.. they don't help:

If I run phploc at a shell prompt, it works just fine. So it must be something with my build.xml file... but I don't know what.

<target name="phploc" description="Measure project size using PHPLOC">
  <exec executable="phploc">
    <arg path="${basedir}/../src" />
    <arg value="--log-csv" />  
    <arg value="${basedir}/build/logs/phploc.csv" />    
  </exec>
</target>

This works fine:

C:\projects\project1\build>phploc ../src
phploc 2.0.6 by Sebastian Bergmann.

My folder structure is

c:\projects\project1

      build
          ...
          vendor
             bin
             ...
      src
      tests

c:\projects\project1\build>ant phploc:

BUILD FAILED
C:\projects\project1\build\build.xml:55: Execute failed: java.io.IOException:
 Cannot run program "phploc": CreateProcess error=2, The system cannot find the
file specified
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
        at java.lang.Runtime.exec(Runtime.java:620)
        at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav

UPDATE

C:\>where phploc
INFO: Could not find files for the given pattern(s).

What am I missing?

Community
  • 1
  • 1
Maxcot
  • 1,513
  • 3
  • 23
  • 51
  • On the command prompt, what do you get when you type: `where phploc`? Please paste the output. – Technext Aug 30 '14 at 09:53
  • Did you try the command? – Technext Aug 30 '14 at 11:22
  • Sorry, just busy with something else... Give me about an hour... – Maxcot Aug 30 '14 at 11:25
  • C:\>where phploc INFO: Could not find files for the given pattern(s). – Maxcot Aug 30 '14 at 11:47
  • Are you able to run phploc from this location itself i.e., C:\? I mean, if you provide the path to _src_ folder while staying at C:\, does it work? – Technext Aug 30 '14 at 11:50
  • Assuming that `phploc` works when you run the command in `C:\projects\project1\build` dir but is not working when you are at C:\, just check whether there is any executable `phploc` in `C:\projects\project1\build` path. – Technext Aug 30 '14 at 11:57
  • In my environment, I have in my path: `.\vendor\bin` So when I change to my build directory and run it at the command prompt, then I get a response C:\....>phploc and c:\......>phploc.bat – Maxcot Aug 30 '14 at 11:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60290/discussion-between-technext-and-maxcot). – Technext Aug 30 '14 at 11:58
  • It's a path problem in ANT's build.xml file. Specifically, putting the explicit path to the executable. Thanks to Techext for the help – Maxcot Aug 30 '14 at 12:27

1 Answers1

1

From chat discussion, it came out to be a PATH related issue. That's exactly what I was thinking it to be.

Setting absolute path of phploc in <exec executable="phploc"> did the trick. It was working on command line from C:\projects\project1\build directory because phploc was in one of its sub-directory (vendor\bin) and this sub-directory was already in the PATH variable.

PATH=C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Calibre2\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\;C:\Program Files (x86)\Java;c:\ant\bin;.\vendor\bin

Note: Although providing absolute path worked here but it's a good practice to use relative path so that your project is portable. In this case, you could use basedir as the reference point for all relative paths.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Technext
  • 7,887
  • 9
  • 48
  • 76