Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorTorbjörn SVENSSON2021-02-23 13:01:54 +0000
committerTorbjörn SVENSSON2021-02-23 13:02:59 +0000
commit7760ce2eb78b0993cd0e3c6b083b71c5e36e8c25 (patch)
tree75a0c8fd8e2ea74ac32d98c7702eff91eea39d0f /build
parentc809bde38113e637dd62f2b3227d3d0fda33a4f9 (diff)
downloadorg.eclipse.cdt-7760ce2eb78b0993cd0e3c6b083b71c5e36e8c25.tar.gz
org.eclipse.cdt-7760ce2eb78b0993cd0e3c6b083b71c5e36e8c25.tar.xz
org.eclipse.cdt-7760ce2eb78b0993cd0e3c6b083b71c5e36e8c25.zip
Properly invoke diff command during test
Contributed by STMicroelectronics Change-Id: Ic67a3331375cf0eb071d2b24e2c9716114aeb4dd Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/DiffUtil.java57
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java4
2 files changed, 17 insertions, 44 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/DiffUtil.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/DiffUtil.java
index 7c28815f94e..1e276b7839d 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/DiffUtil.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/DiffUtil.java
@@ -18,39 +18,23 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-public class DiffUtil {
- private static final String DIFF_CMD = "diff -ub";
- private static DiffUtil fInstance;
-
- private DiffUtil() {
-
- }
-
- public static DiffUtil getInstance() {
- if (fInstance == null)
- fInstance = new DiffUtil();
- return fInstance;
- }
-
- private static String createCommand(String location1, String location2) {
- StringBuilder buf = new StringBuilder();
- buf.append(DIFF_CMD).append(" '").append(location1).append("' '").append(location2).append("'");
- return buf.toString();
- }
-
- public String diff(String location1, String location2) {
- InputStream in = invokeDiff(location1, location2);
- if (in == null)
- return null;
-
- BufferedReader br;
- br = new BufferedReader(new InputStreamReader(in));
- String line;
+public abstract class DiffUtil {
+ public static String diff(String location1, String location2) {
StringBuilder buf = new StringBuilder();
try {
- while ((line = br.readLine()) != null) {
- buf.append("\n");
- buf.append(line);
+ String[] command = new String[] { "diff", "-ub", location1, location2 };
+ Process p = Runtime.getRuntime().exec(command);
+ InputStream in = p.getInputStream();
+ if (in == null) {
+ return null;
+ }
+
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ buf.append("\n");
+ buf.append(line);
+ }
}
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -59,15 +43,4 @@ public class DiffUtil {
}
return buf.toString();
}
-
- private InputStream invokeDiff(String location1, String location2) {
- try {
- Process p = Runtime.getRuntime().exec(createCommand(location1, location2));
- return p.getInputStream();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java
index 03036de452a..c6df3aa9b1f 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java
@@ -471,7 +471,7 @@ public class ManagedBuildTestHelper {
: getFileLocation(project, benchmarkFileLocation);
String location2 = testFileLocation.isAbsolute() ? testFileLocation.toString()
: getFileLocation(project, testFileLocation);
- String diff = DiffUtil.getInstance().diff(location1, location2);
+ String diff = DiffUtil.diff(location1, location2);
if (diff == null)
diff = "!diff failed!";
buffer.append(diff);
@@ -796,7 +796,7 @@ public class ManagedBuildTestHelper {
buffer.append(">>>>>>>>>>>>>>>start diff: \n");
String location1 = getFileLocation(bmFile.getProject(), bmFile.getProjectRelativePath());
String location2 = getFileLocation(tFile.getProject(), tFile.getProjectRelativePath());
- String diff = DiffUtil.getInstance().diff(location1, location2);
+ String diff = DiffUtil.diff(location1, location2);
if (diff == null)
diff = "!diff failed!";
buffer.append(diff);

Back to the top