~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to xlc/org.eclipse.cdt.make.xlc.core/src/org/eclipse/cdt/make/xlc/core/scannerconfig/XLCPerProjectBuildOutputParser.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 * IBM - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.make.xlc.core.scannerconfig;
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.HashMap;
 
15
import java.util.List;
 
16
import java.util.Map;
 
17
 
 
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;
 
27
 
 
28
/**
 
29
 * @author crecoskie
 
30
 *
 
31
 */
 
32
public class XLCPerProjectBuildOutputParser extends
 
33
                AbstractXLCBuildOutputParser {
 
34
        
 
35
        /* (non-Javadoc)
 
36
         * @see org.eclipse.cdt.make.xlc.core.scannerconfig.AbstractXLCBuildOutputParser#processCommand(java.lang.String[])
 
37
         */
 
38
        @Override
 
39
    protected boolean processCommand(String[] tokens) {
 
40
        int compilerInvocationIdx= findCompilerInvocation(tokens);
 
41
        if (compilerInvocationIdx<0) {
 
42
                return false;
 
43
        }
 
44
        
 
45
        if (compilerInvocationIdx+1 >= tokens.length) {
 
46
                return false;
 
47
        }
 
48
 
 
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>();
 
53
 
 
54
        String fileName = null;
 
55
        for (int j= compilerInvocationIdx+1; j < tokens.length; j++) {
 
56
                        String token = tokens[j];
 
57
                        if (token.equals(DASHIDASH)) {
 
58
                        }
 
59
                else if (token.startsWith(DASHI)) {
 
60
                        String candidate= null;
 
61
                                if (token.length() > 2) {
 
62
                                        candidate= token.substring(2).trim();
 
63
                                }
 
64
                                else if (j+1 < tokens.length) {
 
65
                                        candidate= tokens[j+1];
 
66
                                        if (candidate.startsWith("-")) { //$NON-NLS-1$
 
67
                                                candidate= null;
 
68
                                        }
 
69
                                        else {
 
70
                                                j++;
 
71
                                        }
 
72
                                }
 
73
                                if (candidate != null && candidate.length() > 0) {
 
74
                                        if (getUtility() != null) {
 
75
                                                candidate= getUtility().normalizePath(candidate);
 
76
                                        }
 
77
                                        if (!includes.contains(candidate)) {
 
78
                                                includes.add(candidate);
 
79
                                        }
 
80
                                }
 
81
                }
 
82
                else if (token.startsWith(DASHD)) {
 
83
                        String candidate= null;
 
84
                                if (token.length() > 2) {
 
85
                                        candidate= token.substring(2).trim();
 
86
                                }
 
87
                                else if (j+1 < tokens.length) {
 
88
                                        candidate= tokens[j+1];
 
89
                                        if (candidate.startsWith("-")) { //$NON-NLS-1$
 
90
                                                candidate= null;
 
91
                                        }
 
92
                                        else {
 
93
                                                j++;
 
94
                                        }
 
95
                                }
 
96
                        if (candidate != null && candidate.length() > 0) {
 
97
                                if (candidate.indexOf('=') == -1) {
 
98
                                        candidate+= '='+ getUtility().getDefaultMacroDefinitionValue();
 
99
                                }
 
100
                                if (!symbols.contains(candidate)) {
 
101
                                        symbols.add(candidate);
 
102
                                }
 
103
                        }
 
104
                }
 
105
                        
 
106
                else if (fileName == null) {
 
107
                        int extIndex = token.lastIndexOf('.');
 
108
                        String extension=null;
 
109
                        
 
110
                        if(extIndex != -1)
 
111
                                extension = token.substring(extIndex);
 
112
                        
 
113
                        List<String> extensions = getFileExtensionsList();
 
114
                        if(extension != null && extensions.contains(extension))
 
115
                                fileName = token;
 
116
                }
 
117
        }
 
118
 
 
119
        if (fileName == null) {
 
120
                return false;  // return when no file was given (analogous to GCCPerFileBOPConsoleParser)
 
121
        }
 
122
 
 
123
        IProject project = getProject();   
 
124
        IFile file = null;
 
125
        List<String> translatedIncludes = includes;
 
126
        if (includes.size() > 0) {
 
127
                if (fileName != null) {
 
128
                        if (getUtility() != null) {
 
129
                                file = getUtility().findFile(fileName);
 
130
                                if (file != null) {
 
131
                                        project = file.getProject();
 
132
                                        translatedIncludes = getUtility().translateRelativePaths(file, fileName, includes);
 
133
                                }
 
134
                        }
 
135
                }
 
136
                else {
 
137
                        StringBuffer line= new StringBuffer();
 
138
                        for (int j = 0; j < tokens.length; j++) {
 
139
                                        line.append(tokens[j]);
 
140
                                        line.append(' ');
 
141
                                }
 
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);
 
146
                        }
 
147
                }
 
148
                if (file == null && getUtility() != null) {     // real world case
 
149
                        // remove include paths since there was no chance to translate them
 
150
                        translatedIncludes.clear();
 
151
                }
 
152
        }
 
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;
 
162
                        try {
 
163
                                collector.updateScannerConfiguration(null);
 
164
                        } catch (CoreException e) {
 
165
                                // TODO Auto-generated catch block
 
166
                                Activator.log(e);
 
167
                        }
 
168
                }
 
169
 
 
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$
 
172
        }
 
173
                return true;
 
174
 
 
175
}
 
176
 
 
177
 
 
178
        
 
179
}