Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorbjörn Svensson2020-06-30 10:16:18 +0000
committerAlexander Fedorov2020-07-08 09:07:57 +0000
commit46316a1b626fdfc280b0892c82d398cea465d397 (patch)
tree3debd4ba50f2f23d2dc6c542a70a555af0e76533 /qt/org.eclipse.cdt.qt.core/src
parent39d3bfcc4f08e67fe22cd6054a569cf4beba41fe (diff)
downloadorg.eclipse.cdt-46316a1b626fdfc280b0892c82d398cea465d397.tar.gz
org.eclipse.cdt-46316a1b626fdfc280b0892c82d398cea465d397.tar.xz
org.eclipse.cdt-46316a1b626fdfc280b0892c82d398cea465d397.zip
Throw an exception rather than return null on error
Switch to try-with-resources pattern Change-Id: I7bbb1a6faf0ba86e456f8a66776c3eda9b9144ed Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
Diffstat (limited to 'qt/org.eclipse.cdt.qt.core/src')
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java40
1 files changed, 20 insertions, 20 deletions
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java
index 326ab0785dd..bc2330b4f4c 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java
@@ -88,8 +88,11 @@ public final class QMakeInfo implements IQMakeInfo {
}
// run "qmake -query"
- Map<String, String> qmake1 = exec(PATTERN_QUERY_LINE, extraEnv, qmakePath, "-query"); //$NON-NLS-1$
- if (qmake1 == null) {
+ Map<String, String> qmake1;
+ try {
+ qmake1 = exec(PATTERN_QUERY_LINE, extraEnv, qmakePath, "-query"); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.log(e);
return INVALID;
}
@@ -98,9 +101,15 @@ public final class QMakeInfo implements IQMakeInfo {
// TODO - no support for pre-3.0
// for QMake version 3.0 or newer, run "qmake -E file.pro"
- Map<String, String> qmake2 = version != null && version.getMajor() >= 3
- ? exec(PATTERN_EVAL_LINE, extraEnv, qmakePath, "-E", proPath) //$NON-NLS-1$
- : Collections.<String, String>emptyMap();
+ Map<String, String> qmake2 = Collections.emptyMap();
+ if (version != null && version.getMajor() >= 3) {
+ try {
+ qmake2 = exec(PATTERN_EVAL_LINE, extraEnv, qmakePath, "-E", proPath); //$NON-NLS-1$
+ } catch (IOException e) {
+ Activator.log(e);
+ // Continue with an empty map.
+ }
+ }
return new QMakeInfo(true, qmake1, qmake2);
}
@@ -181,13 +190,12 @@ public final class QMakeInfo implements IQMakeInfo {
* @param extraEnv the extra environment for command
* @param cmd the command line
* @return the map of resolved key-value pairs
+ * @throws IOException If command execution failed
*/
- private static Map<String, String> exec(Pattern regex, String[] extraEnv, String... command) {
+ private static Map<String, String> exec(Pattern regex, String[] extraEnv, String... command) throws IOException {
if (command.length < 1 || !new File(command[0]).exists()) {
- Activator.log("qmake: cannot run command: " + (command.length > 0 ? command[0] : "")); //$NON-NLS-1$ //$NON-NLS-2$
- return null;
+ throw new IOException("qmake: cannot run command: " + (command.length > 0 ? command[0] : "")); //$NON-NLS-1$ //$NON-NLS-2$
}
- BufferedReader reader = null;
Process process = null;
try {
if (extraEnv != null && extraEnv.length > 0) {
@@ -195,18 +203,10 @@ public final class QMakeInfo implements IQMakeInfo {
} else {
process = ProcessFactory.getFactory().exec(command);
}
- reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
- return QMakeParser.parse(regex, reader);
- } catch (IOException e) {
- Activator.log(e);
- return null;
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+ return QMakeParser.parse(regex, reader);
+ }
} finally {
- if (reader != null)
- try {
- reader.close();
- } catch (IOException e) {
- /* ignore */
- }
if (process != null) {
process.destroy();
}

Back to the top