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

« back to all changes in this revision

Viewing changes to build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.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) 2004, 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.core.scannerconfig;
 
12
 
 
13
import java.util.Iterator;
 
14
import java.util.List;
 
15
 
 
16
import org.eclipse.cdt.core.model.CoreModel;
 
17
import org.eclipse.cdt.core.model.ICProject;
 
18
import org.eclipse.cdt.core.model.IContainerEntry;
 
19
import org.eclipse.cdt.core.model.IPathEntry;
 
20
import org.eclipse.cdt.make.core.MakeCorePlugin;
 
21
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathContainer;
 
22
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile;
 
23
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
 
24
import org.eclipse.core.resources.ICommand;
 
25
import org.eclipse.core.resources.IProject;
 
26
import org.eclipse.core.resources.IProjectDescription;
 
27
import org.eclipse.core.resources.IProjectNature;
 
28
import org.eclipse.core.runtime.CoreException;
 
29
 
 
30
/**
 
31
 * @deprecated as of CDT 4.0. Used by legacy CDT 3.X projects.
 
32
 * Replaced by ScannerConfigNature in org.eclipse.cdt.managedbuilder.core.
 
33
 * 
 
34
 * @see IProjectNature
 
35
 * 
 
36
 * @noextend This class is not intended to be subclassed by clients.
 
37
 * @noinstantiate This class is not intended to be instantiated by clients.
 
38
 */
 
39
@Deprecated
 
40
public class ScannerConfigNature implements IProjectNature {
 
41
        
 
42
        public final static String NATURE_ID = MakeCorePlugin.getUniqueIdentifier() + ".ScannerConfigNature"; //$NON-NLS-1$
 
43
        private IProject fProject;
 
44
 
 
45
        /**
 
46
         * @see IProjectNature#configure
 
47
         */
 
48
        public void configure() throws CoreException {
 
49
                IProjectDescription description = getProject().getDescription();
 
50
                ICommand[] commands = description.getBuildSpec();
 
51
                for (int i = 0; i < commands.length; ++i) {
 
52
                        if (commands[i].getBuilderName().equals(ScannerConfigBuilder.BUILDER_ID)) {
 
53
                                return;
 
54
                        }
 
55
                }
 
56
                ICommand command = description.newCommand();
 
57
                command.setBuilderName(ScannerConfigBuilder.BUILDER_ID);
 
58
                ICommand[] newCommands = new ICommand[commands.length + 1];
 
59
                System.arraycopy(commands, 0, newCommands, 0, commands.length);
 
60
                newCommands[commands.length] = command;
 
61
                description.setBuildSpec(newCommands);
 
62
                getProject().setDescription(description, null);
 
63
                
 
64
                // set default project scanner config settings
 
65
        }
 
66
 
 
67
        /**
 
68
         * @see IProjectNature#deconfigure
 
69
         */
 
70
        public void deconfigure() throws CoreException {
 
71
                IProjectDescription description = getProject().getDescription();
 
72
                ICommand[] commands = description.getBuildSpec();
 
73
                for (int i = 0; i < commands.length; ++i) {
 
74
                        if (commands[i].getBuilderName().equals(ScannerConfigBuilder.BUILDER_ID)) {
 
75
                                ICommand[] newCommands = new ICommand[commands.length - 1];
 
76
                                System.arraycopy(commands, 0, newCommands, 0, i);
 
77
                                System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
 
78
                                description.setBuildSpec(newCommands);
 
79
                                break;
 
80
                        }
 
81
                }
 
82
                getProject().setDescription(description, null);
 
83
        }
 
84
 
 
85
        /**
 
86
         * @see IProjectNature#getProject
 
87
         */
 
88
        public IProject getProject()  {
 
89
                return fProject;
 
90
        }
 
91
 
 
92
        /**
 
93
         * @see IProjectNature#setProject
 
94
         */
 
95
        public void setProject(IProject project)  {
 
96
                fProject = project;
 
97
        }
 
98
        
 
99
        public static void addScannerConfigNature(IProject project) throws CoreException {
 
100
                IProjectDescription description = project.getDescription();
 
101
                if (description.hasNature(NATURE_ID))
 
102
                        return;
 
103
                String[] ids = description.getNatureIds();
 
104
                String[] newIds = new String[ids.length + 1];
 
105
                System.arraycopy(ids, 0, newIds, 0, ids.length);
 
106
                newIds[ids.length] = NATURE_ID;
 
107
                description.setNatureIds(newIds);
 
108
                project.setDescription(description, null);
 
109
                
 
110
        }
 
111
        
 
112
        public static void removeScannerConfigNature(IProject project) throws CoreException {
 
113
                IProjectDescription description = project.getDescription();
 
114
                if (!description.hasNature(NATURE_ID))
 
115
                        return;
 
116
                String[] ids = description.getNatureIds();
 
117
                for (int i = 0; i < ids.length; ++i) {
 
118
                        if (ids[i].equals(NATURE_ID)) {
 
119
                                String[] newIds = new String[ids.length - 1];
 
120
                                System.arraycopy(ids, 0, newIds, 0, i);
 
121
                                System.arraycopy(ids, i + 1, newIds, i, ids.length - i - 1);
 
122
                                description.setNatureIds(newIds);
 
123
                                project.setDescription(description, null);
 
124
                        }
 
125
                }
 
126
 
 
127
        }
 
128
 
 
129
        /**
 
130
         * @return build command as stored in .project file
 
131
         */
 
132
        public static ICommand getBuildSpec(IProjectDescription description, String builderID) {
 
133
                ICommand[] commands = description.getBuildSpec();
 
134
                for (int i = 0; i < commands.length; ++i) {
 
135
                        if (commands[i].getBuilderName().equals(builderID)) {
 
136
                                return commands[i];
 
137
                        }
 
138
                }
 
139
                return null;
 
140
        }
 
141
 
 
142
        /**
 
143
         * Stores a build command in .project file
 
144
         */
 
145
        public static IProjectDescription setBuildSpec(IProjectDescription description, ICommand newCommand) {
 
146
                ICommand[] oldCommands = description.getBuildSpec();
 
147
                ICommand oldCommand = getBuildSpec(description, newCommand.getBuilderName());
 
148
                ICommand[] newCommands;
 
149
 
 
150
                if (oldCommand == null) {
 
151
                        // Add the build spec at the end
 
152
                        newCommands = new ICommand[oldCommands.length + 1];
 
153
                        System.arraycopy(oldCommands, 0, newCommands, 0, oldCommands.length);
 
154
                        newCommands[oldCommands.length] = newCommand;
 
155
                } 
 
156
                else {
 
157
                        for (int i = 0; i < oldCommands.length; i++) {
 
158
                                if (oldCommands[i] == oldCommand) {
 
159
                                        oldCommands[i] = newCommand;
 
160
                                        break;
 
161
                                }
 
162
                        }
 
163
                        newCommands = oldCommands;
 
164
                }
 
165
 
 
166
                // Commit the spec change into the project
 
167
                description.setBuildSpec(newCommands);
 
168
                return description;
 
169
        }
 
170
 
 
171
        public static void initializeDiscoveryOptions(IProject project) {
 
172
                try {
 
173
                        IScannerConfigBuilderInfo2 scPrefInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(
 
174
                                        MakeCorePlugin.getDefault().getPluginPreferences(), false);
 
175
                        String selectedProfile = scPrefInfo.getSelectedProfileId();
 
176
                        IScannerConfigBuilderInfo2 scProjInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(
 
177
                                        project, selectedProfile);
 
178
                        
 
179
                        scProjInfo.setAutoDiscoveryEnabled(scPrefInfo.isAutoDiscoveryEnabled());
 
180
                        scProjInfo.setProblemReportingEnabled(scPrefInfo.isProblemReportingEnabled());
 
181
        
 
182
                        scProjInfo.setBuildOutputParserEnabled(scPrefInfo.isBuildOutputParserEnabled());
 
183
                        scProjInfo.setBuildOutputFileActionEnabled(scPrefInfo.isBuildOutputFileActionEnabled());
 
184
                        scProjInfo.setBuildOutputFilePath(scPrefInfo.getBuildOutputFilePath());
 
185
        
 
186
                        ScannerConfigProfile profile = ScannerConfigProfileManager.getInstance().getSCProfileConfiguration(selectedProfile);
 
187
                        List<String> providerIdList = scPrefInfo.getProviderIdList();
 
188
                        for (Iterator<String> i = providerIdList.iterator(); i.hasNext();) {
 
189
                                String providerId = i.next();
 
190
                                
 
191
                                scProjInfo.setProviderOutputParserEnabled(providerId, scPrefInfo.isProviderOutputParserEnabled(providerId));
 
192
                                if (profile.getScannerInfoProviderElement(providerId).getProviderKind().equals(
 
193
                                                ScannerConfigProfile.ScannerInfoProvider.RUN)) {
 
194
                                        scProjInfo.setProviderRunCommand(providerId, scPrefInfo.getProviderRunCommand(providerId));
 
195
                                        scProjInfo.setProviderRunArguments(providerId, scPrefInfo.getProviderRunArguments(providerId));
 
196
                                }
 
197
                                else {
 
198
                                        scProjInfo.setProviderOpenFilePath(providerId, scPrefInfo.getProviderOpenFilePath(providerId));
 
199
                                }
 
200
                        }
 
201
                        scProjInfo.save();
 
202
                        
 
203
                        // the last step is to add discovered paths container
 
204
                        ICProject cProject = CoreModel.getDefault().create(project);
 
205
                        IPathEntry[] rawPathEntries = CoreModel.getRawPathEntries(cProject);
 
206
                        boolean found = false;
 
207
                        for (int i = 0; i < rawPathEntries.length; i++) {
 
208
                                if (rawPathEntries[i].getEntryKind() == IPathEntry.CDT_CONTAINER) {
 
209
                                        IContainerEntry container = (IContainerEntry) rawPathEntries[i];
 
210
                                        if (container.getPath().equals(DiscoveredPathContainer.CONTAINER_ID)) {
 
211
                                                found = true;
 
212
                                                break;
 
213
                                        }
 
214
                                }
 
215
                        }
 
216
                        if (!found) {
 
217
                                IPathEntry[] newRawPathEntries = new IPathEntry[rawPathEntries.length + 1];
 
218
                                System.arraycopy(rawPathEntries, 0, newRawPathEntries, 0, rawPathEntries.length);
 
219
                                newRawPathEntries[rawPathEntries.length] = CoreModel.newContainerEntry(DiscoveredPathContainer.CONTAINER_ID);
 
220
                                CoreModel.setRawPathEntries(cProject, newRawPathEntries, null);
 
221
                        }
 
222
//                      if (profile.getProfileScope().equals(ScannerConfigScope.PROJECT_SCOPE)) {
 
223
//                              CoreModel.setPathEntryContainer(new ICProject[]{cProject},
 
224
//                                              new DiscoveredPathContainer(project), null);
 
225
//                      }
 
226
//                      else {  // file scope
 
227
//                              CoreModel.setPathEntryContainer(new ICProject[]{cProject},
 
228
//                                              new PerFileDiscoveredPathContainer(project), null);
 
229
//                      }
 
230
                }
 
231
                catch (CoreException e) {
 
232
                        MakeCorePlugin.log(e);
 
233
                }
 
234
        }
 
235
 
 
236
}