private File createWindowsGitSSH(File key, String user) throws IOException { File ssh = createTempFile("ssh", ".bat"); File sshexe = getSSHExecutable(); try (PrintWriter w = new PrintWriter(ssh, encoding)) { w.println("@echo off"); w.println("\"" + sshexe.getAbsolutePath() + "\" -i \"" + key.getAbsolutePath() +"\" -l \"" + user + "\" -o StrictHostKeyChecking=no %* "); } ssh.setExecutable(true, true); return ssh; }
private File createUsernameFile(StandardUsernamePasswordCredentials userPass) throws IOException { File usernameFile = createTempFile("username", ".txt"); try (PrintWriter w = new PrintWriter(usernameFile, "UTF-8")) { w.println(userPass.getUsername()); } return usernameFile; }
private File createUnixSshAskpass(SSHUserPrivateKey sshUser, @NonNull File passphrase) throws IOException { File ssh = createTempFile("pass", ".sh"); try (PrintWriter w = new PrintWriter(ssh, encoding)) { w.println("#!/bin/sh"); w.println("cat " + unixArgEncodeFileName(passphrase.getAbsolutePath())); } ssh.setExecutable(true, true); return ssh; }
private File createUnixStandardAskpass(StandardUsernamePasswordCredentials creds, File usernameFile, File passwordFile) throws IOException { File askpass = createTempFile("pass", ".sh"); try (PrintWriter w = new PrintWriter(askpass, encoding)) { w.println("#!/bin/sh"); w.println("case \"$1\" in"); w.println("Username*) cat " + unixArgEncodeFileName(usernameFile.getAbsolutePath()) + " ;;"); w.println("Password*) cat " + unixArgEncodeFileName(passwordFile.getAbsolutePath()) + " ;;"); w.println("esac"); } askpass.setExecutable(true, true); return askpass; }
private File createWindowsStandardAskpass(StandardUsernamePasswordCredentials creds, File usernameFile, File passwordFile) throws IOException { File askpass = createTempFile("pass", ".bat"); try (PrintWriter w = new PrintWriter(askpass, encoding)) { w.println("@set arg=%~1"); w.println("@if (%arg:~0,8%)==(Username) type " + windowsArgEncodeFileName(usernameFile.getAbsolutePath())); w.println("@if (%arg:~0,8%)==(Password) type " + windowsArgEncodeFileName(passwordFile.getAbsolutePath())); } askpass.setExecutable(true, true); return askpass; }
private File createPasswordFile(StandardUsernamePasswordCredentials userPass) throws IOException { File passwordFile = createTempFile("password", ".txt"); try (PrintWriter w = new PrintWriter(passwordFile, "UTF-8")) { w.println(Secret.toString(userPass.getPassword())); } return passwordFile; }
private File createPassphraseFile(SSHUserPrivateKey sshUser) throws IOException { File passphraseFile = createTempFile("phrase", ".txt"); try (PrintWriter w = new PrintWriter(passphraseFile, "UTF-8")) { w.println(Secret.toString(sshUser.getPassphrase())); } return passphraseFile; }
/** {@inheritDoc} */ public void commit(String message) throws GitException, InterruptedException { File f = null; try { f = createTempFile("gitcommit", ".txt"); try (OutputStream out = Files.newOutputStream(f.toPath())) { out.write(message.getBytes(Charset.defaultCharset().toString())); } launchCommand("commit", "-F", f.getAbsolutePath()); } catch (GitException | IOException e) { throw new GitException("Cannot commit " + message, e); } finally { deleteTempFile(f); } }
private void createNote(String note, String namespace, String command ) throws GitException, InterruptedException { File msg = null; try { msg = createTempFile("git-note", ".txt"); FileUtils.writeStringToFile(msg,note); launchCommand("notes", "--ref=" + namespace, command, "-F", msg.getAbsolutePath()); } catch (IOException | GitException e) { throw new GitException("Could not apply note " + note, e); } finally { deleteTempFile(msg); } }
private File createUnixGitSSH(File key, String user) throws IOException { File ssh = createTempFile("ssh", ".sh"); File ssh_copy = new File(ssh.toString() + "-copy"); boolean isCopied = false;
private File createSshKeyFile(SSHUserPrivateKey sshUser) throws IOException, InterruptedException { File key = createTempFile("ssh", ".key"); try (PrintWriter w = new PrintWriter(key, encoding)) { List<String> privateKeys = sshUser.getPrivateKeys(); for (String s : privateKeys) { w.println(s); } } if (launcher.isUnix()) { new FilePath(key).chmod(0400); } else { fixSshKeyOnWindows(key); } return key; }