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 new file mode 100644 index 00000000000..155311b0291 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/DiffUtil.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007 Intel Corporation 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.testplugin; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; + +import org.eclipse.cdt.utils.spawner.ProcessFactory; + +public class DiffUtil { + private static final String DIFF_CMD = "diff -u"; + 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){ + StringBuffer buf = new StringBuffer(); + buf.append(DIFF_CMD).append(" ").append(location1).append(" ").append(location2); + return buf.toString(); + } + + public String diff(String location1, String location2){ + InputStream in = invokeDiff(location1, location2); + if(in == null) + return null; + + String charSet = null; + BufferedReader br; + if (null == charSet) { + br = new BufferedReader(new InputStreamReader(in)); + } else { + try { + br = new BufferedReader(new InputStreamReader(in, charSet)); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + } + String line; + String prev_key = null; // previous key read and saved in envVars + String prev_value = null; // value of previous key + StringBuffer buf = new StringBuffer(); + try { + while ((line = br.readLine()) != null) { + buf.append("\n"); + buf.append(line); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + return buf.toString(); + } + + private InputStream invokeDiff(String location1, String location2){ + try { + Process p = ProcessFactory.getFactory().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 0395688e7f7..7333b9496aa 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 @@ -391,7 +391,17 @@ public class ManagedBuildTestHelper { buffer.append("but was:\n "); buffer.append("\"").append(testBuffer).append("\""); buffer.append("\n\n "); - + + buffer.append(">>>>>>>>>>>>>>>start diff: \n"); + String location1 = getFileLocation(project, benchmarkFile); + String location2 = getFileLocation(project, testFile); + String diff = DiffUtil.getInstance().diff(location1, location2); + if(diff == null) + diff = "!diff failed!"; + buffer.append(diff); + buffer.append("\n<<<<<<<<<<