1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.make.xlc.core.scannerconfig;
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.List;
18
import org.eclipse.cdt.core.IMarkerGenerator;
19
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2;
20
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
21
import org.eclipse.cdt.make.internal.core.MakeMessages;
22
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
23
import org.eclipse.cdt.make.xlc.core.activator.Activator;
24
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IProject;
26
import org.eclipse.core.runtime.CoreException;
32
public class XLCPerProjectBuildOutputParser extends
33
AbstractXLCBuildOutputParser {
36
* @see org.eclipse.cdt.make.xlc.core.scannerconfig.AbstractXLCBuildOutputParser#processCommand(java.lang.String[])
39
protected boolean processCommand(String[] tokens) {
40
int compilerInvocationIdx= findCompilerInvocation(tokens);
41
if (compilerInvocationIdx<0) {
45
if (compilerInvocationIdx+1 >= tokens.length) {
49
// Recognized gcc or g++ compiler invocation
50
List<String> includes = new ArrayList<String>();
51
List<String> symbols = new ArrayList<String>();
52
List<String> targetSpecificOptions = new ArrayList<String>();
54
String fileName = null;
55
for (int j= compilerInvocationIdx+1; j < tokens.length; j++) {
56
String token = tokens[j];
57
if (token.equals(DASHIDASH)) {
59
else if (token.startsWith(DASHI)) {
60
String candidate= null;
61
if (token.length() > 2) {
62
candidate= token.substring(2).trim();
64
else if (j+1 < tokens.length) {
65
candidate= tokens[j+1];
66
if (candidate.startsWith("-")) { //$NON-NLS-1$
73
if (candidate != null && candidate.length() > 0) {
74
if (getUtility() != null) {
75
candidate= getUtility().normalizePath(candidate);
77
if (!includes.contains(candidate)) {
78
includes.add(candidate);
82
else if (token.startsWith(DASHD)) {
83
String candidate= null;
84
if (token.length() > 2) {
85
candidate= token.substring(2).trim();
87
else if (j+1 < tokens.length) {
88
candidate= tokens[j+1];
89
if (candidate.startsWith("-")) { //$NON-NLS-1$
96
if (candidate != null && candidate.length() > 0) {
97
if (candidate.indexOf('=') == -1) {
98
candidate+= '='+ getUtility().getDefaultMacroDefinitionValue();
100
if (!symbols.contains(candidate)) {
101
symbols.add(candidate);
106
else if (fileName == null) {
107
int extIndex = token.lastIndexOf('.');
108
String extension=null;
111
extension = token.substring(extIndex);
113
List<String> extensions = getFileExtensionsList();
114
if(extension != null && extensions.contains(extension))
119
if (fileName == null) {
120
return false; // return when no file was given (analogous to GCCPerFileBOPConsoleParser)
123
IProject project = getProject();
125
List<String> translatedIncludes = includes;
126
if (includes.size() > 0) {
127
if (fileName != null) {
128
if (getUtility() != null) {
129
file = getUtility().findFile(fileName);
131
project = file.getProject();
132
translatedIncludes = getUtility().translateRelativePaths(file, fileName, includes);
137
StringBuffer line= new StringBuffer();
138
for (int j = 0; j < tokens.length; j++) {
139
line.append(tokens[j]);
142
final String error = MakeMessages.getString("ConsoleParser.Filename_Missing_Error_Message"); //$NON-NLS-1$
143
TraceUtil.outputError(error, line.toString());
144
if (getUtility() != null) {
145
getUtility().generateMarker(getProject(), -1, error + line.toString(), IMarkerGenerator.SEVERITY_WARNING, null);
148
if (file == null && getUtility() != null) { // real world case
149
// remove include paths since there was no chance to translate them
150
translatedIncludes.clear();
153
// Contribute discovered includes and symbols to the ScannerInfoCollector
154
if (translatedIncludes.size() > 0 || symbols.size() > 0) {
155
Map<ScannerInfoTypes, List<String>> scannerInfo = new HashMap<ScannerInfoTypes, List<String>>();
156
scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, translatedIncludes);
157
scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols);
158
scannerInfo.put(ScannerInfoTypes.TARGET_SPECIFIC_OPTION, targetSpecificOptions);
159
getCollector().contributeToScannerConfig(project, scannerInfo);
160
if(fCollector != null && fCollector instanceof IScannerInfoCollector2) {
161
IScannerInfoCollector2 collector = (IScannerInfoCollector2) fCollector;
163
collector.updateScannerConfiguration(null);
164
} catch (CoreException e) {
165
// TODO Auto-generated catch block
170
TraceUtil.outputTrace("Discovered scanner info for file \'" + fileName + '\'', //$NON-NLS-1$
171
"Include paths", includes, translatedIncludes, "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$