Java Code Examples for hudson.util.ArgumentListBuilder#add()
The following examples show how to use
hudson.util.ArgumentListBuilder#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Deprecated @Override public void push(RemoteConfig repository, String refspec) throws GitException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder(); URIish uri = repository.getURIs().get(0); String url = uri.toPrivateString(); StandardCredentials cred = credentials.get(url); if (cred == null) cred = defaultCredentials; args.add("push"); addCheckedRemoteUrl(args, url); if (refspec != null) args.add(refspec); launchCommandWithCredentials(args, workspace, cred, uri); // Ignore output for now as there's many different formats // That are possible. }
Example 2
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public Map<String, ObjectId> getHeadRev(String url) throws GitException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder("ls-remote"); args.add("-h"); addCheckedRemoteUrl(args, url); StandardCredentials cred = credentials.get(url); if (cred == null) cred = defaultCredentials; String result = launchCommandWithCredentials(args, null, cred, url); Map<String, ObjectId> heads = new HashMap<>(); String[] lines = result.split("\n"); for (String line : lines) { if (line.length() >= 41) { heads.put(line.substring(41), ObjectId.fromString(line.substring(0, 40))); } else { listener.getLogger().println("Unexpected ls-remote output line '" + line + "'"); } } return heads; }
Example 3
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public Set<String> getTagNames(String tagPattern) throws GitException { try { ArgumentListBuilder args = new ArgumentListBuilder(); args.add("tag", "-l", tagPattern); String result = launchCommandIn(args, workspace); Set<String> tags = new HashSet<>(); BufferedReader rdr = new BufferedReader(new StringReader(result)); String tag; while ((tag = rdr.readLine()) != null) { // Add the SHA1 tags.add(tag); } return tags; } catch (GitException | IOException | InterruptedException e) { throw new GitException("Error retrieving tag names", e); } }
Example 4
Source File: AbstractAnsibleInvocation.java From ansible-plugin with Apache License 2.0 | 6 votes |
protected ArgumentListBuilder appendCredentials(ArgumentListBuilder args) throws IOException, InterruptedException { if (credentials instanceof SSHUserPrivateKey) { SSHUserPrivateKey privateKeyCredentials = (SSHUserPrivateKey)credentials; key = Utils.createSshKeyFile(key, ws, privateKeyCredentials, copyCredentialsInWorkspace); args.add("--private-key").add(key); args.add("-u").add(privateKeyCredentials.getUsername()); if (privateKeyCredentials.getPassphrase() != null) { script = Utils.createSshAskPassFile(script, ws, privateKeyCredentials, copyCredentialsInWorkspace); environment.put("SSH_ASKPASS", script.getRemote()); // inspired from https://github.com/jenkinsci/git-client-plugin/pull/168 // but does not work with MacOSX if (! environment.containsKey("DISPLAY")) { environment.put("DISPLAY", ":123.456"); } } } else if (credentials instanceof UsernamePasswordCredentials) { args.add("-u").add(credentials.getUsername()); args.add("-k"); } return args; }
Example 5
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public List<String> showRevision(ObjectId from, ObjectId to, Boolean useRawOutput) throws GitException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder("log", "--full-history", "--no-abbrev", "--format=raw", "-M", "-m"); if (useRawOutput) { args.add("--raw"); } if (from != null){ args.add(from.name() + ".." + to.name()); } else { args.add("-1", to.name()); } StringWriter writer = new StringWriter(); writer.write(launchCommand(args)); return new ArrayList<>(Arrays.asList(writer.toString().split("\\n"))); }
Example 6
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public void reset(boolean hard) throws GitException, InterruptedException { try { validateRevision("HEAD"); } catch (GitException e) { listener.getLogger().println("No valid HEAD. Skipping the resetting"); return; } listener.getLogger().println("Resetting working tree"); ArgumentListBuilder args = new ArgumentListBuilder(); args.add("reset"); if (hard) { args.add("--hard"); } launchCommand(args); }
Example 7
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 5 votes |
/** {@inheritDoc} */ @Override public void fetch(String remoteName, RefSpec... refspec) throws GitException, InterruptedException { listener.getLogger().println( "Fetching upstream changes" + (remoteName != null ? " from " + remoteName : "")); ArgumentListBuilder args = new ArgumentListBuilder(); args.add("fetch", "-t"); if (USE_FORCE_FETCH && isAtLeastVersion(2, 20, 0, 0)) { /* CLI git 2.20.0 fixed a long-standing bug that now requires --force to update existing tags */ args.add("--force"); } if (remoteName == null) remoteName = getDefaultRemote(); String url = getRemoteUrl(remoteName); if (url == null) throw new GitException("remote." + remoteName + ".url not defined"); addCheckedRemoteUrl(args, url); if (refspec != null && refspec.length > 0) for (RefSpec rs: refspec) if (rs != null) args.add(rs.toString()); StandardCredentials cred = credentials.get(url); if (cred == null) cred = defaultCredentials; launchCommandWithCredentials(args, workspace, cred, url); }
Example 8
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 5 votes |
/** * {@inheritDoc} * * Cleans submodules */ @Override public void submoduleClean(boolean recursive) throws GitException, InterruptedException { submoduleReset(true, true); ArgumentListBuilder args = new ArgumentListBuilder(); args.add("submodule", "foreach"); if (recursive) { args.add("--recursive"); } args.add("git clean -fdx"); launchCommand(args); }
Example 9
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 5 votes |
/** * Reset submodules * * @param recursive if true, will recursively reset submodules (requres git>=1.6.5) * @param hard if true, the --hard argument will be passed to submodule reset * @throws hudson.plugins.git.GitException if executing the git command fails * @throws java.lang.InterruptedException if git command interrupted */ public void submoduleReset(boolean recursive, boolean hard) throws GitException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder(); args.add("submodule", "foreach"); if (recursive) { args.add("--recursive"); } args.add("git reset" + (hard ? " --hard" : "")); launchCommand(args); }
Example 10
Source File: WindowsDockerClient.java From docker-workflow-plugin with MIT License | 5 votes |
@Override public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String, String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException { ArgumentListBuilder argb = new ArgumentListBuilder("docker", "run", "-d", "-t"); if (args != null) { argb.addTokenized(args); } if (workdir != null) { argb.add("-w", workdir); } for (Map.Entry<String, String> volume : volumes.entrySet()) { argb.add("-v", volume.getKey() + ":" + volume.getValue()); } for (String containerId : volumesFromContainers) { argb.add("--volumes-from", containerId); } for (Map.Entry<String, String> variable : containerEnv.entrySet()) { argb.add("-e"); argb.addMasked(variable.getKey()+"="+variable.getValue()); } argb.add(image).add(command); LaunchResult result = launch(launchEnv, false, null, argb); if (result.getStatus() == 0) { return result.getOut(); } else { throw new IOException(String.format("Failed to run image '%s'. Error: %s", image, result.getErr())); } }
Example 11
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 5 votes |
/** * SECURITY-1534 found that arguments * added to a git URL from the user interface can allow a user * with job creation permissions to execute an arbitrary program * on the git server if the git server is configured to allow * custom pack programs. Reject a URL if it includes invalid * content. */ private void addCheckedRemoteUrl(@NonNull ArgumentListBuilder args, @NonNull String url) { String trimmedUrl = url.trim(); /* Don't check for invalid args if URL starts with known good cases. * Known good cases include: * '/' - Unix local file * 'C:' - Windows local file * 'file:', 'git:', 'http:', 'https:', 'ssh:', and 'git@' - known protocols */ if (CHECK_REMOTE_URL && !trimmedUrl.startsWith("/") && !trimmedUrl.startsWith("\\\\") && !trimmedUrl.startsWith("file:") && !trimmedUrl.startsWith("git:") && !trimmedUrl.startsWith("git@") && !trimmedUrl.startsWith("http:") && !trimmedUrl.startsWith("https:") && !trimmedUrl.startsWith("ssh:") && !trimmedUrl.matches("^[A-Za-z]:.+")) { /* Not one of the known good cases, check if this could be a bad case * Bad cases include: * '-' - starts with 'dash' as possible argument * '`' - includes backquote in the string (command execution) * ' ' - includes a space (not guaranteed a threat, but threat risk increases) */ if (trimmedUrl.startsWith("-") || trimmedUrl.contains("`") || trimmedUrl.contains("--upload-pack=") || trimmedUrl.matches(".*\\s+.*")) { throw new GitException("Invalid remote URL: " + url); } } // Mark the end of options for git versions that support it. // Tells command line git that later arguments are operands, not options. // See POSIX 1-2017 guideline 10. if (isAtLeastVersion(2, 8, 0, 0)) { args.add("--"); // SECURITY-1534 - end of options, causes tests to fail with git 2.7.4 and older } args.add(trimmedUrl); }
Example 12
Source File: ArcanistClient.java From phabricator-jenkins-plugin with MIT License | 5 votes |
private ArgumentListBuilder getConduitCommand() { ArgumentListBuilder builder = new ArgumentListBuilder(this.arcPath, this.methodName); builder.add(arguments); if (!CommonUtils.isBlank(this.conduitUrl)) { builder.add("--conduit-uri=" + this.conduitUrl); } if (!CommonUtils.isBlank(this.conduitToken)) { builder.addMasked("--conduit-token=" + this.conduitToken); } return builder; }
Example 13
Source File: AbstractAnsibleInvocation.java From ansible-plugin with Apache License 2.0 | 5 votes |
protected ArgumentListBuilder appendSudo(ArgumentListBuilder args) { if (sudo) { args.add("-s"); if (StringUtils.isNotBlank(sudoUser)) { args.add("-U").add(envVars.expand(sudoUser)); } } return args; }
Example 14
Source File: DockerClient.java From docker-workflow-plugin with MIT License | 5 votes |
/** * Run a docker image. * * @param launchEnv Docker client launch environment. * @param image The image name. * @param args Any additional arguments for the {@code docker run} command. * @param workdir The working directory in the container, or {@code null} for default. * @param volumes Volumes to be bound. Supply an empty list if no volumes are to be bound. * @param volumesFromContainers Mounts all volumes from the given containers. * @param containerEnv Environment variables to set in container. * @param user The <strong>uid:gid</strong> to execute the container command as. Use {@link #whoAmI()}. * @param command The command to execute in the image container being run. * @return The container ID. */ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String, String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException { ArgumentListBuilder argb = new ArgumentListBuilder(); argb.add("run", "-t", "-d"); // Username might be empty because we are running on Windows if (StringUtils.isNotEmpty(user)) { argb.add("-u", user); } if (args != null) { argb.addTokenized(args); } if (workdir != null) { argb.add("-w", workdir); } for (Map.Entry<String, String> volume : volumes.entrySet()) { argb.add("-v", volume.getKey() + ":" + volume.getValue() + ":rw,z"); } for (String containerId : volumesFromContainers) { argb.add("--volumes-from", containerId); } for (Map.Entry<String, String> variable : containerEnv.entrySet()) { argb.add("-e"); argb.addMasked(variable.getKey()+"="+variable.getValue()); } argb.add(image).add(command); LaunchResult result = launch(launchEnv, false, null, argb); if (result.getStatus() == 0) { return result.getOut(); } else { throw new IOException(String.format("Failed to run image '%s'. Error: %s", image, result.getErr())); } }
Example 15
Source File: SignArtifactPlugin.java From jenkins-android-signing with Apache License 2.0 | 4 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { if (isPerformDeployment(build)) { for (Apk entry : entries) { StringTokenizer rpmGlobTokenizer = new StringTokenizer(entry.getSelection(), ","); KeystoreCredentials keystore = getKeystore(entry.getKeyStore()); listener.getLogger().println("[AndroidSignPlugin] - Signing " + rpmGlobTokenizer.countTokens() + " APKs"); while (rpmGlobTokenizer.hasMoreTokens()) { String rpmGlob = rpmGlobTokenizer.nextToken(); FilePath[] matchedApks = build.getWorkspace().list(rpmGlob); if (ArrayUtils.isEmpty(matchedApks)) { listener.getLogger().println("[AndroidSignPlugin] - No APKs matching " + rpmGlob); } else { for (FilePath rpmFilePath : matchedApks) { ArgumentListBuilder apkSignCommand = new ArgumentListBuilder(); String cleanPath = rpmFilePath.toURI().normalize().getPath(); String signedPath = cleanPath.replace("unsigned", "signed"); String alignedPath = signedPath.replace("signed", "signed-aligned"); FilePath key = keystore.makeTempPath(build.getWorkspace()); //jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name apkSignCommand.add("jarsigner"); apkSignCommand.add("-sigalg", "SHA1withRSA"); apkSignCommand.add("-digestalg", "SHA1"); apkSignCommand.add("-keystore", key.getRemote()); apkSignCommand.add("-storepass"); apkSignCommand.addMasked(keystore.getPassphrase()); apkSignCommand.add("-signedjar", signedPath); apkSignCommand.add(cleanPath); apkSignCommand.add(entry.getAlias()); listener.getLogger().println("[AndroidSignPlugin] - Signing on " + Computer.currentComputer().getDisplayName()); Launcher.ProcStarter ps = launcher.new ProcStarter(); ps = ps.cmds(apkSignCommand).stdout(listener); ps = ps.pwd(rpmFilePath.getParent()).envs(build.getEnvironment(listener)); Proc proc = launcher.launch(ps); int retcode = proc.join(); key.delete(); if (retcode != 0) { listener.getLogger().println("[AndroidSignPlugin] - Failed signing APK"); return false; } Map<String,String> artifactsInsideWorkspace = new LinkedHashMap<String,String>(); artifactsInsideWorkspace.put(signedPath, stripWorkspace(build.getWorkspace(), signedPath)); ///opt/android-sdk/build-tools/20.0.0/zipalign String zipalign = build.getEnvironment(listener).get("ANDROID_ZIPALIGN"); if(zipalign == null || StringUtils.isEmpty(zipalign)){ throw new RuntimeException("You must set the environmental variable ANDROID_ZIPALIGN to point to the correct binary"); } ArgumentListBuilder zipalignCommand = new ArgumentListBuilder(); zipalignCommand.add(zipalign); zipalignCommand.add("4"); zipalignCommand.add(signedPath); zipalignCommand.add(alignedPath); Launcher.ProcStarter ps2 = launcher.new ProcStarter(); ps2 = ps2.cmds(zipalignCommand).stdout(listener); ps2 = ps2.pwd(rpmFilePath.getParent()).envs(build.getEnvironment(listener)); Proc proc2 = launcher.launch(ps2); retcode = proc2.join(); if(retcode != 0) { listener.getLogger().println("[AndroidSignPlugin] - Failed aligning APK"); return true; } artifactsInsideWorkspace.put(alignedPath, stripWorkspace(build.getWorkspace(), alignedPath)); build.pickArtifactManager().archive(build.getWorkspace(), launcher, listener, artifactsInsideWorkspace); } } } } listener.getLogger().println("[AndroidSignPlugin] - Finished signing APKs ..."); } else { listener.getLogger().println("[AndroidSignPlugin] - Skipping signing APKs ..."); } return true; }
Example 16
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 4 votes |
/** {@inheritDoc} */ @Override public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boolean headsOnly, boolean tagsOnly) throws GitException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder("ls-remote"); if (headsOnly) { args.add("-h"); } if (tagsOnly) { args.add("-t"); } addCheckedRemoteUrl(args, url); if (pattern != null) { args.add(pattern); } StandardCredentials cred = credentials.get(url); if (cred == null) cred = defaultCredentials; String result = launchCommandWithCredentials(args, null, cred, url); Map<String, ObjectId> references = new HashMap<>(); String[] lines = result.split("\n"); for (String line : lines) { if (line.length() < 41) { continue; // throw new GitException("unexpected ls-remote output " + line); } String refName = line.substring(41); ObjectId refObjectId = ObjectId.fromString(line.substring(0, 40)); if (refName.startsWith("refs/tags") && refName.endsWith("^{}")) { // get peeled object id for annotated tag String tagName = refName.replace("^{}", ""); // Replace with the peeled object id if the entry with tagName exists references.put(tagName, refObjectId); } else { if (!references.containsKey(refName)) { references.put(refName, refObjectId); } } } return references; }
Example 17
Source File: AnsiblePlaybookInvocation.java From ansible-plugin with Apache License 2.0 | 4 votes |
private ArgumentListBuilder appendPlaybook(ArgumentListBuilder args) { args.add(envVars.expand(playbook)); return args; }
Example 18
Source File: AnsibleAdHocCommandInvocation.java From ansible-plugin with Apache License 2.0 | 4 votes |
private ArgumentListBuilder appendHostPattern(ArgumentListBuilder args) { args.add(envVars.expand(hostPattern)); return args; }
Example 19
Source File: CliGitCommand.java From git-client-plugin with MIT License | 4 votes |
private String[] runWithoutAssert(String... arguments) throws IOException, InterruptedException { args = new ArgumentListBuilder("git"); args.add(arguments); return run(false); }
Example 20
Source File: CliGitCommand.java From git-client-plugin with MIT License | 4 votes |
String[] run(String... arguments) throws IOException, InterruptedException { args = new ArgumentListBuilder("git"); args.add(arguments); return run(true); }