Java Code Examples for hudson.model.TaskListener#NULL

The following examples show how to use hudson.model.TaskListener#NULL . 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: Git.java    From git-client-plugin with MIT License 6 votes vote down vote up
public GitClient invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
    if (listener == null) listener = TaskListener.NULL;
    if (env == null) env = new EnvVars();

    if (Main.isUnitTest && System.getProperty(Git.class.getName() + ".mockClient") != null) {
        return initMockClient(System.getProperty(Git.class.getName() + ".mockClient"),
                exe, env, f, listener);
    }

    if (exe == null || JGitTool.MAGIC_EXENAME.equalsIgnoreCase(exe)) {
        return new JGitAPIImpl(f, listener);
    }

    if (JGitApacheTool.MAGIC_EXENAME.equalsIgnoreCase(exe)) {
        final PreemptiveAuthHttpClientConnectionFactory factory = new PreemptiveAuthHttpClientConnectionFactory();
        return new JGitAPIImpl(f, listener, factory);
    }
    // Ensure we return a backward compatible GitAPI, even API only claim to provide a GitClient
    return new GitAPI(exe, f, listener, env);
}
 
Example 2
Source File: AnalysisExecution.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the {@link TaskListener} for this execution.
 *
 * @return the task listener (or a silent listener if no task listener could be found)
 * @throws InterruptedException
 *         if the user canceled the execution
 */
protected TaskListener getTaskListener() throws InterruptedException {
    try {
        TaskListener listener = getContext().get(TaskListener.class);
        if (listener != null) {
            return listener;
        }
    }
    catch (IOException ignored) {
        // ignore
    }
    return TaskListener.NULL;
}
 
Example 3
Source File: RegistryKeyMaterialFactoryTest.java    From docker-commons-plugin with MIT License 5 votes vote down vote up
@Before
   public void setup() throws Exception {
// fake launcher for the docker login invocation
FakeLauncher faker = new FakeLauncher() {
    @Override
    public Proc onLaunch(final ProcStarter p) throws IOException {
	return new FinishedProc(0);
    }
};

PretendSlave slave = j.createPretendSlave(faker);
// VirtualChannel channel = slave.getChannel();
// FreeStyleProject project = j.createFreeStyleProject();

TaskListener listener = TaskListener.NULL;
Launcher launcher = slave.createLauncher(listener);
launcher = new Launcher.DecoratedLauncher(launcher) {
    @Override
    public VirtualChannel getChannel() {
	return new LocalChannel(null) {
	    @Override
	    public <V, T extends Throwable> V call(final Callable<V, T> callable) throws T {
		// ugly as hell, but we need a way to mock fetching the home directory
		return (V) new FilePath(tempFolder.getRoot());
	    }
	};
    }
};

URL endpoint = new DockerRegistryEndpoint(null, null).getEffectiveUrl();
EnvVars env = new EnvVars();
String dockerExecutable = DockerTool.getExecutable(null, null, listener, env);

factory = new RegistryKeyMaterialFactory("username", "password", endpoint, launcher, env, listener,
	dockerExecutable).contextualize(new KeyMaterialContext(new FilePath(tempFolder.newFolder())));
   }
 
Example 4
Source File: CliGitAPIImpl.java    From git-client-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor for CliGitAPIImpl.
 *
 * @param gitExe a {@link java.lang.String} object.
 * @param workspace a {@link java.io.File} object.
 * @param listener a {@link hudson.model.TaskListener} object.
 * @param environment a {@link hudson.EnvVars} object.
 */
protected CliGitAPIImpl(String gitExe, File workspace, TaskListener listener, EnvVars environment) {
    super(workspace);
    this.listener = listener;
    this.gitExe = gitExe;
    this.environment = environment;

    if( isZos() && System.getProperty("ibm.system.encoding") != null ) {
        this.encoding = Charset.forName(System.getProperty("ibm.system.encoding")).toString();
    } else {
        this.encoding = Charset.defaultCharset().toString();
    }

    launcher = new LocalLauncher(IGitAPI.verbose ? listener : TaskListener.NULL);
}
 
Example 5
Source File: GitClientFetchTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Before
public void setUpRepositories() throws Exception {
    workspace = new WorkspaceWithRepo(repo.getRoot(), gitImplName, TaskListener.NULL);
    testGitClient = workspace.getGitClient();
    testGitDir = workspace.getGitFileDir();
    cliGitCommand = workspace.getCliGitCommand();
}
 
Example 6
Source File: GitClientFetchTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void test_fetch_from_url() throws Exception {
    newAreaWorkspace = new WorkspaceWithRepo(thirdRepo.getRoot(), gitImplName, TaskListener.NULL);
    newAreaWorkspace.getGitClient().init();
    newAreaWorkspace.launchCommand("git", "commit", "--allow-empty", "-m", "init");
    String sha1 = newAreaWorkspace.launchCommand("git", "rev-list", "--no-walk", "--max-count=1", "HEAD");

    testGitClient.init();
    cliGitCommand.run("remote", "add", "origin", newAreaWorkspace.getGitFileDir().getAbsolutePath());
    testGitClient.fetch(new URIish(newAreaWorkspace.getGitFileDir().toString()), Collections.<RefSpec>emptyList());
    assertThat(sha1.contains(newAreaWorkspace.launchCommand("git", "rev-list", "--no-walk", "--max-count=1", "HEAD")), is(true));
}
 
Example 7
Source File: PodTemplate.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Nonnull
public TaskListener getListener() {
    return listener == null ? TaskListener.NULL : listener;
}
 
Example 8
Source File: AllContainersRunningPodWatcher.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public AllContainersRunningPodWatcher(KubernetesClient client, Pod pod, @CheckForNull TaskListener runListener) {
    this.client = client;
    this.pod = pod;
    this.runListener = runListener == null ? TaskListener.NULL : runListener;
    updateState(pod);
}
 
Example 9
Source File: GitClientFetchTest.java    From git-client-plugin with MIT License 4 votes vote down vote up
/**
 * JGit 3.3.0 thru 4.5.4 "prune during fetch" prunes more remote
 * branches than command line git prunes during fetch.  JGit 5.0.2
 * fixes the problem.
 * Refer to https://bugs.eclipse.org/bugs/show_bug.cgi?id=533549
 * Refer to https://bugs.eclipse.org/bugs/show_bug.cgi?id=533806
 */
@Test
@Issue("JENKINS-26197")
public void test_fetch_with_prune() throws Exception {
    bareWorkspace = new WorkspaceWithRepo(secondRepo.getRoot(), gitImplName, TaskListener.NULL);
    bareWorkspace.initBareRepo(bareWorkspace.getGitClient(), true);
    /* Create a working repo containing three branches */
    /* master -> branch1 */
    /*        -> branch2 */
    testGitClient.init();
    testGitClient.setRemoteUrl("origin", bareWorkspace.getGitFileDir().getAbsolutePath());
    workspace.touch(testGitDir, "file-master", "file master content " + UUID.randomUUID().toString());
    testGitClient.add("file-master");
    testGitClient.commit("master-commit");
    assertThat("Wrong branch count", testGitClient.getBranches().size(), is(1));
    testGitClient.push("origin", "master"); /* master branch is now on bare repo */

    testGitClient.checkout().ref("master").execute();
    testGitClient.branch("branch1");
    workspace.touch(testGitDir, "file-branch1", "file branch1 content " + UUID.randomUUID().toString());
    testGitClient.add("file-branch1");
    testGitClient.commit("branch1-commit");
    assertThat(getBranchNames(testGitClient.getBranches()), containsInAnyOrder("master", "branch1"));
    testGitClient.push("origin", "branch1"); /* branch1 is now on bare repo */

    testGitClient.checkout().ref("master").execute();
    testGitClient.branch("branch2");
    workspace.touch(testGitDir, "file-branch2", "file branch2 content " + UUID.randomUUID().toString());
    testGitClient.add("file-branch2");
    testGitClient.commit("branch2-commit");
    assertThat(getBranchNames(testGitClient.getBranches()), containsInAnyOrder("master", "branch1", "branch2"));
    assertThat(testGitClient.getRemoteBranches(), is(empty()));
    testGitClient.push("origin", "branch2"); /* branch2 is now on bare repo */

    /* Clone new working repo from bare repo */
    newAreaWorkspace = new WorkspaceWithRepo(thirdRepo.getRoot(), gitImplName, TaskListener.NULL);
    newAreaWorkspace.cloneRepo(newAreaWorkspace, bareWorkspace.getGitFileDir().getAbsolutePath());
    ObjectId newAreaHead = newAreaWorkspace.getGitClient().revParse("HEAD");
    Set<Branch> remoteBranches = newAreaWorkspace.getGitClient().getRemoteBranches();
    assertThat(getBranchNames(remoteBranches), containsInAnyOrder("origin/master", "origin/branch1", "origin/branch2", "origin/HEAD"));

    /* Remove branch1 from bare repo using original repo */
    cliGitCommand.run("push", bareWorkspace.getGitFileDir().getAbsolutePath(), ":branch1");

    List<RefSpec> refSpecs = Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));

    /* Fetch without prune should leave branch1 in newArea */
    newAreaWorkspace.launchCommand("git", "config", "fetch.prune", "false");
    newAreaWorkspace.getGitClient().fetch_().from(new URIish(bareWorkspace.getGitFileDir().toString()), refSpecs).execute();
    remoteBranches = newAreaWorkspace.getGitClient().getRemoteBranches();
    assertThat(getBranchNames(remoteBranches), containsInAnyOrder("origin/master", "origin/branch1", "origin/branch2", "origin/HEAD"));

    /* Fetch with prune should remove branch1 from newArea */
    newAreaWorkspace.getGitClient().fetch_().from(new URIish(bareWorkspace.getGitFileDir().toString()), refSpecs).prune(true).execute();
    remoteBranches = newAreaWorkspace.getGitClient().getRemoteBranches();

    /* Git older than 1.7.9 (like 1.7.1 on Red Hat 6) does not prune branch1, don't fail the test
     * on that old git version.
     */
    if (newAreaWorkspace.getGitClient() instanceof CliGitAPIImpl && !workspace.cgit().isAtLeastVersion(1, 7, 9, 0)) {
        assertThat(getBranchNames(remoteBranches), containsInAnyOrder("origin/master", "origin/branch1", "origin/branch2", "origin/HEAD"));
    } else {
        assertThat(getBranchNames(remoteBranches), containsInAnyOrder("origin/master", "origin/branch2", "origin/HEAD"));
    }
}