1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

patch from Vmir -

This patch contains fixes for following problems:

- PR 64014: [Scanner Config] Path discovery should be on by default,
- PR 63971: [Scanner Config] Debugging messages on console,
- PR 62742: CDT-specific file changes to .project are not saved - Scanner config portion
- Target specific options are applicable only to default generate scanner info command (and not to custom commands),
- Discovered scanner info file name associated with project instead with project name (problem when deleting a project, then creating a new one with the same name or renaming a project).
This commit is contained in:
David Inglis 2004-05-28 14:17:04 +00:00
parent 67cd9ad95c
commit e5c605c11d
9 changed files with 128 additions and 47 deletions

View file

@ -127,7 +127,7 @@ public class MakeCorePlugin extends Plugin {
// default plugin preferences for scanner configuration discovery
IScannerConfigBuilderInfo scInfo = createScannerConfigBuildInfo(getPluginPreferences(), ScannerConfigBuilder.BUILDER_ID, true);
try {
scInfo.setAutoDiscoveryEnabled(false);
scInfo.setAutoDiscoveryEnabled(true);
scInfo.setMakeBuilderConsoleParserEnabled(true);
scInfo.setESIProviderCommandEnabled(true);
scInfo.setUseDefaultESIProviderCmd(true);

View file

@ -112,13 +112,12 @@ public class ScannerConfigNature implements IProjectNature {
/**
* Returns build command as stored in .project file
*
* @param project
* @param description
* @param builderID
* @return ICommand
* @throws CoreException
*/
public static ICommand getBuildSpec(IProject project, String builderID) throws CoreException {
IProjectDescription description = project.getDescription();
public static ICommand getBuildSpec(IProjectDescription description, String builderID) throws CoreException {
ICommand[] commands = description.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(builderID)) {
@ -128,4 +127,37 @@ public class ScannerConfigNature implements IProjectNature {
return null;
}
/**
* Stores a build command in .project file
*
* @param description
* @param newCommand
* @return IProjecDescription
* @throws CoreException
*/
public static IProjectDescription setBuildSpec(IProjectDescription description, ICommand newCommand) throws CoreException {
ICommand[] oldCommands = description.getBuildSpec();
ICommand oldCommand = getBuildSpec(description, newCommand.getBuilderName());
ICommand[] newCommands;
if (oldCommand == null) {
// Add the build spec at the end
newCommands = new ICommand[oldCommands.length + 1];
System.arraycopy(oldCommands, 0, newCommands, 0, oldCommands.length);
newCommands[oldCommands.length] = newCommand;
}
else {
for (int i = 0; i < oldCommands.length; i++) {
if (oldCommands[i] == oldCommand) {
oldCommands[i] = newCommand;
break;
}
}
newCommands = oldCommands;
}
// Commit the spec change into the project
description.setBuildSpec(newCommands);
return description;
}
}

View file

@ -29,6 +29,8 @@ ExternalScannerInfoProvider.Creating_Markers=Generating markers ...
ScannerInfoCollector.Processing=Processing discovered scanner configuration ...
ScannerInfoCollector.Updating=Updating Scanner Configuration for project
DiscoveredPathManager.File_Error_Message=Error accessing scanner config file for project
GCCScannerConfigUtil.Error_Message=Error creating specs file
DiscoveredContainer.description=Discovered Paths

View file

@ -68,7 +68,7 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
if (targetSpecificOptions == null) {
targetSpecificOptions = new ArrayList();
}
if (!initialize(currentProject, buildInfo, targetSpecificOptions)) {
if (!initialize(currentProject, buildInfo)) {
return false;
}
if (monitor == null) {
@ -90,7 +90,11 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
launcher.showCommand(true);
// add file and TSO
String[] compileArguments = prepareArguments(targetSpecificOptions);
String[] compileArguments = fCompileArguments;
if (buildInfo.isDefaultESIProviderCmd()) {
// consider TSO only if default command
compileArguments = prepareArguments(targetSpecificOptions);
}
String ca = coligate(compileArguments);
@ -140,10 +144,9 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
/**
* @param currentProject
* @param buildInfo
* @param targetSpecificOptions
* @return boolean
*/
private boolean initialize(IProject currentProject, IScannerConfigBuilderInfo buildInfo, List targetSpecificOptions) {
private boolean initialize(IProject currentProject, IScannerConfigBuilderInfo buildInfo) {
boolean rc = false;
fWorkingDirectory = currentProject.getLocation();

View file

@ -85,11 +85,7 @@ public class DiscoveredPathManager implements IDiscoveredPathManager {
}
public void removeDiscoveredInfo(IProject project) {
IPath path = MakeCorePlugin.getWorkingDirectory();
path = path.append(project.getName() + ".sc"); //$NON-NLS-1$
if (path.toFile().exists()) {
path.toFile().delete();
}
ScannerConfigUtil.getDiscoveredScannerConfigStore(project, true);
DiscoveredPathInfo info = (DiscoveredPathInfo)fDiscoveredMap.remove(project);
fireUpdate(INFO_REMOVED, info);
}
@ -104,8 +100,7 @@ public class DiscoveredPathManager implements IDiscoveredPathManager {
private void loadDiscoveredScannerInfoFromState(IProject project, LinkedHashMap includes, LinkedHashMap symbols)
throws CoreException {
// Save the document
IPath path = MakeCorePlugin.getWorkingDirectory();
path = path.append(project.getName() + ".sc"); //$NON-NLS-1$
IPath path = ScannerConfigUtil.getDiscoveredScannerConfigStore(project, false);
if (path.toFile().exists()) {
try {
FileInputStream file = new FileInputStream(path.toFile());
@ -118,15 +113,15 @@ public class DiscoveredPathManager implements IDiscoveredPathManager {
}
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
} catch (ParserConfigurationException e) {
MakeCorePlugin.log(e);
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
} catch (SAXException e) {
MakeCorePlugin.log(e);
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
}
}
}
@ -218,15 +213,14 @@ public class DiscoveredPathManager implements IDiscoveredPathManager {
transformer.transform(source, result);
// Save the document
IPath path = MakeCorePlugin.getWorkingDirectory();
path = path.append(info.getProject().getName() + ".sc"); //$NON-NLS-1$
try {
IPath path = ScannerConfigUtil.getDiscoveredScannerConfigStore(info.getProject(), false);
FileOutputStream file = new FileOutputStream(path.toFile());
file.write(stream.toByteArray());
file.close();
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
}
// Close the streams
@ -234,15 +228,15 @@ public class DiscoveredPathManager implements IDiscoveredPathManager {
} catch (TransformerException e) {
MakeCorePlugin.log(e);
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
} catch (IOException e) {
MakeCorePlugin.log(e);
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
} catch (ParserConfigurationException e) {
MakeCorePlugin.log(e);
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
MakeMessages.getString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$
MakeMessages.getString("DiscoveredPathManager.File_Error_Message"), e)); //$NON-NLS-1$
}
}

View file

@ -15,6 +15,7 @@ import java.util.Map;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@ -25,6 +26,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.MakeProjectNature;
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo;
import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature;
import org.eclipse.cdt.make.internal.core.MakeMessages;
@ -271,7 +273,7 @@ public class ScannerConfigInfoFactory {
BuildProperty(IProject project, String builderID) throws CoreException {
this.project = project;
this.builderID = builderID;
ICommand builder = ScannerConfigNature.getBuildSpec(project, builderID);
ICommand builder = ScannerConfigNature.getBuildSpec(project.getDescription(), builderID);
if (builder == null) {
throw new CoreException(new Status(IStatus.ERROR,
MakeCorePlugin.getUniqueIdentifier(), -1,
@ -286,10 +288,14 @@ public class ScannerConfigInfoFactory {
if (curValue != null && curValue.equals(value)) {
return;
}
ICommand builder = ScannerConfigNature.getBuildSpec(project, builderID);
IProjectDescription description = project.getDescription();
ICommand builder = ScannerConfigNature.getBuildSpec(description, builderID);
args.put(name, value);
builder.setArguments(args);
project.setDescription(project.getDescription(), null);
ICommand newBuilder = description.newCommand();
newBuilder.setBuilderName(builder.getBuilderName());
newBuilder.setArguments(args);
description = MakeProjectNature.setBuildSpec(description, newBuilder);
project.setDescription(description, null);
}
protected String getString(String name) {

View file

@ -10,6 +10,7 @@
**********************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -17,9 +18,14 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.QualifiedName;
/**
* Utility class that handles some Scanner Config specifig collection conversions
@ -27,6 +33,9 @@ import org.eclipse.core.runtime.IPath;
* @author vhirsl
*/
public final class ScannerConfigUtil {
private static Random sRandom = new Random();
private static final QualifiedName discoveredScannerConfigFileNameProperty = new
QualifiedName(MakeCorePlugin.getUniqueIdentifier(), "discoveredScannerConfigFileName"); //$NON-NLS-1$
/**
* Adds all new discovered symbols/values to the existing ones.
*
@ -286,4 +295,29 @@ public final class ScannerConfigUtil {
}
return rv;
}
public static IPath getDiscoveredScannerConfigStore(IProject project, boolean delete) {
if (project != null) {
try {
String fileName = (String) project.getPersistentProperty(discoveredScannerConfigFileNameProperty);
if (fileName == null) {
fileName = String.valueOf(sRandom.nextLong()) + ".sc"; //$NON-NLS-1$
project.setPersistentProperty(discoveredScannerConfigFileNameProperty, fileName);
}
IPath path = MakeCorePlugin.getWorkingDirectory();
path = path.append(fileName);
if (delete) {
File file = path.toFile();
if (file.exists()) {
file.delete();
}
}
return path;
} catch (CoreException e) {
MakeCorePlugin.log(e.getStatus());
}
}
return null;
}
}

View file

@ -27,8 +27,10 @@ public class TraceUtil {
}
public static void outputTrace(String prefix, String msg, String postfix) {
System.out.println();
System.out.println(prefix + ' ' + msg + ' ' + postfix);
if (isTracing()) {
System.out.println();
System.out.println(prefix + ' ' + msg + ' ' + postfix);
}
}
/**

View file

@ -33,6 +33,7 @@ import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage;
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@ -147,27 +148,34 @@ public class DiscoveryOptionsBlock extends AbstractCOptionPage {
buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(project, ScannerConfigBuilder.BUILDER_ID);
if (fCreatePathContainer) {
createDiscoveredPathContainer(project);
// create a new discovered scanner config store
MakeCorePlugin.getDefault().getDiscoveryManager().removeDiscoveredInfo(project);
}
}
else {
buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, false);
}
buildInfo.setAutoDiscoveryEnabled(isScannerConfigDiscoveryEnabled());
if (isScannerConfigDiscoveryEnabled()) {
buildInfo.setMakeBuilderConsoleParserEnabled(isBuilderParserEnabled());
if (isBuilderParserEnabled()) {
buildInfo.setMakeBuilderConsoleParserId((String) builderParsers.get(makeBuilderSIParserComboBox.getText()));
}
buildInfo.setESIProviderCommandEnabled(isProviderCommandEnabled());
if (isProviderCommandEnabled()) {
buildInfo.setUseDefaultESIProviderCmd(useDefaultESIProviderCmd());
if (!useDefaultESIProviderCmd()) {
storeSIProviderCommandLine(buildInfo);
final IScannerConfigBuilderInfo fInfo = buildInfo;
MakeUIPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
fInfo.setAutoDiscoveryEnabled(isScannerConfigDiscoveryEnabled());
if (isScannerConfigDiscoveryEnabled()) {
fInfo.setMakeBuilderConsoleParserEnabled(isBuilderParserEnabled());
if (isBuilderParserEnabled()) {
fInfo.setMakeBuilderConsoleParserId((String) builderParsers.get(makeBuilderSIParserComboBox.getText()));
}
fInfo.setESIProviderCommandEnabled(isProviderCommandEnabled());
if (isProviderCommandEnabled()) {
fInfo.setUseDefaultESIProviderCmd(useDefaultESIProviderCmd());
if (!useDefaultESIProviderCmd()) {
storeSIProviderCommandLine(fInfo);
}
fInfo.setESIProviderConsoleParserId((String) providerParsers.get(esiProviderParserComboBox.getText()));
}
}
buildInfo.setESIProviderConsoleParserId((String) providerParsers.get(esiProviderParserComboBox.getText()));
}
}
} /* IWorkspaceRunnable */, monitor);
}
/**
@ -208,7 +216,7 @@ public class DiscoveryOptionsBlock extends AbstractCOptionPage {
makeBuilderSIParserComboBox.setText(getParserName(builderParsers, info.getMakeBuilderConsoleParserId()));
enableProviderCommandButton.setSelection(info.isESIProviderCommandEnabled());
defESIProviderCommandButton.setSelection(info.isDefaultESIProviderCmd());
setESIProviderCommand(info);
setESIProviderCommandFrom(info);
esiProviderParserComboBox.setText(getParserName(providerParsers, info.getESIProviderConsoleParserId()));
enableAllControls();
@ -302,7 +310,7 @@ public class DiscoveryOptionsBlock extends AbstractCOptionPage {
/**
* Handles scanner configuration discovery selection change
*/
protected void handleScannerConfigEnable() {
private void handleScannerConfigEnable() {
boolean enable = scEnabledButton.getSelection();
if (enable && needsSCNature) {
// first install the SC nature
@ -436,7 +444,7 @@ public class DiscoveryOptionsBlock extends AbstractCOptionPage {
esiProviderCommand = ControlFactory.createTextField(parent, SWT.SINGLE | SWT.BORDER);
((GridData) (esiProviderCommand.getLayoutData())).horizontalAlignment = GridData.FILL;
((GridData) (esiProviderCommand.getLayoutData())).grabExcessHorizontalSpace = true;
setESIProviderCommand(fBuildInfo);
setESIProviderCommandFrom(fBuildInfo);
if (fBuildInfo.isDefaultESIProviderCmd()) {
esiProviderCommand.setEnabled(false);
}
@ -451,7 +459,7 @@ public class DiscoveryOptionsBlock extends AbstractCOptionPage {
/**
*
*/
private void setESIProviderCommand(IScannerConfigBuilderInfo buildInfo) {
private void setESIProviderCommandFrom(IScannerConfigBuilderInfo buildInfo) {
IPath sCommand = buildInfo.getESIProviderCommand();
if (sCommand != null) {
StringBuffer cmd = new StringBuffer(sCommand.toOSString());