@Override public void setup(JenkinsRule jenkinsRule, EndToEndTfs recipe) throws Exception { final Description testDescription = jenkinsRule.getTestDescription(); final Class clazz = testDescription.getTestClass(); testClassName = clazz.getSimpleName(); testCaseName = testDescription.getMethodName(); final String hostName = IntegrationTestHelper.tryToDetermineHostName(); final File currentFolder = new File("").getAbsoluteFile(); final File workspaces = new File(currentFolder, "workspaces"); // TODO: Consider NOT using the Server class server = new Server(null, null, serverUrl, helper.getUserName(), helper.getUserPassword()); final MockableVersionControlClient vcc = server.getVersionControlClient(); // workspaceName MUST be unique across computers hitting the same server workspaceName = hostName + "-" + testCaseName; workspace = createWorkspace(vcc, workspaceName); pathInTfvc = IntegrationTestHelper.determinePathInTfvcForTestCase(testDescription); final File localTestClassFolder = new File(workspaces, testClassName); localBaseFolderFile = new File(localTestClassFolder, testCaseName); //noinspection ResultOfMethodCallIgnored localBaseFolderFile.mkdirs(); final String localBaseFolder = localBaseFolderFile.getAbsolutePath(); final WorkingFolder workingFolder = new WorkingFolder(pathInTfvc, localBaseFolder); workspace.createWorkingFolder(workingFolder); // TODO: Is this necessary if we're about to delete it, anyway? workspace.get(GetOptions.NONE); // Delete the folder associated with this test in TFVC workspace.pendDelete( new String[] {pathInTfvc}, RecursionType.FULL, LockLevel.UNCHANGED, GetOptions.NONE, PendChangesOptions.NONE); checkIn("Cleaning up for the " + testCaseName + " test."); // we don't need to verify this check-in, because a first run on a server will be a no-op // create the folder in TFVC workspace.pendAdd( new String[] {localBaseFolder}, false, null, LockLevel.UNCHANGED, GetOptions.NONE, PendChangesOptions.NONE); final int changeSet = checkIn("Setting up for the " + testCaseName + " test."); Assert.assertTrue(changeSet >= 0); final Class<? extends StubRunner> runnerClass = recipe.value(); if (runnerClass != null) { runner = runnerClass.newInstance(); runner.setParent(this); runner.setHelper(this.helper); runner.setup(jenkinsRule, recipe); } }
@Override public void decorateHome(final JenkinsRule jenkinsRule, final File home) throws Exception { final String jobFolder = parent.getJobFolder(); final String configXmlPath = jobFolder + "config.xml"; final File configXmlFile = new File(home, configXmlPath); final String tfsServerUrl = helper.getServerUrl(); XmlHelper.pokeValue(configXmlFile, "/project/scm/serverUrl", tfsServerUrl); final String projectPath = parent.getPathInTfvc(); XmlHelper.pokeValue(configXmlFile, "/project/scm/projectPath", projectPath); final String workspaceName = "Hudson-${JOB_NAME}-${COMPUTERNAME}"; XmlHelper.pokeValue(configXmlFile, "/project/scm/workspaceName", workspaceName); final String userName = helper.getUserName(); XmlHelper.pokeValue(configXmlFile, "/project/scm/userName", userName); final String userPassword = helper.getUserPassword(); final SecretOverride secretOverride = new SecretOverride(); try { final Secret secret = Secret.fromString(userPassword); encryptedPassword = secret.getEncryptedValue(); } finally { try { secretOverride.close(); } catch (IOException e) { // ignore } } final String projectScmPassword = "******"; final String currentPassword = XmlHelper.peekValue(configXmlFile, projectScmPassword); if (currentPassword != null) { XmlHelper.pokeValue(configXmlFile, projectScmPassword, encryptedPassword); } }