Java Code Examples for hudson.util.StreamTaskListener#fromStderr()

The following examples show how to use hudson.util.StreamTaskListener#fromStderr() . 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: PushTest.java    From git-client-plugin with MIT License 6 votes vote down vote up
@Before
public void createWorkingRepository() throws IOException, InterruptedException, URISyntaxException {
    hudson.EnvVars env = new hudson.EnvVars();
    TaskListener listener = StreamTaskListener.fromStderr();
    List<RefSpec> refSpecs = new ArrayList<>();
    workingRepo = temporaryFolder.newFolder();
    workingGitClient = Git.with(listener, env).in(workingRepo).using(gitImpl).getClient();
    workingGitClient.clone_()
            .url(bareRepo.getAbsolutePath())
            .repositoryName("origin")
            .execute();
    workingGitClient.checkout()
            .branch(branchName)
            .deleteBranchIfExist(true)
            .ref("origin/" + branchName)
            .execute();
    assertNotNull(bareFirstCommit);
    assertTrue("Clone does not contain " + bareFirstCommit,
            workingGitClient.revList("origin/" + branchName).contains(bareFirstCommit));
    ObjectId workingHead = workingGitClient.getHeadRev(workingRepo.getAbsolutePath(), branchName);
    ObjectId bareHead = bareGitClient.getHeadRev(bareRepo.getAbsolutePath(), branchName);
    assertEquals("Initial checkout of " + branchName + " has different HEAD than bare repo", bareHead, workingHead);
}
 
Example 2
Source File: CachesTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testBranchCacheLoaderNoMetadata() throws Exception {
    sampleRepo1.init();
    sampleRepo1.write("Jenkinsfile", "node { echo 'hi'; }");
    sampleRepo1.git("add", "Jenkinsfile");
    sampleRepo1.git("commit", "--all", "--message=buildable");

    WorkflowMultiBranchProject project = r.jenkins.createProject(WorkflowMultiBranchProject.class, "Repo");
    GitSCMSource source = new GitSCMSource(sampleRepo1.toString());
    source.setTraits(new ArrayList<>(Arrays.asList(new BranchDiscoveryTrait())));

    BranchSource branchSource = new BranchSource(source);
    branchSource.setStrategy(new DefaultBranchPropertyStrategy(null));

    TaskListener listener = StreamTaskListener.fromStderr();
    assertEquals("[SCMHead{'master'}]", source.fetch(listener).toString());
    project.setSourcesList(new ArrayList<>(Arrays.asList(branchSource)));

    project.scheduleBuild2(0).getFuture().get();

    Caches.BranchCacheLoader loader = new Caches.BranchCacheLoader(r.jenkins);
    BranchImpl.Branch branch = loader.load(project.getFullName() + "/master").orNull();

    // if branch is defined, it'll be sorted by branch
    assertNotNull(branch);
    assertTrue(branch.isPrimary());
    assertEquals("master", branch.getUrl());
}
 
Example 3
Source File: DockerClientTest.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
    DockerTestUtil.assumeDocker();

    // Set stuff up for the test
    TaskListener taskListener = StreamTaskListener.fromStderr();
    Launcher.LocalLauncher launcher = new Launcher.LocalLauncher(taskListener);

    dockerClient = new DockerClient(launcher, null, null);
}
 
Example 4
Source File: WindowsDockerClientTest.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
    DockerTestUtil.assumeDocker();

    TaskListener taskListener = StreamTaskListener.fromStderr();
    Launcher.LocalLauncher launcher = new Launcher.LocalLauncher(taskListener);

    dockerClient = new WindowsDockerClient(launcher, null, null);
}
 
Example 5
Source File: AbstractGitTestCase.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  listener = StreamTaskListener.fromStderr();

  testRepo = new TestGitRepo("unnamed", this, listener);
  johnDoe = testRepo.johnDoe;
  janeDoe = testRepo.janeDoe;
  workDir = testRepo.gitDir;
  workspace = testRepo.gitDirPath;
  git = testRepo.git;
}
 
Example 6
Source File: GitClientSampleRepoRule.java    From git-client-plugin with MIT License 5 votes vote down vote up
public boolean gitVersionAtLeast(int neededMajor, int neededMinor, int neededPatch) {
    final TaskListener procListener = StreamTaskListener.fromStderr();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        int returnCode = new Launcher.LocalLauncher(procListener).launch().cmds("git", "--version").stdout(out).join();
        if (returnCode != 0) {
            LOGGER.log(Level.WARNING, "Command 'git --version' returned " + returnCode);
        }
    } catch (IOException | InterruptedException ex) {
        LOGGER.log(Level.WARNING, "Exception checking git version " + ex);
    }
    final String versionOutput = out.toString().trim();
    final String[] fields = versionOutput.split(" ")[2].replaceAll("msysgit.", "").replaceAll("windows.", "").split("\\.");
    final int gitMajor = Integer.parseInt(fields[0]);
    final int gitMinor = Integer.parseInt(fields[1]);
    final int gitPatch = Integer.parseInt(fields[2]);
    if (gitMajor < 1 || gitMajor > 3) {
        LOGGER.log(Level.WARNING, "Unexpected git major version " + gitMajor + " parsed from '" + versionOutput + "', field:'" + fields[0] + "'");
    }
    if (gitMinor < 0 || gitMinor > 50) {
        LOGGER.log(Level.WARNING, "Unexpected git minor version " + gitMinor + " parsed from '" + versionOutput + "', field:'" + fields[1] + "'");
    }
    if (gitPatch < 0 || gitPatch > 20) {
        LOGGER.log(Level.WARNING, "Unexpected git patch version " + gitPatch + " parsed from '" + versionOutput + "', field:'" + fields[2] + "'");
    }

    return gitMajor >  neededMajor ||
            (gitMajor == neededMajor && gitMinor >  neededMinor) ||
            (gitMajor == neededMajor && gitMinor == neededMinor  && gitPatch >= neededPatch);
}
 
Example 7
Source File: GitAPIBadInitTest.java    From git-client-plugin with MIT License 4 votes vote down vote up
@Before
public void setUp() throws IOException, InterruptedException {
    tempDir = tempFolder.newFolder();
    listener = StreamTaskListener.fromStderr();
}
 
Example 8
Source File: PushTest.java    From git-client-plugin with MIT License 4 votes vote down vote up
@BeforeClass
public static void createBareRepository() throws Exception {
    /* Command line git commands fail unless certain default values are set */
    CliGitCommand gitCmd = new CliGitCommand(null);
    gitCmd.setDefaults();

    /* Randomly choose git implementation to create bare repository */
    final String[] gitImplementations = {"git", "jgit"};
    Random random = new Random();
    String gitImpl = gitImplementations[random.nextInt(gitImplementations.length)];

    /* Create the bare repository */
    bareRepo = staticTemporaryFolder.newFolder();
    bareURI = new URIish(bareRepo.getAbsolutePath());
    hudson.EnvVars env = new hudson.EnvVars();
    TaskListener listener = StreamTaskListener.fromStderr();
    bareGitClient = Git.with(listener, env).in(bareRepo).using(gitImpl).getClient();
    bareGitClient.init_().workspace(bareRepo.getAbsolutePath()).bare(true).execute();

    /* Clone the bare repository into a working copy */
    File cloneRepo = staticTemporaryFolder.newFolder();
    GitClient cloneGitClient = Git.with(listener, env).in(cloneRepo).using(gitImpl).getClient();
    cloneGitClient.clone_()
            .url(bareRepo.getAbsolutePath())
            .repositoryName("origin")
            .execute();

    for (String branchName : BRANCH_NAMES) {
        /* Add a file with random content to the current branch of working repo */
        File added = File.createTempFile("added-", ".txt", cloneRepo);
        String randomContent = java.util.UUID.randomUUID().toString();
        String addedContent = "Initial commit to branch " + branchName + " content '" + randomContent + "'";
        FileUtils.writeStringToFile(added, addedContent, "UTF-8");
        cloneGitClient.add(added.getName());
        cloneGitClient.commit("Initial commit to " + branchName + " file " + added.getName() + " with " + randomContent);
        // checkoutOldBranchAndCommitFile needs at least two commits to the branch
        FileUtils.writeStringToFile(added, "Another revision " + randomContent, "UTF-8");
        cloneGitClient.add(added.getName());
        cloneGitClient.commit("Second commit to " + branchName);

        /* Push HEAD of current branch to branchName on the bare repository */
        cloneGitClient.push().to(bareURI).ref("HEAD:" + branchName).execute();
    }

    /* Remember the SHA1 of the first commit */
    bareFirstCommit = bareGitClient.getHeadRev(bareRepo.getAbsolutePath(), "master");
}