From c9f9ee1bb9ce4cf3d8df9c4fecce949a3d1473d4 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 5 Nov 2014 16:02:51 -0500 Subject: [PATCH] Initial Standalone debugger SWTBot test - includes a launch configuration for launching directly from an Eclipse session Change-Id: I238e72894b739f827dd6efba3acef9d304771f0d --- .../.classpath | 7 + .../.project | 28 +++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 20 ++ .../StandaloneTests.launch | 45 ++++ .../about.html | 22 ++ .../build.properties | 16 ++ .../plugin.properties | 12 ++ .../pom.xml | 51 +++++ .../projects/hello/Makefile | 15 ++ .../projects/hello/hello.c | 13 ++ .../projects/hello/somehdr.h | 9 + .../projects/hello/x.c | 3 + .../cdt/debug/application/tests/AllTests.java | 23 ++ .../application/tests/StandaloneTest.java | 95 +++++++++ .../application/tests/StandaloneTest1.java | 139 ++++++++++++ .../debug/application/tests/Utilities.java | 200 ++++++++++++++++++ pom.xml | 1 + 18 files changed, 706 insertions(+) create mode 100644 debug/org.eclipse.cdt.debug.application.tests/.classpath create mode 100644 debug/org.eclipse.cdt.debug.application.tests/.project create mode 100644 debug/org.eclipse.cdt.debug.application.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 debug/org.eclipse.cdt.debug.application.tests/META-INF/MANIFEST.MF create mode 100644 debug/org.eclipse.cdt.debug.application.tests/StandaloneTests.launch create mode 100644 debug/org.eclipse.cdt.debug.application.tests/about.html create mode 100644 debug/org.eclipse.cdt.debug.application.tests/build.properties create mode 100644 debug/org.eclipse.cdt.debug.application.tests/plugin.properties create mode 100644 debug/org.eclipse.cdt.debug.application.tests/pom.xml create mode 100644 debug/org.eclipse.cdt.debug.application.tests/projects/hello/Makefile create mode 100644 debug/org.eclipse.cdt.debug.application.tests/projects/hello/hello.c create mode 100644 debug/org.eclipse.cdt.debug.application.tests/projects/hello/somehdr.h create mode 100644 debug/org.eclipse.cdt.debug.application.tests/projects/hello/x.c create mode 100644 debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/AllTests.java create mode 100644 debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest.java create mode 100644 debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest1.java create mode 100644 debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/Utilities.java diff --git a/debug/org.eclipse.cdt.debug.application.tests/.classpath b/debug/org.eclipse.cdt.debug.application.tests/.classpath new file mode 100644 index 00000000000..098194ca4b7 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.application.tests/.project b/debug/org.eclipse.cdt.debug.application.tests/.project new file mode 100644 index 00000000000..32ffe49348b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.debug.application.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/debug/org.eclipse.cdt.debug.application.tests/.settings/org.eclipse.jdt.core.prefs b/debug/org.eclipse.cdt.debug.application.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..f42de363afa --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/debug/org.eclipse.cdt.debug.application.tests/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.application.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..20d9ac817f5 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.cdt.debug.application.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %bundleVendor +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Require-Bundle: org.eclipse.cdt.debug.application, + org.eclipse.cdt.debug.application.doc, + org.eclipse.swtbot.eclipse.finder, + org.eclipse.swtbot.go, + org.eclipse.swtbot.junit4_x, + org.junit, + org.eclipse.cdt.core.native +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin +Import-Package: org.eclipse.cdt.utils.pty, + org.eclipse.core.resources, + org.eclipse.debug.core +Export-Package: org.eclipse.cdt.debug.application.tests;x-internal:=true diff --git a/debug/org.eclipse.cdt.debug.application.tests/StandaloneTests.launch b/debug/org.eclipse.cdt.debug.application.tests/StandaloneTests.launch new file mode 100644 index 00000000000..f4274983f9c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/StandaloneTests.launch @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.application.tests/about.html b/debug/org.eclipse.cdt.debug.application.tests/about.html new file mode 100644 index 00000000000..fcbffcd8b64 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

June 23, 2005

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

+ + + \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.application.tests/build.properties b/debug/org.eclipse.cdt.debug.application.tests/build.properties new file mode 100644 index 00000000000..4e3cb6cef5d --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/build.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2015 RedHat, Inc. 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: +# Red Hat Incorporated - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + about.html diff --git a/debug/org.eclipse.cdt.debug.application.tests/plugin.properties b/debug/org.eclipse.cdt.debug.application.tests/plugin.properties new file mode 100644 index 00000000000..057380fc6f1 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/plugin.properties @@ -0,0 +1,12 @@ +################################################################################# +# Copyright (c) 2015 Red Hat, Inc. +# 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: +# Red Hat Incorporated - initial API and implementation +################################################################################# +bundleName=C/C++ Stand-alone Debugger Tests +bundleVendor=Eclipse CDT diff --git a/debug/org.eclipse.cdt.debug.application.tests/pom.xml b/debug/org.eclipse.cdt.debug.application.tests/pom.xml new file mode 100644 index 00000000000..57132bc3d8b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.6.0-SNAPSHOT + ../../pom.xml + + + 1.0.0-SNAPSHOT + org.eclipse.cdt.debug.application.tests + eclipse-test-plugin + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + true + false + org.eclipse.cdt.debug.application.product + org.eclipse.cdt.debug.application.app + ${base.ui.test.vmargs} + + **/AllTests.* + + true + + + org.eclipse.platform.feature.group + p2-installable-unit + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.application.tests/projects/hello/Makefile b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/Makefile new file mode 100644 index 00000000000..942ade9b2da --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/Makefile @@ -0,0 +1,15 @@ +all: a.out + +CFLAGS=-I. -g3 -O2 -Djeff=2 + +a.out: hello.o x.o + gcc -g -o a.out $? + +hello.o: hello.c somehdr.h + gcc -c $(CFLAGS) hello.c + +x.o: x.c + gcc -c $(CFLAGS) $< + +clean: + rm *.o *.out diff --git a/debug/org.eclipse.cdt.debug.application.tests/projects/hello/hello.c b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/hello.c new file mode 100644 index 00000000000..1579168aca0 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/hello.c @@ -0,0 +1,13 @@ +#include +#include "somehdr.h" + +int main(int argc, char **argv) { + int k = SOME_VALUE; /* comment */ + int j = x(k); + int i; + for (i = 0; i < argc; ++i) { + printf("argv %d is %s\n", i, argv[i]); + } + printf ("hello world %d\n", j); + return 0; +} diff --git a/debug/org.eclipse.cdt.debug.application.tests/projects/hello/somehdr.h b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/somehdr.h new file mode 100644 index 00000000000..511fd8418f6 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/somehdr.h @@ -0,0 +1,9 @@ +#ifndef _SOMEHDR_H +#define _SOMEHDR_H +#ifdef jeff +#define SOME_VALUE 6 +#else +#define SOME_VALUE 8 +#endif +extern int x(int); +#endif diff --git a/debug/org.eclipse.cdt.debug.application.tests/projects/hello/x.c b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/x.c new file mode 100644 index 00000000000..d3776e46aaa --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/projects/hello/x.c @@ -0,0 +1,3 @@ +int x(int y) { + return y * 7; +} diff --git a/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/AllTests.java b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/AllTests.java new file mode 100644 index 00000000000..4ed3d36c58f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/AllTests.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2015 Red Hat, Inc. + * 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: + * Red Hat Incorporated - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.application.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + StandaloneTest1.class, +}) + +public class AllTests { + +} diff --git a/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest.java b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest.java new file mode 100644 index 00000000000..23544ac16b8 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2015 Red Hat, Inc. + * 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: + * Red Hat Incorporated - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.application.tests; + +import static org.junit.Assert.assertNotNull; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.junit.After; + +public abstract class StandaloneTest { + + protected static SWTBot bot; + protected static String projectName; + protected static SWTBotShell mainShell; + protected static SWTBotView projectExplorer; + + public static void init(String projectName) throws Exception { + SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; + + Utilities.getDefault().buildProject(projectName); + bot = new SWTBot(); + + SWTBotShell executableShell = null; + for (int i = 0, attempts = 100; i < attempts; i++) { + for (SWTBotShell shell : bot.shells()) { + if (shell.getText().contains("Debug New Executable")) { + executableShell = shell; + shell.setFocus(); + break; + } + } + if (executableShell != null) + break; + bot.sleep(10); + } + + IPath executablePath = Utilities.getDefault().getProjectPath(projectName).append("a.out"); // $NON-NLS-1$ + + executableShell.bot().textWithLabel("Binary: ").typeText(executablePath.toOSString()); + bot.sleep(2000); + + executableShell.bot().button("OK").click(); + + mainShell = null; + for (int i = 0, attempts = 100; i < attempts; i++) { + for (SWTBotShell shell : bot.shells()) { + if (shell.getText().contains("C/C++ Stand-alone Debugger")) { + mainShell = shell; + shell.setFocus(); + break; + } + } + if (mainShell != null) + break; + bot.sleep(10); + } + assertNotNull(mainShell); + } + + @After + public void cleanUp() { + // SWTBotShell[] shells = bot.shells(); + // for (final SWTBotShell shell : shells) { + // if (!shell.equals(mainShell)) { + // String shellTitle = shell.getText(); + // if (shellTitle.length() > 0 + // && !shellTitle.startsWith("Quick Access")) { + // UIThreadRunnable.syncExec(new VoidResult() { + // @Override + // public void run() { + // if (shell.widget.getParent() != null + // && !shell.isOpen()) { + // shell.close(); + // } + // } + // }); + // } + // } + // } + // mainShell.activate(); + } + +} diff --git a/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest1.java b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest1.java new file mode 100644 index 00000000000..988a349d413 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/StandaloneTest1.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2015 Red Hat, Inc. + * 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: + * Red Hat Incorporated - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.application.tests; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(SWTBotJunit4ClassRunner.class) +public class StandaloneTest1 extends StandaloneTest { + + private static final String PROJECT_NAME = "hello"; + + @BeforeClass + public static void beforeClass() throws Exception { + init(PROJECT_NAME); + } + + @Test + public void Test1() throws Exception { + // Verify the top-level menus are there + SWTBotMenu fileMenu = bot.menu("File"); + assertNotNull(fileMenu); + SWTBotMenu editMenu = bot.menu("Edit"); + assertNotNull(editMenu); + SWTBotMenu searchMenu = bot.menu("Search"); + assertNotNull(searchMenu); + SWTBotMenu runMenu = bot.menu("Run"); + assertNotNull(runMenu); + SWTBotMenu windowMenu = bot.menu("Window"); + assertNotNull(windowMenu); + SWTBotMenu helpMenu = bot.menu("Help"); + assertNotNull(helpMenu); + + // Verify other common top-level menus are not there + SWTBotMenu notThere = null; + try { + notThere = bot.menu("Navigate"); + } catch (WidgetNotFoundException e) { + // correct + } + assertNull(notThere); + try { + notThere = bot.menu("Refactor"); + } catch (WidgetNotFoundException e) { + // correct + } + assertNull(notThere); + try { + notThere = bot.menu("Source"); + } catch (WidgetNotFoundException e) { + // correct + } + assertNull(notThere); + try { + notThere = bot.menu("Target"); + } catch (WidgetNotFoundException e) { + // correct + } + assertNull(notThere); + try { + // We want to prove there isn't a top-level Project menu + // There happens to be a lower-level Project menu from the Text menu + // Verify we find it, but no other menus named Project + SWTBotMenu textMenu = bot.menu("Text"); + @SuppressWarnings("unused") + SWTBotMenu projectMenu = textMenu.menu("Project"); + notThere = bot.menu("Project", 1); + } catch (IndexOutOfBoundsException e) { + // correct + } + assertNull(notThere); + + SWTBotMenu attachExecutableDialog = fileMenu.menu("Debug Attached Executable..."); + assertNotNull(attachExecutableDialog); + SWTBotMenu coreFileDialog = fileMenu.menu("Debug Core File..."); + assertNotNull(coreFileDialog); + SWTBotMenu newExecutableDialog = fileMenu.menu("Debug New Executable..."); + assertNotNull(newExecutableDialog); + newExecutableDialog.click(); + SWTBotShell shell = bot.shell("Debug New Executable"); + shell.setFocus(); + // Try and have two open debug sessions on same binary + IPath projectPath = Utilities.getDefault().getProjectPath(PROJECT_NAME).append("a.out"); + shell.bot().textWithLabel("Binary: ").setText(projectPath.toOSString()); + shell.bot().textWithLabel("Arguments: ").setText("1 2 3"); + bot.sleep(2000); + + bot.button("OK").click(); + + bot.sleep(1000); + + coreFileDialog.click(); + + shell = bot.shell("Debug Core File"); + shell.setFocus(); + + SWTBotText text = shell.bot().textWithLabel("Binary: "); + assertNotNull(text); + + SWTBotText corefile = shell.bot().textWithLabel("Core File Path:"); + assertNotNull(corefile); + + bot.sleep(2000); + + bot.button("Cancel").click(); + + bot.sleep(2000); + + SWTBotMenu exitMenu = fileMenu.menu("Exit"); + assertNotNull(exitMenu); + exitMenu.click(); + } + + @AfterClass + public static void afterClass() { + bot.sleep(1000); + } + + +} diff --git a/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/Utilities.java b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/Utilities.java new file mode 100644 index 00000000000..78bccaf62e8 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application.tests/src/org/eclipse/cdt/debug/application/tests/Utilities.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2015 Red Hat, Inc. + * 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: + * Red Hat Incorporated - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.application.tests; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.utils.pty.PTY; +import org.eclipse.cdt.utils.spawner.ProcessFactory; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.DebugPlugin; + +public class Utilities { + + private static Utilities instance; + + private Utilities() { + } + + public static Utilities getDefault() { + if (instance == null) + instance = new Utilities(); + return instance; + } + + public IPath getProjectPath (String name) { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IPath rootLocation = root.getLocation(); + + IPath destProjectDirPath = rootLocation.append(name); + + return destProjectDirPath; + } + + public boolean buildProject (String name) { + File destProjectDir = getProjectPath(name).toFile(); + + String resourceDirPath = "/projects/" + name; //$NON-NLS-1$ + try { + String path = FileLocator.toFileURL( + this.getClass().getResource(resourceDirPath)).getPath(); + + File projectDir = new Path(path).toFile(); + copy(projectDir, destProjectDir); + + Process process = execute(new String[]{"make","all","2>&1"}, null, destProjectDir, false); + + boolean done = false; + while (!done) { + try { + process.exitValue(); + done = true; + byte b[] = new byte[1000]; + int numread = 0; + InputStream stream = process.getInputStream(); + do { + numread = stream.read(b); + String x = new String(b); + System.out.print(x); + } while (numread >= 0); + } catch (IllegalThreadStateException e) { + try { + Thread.sleep(100); + } catch (InterruptedException e1) { + } + } + } + process.destroy(); + process = execute(new String[]{"ls","-l"}, null, destProjectDir, false); + + done = false; + while (!done) { + try { + process.exitValue(); + done = true; + byte b[] = new byte[1000]; + int numread = 0; + while (numread >= 0) { + numread = process.getInputStream().read(b); + String x = new String(b); + System.out.println(x); + } + } catch (IllegalThreadStateException e) { + try { + Thread.sleep(100); + } catch (InterruptedException e1) { + } + } + } + process.destroy(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + public boolean cleanProject (String name) { + IPath destProjectDirPath = getProjectPath(name); + File destProjectDir = destProjectDirPath.toFile(); + + try { + + Process process = execute(new String[]{"make","clean"}, null, destProjectDir, false); + + boolean done = false; + while (!done) { + try { + process.exitValue(); + done = true; + byte b[] = new byte[1000]; + process.getInputStream().read(b); + System.out.println(b); + } catch (IllegalThreadStateException e) { + try { + Thread.sleep(100); + } catch (InterruptedException e1) { + } + } + } + process.destroy(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + public static Process execute(String[] commandArray, String[] env, File wd, boolean usePty) throws IOException { + Process process = null; + if (env == null) { + Map envMap = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment(); + env = new String[envMap.size()]; + int i = 0; + for (Entry entry : envMap.entrySet()) { + env[i++] = entry.getKey() + "=" + entry.getValue(); + } + } + try { + process = startProcess(commandArray, env, wd, false); + return process; + } catch (IOException e) { + throw e; + } + } + + private static Process startProcess(String[] commandArray, String[] envp, File workDir, boolean usePty) throws IOException { + if (workDir == null) { + return ProcessFactory.getFactory().exec(commandArray, envp); + } + if (PTY.isSupported() && usePty) { + return ProcessFactory.getFactory().exec(commandArray, envp, workDir, new PTY()); + } else { + return ProcessFactory.getFactory().exec(commandArray, envp, workDir); + } + } + + public static void copy (File src, File dest) + throws IOException { + + if (src.isDirectory()) { + + // ensure destination directory exists + if (!dest.exists()){ + dest.mkdir(); + } + + // copy all children files recursively + String files[] = src.list(); + + for (String file : files) { + File srcFile = new File(src, file); + File destFile = new File(dest, file); + copy(srcFile, destFile); + } + + } else { // is a file, manually copy the contents over + Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + } +} diff --git a/pom.xml b/pom.xml index d4d956199a1..89468b2d169 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,7 @@ debug/org.eclipse.cdt.debug.application.doc debug/org.eclipse.cdt.debug.standalone-feature debug/org.eclipse.cdt.debug.standalone.source-feature + debug/org.eclipse.cdt.debug.application.tests dsf-gdb/org.eclipse.cdt.dsf.gdb dsf-gdb/org.eclipse.cdt.dsf.gdb.ui