From 0fc24a0c786f17254dd998bb4962fa662234f162 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Tue, 18 Apr 2017 17:14:11 +0100 Subject: [PATCH] Bug 515374: Stop using user.home as a temporary directory in tests Change-Id: I20533ba4910ae9d691f51533183b4f475eaa5bbc --- .../core/tests/StandardBuildTestHelper.java | 102 ------------ .../testplugin/ManagedBuildTestHelper.java | 153 +++++++++--------- .../tests/ManagedProject21MakefileTests.java | 31 +++- .../tests/ManagedProject30MakefileTests.java | 33 +++- 4 files changed, 126 insertions(+), 193 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/core/tests/StandardBuildTestHelper.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/core/tests/StandardBuildTestHelper.java index c975f68bfb1..e4e5971e169 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/core/tests/StandardBuildTestHelper.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/core/tests/StandardBuildTestHelper.java @@ -177,106 +177,4 @@ public class StandardBuildTestHelper { } return buff; } - - static public IPath copyFilesToTempDir(IPath srcDir, IPath tmpSubDir, IPath[] files) { - IPath tmpSrcDir = null; - String userDirStr = System.getProperty("user.home"); - if (userDirStr != null) { - IPath userDir = Path.fromOSString(userDirStr); - tmpSrcDir = userDir.append(tmpSubDir); - if (userDir.toString().equalsIgnoreCase(tmpSrcDir.toString())) { - Assert.fail("Temporary sub-directory cannot be the empty string."); - } else { - File tmpSrcDirFile = tmpSrcDir.toFile(); - if (tmpSrcDirFile.exists()) { - // Make sure that this is the expected directory before we delete it... - if (tmpSrcDir.lastSegment().equals(tmpSubDir.lastSegment())) { - deleteDirectory(tmpSrcDirFile); - } else { - Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " already exists."); - } - } - boolean succeed = tmpSrcDirFile.mkdir(); - if (succeed) { - for (int i=0; i 1) { - IPath newDir = tmpSrcDir; - do { - IPath dir = file.uptoSegment(1); - newDir = newDir.append(dir); - file = file.removeFirstSegments(1); - succeed = newDir.toFile().mkdir(); - } while (file.segmentCount() > 1); - } - IPath destFile = tmpSrcDir.append(files[i]); - FileWriter writer = null; - try { - writer = new FileWriter(destFile.toFile()); - } catch (Exception e) { - Assert.fail("File " + files[i].toString() + " could not be written."); - } - try { - int c; - do { - c = srcReader.read(); - if (c == -1) break; - writer.write(c); - } while (c != -1); - srcReader.close(); - writer.close(); - } catch (Exception e) { - Assert.fail("File " + file.toString() + " could not be copied."); - } - } - } - } - } - return tmpSrcDir; - } - - static public void deleteTempDir(IPath tmpSubDir, IPath[] files) { - IPath tmpSrcDir = null; - String userDirStr = System.getProperty("user.home"); - if (userDirStr != null) { - IPath userDir = Path.fromOSString(userDirStr); - tmpSrcDir = userDir.append(tmpSubDir); - if (userDir.toString().equalsIgnoreCase(tmpSrcDir.toString())) { - Assert.fail("Temporary sub-directory cannot be the empty string."); - } else { - File tmpSrcDirFile = tmpSrcDir.toFile(); - if (!tmpSrcDirFile.exists()) { - Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " does not exist."); - } else { - for (int i=0; i 1) { - IPath newDir = tmpSrcDir; - do { - IPath dir = file.uptoSegment(1); - newDir = newDir.append(dir); - file = file.removeFirstSegments(1); - newDir.toFile().mkdir(); - if (!newDir.toFile().exists()) { - Assert.fail("Can't create temporary directory " + tmpSrcDirFile.toString()); - } - } while (file.segmentCount() > 1); - } - IPath destFile = tmpSrcDir.append(files[i]); - FileWriter writer = null; - try { - writer = new FileWriter(destFile.toFile()); - } catch (Exception e) { - Assert.fail("File " + files[i].toString() + " could not be written."); - return null; - } - try { - int c; - do { - c = srcReader.read(); - if (c == -1) break; - writer.write(c); - } while (c != -1); - srcReader.close(); - writer.close(); - } catch (Exception e) { - Assert.fail("File " + file.toString() + " could not be copied."); - } + if (file.segmentCount() > 1) { + IPath newDir = tmpSrcDir; + do { + IPath dir = file.uptoSegment(1); + newDir = newDir.append(dir); + file = file.removeFirstSegments(1); + newDir.toFile().mkdir(); + if (!newDir.toFile().exists()) { + Assert.fail("Can't create temporary directory " + tmpSrcDirFile.toString()); + } + } while (file.segmentCount() > 1); + } + IPath destFile = tmpSrcDir.append(files[i]); + FileWriter writer = null; + try { + writer = new FileWriter(destFile.toFile()); + } catch (Exception e) { + Assert.fail("File " + files[i].toString() + " could not be written."); + return null; + } + try { + int c; + do { + c = srcReader.read(); + if (c == -1) break; + writer.write(c); + } while (c != -1); + srcReader.close(); + writer.close(); + } catch (Exception e) { + Assert.fail("File " + file.toString() + " could not be copied."); } } } + IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); for (IFile rc : root.findFilesForLocation(tmpSrcDir)) { @@ -951,29 +948,28 @@ public class ManagedBuildTestHelper { return tmpSrcDir; } - static public void deleteTempDir(IPath tmpSubDir, IPath[] files) { + static public void deleteTempDir(IPath tmpRootDir, IPath tmpSubDir, IPath[] files) { IPath tmpSrcDir = null; - String userDirStr = System.getProperty("user.home"); - if (userDirStr != null) { - IPath userDir = Path.fromOSString(userDirStr); - tmpSrcDir = userDir.append(tmpSubDir); - if (userDir.toString().equalsIgnoreCase(tmpSrcDir.toString())) { - Assert.fail("Temporary sub-directory cannot be the empty string."); - } else { - File tmpSrcDirFile = tmpSrcDir.toFile(); - if (tmpSrcDirFile.exists()) { - for (int i=0; i