Lines 43-51
Link Here
|
43 |
package org.netbeans.modules.maven.profiler; |
43 |
package org.netbeans.modules.maven.profiler; |
44 |
|
44 |
|
45 |
import java.io.File; |
45 |
import java.io.File; |
|
|
46 |
import java.util.ArrayList; |
47 |
import java.util.List; |
46 |
import java.util.Map; |
48 |
import java.util.Map; |
47 |
import java.util.Properties; |
49 |
import java.util.Properties; |
48 |
import java.util.WeakHashMap; |
50 |
import java.util.WeakHashMap; |
|
|
51 |
import java.util.logging.Level; |
52 |
import java.util.logging.Logger; |
49 |
import org.netbeans.api.project.Project; |
53 |
import org.netbeans.api.project.Project; |
50 |
import org.netbeans.lib.profiler.common.Profiler; |
54 |
import org.netbeans.lib.profiler.common.Profiler; |
51 |
import org.netbeans.lib.profiler.common.ProfilingSettings; |
55 |
import org.netbeans.lib.profiler.common.ProfilingSettings; |
Lines 55-60
Link Here
|
55 |
import org.netbeans.modules.maven.api.execute.RunConfig; |
59 |
import org.netbeans.modules.maven.api.execute.RunConfig; |
56 |
import org.netbeans.spi.project.ProjectServiceProvider; |
60 |
import org.netbeans.spi.project.ProjectServiceProvider; |
57 |
import org.openide.util.RequestProcessor; |
61 |
import org.openide.util.RequestProcessor; |
|
|
62 |
import org.openide.util.Utilities; |
58 |
|
63 |
|
59 |
/** |
64 |
/** |
60 |
* |
65 |
* |
Lines 67-72
Link Here
|
67 |
private static final String ACTION_PROFILE = "profile"; // NOI18N |
72 |
private static final String ACTION_PROFILE = "profile"; // NOI18N |
68 |
private static final String ACTION_PROFILE_SINGLE = "profile-single"; // NOI18N |
73 |
private static final String ACTION_PROFILE_SINGLE = "profile-single"; // NOI18N |
69 |
private static final String ACTION_PROFILE_TESTS = "profile-tests"; // NOI18N |
74 |
private static final String ACTION_PROFILE_TESTS = "profile-tests"; // NOI18N |
|
|
75 |
|
76 |
private static final Logger LOG = Logger.getLogger(RunCheckerImpl.class.getName()); |
70 |
|
77 |
|
71 |
// private static final String EXEC_ARGS = "exec.args"; // NOI18N |
78 |
// private static final String EXEC_ARGS = "exec.args"; // NOI18N |
72 |
private static final String PROFILER_ARGS = "${profiler.args}"; // NOI18N |
79 |
private static final String PROFILER_ARGS = "${profiler.args}"; // NOI18N |
Lines 106-121
Link Here
|
106 |
|
113 |
|
107 |
String value = configProperties.get(key); |
114 |
String value = configProperties.get(key); |
108 |
if (value.contains(PROFILER_ARGS)) { |
115 |
if (value.contains(PROFILER_ARGS)) { |
109 |
String agentArg = fixAgentArg(sessionProperties.getProperty("profiler.info.jvmargs.agent")); |
116 |
value = value.replace(PROFILER_ARGS, profilerArgs(sessionProperties, false)); |
110 |
value = value.replace(PROFILER_ARGS, sessionProperties.getProperty("profiler.info.jvmargs") // NOI18N |
|
|
111 |
+ " " + agentArg); // NOI18N |
112 |
config.setProperty(key, value.trim()); |
117 |
config.setProperty(key, value.trim()); |
113 |
} |
118 |
} |
114 |
if (value.contains(PROFILER_ARGS_PREFIXED)) { |
119 |
if (value.contains(PROFILER_ARGS_PREFIXED)) { |
115 |
String agentArg = fixAgentArg(sessionProperties.getProperty("profiler.info.jvmargs.agent")); |
120 |
value = value.replace(PROFILER_ARGS_PREFIXED, profilerArgs(sessionProperties, true)); |
116 |
value = value.replace(PROFILER_ARGS_PREFIXED, |
121 |
config.setProperty(key, value.trim()); |
117 |
(sessionProperties.getProperty("profiler.info.jvmargs") + " " + agentArg).trim().replaceAll("^|(?<= +)(?! )", "-J")); |
|
|
118 |
config.setProperty(key, value); |
119 |
} |
122 |
} |
120 |
if (value.contains(PROFILER_JAVA)) { |
123 |
if (value.contains(PROFILER_JAVA)) { |
121 |
String profilerJava = sessionProperties.getProperty("profiler.info.jvm"); // NOI18N |
124 |
String profilerJava = sessionProperties.getProperty("profiler.info.jvm"); // NOI18N |
Lines 129-135
Link Here
|
129 |
if (profilerJava != null) { |
132 |
if (profilerJava != null) { |
130 |
File binJava = new File(profilerJava); |
133 |
File binJava = new File(profilerJava); |
131 |
if (binJava.isFile() && binJava.getName().matches("java([.]exe)?") && binJava.getParentFile().getName().equals("bin")) { |
134 |
if (binJava.isFile() && binJava.getName().matches("java([.]exe)?") && binJava.getParentFile().getName().equals("bin")) { |
132 |
opt = "--jdkhome " + binJava.getParentFile().getParent(); |
135 |
String jdkhome = binJava.getParentFile().getParent(); |
|
|
136 |
opt = Utilities.escapeParameters(new String[] {"--jdkhome", jdkhome}); |
137 |
LOG.log(Level.FINE, "from {0} escaped {1}", new Object[] {jdkhome, opt}); |
133 |
} |
138 |
} |
134 |
} |
139 |
} |
135 |
value = value.replace(PROFILER_JDKHOME_OPT, opt); |
140 |
value = value.replace(PROFILER_JDKHOME_OPT, opt); |
Lines 155-169
Link Here
|
155 |
return true; |
160 |
return true; |
156 |
} |
161 |
} |
157 |
|
162 |
|
158 |
private String fixAgentArg(String agentArg) { |
163 |
private String profilerArgs(Properties sessionProperties, boolean prefixed) { |
159 |
// !!!!!!!!!!!!!!!!!!!!!!!! Never remove this replacement !!!!!!!!!!!!!!!!!!!!!!!!!! |
164 |
List<String> args = new ArrayList<String>(); |
160 |
// !! It is absolutely needed for correct profiling of maven projects on Windows !! |
165 |
String jvmargs = sessionProperties.getProperty("profiler.info.jvmargs"); |
161 |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
166 |
for (String arg : Utilities.parseParameters(jvmargs)) { |
162 |
agentArg = agentArg.replace("\\", "/"); // NOI18N |
167 |
args.add(prefixed ? "-J" + arg : arg); |
|
|
168 |
} |
169 |
String agentarg = sessionProperties.getProperty("profiler.info.jvmargs.agent"); |
170 |
if (Utilities.isWindows()) { |
171 |
agentarg = agentarg.replace('\\', '/'); // XXX is this still necessary given quoting? |
172 |
} |
173 |
args.add(prefixed ? "-J" + agentarg : agentarg); |
174 |
String escaped = Utilities.escapeParameters(args.toArray(new String[args.size()])); |
175 |
LOG.log(Level.FINE, "from {0} and {1} produced {2}", new Object[] {jvmargs, agentarg, escaped}); |
176 |
return escaped; |
177 |
} |
163 |
|
178 |
|
164 |
if (agentArg.indexOf(' ') != -1) { //NOI18N |
|
|
165 |
return "\"" + agentArg + "\""; // NOI18N |
166 |
} |
167 |
return agentArg; |
168 |
} |
169 |
} |
179 |
} |