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
9
* IBM - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.make.core.scannerconfig;
13
import java.util.Iterator;
14
import java.util.List;
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;
31
* @deprecated as of CDT 4.0. Used by legacy CDT 3.X projects.
32
* Replaced by ScannerConfigNature in org.eclipse.cdt.managedbuilder.core.
36
* @noextend This class is not intended to be subclassed by clients.
37
* @noinstantiate This class is not intended to be instantiated by clients.
40
public class ScannerConfigNature implements IProjectNature {
42
public final static String NATURE_ID = MakeCorePlugin.getUniqueIdentifier() + ".ScannerConfigNature"; //$NON-NLS-1$
43
private IProject fProject;
46
* @see IProjectNature#configure
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)) {
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);
64
// set default project scanner config settings
68
* @see IProjectNature#deconfigure
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);
82
getProject().setDescription(description, null);
86
* @see IProjectNature#getProject
88
public IProject getProject() {
93
* @see IProjectNature#setProject
95
public void setProject(IProject project) {
99
public static void addScannerConfigNature(IProject project) throws CoreException {
100
IProjectDescription description = project.getDescription();
101
if (description.hasNature(NATURE_ID))
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);
112
public static void removeScannerConfigNature(IProject project) throws CoreException {
113
IProjectDescription description = project.getDescription();
114
if (!description.hasNature(NATURE_ID))
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);
130
* @return build command as stored in .project file
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)) {
143
* Stores a build command in .project file
145
public static IProjectDescription setBuildSpec(IProjectDescription description, ICommand newCommand) {
146
ICommand[] oldCommands = description.getBuildSpec();
147
ICommand oldCommand = getBuildSpec(description, newCommand.getBuilderName());
148
ICommand[] newCommands;
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;
157
for (int i = 0; i < oldCommands.length; i++) {
158
if (oldCommands[i] == oldCommand) {
159
oldCommands[i] = newCommand;
163
newCommands = oldCommands;
166
// Commit the spec change into the project
167
description.setBuildSpec(newCommands);
171
public static void initializeDiscoveryOptions(IProject project) {
173
IScannerConfigBuilderInfo2 scPrefInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(
174
MakeCorePlugin.getDefault().getPluginPreferences(), false);
175
String selectedProfile = scPrefInfo.getSelectedProfileId();
176
IScannerConfigBuilderInfo2 scProjInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(
177
project, selectedProfile);
179
scProjInfo.setAutoDiscoveryEnabled(scPrefInfo.isAutoDiscoveryEnabled());
180
scProjInfo.setProblemReportingEnabled(scPrefInfo.isProblemReportingEnabled());
182
scProjInfo.setBuildOutputParserEnabled(scPrefInfo.isBuildOutputParserEnabled());
183
scProjInfo.setBuildOutputFileActionEnabled(scPrefInfo.isBuildOutputFileActionEnabled());
184
scProjInfo.setBuildOutputFilePath(scPrefInfo.getBuildOutputFilePath());
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();
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));
198
scProjInfo.setProviderOpenFilePath(providerId, scPrefInfo.getProviderOpenFilePath(providerId));
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)) {
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);
222
// if (profile.getProfileScope().equals(ScannerConfigScope.PROJECT_SCOPE)) {
223
// CoreModel.setPathEntryContainer(new ICProject[]{cProject},
224
// new DiscoveredPathContainer(project), null);
226
// else { // file scope
227
// CoreModel.setPathEntryContainer(new ICProject[]{cProject},
228
// new PerFileDiscoveredPathContainer(project), null);
231
catch (CoreException e) {
232
MakeCorePlugin.log(e);