diff options
author | Doug Schaefer | 2016-03-22 14:19:26 +0000 |
---|---|---|
committer | Doug Schaefer | 2016-03-22 14:32:31 +0000 |
commit | c29243b187cb113ae6817c81789b1839c8423e20 (patch) | |
tree | f6d3b38fbc9c6f2d13ecba4c5c184ce0b3e5b75e /qt | |
parent | 52432d73702960aaab6810bbda22feb2f11dfdd1 (diff) | |
download | org.eclipse.cdt-c29243b187cb113ae6817c81789b1839c8423e20.tar.gz org.eclipse.cdt-c29243b187cb113ae6817c81789b1839c8423e20.tar.xz org.eclipse.cdt-c29243b187cb113ae6817c81789b1839c8423e20.zip |
Revert "Bug 489563 - API change for Language Settings Providers."
This reverts the changes we've made for language settings providers
so that I can start again with a cleaner approach.
Change-Id: Icddd5a465a8f217594af5b07011a56bf1dfdf014
Diffstat (limited to 'qt')
2 files changed, 94 insertions, 111 deletions
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePaths.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePaths.java index 878dc1c784b..4216f8b1188 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePaths.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePaths.java @@ -18,25 +18,24 @@ import java.util.List; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.utils.spawner.ProcessFactory; -import org.eclipse.core.resources.IBuildConfiguration; import org.eclipse.core.resources.IResource; import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Discovers and persists the list of Qt include paths for a particular - * installation of Qt. The Qt installation is described by the path to qmake. + * Discovers and persists the list of Qt include paths for a particular installation of + * Qt. The Qt installation is described by the path to qmake. * <p> - * Qt uses a tool called qmake to generate makefiles for Qt projects. The tool - * has a query mode that can be used to discover information about the Qt - * installation. Here qmake is used to build a list of all installed Qt include - * paths. + * Qt uses a tool called qmake to generate makefiles for Qt projects. The tool has a + * query mode that can be used to discover information about the Qt installation. Here + * qmake is used to build a list of all installed Qt include paths. * <p> - * These paths are persisted into a file called language-settings.xml in the - * workspace metadata area. + * These paths are persisted into a file called language-settings.xml in the workspace + * metadata area. * * @see QtIncludePathsProvider */ @@ -53,34 +52,34 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { private long qmakeModTime; /** - * The cached data is reloaded when the folder holding the include paths is - * removed. + * The cached data is reloaded when the folder holding the include paths + * is removed. */ private String qtInstallHeadersPath; /** - * The cached data is reloaded when the folder containing the include - * folders is modified. + * The cached data is reloaded when the folder containing the include folders is + * modified. */ private long qtInstallHeadersModTime; - private static final String ATTR_QMAKE = "qmake"; //$NON-NLS-1$ - private static final String ATTR_QMAKE_MOD = "qmakeModification"; //$NON-NLS-1$ - private static final String ATTR_QT_INSTALL_HEADERS = "QT_INSTALL_HEADERS"; //$NON-NLS-1$ - private static final String ATTR_QT_INSTALL_HEADERS_MOD = "qtInstallHeadersModification"; //$NON-NLS-1$ + private static final String ATTR_QMAKE = "qmake"; + private static final String ATTR_QMAKE_MOD = "qmakeModification"; + private static final String ATTR_QT_INSTALL_HEADERS = "QT_INSTALL_HEADERS"; + private static final String ATTR_QT_INSTALL_HEADERS_MOD = "qtInstallHeadersModification"; /** - * Create a new instance of the include path wrapper for the Qt installation - * for the given qmake binary. + * Create a new instance of the include path wrapper for the Qt installation for + * the given qmake binary. */ public QtIncludePaths(String qmakePath) { this.qmakePath = qmakePath; } /** - * Create and load an instance of QtIncludePaths from data that was - * serialized into the given XML element. Return null if an instance cannot - * be loaded or if the installation is no longer valid. + * Create and load an instance of QtIncludePaths from data that was serialized into the + * given XML element. Return null if an instance cannot be loaded or if the installation + * is no longer valid. */ public static QtIncludePaths loadFrom(Node node) { if (node.getNodeType() != Node.ELEMENT_NODE) @@ -88,7 +87,8 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { Element element = (Element) node; String qmakePath = element.getAttribute(ATTR_QMAKE); - if (qmakePath == null || qmakePath.isEmpty()) + if (qmakePath == null + || qmakePath.isEmpty()) return null; QtIncludePaths qtIncludePaths = new QtIncludePaths(qmakePath); @@ -101,16 +101,18 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { } /** - * Return true if the receiver points to a valid Qt installation and false - * otherwise. The installation is considered valid if an executable qmake - * binary exists at the expected location. + * Return true if the receiver points to a valid Qt installation and false otherwise. + * The installation is considered valid if an executable qmake binary exists at the + * expected location. */ public boolean isValid() { - if (qmakePath == null || qmakePath.isEmpty()) + if (qmakePath == null + || qmakePath.isEmpty()) return false; File qmake = new File(qmakePath); - return qmake.exists() && qmake.canExecute(); + return qmake.exists() + && qmake.canExecute(); } @Override @@ -118,10 +120,8 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { if (!(obj instanceof QtIncludePaths)) return super.equals(obj); - // Include paths are equivalent when they point to the same qmake - // binary. All other - // values are reloaded from that binary and do not need to be directly - // compared. + // Include paths are equivalent when they point to the same qmake binary. All other + // values are reloaded from that binary and do not need to be directly compared. QtIncludePaths other = (QtIncludePaths) obj; return qmakePath == null ? other.qmakePath == null : qmakePath.equals(other.qmakePath); } @@ -132,32 +132,33 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { } /** - * Return a current list of the include paths for this Qt installation. - * Return null if no such paths can be found. + * Return a current list of the include paths for this Qt installation. Return null if + * no such paths can be found. * <p> - * Updates the cached results if needed. If the settings are updated then - * the new list will be serialized into the workspace metadata area. + * Updates the cached results if needed. If the settings are updated then the new list + * will be serialized into the workspace metadata area. */ @Override - public List<ICLanguageSettingEntry> getSettingEntries(IBuildConfiguration config, IResource rc, String languageId) { + public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription configDesc, IResource rc, String languageId) { List<ICLanguageSettingEntry> entries = null; File qmake = new File(qmakePath); - if (!qmake.exists() || qmakeModTime != qmake.lastModified()) + if (!qmake.exists() + || qmakeModTime != qmake.lastModified()) entries = reload(); else { File qtInstallHeadersDir = new File(qtInstallHeadersPath); - if (!qtInstallHeadersDir.exists() || qtInstallHeadersModTime != qtInstallHeadersDir.lastModified()) + if (!qtInstallHeadersDir.exists() + || qtInstallHeadersModTime != qtInstallHeadersDir.lastModified()) entries = reload(); } - // If the cache was not reloaded, then return the previously discovered - // entries. + // If the cache was not reloaded, then return the previously discovered entries. if (entries == null) - return super.getSettingEntries(config, rc, languageId); + return super.getSettingEntries(configDesc, rc, languageId); // Otherwise store, persist, and return the newly discovered values. - setSettingEntries(config, rc, languageId, entries); + setSettingEntries(configDesc, rc, languageId, entries); serializeLanguageSettingsInBackground(null); return entries; } @@ -169,10 +170,8 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { parentElement.setAttribute(ATTR_QT_INSTALL_HEADERS, qtInstallHeadersPath); parentElement.setAttribute(ATTR_QT_INSTALL_HEADERS_MOD, Long.toString(qtInstallHeadersModTime)); - // The parent implementation tries to create a new child node (provider) - // that is used - // as the part for later entries. This isn't needed in this case, we - // just want to + // The parent implementation tries to create a new child node (provider) that is used + // as the part for later entries. This isn't needed in this case, we just want to // use the part that serializes the languages. return parentElement; } @@ -183,26 +182,25 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { qtInstallHeadersPath = element.getAttribute(ATTR_QT_INSTALL_HEADERS); qtInstallHeadersModTime = getLongAttribute(element, ATTR_QT_INSTALL_HEADERS_MOD); - // The parent implementation tries to create a new child node (provider) - // that is used - // as the part for later entries. This isn't needed in this case, we - // just want to + // The parent implementation tries to create a new child node (provider) that is used + // as the part for later entries. This isn't needed in this case, we just want to // use the part that serializes the languages. } /** - * Parse and return the given attribute as a long. Return 0 if the attribute - * does not have a valid value. + * Parse and return the given attribute as a long. Return 0 if the attribute does + * not have a valid value. */ private static long getLongAttribute(Element element, String attr) { String value = element.getAttribute(attr); - if (value == null || value.isEmpty()) + if (value == null + || value.isEmpty()) return 0; try { return Long.parseLong(value); - } catch (NumberFormatException e) { - Activator.log("attribute name:" + attr + " value:" + value, e); //$NON-NLS-1$ //$NON-NLS-2$ + } catch(NumberFormatException e) { + Activator.log("attribute name:" + attr + " value:" + value, e); return 0; } } @@ -211,34 +209,33 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { * Reload and return the entries if possible, return null otherwise. */ private List<ICLanguageSettingEntry> reload() { - // All keys are reset and then updated as their values are discovered. - // This allows partial + // All keys are reset and then updated as their values are discovered. This allows partial // success to skip over previously calculated values. qmakeModTime = 0; qtInstallHeadersPath = null; qtInstallHeadersModTime = 0; File qmake = new File(qmakePath); - if (!qmake.exists() || !qmake.canExecute()) + if (!qmake.exists() + || !qmake.canExecute()) return Collections.emptyList(); qmakeModTime = qmake.lastModified(); - // Run `qmake -query QT_INSTALL_HEADERS` to get output like - // "/opt/qt-5.0.0/include". + // Run `qmake -query QT_INSTALL_HEADERS` to get output like "/opt/qt-5.0.0/include". BufferedReader reader = null; Process process = null; try { - process = ProcessFactory.getFactory().exec(new String[] { qmakePath, "-query", "QT_INSTALL_HEADERS" }); //$NON-NLS-1$ //$NON-NLS-2$ + process = ProcessFactory.getFactory().exec(new String[]{ qmakePath, "-query", "QT_INSTALL_HEADERS" }); reader = new BufferedReader(new InputStreamReader(process.getInputStream())); qtInstallHeadersPath = reader.readLine(); - } catch (IOException e) { + } catch(IOException e) { Activator.log(e); } finally { try { if (reader != null) reader.close(); - } catch (IOException e) { + } catch(IOException e) { /* ignore */ } finally { if (process != null) @@ -252,11 +249,12 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { File qtInstallHeadersDir = new File(qtInstallHeadersPath); qtInstallHeadersModTime = qtInstallHeadersDir.lastModified(); - if (!qtInstallHeadersDir.exists() || !qtInstallHeadersDir.canRead() || !qtInstallHeadersDir.isDirectory()) + if (!qtInstallHeadersDir.exists() + || !qtInstallHeadersDir.canRead() + || !qtInstallHeadersDir.isDirectory()) return Collections.emptyList(); - // Create an include path entry for all sub-folders in the - // QT_INSTALL_HEADERS location, including + // Create an include path entry for all sub-folders in the QT_INSTALL_HEADERS location, including // the QT_INSTALL_HEADERS folder itself. File[] files = qtInstallHeadersDir.listFiles(new FileFilter() { @Override @@ -267,7 +265,7 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>(files.length + 1); safeAdd(entries, qtInstallHeadersDir); - for (File file : files) + for(File file : files) safeAdd(entries, file); return entries; @@ -275,9 +273,8 @@ public class QtIncludePaths extends LanguageSettingsSerializableProvider { private static void safeAdd(List<ICLanguageSettingEntry> entries, File file) { try { - entries.add( - new CIncludePathEntry(file.getCanonicalPath(), ICSettingEntry.READONLY | ICSettingEntry.RESOLVED)); - } catch (IOException e) { + entries.add(new CIncludePathEntry(file.getCanonicalPath(), ICSettingEntry.READONLY | ICSettingEntry.RESOLVED)); + } catch(IOException e) { Activator.log(e); } } diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePathsProvider.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePathsProvider.java index c9f1e63e8ea..fa832c66d79 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePathsProvider.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtIncludePathsProvider.java @@ -16,7 +16,6 @@ import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.core.resources.IBuildConfiguration; import org.eclipse.core.resources.IResource; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -25,8 +24,8 @@ import org.w3c.dom.NodeList; /** * This provider uses persistent cache to store the include paths for different - * Qt installations. A Qt installation is uniquely identified by the path to the - * qmake binary within the installation. + * Qt installations. A Qt installation is uniquely identified by the path to + * the qmake binary within the installation. * <p> * This result is shared among all Build Configurations that use the provider * with the same value for the QMAKE environment variable. @@ -34,19 +33,17 @@ import org.w3c.dom.NodeList; public class QtIncludePathsProvider extends LanguageSettingsSerializableProvider { /** - * The provider identifies Qt installations by the absolute path to the - * qmake binary. The include paths relevant to the installations are - * computed and persisted in {@link QtIncludePaths}. + * The provider identifies Qt installations by the absolute path to the qmake binary. The + * include paths relevant to the installations are computed and persisted in {@link QtIncludePaths}. */ private final Map<String, QtIncludePaths> qtInstallHeaders = new HashMap<String, QtIncludePaths>(); /** - * The build configuration stores the path to the qmake binary as an - * environment variable. + * The build configuration stores the path to the qmake binary as an environment variable. */ - private static final String ENVVAR_QMAKE = "QMAKE"; //$NON-NLS-1$ + private static final String ENVVAR_QMAKE = "QMAKE"; - private static final String ELEMENT_QMAKE = "qmake"; //$NON-NLS-1$ + private static final String ELEMENT_QMAKE = "qmake"; @Override public boolean equals(Object obj) { @@ -71,19 +68,17 @@ public class QtIncludePathsProvider extends LanguageSettingsSerializableProvider public void loadEntries(Element providerNode) { super.loadEntries(providerNode); - // Find and load all qmake child nodes. There will be one node for each - // Qt - // installation that has been used. Qt installations that are no longer - // valid - // are not loaded. This means they will be removed from the file the - // next time + // Find and load all qmake child nodes. There will be one node for each Qt + // installation that has been used. Qt installations that are no longer valid + // are not loaded. This means they will be removed from the file the next time // that the language setting providers are serialized. NodeList children = providerNode.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node child = children.item(i); if (ELEMENT_QMAKE.equals(child.getNodeName())) { QtIncludePaths qtIncludePaths = QtIncludePaths.loadFrom(child); - if (qtIncludePaths != null && qtIncludePaths.isValid()) + if (qtIncludePaths != null + && qtIncludePaths.isValid()) qtInstallHeaders.put(qtIncludePaths.getQMakePath(), qtIncludePaths); } } @@ -91,17 +86,14 @@ public class QtIncludePathsProvider extends LanguageSettingsSerializableProvider @Override public void serializeEntries(Element parent) { - // NOTE: This creates its own XML structure where children of the - // provider node are qmake nodes. - // Within each qmake node is a list of include paths for that - // installation. Calling the - // base #serializeEntries here would try to write this instance's - // (empty) list of settings - // to the file. + // NOTE: This creates its own XML structure where children of the provider node are qmake nodes. + // Within each qmake node is a list of include paths for that installation. Calling the + // base #serializeEntries here would try to write this instance's (empty) list of settings + // to the file. // Each value is serialized into a new element in the XML document. - Document document = parent instanceof Document ? (Document) parent : parent.getOwnerDocument(); - for (QtIncludePaths qtIncludePaths : qtInstallHeaders.values()) { + Document document = parent instanceof Document ? (Document)parent : parent.getOwnerDocument(); + for(QtIncludePaths qtIncludePaths : qtInstallHeaders.values()) { Element child = document.createElement(ELEMENT_QMAKE); qtIncludePaths.serialize(child); parent.appendChild(child); @@ -109,24 +101,19 @@ public class QtIncludePathsProvider extends LanguageSettingsSerializableProvider } /** - * The given build configuration's QMAKE environment variable is used to - * identify the appropriate Qt installation. The language settings are then - * either returned from the previously persisted data or loaded, serialized, - * and returned. + * The given build configuration's QMAKE environment variable is used to identify the appropriate + * Qt installation. The language settings are then either returned from the previously persisted + * data or loaded, serialized, and returned. */ @Override - public synchronized List<ICLanguageSettingEntry> getSettingEntries(IBuildConfiguration config, IResource rc, - String languageId) { + public synchronized List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription configDesc, IResource rc, String languageId) { // Make sure the requested language is in scope for this provider. if (!getLanguageScope().contains(languageId)) return null; - // The value of the build configuration's QMAKE environment variable is - // used to select the + // The value of the build configuration's QMAKE environment variable is used to select the // right version of qmake. - ICConfigurationDescription configDesc = config.getAdapter(ICConfigurationDescription.class); - IEnvironmentVariable qmake_var = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENVVAR_QMAKE, - configDesc, true); + IEnvironmentVariable qmake_var = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENVVAR_QMAKE, configDesc, true); if (qmake_var == null) return null; @@ -134,14 +121,13 @@ public class QtIncludePathsProvider extends LanguageSettingsSerializableProvider if (qmake == null) return null; - // The path to qmake is used as the key into the in-memory cache of - // header paths. + // The path to qmake is used as the key into the in-memory cache of header paths. QtIncludePaths paths = qtInstallHeaders.get(qmake); if (paths == null) { paths = new QtIncludePaths(qmake); qtInstallHeaders.put(qmake, paths); } - return paths.getSettingEntries(config, null, languageId); + return paths.getSettingEntries(configDesc, null, languageId); } } |