hudson.FilePath.FileCallable Java Examples
The following examples show how to use
hudson.FilePath.FileCallable.
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: JvctgPerformer.java From violation-comments-to-github-plugin with MIT License | 4 votes |
public static void jvctsPerform( final ViolationsToGitHubConfig configUnexpanded, final FilePath fp, final Run<?, ?> build, final TaskListener listener) { final PrintStream logger = listener.getLogger(); try { final EnvVars env = build.getEnvironment(listener); final ViolationsToGitHubConfig configExpanded = expand(configUnexpanded, env); logger.println("---"); logger.println("--- Jenkins Violation Comments to GitHub ---"); logger.println("---"); logConfiguration(configExpanded, build, listener); final Optional<StandardCredentials> credentials = findCredentials( build.getParent(), configExpanded.getCredentialsId(), configExpanded.getGitHubUrl()); if (!isNullOrEmpty(configExpanded.getoAuth2Token())) { logger.println("Using OAuth2Token"); } else if (credentials.isPresent()) { final StandardCredentials standardCredentials = credentials.get(); if (standardCredentials instanceof StandardUsernamePasswordCredentials) { logger.println("Using username / password"); } else if (standardCredentials instanceof StringCredentials) { logger.println("Using OAuth2Token credential style"); } } else { throw new IllegalStateException("No credentials found!"); } logger.println("Running Jenkins Violation Comments To GitHub"); logger.println("PR " + configExpanded.getPullRequestId()); fp.act( new FileCallable<Void>() { private static final long serialVersionUID = 6166111757469534436L; @Override public void checkRoles(final RoleChecker checker) throws SecurityException {} @Override public Void invoke(final File workspace, final VirtualChannel channel) throws IOException, InterruptedException { setupFindBugsMessages(); listener.getLogger().println("Workspace: " + workspace.getAbsolutePath()); doPerform(configExpanded, workspace, credentials.orNull(), listener); return null; } }); } catch (final Exception e) { Logger.getLogger(JvctgPerformer.class.getName()).log(SEVERE, "", e); final StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); logger.println(sw.toString()); return; } }
Example #2
Source File: JvctbPerformer.java From violation-comments-to-stash-plugin with MIT License | 4 votes |
public static void jvctsPerform( final ProxyConfigDetails proxyConfigDetails, final ViolationsToBitbucketServerConfig configUnexpanded, final FilePath fp, final Run<?, ?> build, final TaskListener listener) { try { final EnvVars env = build.getEnvironment(listener); final ViolationsToBitbucketServerConfig configExpanded = expand(configUnexpanded, env); listener.getLogger().println("---"); listener.getLogger().println("--- Jenkins Violation Comments to Bitbucket Server ---"); listener.getLogger().println("---"); logConfiguration(configExpanded, build, listener); final Optional<StandardCredentials> credentials = findCredentials( build.getParent(), configExpanded.getCredentialsId(), configExpanded.getBitbucketServerUrl()); if (!credentials.isPresent()) { listener.getLogger().println("Credentials not found!"); return; } listener.getLogger().println("Pull request: " + configExpanded.getPullRequestId()); fp.act( new FileCallable<Void>() { private static final long serialVersionUID = 6166111757469534436L; @Override public void checkRoles(final RoleChecker checker) throws SecurityException {} @Override public Void invoke(final File workspace, final VirtualChannel channel) throws IOException, InterruptedException { setupFindBugsMessages(); listener.getLogger().println("Workspace: " + workspace.getAbsolutePath()); doPerform( proxyConfigDetails, configExpanded, workspace, credentials.orNull(), listener); return null; } }); } catch (final Exception e) { Logger.getLogger(JvctbPerformer.class.getName()).log(SEVERE, "", e); final StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); listener.getLogger().println(sw.toString()); return; } }
Example #3
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 4 votes |
/** * List model to choose the ZAP session to use. It's called on the remote machine (if present) * to load all session files in the build's workspace. * * @return a {@link ListBoxModel}. It can be empty if the workspace doesn't contain any ZAP sessions. * @throws InterruptedException * @throws IOException */ public ListBoxModel doFillFilenameLoadSessionItems() throws IOException, InterruptedException { ListBoxModel items = new ListBoxModel(); // No workspace before the first build, so workspace is null if(workspace != null) { Collection<String> sessionsInString = workspace.act(new FileCallable<Collection<String>>() { private static final long serialVersionUID = 1328740269013881941L; public Collection<String> invoke(File f, VirtualChannel channel) { // List all files with FILE_SESSION_EXTENSION on the machine where the workspace is located Collection<File> colFiles = FileUtils.listFiles(f, FileFilterUtils.suffixFileFilter(FILE_SESSION_EXTENSION), TrueFileFilter.INSTANCE); Collection<String> colString = new ArrayList<String>(); // "Transform" File into String for (File file : colFiles) { colString.add(file.getAbsolutePath()); // The following line is to remove the full path to the workspace, // keep just the relative path to the session //colString.add(file.getAbsolutePath().replace(workspace.getRemote() + File.separatorChar, "")); } return colString; } @Override public void checkRoles(RoleChecker checker) throws SecurityException { // Nothing to do } }); items.add(""); // To not load a session, add a blank choice for (String s : sessionsInString) { items.add(s); } } return items; }