diff --git a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF index 12ec26eac40..22feef84ebc 100644 --- a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF @@ -35,7 +35,8 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)", org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)";resolution:=optional, org.eclipse.compare;bundle-version="[3.3.0,4.0.0)", - org.eclipse.core.filesystem;bundle-version="1.2.0" + org.eclipse.core.filesystem;bundle-version="1.2.0", + org.eclipse.ui.console;bundle-version="3.5.100" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.ibm.icu.text diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index c9c87cb44f6..f4a3166eb0c 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -563,4 +563,11 @@ class="org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole"> + + + + diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java new file mode 100644 index 00000000000..9a12186664c --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/scannerconfig/ScannerDiscoveryGlobalConsole.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2011, 2011 Andrew Gvozdev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Gvozdev - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.make.internal.ui.scannerconfig; + +import java.io.IOException; +import java.net.URL; + +import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.internal.core.ICConsole; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociation; +import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +public class ScannerDiscoveryGlobalConsole implements ICConsole { + private MessageConsole console; + private ConsoleOutputStreamAdapter stream; + + private class ConsoleOutputStreamAdapter extends ConsoleOutputStream { + private MessageConsoleStream fConsoleStream; + public ConsoleOutputStreamAdapter(MessageConsoleStream stream) { + fConsoleStream = stream; + } + @Override + public void write(int arg0) throws IOException { + fConsoleStream.write(arg0); + } + @Override + public synchronized void write(byte[] b, int off, int len) throws IOException { + fConsoleStream.write(b, off, len); + } + + @Override + public void flush() throws IOException { + fConsoleStream.flush(); + } + + @Override + public void close() throws IOException { + fConsoleStream.close(); + } + } + + public void start(IProject project) { + Assert.isTrue(project == null); + } + + public ConsoleOutputStream getOutputStream() throws CoreException { + return stream; + } + + public ConsoleOutputStream getInfoStream() throws CoreException { + return stream; + } + + public ConsoleOutputStream getErrorStream() throws CoreException { + return stream; + } + + public void init(String consoleId, String name, URL defaultIconUrl) { + console = null; + + IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); + IConsole[] allConsoles = consoleManager.getConsoles(); + for (IConsole con : allConsoles) { + if (name.equals(con.getName()) && con instanceof MessageConsole) { + console = (MessageConsole) con; + console.clearConsole(); + break; + } + } + + if (console==null) { + URL iconUrl = LanguageSettingsProviderAssociation.getImageUrl(consoleId); + if (iconUrl==null) { + iconUrl = defaultIconUrl; + } + + console = new MessageConsole(name, CDTSharedImages.getImageDescriptor(iconUrl.toString())); + console.activate(); + consoleManager.addConsoles(new IConsole[]{ console }); + } + + stream = new ConsoleOutputStreamAdapter(console.newMessageStream()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index f1579d629c5..be712a6d999 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -617,14 +617,6 @@ - - - - + + + + + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index f518772b791..3ceff84cc8b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -423,7 +423,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner { if(clParserList.size() != 0){ IConsoleParser[] parsers = clParserList.toArray(new IConsoleParser[clParserList.size()]); - return new ConsoleOutputSniffer(outputStream, errorStream, parsers, epm); + return new ConsoleOutputSniffer(outputStream, errorStream, parsers); } return null; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 337801b1342..95fdcd6bfd2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -4825,7 +4825,7 @@ public class ManagedBuildManager extends AbstractCExtension { if (detector.getLanguageScope()==null || detector.getLanguageScope().contains(languageId)) { try { if (isWorkspaceProvider) { - detector.run(project, languageId, workingDirectory, env, monitor); + detector.run((IProject)null, languageId, workingDirectory, env, monitor); } else { detector.run(cfgDescription, languageId, workingDirectory, env, monitor); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java index 3fc8ba3d846..8af3c53f939 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/scannerconfig/AbstractBuiltinSpecsDetector.java @@ -23,6 +23,8 @@ import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.core.IConsoleParser; +import org.eclipse.cdt.core.IMarkerGenerator; +import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.resources.IConsole; @@ -35,7 +37,6 @@ import org.eclipse.cdt.make.core.scannerconfig.AbstractLanguageSettingsOutputSca import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.StreamMonitor; -import org.eclipse.cdt.make.internal.core.scannerconfig2.SCMarkerGenerator; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; @@ -43,8 +44,11 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.utils.CommandLineUtil; import org.eclipse.cdt.utils.PathUtil; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -55,6 +59,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ILanguageSettingsBuiltinSpecsDetector { @@ -72,6 +77,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private String currentCommandResolved = null; protected List detectedSettingEntries = null; + protected int collected = 0; private boolean runOnce = true; private boolean isConsoleEnabled = false; @@ -81,6 +87,67 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected URI mappedRootURI = null; protected URI buildDirURI = null; + private class SDMarkerGenerator implements IMarkerGenerator { + protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = ManagedBuilderCorePlugin.PLUGIN_ID + ".scanner.discovery.problem"; //$NON-NLS-1$ + protected static final String PROVIDER = "provider"; //$NON-NLS-1$ + + public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) { + ProblemMarkerInfo info = new ProblemMarkerInfo(file, lineNumber, errorDesc, severity, errorVar); + addMarker(info); + } + + public void addMarker(final ProblemMarkerInfo problemMarkerInfo) { + final String providerName = getName(); + final String providerId = getId(); + // we have to add the marker in the job or we can deadlock other + // threads that are responding to a resource delta by doing something + // that accesses the project description + Job markerJob = new Job("Adding Scanner Discovery markers") { + @Override + protected IStatus run(IProgressMonitor monitor) { + // Try to find matching markers and don't put in duplicates + try { + IMarker[] cur = problemMarkerInfo.file.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + if ((cur != null) && (cur.length > 0)) { + for (int i = 0; i < cur.length; i++) { + int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue(); + String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE); + if (sev == problemMarkerInfo.severity && mesg.equals(problemMarkerInfo.description)) { + return Status.OK_STATUS; + } + } + } + } catch (CoreException e) { + return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error removing markers.", e); + } + + // add new marker + try { + IMarker marker = problemMarkerInfo.file.createMarker(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER); + marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description); + marker.setAttribute(IMarker.SEVERITY, problemMarkerInfo.severity); + marker.setAttribute(SDMarkerGenerator.PROVIDER, providerId); + + if (problemMarkerInfo.file instanceof IWorkspaceRoot) { + marker.setAttribute(IMarker.LOCATION, "SD90 Providers, [" + providerName + "] options in Preferences"); + } else { + marker.setAttribute(IMarker.LOCATION, "SD90 Providers, [" + providerName + "] options in project properties"); + } + } catch (CoreException e) { + return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error adding markers.", e); + } + + return Status.OK_STATUS; + } + }; + + markerJob.setRule(problemMarkerInfo.file); + markerJob.schedule(); + } + + } + + /** * TODO */ @@ -178,6 +245,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } detectedSettingEntries = new ArrayList(); + collected = 0; currentCommandResolved = customParameter; specFile = null; @@ -195,6 +263,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries); + collected = detectedSettingEntries.size(); IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName() + " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId); @@ -248,17 +317,30 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (isConsoleEnabled) { console = startProviderConsole(); } else { - // that looks in extension points registry and won't find the id + // that looks in extension points registry and won't find the id, this console is not shown console = CCorePlugin.getDefault().getConsole(MakeCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$ } console.start(currentProject); OutputStream cos = console.getOutputStream(); - ErrorParserManager epm = null; - if (currentProject!=null) { - epm = new ErrorParserManager(currentProject, new SCMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); - epm.setOutputStream(cos); + // Using GMAKE_ERROR_PARSER_ID as it can handle shell error messages + ErrorParserManager epm = new ErrorParserManager(currentProject, new SDMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID}); + epm.setOutputStream(cos); + + IResource markersResource = currentProject!= null ? currentProject : ResourcesPlugin.getWorkspace().getRoot(); + + // clear old markers + try { + IMarker[] cur = markersResource.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + for (IMarker marker : cur) { + if (getId().equals(marker.getAttribute(SDMarkerGenerator.PROVIDER))) { + marker.delete(); + } + } + } catch (CoreException e) { + ManagedBuilderCorePlugin.log(e); } + if (monitor==null) { monitor = new NullProgressMonitor(); @@ -323,8 +405,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (p != null) { // Before launching give visual cues via the monitor monitor.subTask("Invoking command " + command); - if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) - != ICommandLauncher.OK) { + if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) != ICommandLauncher.OK) { errMsg = launcher.getErrorMessage(); } } else { @@ -352,6 +433,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return false; } + printLine(consoleOut, NEWLINE + "**** Collected " + collected + " entries. ****"); return true; } @@ -366,13 +448,18 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } private IConsole startProviderConsole() { + String extConsoleId; + if (currentProject != null) { + extConsoleId = "org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole"; + } else { + extConsoleId = "org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryGlobalConsole"; + } ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId); - String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; String consoleName = getName() + ", " + ld.getName(); URL defaultIcon = Platform.getBundle(PLUGIN_CDT_MAKE_UI_ID).getEntry("icons/obj16/inspect_system.gif"); - IConsole console = CCorePlugin.getDefault().getConsole("org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole", consoleId, consoleName, defaultIcon); + IConsole console = CCorePlugin.getDefault().getConsole(extConsoleId, consoleId, consoleName, defaultIcon); return console; } @@ -381,7 +468,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti if (envStrings!=null) { String varPrefix = envVar+'='; for (String envStr : envStrings) { - if (envStr.startsWith(varPrefix)) { + boolean found = false; + // need to convert "Path" to "PATH" on Windows + if (Platform.getOS().equals(Platform.OS_WIN32)) { + found = envStr.substring(0,varPrefix.length()).toUpperCase().startsWith(varPrefix); + } else { + found = envStr.startsWith(varPrefix); + } + if (found) { envPath = envStr.substring(varPrefix.length()); break; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java index bf81b071c09..85d1dc3c62b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ConsoleOutputSniffer.java @@ -130,8 +130,6 @@ public class ConsoleOutputSniffer { private OutputStream consoleErrorStream; private IConsoleParser[] parsers; - private ErrorParserManager errorParserManager = null; - public ConsoleOutputSniffer(IConsoleParser[] parsers) { this.parsers = parsers; } @@ -142,11 +140,6 @@ public class ConsoleOutputSniffer { this.consoleErrorStream = errorStream; } - public ConsoleOutputSniffer(OutputStream outputStream, OutputStream errorStream, IConsoleParser[] parsers, ErrorParserManager epm) { - this(outputStream, errorStream, parsers); - this.errorParserManager = epm; - } - /** * Returns an output stream that will be sniffed. * This stream should be hooked up so the command @@ -177,7 +170,7 @@ public class ConsoleOutputSniffer { if (nOpens > 0 && --nOpens == 0) { for (int i = 0; i < parsers.length; ++i) { try { - parsers[i].shutdown(); + parsers[i].shutdown(); } catch (Throwable e) { // Report exception if any but let all the parsers chance to shutdown. CCorePlugin.log(e); @@ -195,10 +188,10 @@ public class ConsoleOutputSniffer { private synchronized void processLine(String line) { for (IConsoleParser parser : parsers) { try { - if (parser instanceof IErrorParser) { - // IErrorParser interface is used here only to pass ErrorParserManager + if (consoleOutputStream instanceof ErrorParserManager && parser instanceof IErrorParser ) { + // IErrorParser interface is used here only with purpose to pass ErrorParserManager // which keeps track of CWD and provides useful methods for locating files - ((IErrorParser)parser).processLine(line, errorParserManager); + ((IErrorParser)parser).processLine(line, (ErrorParserManager) consoleOutputStream); } else { parser.processLine(line); }