Java 类hudson.model.Cause.UserIdCause 实例源码

项目:p4-jenkins    文件:ConnectionTest.java   
@Test
public void testFreeStyleProject_buildHead() throws Exception {

    FreeStyleProject project = jenkins.createFreeStyleProject("BuildHead");
    Workspace workspace = new StaticWorkspaceImpl("none", false, defaultClient());
    Populate populate = new AutoCleanImpl();
    PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate);
    project.setScm(scm);
    project.save();

    FreeStyleBuild build;
    UserIdCause cause = new Cause.UserIdCause();
    build = project.scheduleBuild2(0, cause).get();
    assertEquals(Result.SUCCESS, build.getResult());

    List<String> log = build.getLog(LOG_LIMIT);
    assertTrue(log.contains("P4 Task: syncing files at change: 40"));

    CredentialsDescriptor desc = auth.getDescriptor();
    assertNotNull(desc);
    assertEquals("Perforce Password Credential", desc.getDisplayName());
    P4PasswordImpl.DescriptorImpl impl = (P4PasswordImpl.DescriptorImpl) desc;
    FormValidation form = impl.doTestConnection(p4d.getRshPort(), "false", null, null, "jenkins", "jenkins", false);
    assertEquals(FormValidation.Kind.OK, form.kind);
}
项目:jira-steps    文件:JiraStepExecution.java   
/**
 * Return the current build user.
 * 
 * @param causes
 *            build causes.
 * @return user name.
 */
protected static String prepareBuildUser(List<Cause> causes) {
    String buildUser = "anonymous";
    if (causes != null && causes.size() > 0) {
        if (causes.get(0) instanceof UserIdCause) {
            buildUser = ((UserIdCause) causes.get(0)).getUserName();
        } else if (causes.get(0) instanceof UpstreamCause) {
            List<Cause> upstreamCauses = ((UpstreamCause) causes.get(0)).getUpstreamCauses();
            prepareBuildUser(upstreamCauses);
        }
    }
    return buildUser;
}
项目:jira-steps-plugin    文件:JiraStepExecution.java   
/**
 * Return the current build user.
 *
 * @param causes build causes.
 * @return user name.
 */
protected static String prepareBuildUser(List<Cause> causes) {
  String buildUser = "anonymous";
  if (causes != null && causes.size() > 0) {
    if (causes.get(0) instanceof UserIdCause) {
      buildUser = ((UserIdCause) causes.get(0)).getUserId();
    } else if (causes.get(0) instanceof UpstreamCause) {
      List<Cause> upstreamCauses = ((UpstreamCause) causes.get(0)).getUpstreamCauses();
      prepareBuildUser(upstreamCauses);
    }
  }
  return Util.fixEmpty(buildUser) == null ? "anonymous" : buildUser;
}
项目:mirrorgate-jenkins-builds-collector    文件:BuildBuilder.java   
private void setCulprits(Run run) {

        List<String> culprits = new ArrayList<>(0);

        // Get culprits from the causes of the build
        run.getCauses().forEach((cause -> {
            switch (cause.getClass().getSimpleName()) {
                case "UserIdCause":
                    if (!culprits.contains(((UserIdCause) cause).getUserName())) {
                        culprits.add(((UserIdCause) cause).getUserName());
                    }
                    break;
            }
        }));

        // Use introspective class to avoid plugins compatibility problems
        try {
            Method method = run.getClass().getMethod("getChangeSets");
            method.setAccessible(true);
            ((List<ChangeLogSet>) method.invoke(run, new Object[]{})).forEach(cset -> {
                for (Object object : ((ChangeLogSet) cset).getItems()) {
                    ChangeLogSet.Entry change = (ChangeLogSet.Entry) object;
                    if (!culprits.contains(change.getAuthor().getFullName())) {
                        culprits.add(change.getAuthor().getFullName());
                    }
                }
            });
        } catch (SecurityException | IllegalAccessException |
                IllegalArgumentException | InvocationTargetException | NoSuchMethodException ex) {
            Logger.getLogger(MirrorGateRunListener.class.getName()).log(Level.SEVERE, null, ex);
        }

        request.setCulprits(culprits);
    }
项目:hubot-steps-plugin    文件:HubotAbstractSynchronousNonBlockingStepExecution.java   
/**
 * Return the current build user.
 * 
 * @param causes build causes.
 * @return user name.
 */
protected static String prepareBuildUser(List<Cause> causes) {
  String buildUser = "anonymous";
  if (causes != null && causes.size() > 0) {
    if (causes.get(0) instanceof UserIdCause) {
      buildUser = ((UserIdCause) causes.get(0)).getUserName();
    } else if (causes.get(0) instanceof UpstreamCause) {
      List<Cause> upstreamCauses = ((UpstreamCause) causes.get(0)).getUpstreamCauses();
      prepareBuildUser(upstreamCauses);
    }
  }
  return buildUser;
}
项目:hubot-steps-plugin    文件:HubotStepExecution.java   
/**
 * Return the current build user.
 * 
 * @param causes build causes.
 * @return user name.
 */
protected static String prepareBuildUser(List<Cause> causes) {
  String buildUser = "anonymous";
  if (causes != null && causes.size() > 0) {
    if (causes.get(0) instanceof UserIdCause) {
      buildUser = ((UserIdCause) causes.get(0)).getUserName();
    } else if (causes.get(0) instanceof UpstreamCause) {
      List<Cause> upstreamCauses = ((UpstreamCause) causes.get(0)).getUpstreamCauses();
      prepareBuildUser(upstreamCauses);
    }
  }
  return buildUser;
}
项目:p4-jenkins    文件:ConnectionTest.java   
@Test
public void testPinHost_ManualWs() throws Exception {

    String client = "manual.ws";
    String stream = null;
    String line = "LOCAL";
    String view = "//depot/Data/... //" + client + "/...";
    WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);

    FreeStyleProject project = jenkins.createFreeStyleProject("Manual-Head");
    ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec);
    Populate populate = new AutoCleanImpl();
    PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate);
    project.setScm(scm);
    project.save();

    FreeStyleBuild build;
    UserIdCause cause = new Cause.UserIdCause();
    build = project.scheduleBuild2(0, cause).get();
    assertEquals(Result.SUCCESS, build.getResult());

    // Log in with client for next set of tests...
    ClientHelper p4 = new ClientHelper(auth, null, "manual.ws", "utf8");
    IClient iclient = p4.getClient();
    String clienthost = iclient.getHostName();
    String hostname = InetAddress.getLocalHost().getHostName();

    assertNotNull(clienthost);
    assertEquals(hostname, clienthost);
}
项目:DotCi    文件:DynamicBuildFactory.java   
public DynamicBuildFactory manualStart(String userId, String branch) {
    UserIdCause userIdCause = mock(UserIdCause.class);
    when(userIdCause.getUserId()).thenReturn(userId);
    when(build.getCause(UserIdCause.class)).thenReturn(userIdCause);
    addBranchParam(branch);
    return this;
}
项目:jenkins-inheritance-plugin    文件:TestInheritanceSanity.java   
/**
 * @param sleep
 * @param eps
 * @param parallel
 * @param p
 */
private void buildTwoandCheckOrder(long sleep, double eps, boolean parallel, InheritanceProject p) {
    try {
        /* Scheduling the builds.
         * We need to give the gpp a random parameter, to avoid Jenkins
         * from mercilessly killing our duplicated jobs, if two of them
         * happen to be simultaneously in the queue.
         */
        QueueTaskFuture<InheritanceBuild> f1 = p.scheduleBuild2(
                0, new UserIdCause(),
                new ParametersAction(
                        new StringParameterValue("RNG", UUID.randomUUID().toString())
                )
        );
        QueueTaskFuture<InheritanceBuild> f2 = p.scheduleBuild2(
                0, new UserIdCause(),
                new ParametersAction(
                        new StringParameterValue("RNG", UUID.randomUUID().toString())
                )
        );
        assertNotNull("First build failed to start, miserably", f1);
        assertNotNull("Second build failed to start, miserably", f2);

        InheritanceBuild[] builds = { f1.get(), f2.get() };
        assertNotNull("First build failed to evaluate", builds[0]);
        assertNotNull("Second build failed to evaluate", builds[1]);

        checkBuildOrder((long)eps*sleep, parallel, builds);
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}
项目:p4-jenkins    文件:ConnectionTest.java   
@Test
public void testManual_Modtime() throws Exception {

    String client = "modtime.ws";
    String stream = null;
    String line = "LOCAL";
    String view = "//depot/Data/... //" + client + "/...";

    // The test was designed for pre 15.1 modtime checks.  Since RSH requires 15.1
    // the test is not required, however later assets have some use.  The pre20151
    // bool 'fakes' the test and allows the other checks to pass.
    boolean pre20151 = false;
    WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, !pre20151, false, stream, line, view);

    FreeStyleProject project = jenkins.createFreeStyleProject("Manual_Modtime");
    ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);
    boolean isModtime = true;
    Populate populate = new AutoCleanImpl(true, true, isModtime, false, null, null);
    PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate);
    project.setScm(scm);
    project.save();

    FreeStyleBuild build;
    UserIdCause cause = new Cause.UserIdCause();
    build = project.scheduleBuild2(0, cause).get();
    assertEquals(Result.SUCCESS, build.getResult());

    // Log in for next set of tests...
    ClientHelper p4 = new ClientHelper(auth, null, client, "utf8");
    boolean mod = p4.getClient().getOptions().isModtime();
    assertEquals(true, mod);

    // Check file exists with the correct date
    String ws = build.getWorkspace().getRemote();
    File file = new File(ws + "/file-0.dat");
    assertEquals(true, file.exists());

    String ver = Metadata.getP4JVersionString();
    logger.info("P4Java Version: " + ver);

    long epoch = file.lastModified();
    assertEquals(1397049803000L, epoch);
}