See bug #199922 comment #13.
Imho this is at least P2 because on windows(majority of NB users) where almost any path has spaces in it the maven profiling is thus completely broken.
By carefully parsing, processing, and re-escaping everything the run hook gets, I can produce what seems like the right command sent to Maven:
cd C:\Documents and Settings\Jesse Glick\Local Settings\Temp\mavenproject10\application; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.7.0_01" "\"F:\\tmp\\netbeans with spaces\\java\\maven\\bin\\mvn.bat\"" "-Dnetbeans.run.params.ide=-J-XX:+HeapDumpOnOutOfMemoryError \\\"-J-XX:HeapDumpPath=C:\\\\Documents and Settings\\\\Jesse Glick\\\\.netbeans\\\\dev\\\\var\\\\cache\\\\mavencachedirs\\\\1618297522\\\\org-netbeans-modules-profiler\\\" \\\"-J-agentpath:F:/tmp/netbeans with spaces/profiler/lib/deployed/jdk16/windows/profilerinterface.dll=F:/tmp/netbeans with spaces/profiler/lib,5140,10\\\" --jdkhome \\\"C:\\\\Program Files\\\\Java\\\\jdk1.7.0_01\\\"" -Dprofiler.action=profile --debug install nbm:run-platform
but this gets mangled by the time Maven core sees it:
netbeans.run.params.ide=-J-XX:+HeapDumpOnOutOfMemoryError "-J-XX:HeapDumpPath=C:\\Documents and Settings\\Jesse Glick\\.netbeans\\dev\\var\\cache\\mavencachedirs\\1618297522\\org-netbeans-modules-profiler" "-J-agentpath:F:/tmp/netbeans with spaces/profiler/lib/deployed/jdk16/windows/profilerinterface.dll=F:/tmp/netbeans with spaces/profiler/lib,5140,10" --jdkhome "C:\\Program Files\\Java\\jdk1.7.0_01
Note the missing final quote, so:
Failed to execute goal org.codehaus.mojo:nbm-maven-plugin:3.6:run-platform (default-cli) on project mavenproject10-app: Failed executing NetBeans: unbalanced quotes in -J-XX:+HeapDumpOnOutOfMemoryError "-J-XX:HeapDumpPath=C:\\Documents and Settings\\Jesse Glick\\.netbeans\\dev\\var\\cache\\mavencachedirs\\1618297522\\org-netbeans-modules-profiler" "-J-agentpath:F:/tmp/netbeans with spaces/profiler/lib/deployed/jdk16/windows/profilerinterface.dll=F:/tmp/netbeans with spaces/profiler/lib,5140,10" --jdkhome "C:\\Program Files\\Java\\jdk1.7.0_01 -> [Help 1]
I have no explanation for this other than a possible bug in mvn.bat, or maybe it is just not possible to get quoting right on Windows.
Created attachment 113784 [details]
Patch for testing
I committed what I have so far, but have no further ideas for a Windows fix; perhaps someone with Windows batch script expertise would know what is going on. Workaround is, as always, to avoid paths with spaces in them.
Integrated into 'main-golden'
User: Jesse Glick <email@example.com>
Log: #201132: spaces in paths break Maven NBM profiling.
Current attempt at a fix, which seems beneficial on Unix and does not make the
situation on Windows any better; there seems to be some bug either in mvn.bat or
in the Windows batch script system which causes quoting of the JDK path to fail.
Not a patch candidate since there is no known fix. (Miloš any clue?)
what about working on the nbm:run-platform goal. maybe different format of parameters, special goal for profiler and/or running via commons-exec rather than maven's own plexus-utils..
But I do not see anything wrong with the command the plugin has prepared; the problem appears to be happening in the Maven launcher.
(In reply to comment #8)
> But I do not see anything wrong with the command the plugin has prepared; the
> problem appears to be happening in the Maven launcher.
Yes and by simplifying what gets passed to the maven launcher we could avoid translation problems. Eg. if we pass just -Dnetbeans.profiler.agentPath=<path with spaces>
Hardcoding this kind of information in the nbm:run-platform goal seems wrong. Better IMHO to figure out why what we have now does not work and see if there is a straightforward fix.
*** Bug 208780 has been marked as a duplicate of this bug. ***
Certainly not a P1. There is a simple workaround: use reasonable path names, without spaces in them.
a special agent path parameter would only only be useful for profiling, but also agents like jrebel or javeleon, right?
in general I think avoiding the parameter in parameter wrapping helps also the user experience, can be better documented and so on.
the final quote is NOT missing when I add "aaa" to the property in the Actions/profile project mapping.
Interestingly the various quoting is done at multiple places.
1. RunCheckerImpl.profilerArgs performs Utilities.escapeParameters()
2. MavenCommandLineExecutor.createMavenExecutionCommand() performs String.replace("\"", "\\\"")
3. java's ProcessImpl() will check if the entry with spaces starts with " and when not, wrap the entry in "" quotes.
my head still hurts from even thinking about it, but I believe the 3. wrapping (which is happening for the troubled parameter) causes problems as the eventual existing "" characters are not escaped while wrapping into a new set..
(In reply to comment #13)
> a special agent path parameter would only only be useful for profiling, but
> also agents like jrebel or javeleon, right?
Yes, at least Javeleon for 7.2 uses issue #206196 to add agent args; I suppose that might suffer from this bug as well.
(In reply to comment #14)
> 2. MavenCommandLineExecutor.createMavenExecutionCommand() performs
> String.replace("\"", "\\\"")
This seems suspicious. The args are being passed to ProcessBuilder as a List<String> so quoting their contents should be redundant. At least that should be true on Unix AFAIK.
(In reply to comment #15)
> (In reply to comment #14)
> > 2. MavenCommandLineExecutor.createMavenExecutionCommand() performs
> > String.replace("\"", "\\\"")
> This seems suspicious. The args are being passed to ProcessBuilder as a
> List<String> so quoting their contents should be redundant. At least that
> should be true on Unix AFAIK.
yes, but it's parameter for mvn execution that contains parameters to the jvm executed by a goal, and some of these contains spaces in their values. Without the escaping, the processbuilder would still add quotes at start and end, but the unescaped quotes would interfere then and chop the parameter in parts. Somehow it's happening anyway in the setup we have, but in my experiment with appending aaa et the end of the run.args property it was not happening.
a few random searches on stackoverflow suggest that "" means an escape for "
that would explain the breaking after the --jdkhome \\\"C:\\\\Program
Files\\\\Java\\\\jdk1.7.0_01\\\"" in your example, as that's the only place with 2 quotes. why my experiment with appending aaa works also supports this claim as then there are no "" in place.
Created attachment 116264 [details]
A new exploratory patch
Interesting lead, but I did not manage to get any variant of this to work.
Created attachment 116380 [details]
patch exploring the double quote edge case
attached patch seems to handle the case described in the issue, I'm able to profile an nbm application afterwards. I'm (still, not sure it it was the case before though) having problems now profiling simple j2se apps now.
applied my latest patch which was tested by jbachorik and appears to be working..
Integrated into 'main-golden', will be available in build *201205010400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: Milos Kleint <firstname.lastname@example.org>
Log: #201132 on windows append a space after trailing doublequotes..see issue for more details
*** Bug 212434 has been marked as a duplicate of this bug. ***