|
Lines 37-42
Link Here
|
| 37 |
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerInfoConsoleParserFactory; |
37 |
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerInfoConsoleParserFactory; |
| 38 |
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; |
38 |
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; |
| 39 |
import org.eclipse.cdt.utils.EFSExtensionManager; |
39 |
import org.eclipse.cdt.utils.EFSExtensionManager; |
|
|
40 |
import org.eclipse.cdt.utils.PathUtil; |
| 40 |
import org.eclipse.core.resources.IProject; |
41 |
import org.eclipse.core.resources.IProject; |
| 41 |
import org.eclipse.core.resources.IResource; |
42 |
import org.eclipse.core.resources.IResource; |
| 42 |
import org.eclipse.core.runtime.IPath; |
43 |
import org.eclipse.core.runtime.IPath; |
|
Lines 44-49
Link Here
|
| 44 |
import org.eclipse.core.runtime.NullProgressMonitor; |
45 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 45 |
import org.eclipse.core.runtime.Path; |
46 |
import org.eclipse.core.runtime.Path; |
| 46 |
import org.eclipse.core.runtime.SubProgressMonitor; |
47 |
import org.eclipse.core.runtime.SubProgressMonitor; |
|
|
48 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
| 49 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
| 50 |
import org.osgi.service.prefs.BackingStoreException; |
| 47 |
|
51 |
|
| 48 |
/** |
52 |
/** |
| 49 |
* New default external scanner info provider of type 'run' |
53 |
* New default external scanner info provider of type 'run' |
|
Lines 51-59
Link Here
|
| 51 |
* @author vhirsl |
55 |
* @author vhirsl |
| 52 |
*/ |
56 |
*/ |
| 53 |
public class DefaultRunSIProvider implements IExternalScannerInfoProvider { |
57 |
public class DefaultRunSIProvider implements IExternalScannerInfoProvider { |
|
|
58 |
/** console id which should match the definition in extension point */ |
| 59 |
public static final String EXTERNAL_SI_PROVIDER_CONSOLE_ID = "org.eclipse.cdt.make.core.ExternalScannerInfoProviderConsole"; //$NON-NLS-1$ |
| 60 |
private static final String PREF_CONSOLE_ENABLED = "org.eclipse.cdt.make.core.scanner.discovery.console.enabled"; //$NON-NLS-1$ |
| 54 |
private static final String EXTERNAL_SI_PROVIDER_ERROR = "ExternalScannerInfoProvider.Provider_Error"; //$NON-NLS-1$ |
61 |
private static final String EXTERNAL_SI_PROVIDER_ERROR = "ExternalScannerInfoProvider.Provider_Error"; //$NON-NLS-1$ |
| 55 |
private static final String EXTERNAL_SI_PROVIDER_CONSOLE_ID = MakeCorePlugin.getUniqueIdentifier() + ".ExternalScannerInfoProviderConsole"; //$NON-NLS-1$ |
|
|
| 56 |
private static final String LANG_ENV_VAR = "LANG"; //$NON-NLS-1$ |
62 |
private static final String LANG_ENV_VAR = "LANG"; //$NON-NLS-1$ |
|
|
63 |
private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 64 |
private static final String PATH_ENV = "PATH"; //$NON-NLS-1$ |
| 57 |
|
65 |
|
| 58 |
protected IResource resource; |
66 |
protected IResource resource; |
| 59 |
protected String providerId; |
67 |
protected String providerId; |
|
Lines 96-102
Link Here
|
| 96 |
monitor.beginTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs"), 100); //$NON-NLS-1$ |
104 |
monitor.beginTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs"), 100); //$NON-NLS-1$ |
| 97 |
|
105 |
|
| 98 |
try { |
106 |
try { |
| 99 |
IConsole console = CCorePlugin.getDefault().getConsole(EXTERNAL_SI_PROVIDER_CONSOLE_ID); |
107 |
String consoleId = EXTERNAL_SI_PROVIDER_CONSOLE_ID; |
|
|
108 |
if (!isConsoleEnabled()) |
| 109 |
consoleId = EXTERNAL_SI_PROVIDER_CONSOLE_ID+".disabled"; // do not show in Console view //$NON-NLS-1$ |
| 110 |
|
| 111 |
IConsole console = CCorePlugin.getDefault().getConsole(consoleId); |
| 100 |
console.start(currentProject); |
112 |
console.start(currentProject); |
| 101 |
OutputStream cos = console.getOutputStream(); |
113 |
OutputStream cos = console.getOutputStream(); |
| 102 |
|
114 |
|
|
Lines 138-150
Link Here
|
| 138 |
errMsg = launcher.getErrorMessage(); |
150 |
errMsg = launcher.getErrorMessage(); |
| 139 |
} |
151 |
} |
| 140 |
|
152 |
|
| 141 |
if (errMsg != null) { |
153 |
if (errMsg != null) { |
| 142 |
String errorDesc = MakeMessages.getFormattedString(EXTERNAL_SI_PROVIDER_ERROR, |
154 |
String buildCommandStr = fCompileCommand.toString(); |
| 143 |
fCompileCommand.toString() + ca); |
155 |
String errorDesc = MakeMessages.getFormattedString(EXTERNAL_SI_PROVIDER_ERROR, |
| 144 |
markerGenerator.addMarker(currentProject, -1, errorDesc, IMarkerGenerator.SEVERITY_WARNING, null); |
156 |
buildCommandStr + ca); |
| 145 |
} |
157 |
consoleOut.write((errorDesc + NEWLINE).getBytes()); |
|
|
158 |
consoleOut.flush(); |
| 159 |
|
| 160 |
// Launching failed, trying to figure out possible cause |
| 161 |
String errorPrefix = MakeMessages.getString("ExternalScannerInfoProvider.Error_Prefix"); //$NON-NLS-1$ |
| 162 |
Properties envMap = getEnvMap(launcher, env); |
| 163 |
String envPath = envMap.getProperty(PATH_ENV); |
| 164 |
if (envPath == null) { |
| 165 |
envPath = System.getenv(PATH_ENV); |
| 166 |
} |
| 167 |
StringBuffer buf = new StringBuffer(); |
| 168 |
if (PathUtil.findProgramLocation(buildCommandStr, envPath) == null) { |
| 169 |
buf.append(errMsg).append(NEWLINE); |
| 170 |
errMsg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Program_Not_In_Path", buildCommandStr); //$NON-NLS-1$ |
| 171 |
buf.append(errorPrefix).append(errMsg).append(NEWLINE); |
| 172 |
buf.append(NEWLINE); |
| 173 |
buf.append(PATH_ENV + "=[" + envPath + "]").append(NEWLINE); //$NON-NLS-1$//$NON-NLS-2$ |
| 174 |
} else { |
| 175 |
buf.append(errorPrefix).append(errMsg).append(NEWLINE); |
| 176 |
} |
| 177 |
consoleErr.write(buf.toString().getBytes()); |
| 178 |
consoleErr.flush(); |
| 179 |
|
| 180 |
if (!isConsoleEnabled()) { |
| 181 |
monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Creating_Markers")); //$NON-NLS-1$ |
| 182 |
markerGenerator.addMarker(currentProject, -1, errorDesc, IMarkerGenerator.SEVERITY_WARNING, null); |
| 183 |
} |
| 184 |
} |
| 146 |
|
185 |
|
| 147 |
monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Creating_Markers")); //$NON-NLS-1$ |
|
|
| 148 |
consoleOut.close(); |
186 |
consoleOut.close(); |
| 149 |
consoleErr.close(); |
187 |
consoleErr.close(); |
| 150 |
cos.close(); |
188 |
cos.close(); |
|
Lines 212-219
Link Here
|
| 212 |
return ca; |
250 |
return ca; |
| 213 |
} |
251 |
} |
| 214 |
|
252 |
|
| 215 |
protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) { |
253 |
private Properties getEnvMap(ICommandLauncher launcher, Properties initialEnv) { |
| 216 |
// Set the environmennt, some scripts may need the CWD var to be set. |
254 |
// Set the environmennt, some scripts may need the CWD var to be set. |
| 217 |
Properties props = initialEnv != null ? initialEnv : launcher.getEnvironment(); |
255 |
Properties props = initialEnv != null ? initialEnv : launcher.getEnvironment(); |
| 218 |
|
256 |
|
| 219 |
if (fWorkingDirectory != null) { |
257 |
if (fWorkingDirectory != null) { |
|
Lines 229-234
Link Here
|
| 229 |
if (props.containsKey(LANG_ENV_VAR)) { |
267 |
if (props.containsKey(LANG_ENV_VAR)) { |
| 230 |
props.put(LANG_ENV_VAR, "en_US.UTF-8"); //$NON-NLS-1$ |
268 |
props.put(LANG_ENV_VAR, "en_US.UTF-8"); //$NON-NLS-1$ |
| 231 |
} |
269 |
} |
|
|
270 |
return props; |
| 271 |
} |
| 272 |
|
| 273 |
protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) { |
| 274 |
Properties props = getEnvMap(launcher, initialEnv); |
| 232 |
String[] env = null; |
275 |
String[] env = null; |
| 233 |
ArrayList<String> envList = new ArrayList<String>(); |
276 |
ArrayList<String> envList = new ArrayList<String>(); |
| 234 |
Enumeration<?> names = props.propertyNames(); |
277 |
Enumeration<?> names = props.propertyNames(); |
|
Lines 242-245
Link Here
|
| 242 |
return env; |
285 |
return env; |
| 243 |
} |
286 |
} |
| 244 |
|
287 |
|
|
|
288 |
|
| 289 |
/** |
| 290 |
* Set preference to stream output of scanner discovery to a console. |
| 291 |
*/ |
| 292 |
public static void setConsoleEnabled(boolean value) { |
| 293 |
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(MakeCorePlugin.PLUGIN_ID); |
| 294 |
node.putBoolean(PREF_CONSOLE_ENABLED, value); |
| 295 |
try { |
| 296 |
node.flush(); |
| 297 |
} catch (BackingStoreException e) { |
| 298 |
// TODO Auto-generated catch block |
| 299 |
e.printStackTrace(); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Check preference to stream output of scanner discovery to a console. |
| 305 |
* |
| 306 |
* @return boolean preference value |
| 307 |
*/ |
| 308 |
public static boolean isConsoleEnabled() { |
| 309 |
boolean value = InstanceScope.INSTANCE.getNode(MakeCorePlugin.PLUGIN_ID) |
| 310 |
.getBoolean(PREF_CONSOLE_ENABLED, true); |
| 311 |
return value; |
| 312 |
} |
| 313 |
|
| 245 |
} |
314 |
} |