/**
   * When a build is marked as NOT_BUILD And more builds are started And there are no changes Then
   * all following builds should also be marked NOT_BUILD
   */
  public void testShouldMarkBuildsAsNotBuilt() throws Exception {
    setup();
    File dir = createTempDirectory();
    MercurialBridge plugin = new MercurialBridge(false, "test", "default");
    plugin.setWorkingDirectory(new FilePath(dir));

    hg(dir, "init");
    shell(dir, "touch", "foo");
    hg(dir, "add", "foo");
    hg(dir, "commit", "-m", "\"added foo\"");
    // String rev = hg(dir,"tip","--template","{node}").toString();
    hg(dir, "branch", "test");
    shell(dir, "touch", "bar");
    hg(dir, "add", "bar");
    hg(dir, "commit", "-m", "\"added bar\"");

    MercurialSCM scm =
        new MercurialSCM(null, dir.getAbsolutePath(), "test", null, null, null, true);
    FreeStyleProject project =
        Hudson.getInstance().createProject(FreeStyleProject.class, "testproject");
    project.setScm(scm);
    project.getBuildWrappersList().add(new PretestedIntegrationBuildWrapper(plugin));

    Future<FreeStyleBuild> f = project.scheduleBuild2(0);
    FreeStyleBuild build = f.get();
    assertEquals(Result.SUCCESS, build.getResult());
    f = project.scheduleBuild2(0);
    build = f.get();
    assertEquals(Result.NOT_BUILT, build.getResult());
    f = project.scheduleBuild2(0);
    build = f.get();
    assertEquals(Result.NOT_BUILT, build.getResult());
    cleanup(dir);
  }
  public void testSelfExcludingJobs() throws Exception {

    BuildBlockerProperty theProperty = new BuildBlockerProperty();
    theProperty.setBlockingJobs("SelfExcluding_.*");

    FreeStyleProject theJob1 = createFreeStyleProject("SelfExcluding_Job1");
    theJob1.addProperty(theProperty);
    assertTrue(theJob1.getBuilds().isEmpty());

    FreeStyleProject theJob2 = createFreeStyleProject("SelfExcluding_Job2");
    theJob2.addProperty(theProperty);
    assertTrue(theJob1.getBuilds().isEmpty());

    // allow executing two simultanious jobs
    int theOldNumExecutors = Hudson.getInstance().getNumExecutors();
    Hudson.getInstance().setNumExecutors(2);

    Future<FreeStyleBuild> theFuture1 = theJob1.scheduleBuild2(0);
    Future<FreeStyleBuild> theFuture2 = theJob2.scheduleBuild2(0);

    long theStartTime = System.currentTimeMillis();
    long theEndTime = theStartTime;
    while ((!theFuture1.isDone() || !theFuture2.isDone()) && theEndTime < theStartTime + 5000) {
      theEndTime = System.currentTimeMillis();
    }

    // if more then five seconds have passed, we assume its a deadlock.
    assertTrue(theEndTime < theStartTime + 5000);

    // restore changed settings
    Hudson.getInstance().setNumExecutors(theOldNumExecutors);
    theJob2.delete();
    theJob1.delete();
  }
示例#3
0
  public void testTakeBlockedByProperty() throws Exception {
    Slave slave = createSlave();
    FreeStyleProject project = createFreeStyleProject();

    // First, attempt to run our project before adding the property
    Future<FreeStyleBuild> build = project.scheduleBuild2(0);
    assertBuildStatus(Result.SUCCESS, build.get(20, TimeUnit.SECONDS));

    // Add the build-blocker property and try again
    slave.getNodeProperties().add(new RejectAllTasksProperty());

    build = project.scheduleBuild2(0);
    try {
      build.get(10, TimeUnit.SECONDS);
      fail("Expected timeout exception");
    } catch (TimeoutException e) {
      List<BuildableItem> buildables = jenkins.getQueue().getBuildableItems();
      assertNotNull(buildables);
      assertEquals(1, buildables.size());

      BuildableItem item = buildables.get(0);
      assertEquals(project, item.task);
      assertNotNull(item.getCauseOfBlockage());
      assertEquals(
          Messages.Queue_WaitingForNextAvailableExecutor(),
          item.getCauseOfBlockage().getShortDescription());
    }
  }
 public void testMissingStableBuild() throws Exception {
   FreeStyleProject other = createFreeStyleProject(),
       p = createProject(other.getName(), "", "", true, false, false);
   // Make an unstable build in "other"
   other.getBuildersList().add(new UnstableBuilder());
   assertBuildStatus(Result.UNSTABLE, other.scheduleBuild2(0, new UserCause()).get());
   assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0, new UserCause()).get());
 }
  @Test
  public void testRebuild() throws Exception {
    // job with promotion process
    FreeStyleProject p1 = j.createFreeStyleProject("promojob");

    // setup promotion process
    JobPropertyImpl promotion = new JobPropertyImpl(p1);
    p1.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new SelfPromotionCondition(false));

    // build it
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p1.scheduleBuild2(0));
    j.waitUntilNoActivity();

    // verify that promotion happened
    Assert.assertSame(proc.getBuilds().getLastBuild().getTarget(), b1);

    // job with parameter
    FreeStyleProject p2 = j.createFreeStyleProject("paramjob");

    // add promoted build param
    p2.addProperty(
        new ParametersDefinitionProperty(
            new PromotedBuildParameterDefinition(
                "var", "promojob", "promo", "promoted build param to test rebuild")));

    // build with parameter
    FreeStyleBuild b2 = j.assertBuildStatusSuccess(p2.scheduleBuild2(0));

    // validate presence of parameter
    ParametersAction a1 = b2.getAction(ParametersAction.class);
    Assert.assertNotNull(a1);
    Assert.assertFalse(a1.getParameters().isEmpty());
    ParameterValue v1 = a1.getParameter("var");
    Assert.assertTrue(v1 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv1 = (PromotedBuildParameterValue) v1;
    Assert.assertEquals(b1.getNumber(), pbpv1.getRun().getNumber());

    // rebuild it
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage page = wc.getPage(b2, "rebuild");
    HtmlForm form = page.getFormByName("config");
    j.submit(form);
    j.waitUntilNoActivity();

    // validate presence of parameter
    FreeStyleBuild rebuild = p2.getLastBuild();
    j.assertBuildStatusSuccess(rebuild);
    Assert.assertNotEquals(b2.getNumber(), rebuild.getNumber());
    ParametersAction a2 = rebuild.getAction(ParametersAction.class);
    Assert.assertNotNull(a2);
    Assert.assertFalse(a2.getParameters().isEmpty());
    ParameterValue v2 = a2.getParameter("var");
    Assert.assertTrue(v2 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv2 = (PromotedBuildParameterValue) v2;
    Assert.assertEquals(b1.getNumber(), pbpv2.getRun().getNumber());
  }
 public void testCopyWithFilter() throws Exception {
   FreeStyleProject other = createArtifactProject(),
       p = createProject(other.getName(), "**/bogus*, **/sub*, bogus/**", "", false, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(false, "foo.txt", b);
   assertFile(true, "subdir/subfoo.txt", b);
   assertFile(false, "deepfoo/a/b/c.log", b);
 }
 public void testFlatten() throws Exception {
   FreeStyleProject other = createArtifactProject(),
       p = createProject(other.getName(), "", "newdir", false, true, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(true, "newdir/foo.txt", b);
   assertFile(true, "newdir/subfoo.txt", b);
   assertFile(true, "newdir/c.log", b);
 }
 public void testCopyToTarget() throws Exception {
   FreeStyleProject other = createArtifactProject(),
       p = createProject(other.getName(), "deep*/**", "new/deep/dir", true, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(false, "foo.txt", b);
   assertFile(false, "new/deep/dir/foo.txt", b);
   assertFile(true, "new/deep/dir/deepfoo/a/b/c.log", b);
 }
 /** Test that info about selected builds is added into the environment for later build steps. */
 public void testEnvData() throws Exception {
   // Also test conversion of job name to env var name, only keeping letters:
   FreeStyleProject other = createArtifactProject("My (Test) Job"),
       p = createProject(other.getName(), "", "", false, false, false);
   CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
   p.getBuildersList().add(envStep);
   // Bump up the build number a bit:
   for (int i = 0; i < 3; i++) other.assignBuildNumber();
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertEquals("4", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_MY_TEST_JOB"));
 }
 private Build safelyGenerateBuild(FreeStyleProject prj)
     throws InterruptedException, java.util.concurrent.ExecutionException {
   Build b;
   if (jRule
       .getPluginManager()
       .getPlugin("git")
       .getVersionNumber()
       .isNewerThan(new VersionNumber("2.4.0"))) {
     b = prj.scheduleBuild2(0, new Cause.UserIdCause(), new BuildData()).get();
   } else {
     b = prj.scheduleBuild2(0).get();
   }
   return b;
 }
  /** Verifies the queueing behavior in the presence of the expression. */
  public void testQueueBehavior() throws Exception {
    DumbSlave w32 = createSlave("win 32bit", null);
    DumbSlave w64 = createSlave("win 64bit", null);
    createSlave("linux 32bit", null);

    final SequenceLock seq = new SequenceLock();

    FreeStyleProject p1 = createFreeStyleProject();
    p1.getBuildersList()
        .add(
            new TestBuilder() {
              public boolean perform(
                  AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
                  throws InterruptedException, IOException {
                seq.phase(0); // first, make sure the w32 slave is occupied
                seq.phase(2);
                seq.done();
                return true;
              }
            });
    p1.setAssignedLabel(jenkins.getLabel("win && 32bit"));

    FreeStyleProject p2 = createFreeStyleProject();
    p2.setAssignedLabel(jenkins.getLabel("win && 32bit"));

    FreeStyleProject p3 = createFreeStyleProject();
    p3.setAssignedLabel(jenkins.getLabel("win"));

    Future<FreeStyleBuild> f1 = p1.scheduleBuild2(0);

    seq.phase(1); // we schedule p2 build after w32 slave is occupied
    Future<FreeStyleBuild> f2 = p2.scheduleBuild2(0);

    Thread.sleep(1000); // time window to ensure queue has tried to assign f2 build

    // p3 is tied to 'win', so even though p1 is busy, this should still go ahead and complete
    FreeStyleBuild b3 = assertBuildStatusSuccess(p3.scheduleBuild2(0));
    assertSame(w64, b3.getBuiltOn());

    seq.phase(3); // once we confirm that p3 build is over, we let p1 proceed

    // p1 should have been built on w32
    FreeStyleBuild b1 = assertBuildStatusSuccess(f1);
    assertSame(w32, b1.getBuiltOn());

    // and so is p2
    FreeStyleBuild b2 = assertBuildStatusSuccess(f2);
    assertSame(w32, b2.getBuiltOn());
  }
 /** Test copy from workspace instead of artifacts area */
 public void testCopyFromWorkspace() throws Exception {
   FreeStyleProject other = createFreeStyleProject(), p = createFreeStyleProject();
   p.getBuildersList()
       .add(
           new CopyArtifact(
               other.getName(), new WorkspaceSelector(), "**/*.txt", "", true, false));
   // Run a build that places a file in the workspace, but does not archive anything
   other.getBuildersList().add(new ArtifactBuilder());
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(true, "foo.txt", b);
   assertFile(true, "subfoo.txt", b);
   assertFile(false, "c.log", b);
 }
  @Bug(22641)
  public void testProcessProperlyKilledUnix() throws Exception {
    ProcessTree.enabled = true;
    if (Functions.isWindows()) return; // This test does not involve windows.

    FreeStyleProject sleepProject = createFreeStyleProject();
    FreeStyleProject processJob = createFreeStyleProject();

    sleepProject.getBuildersList().add(new Shell("nohup sleep 100000 &"));

    assertBuildStatusSuccess(sleepProject.scheduleBuild2(0).get());

    processJob.getBuildersList().add(new Shell("ps -ef | grep sleep"));

    assertLogNotContains("sleep 100000", processJob.scheduleBuild2(0).get());
  }
  @Test
  public void testParameterisedJobShouldSaveAllParameters() throws Exception {
    final FreeStyleProject project = createFreeStyleProject("ParameterisedJob");

    // set parameters
    final ParameterDefinition param1 =
        new StringParameterDefinition("myStringParam", "myStringValue", "My String Parameter");
    final ParameterDefinition param2 =
        new BooleanParameterDefinition("myBooleanParam", false, "My Boolean Parameter");
    project.addProperty(new ParametersDefinitionProperty(param1, param2));

    // enable audit2db plugin
    final DbAuditPublisher plugin = getPlugin();
    project.getPublishersList().add((Publisher) plugin);

    // build now
    final Future<FreeStyleBuild> futureBuild = project.scheduleBuild2(0);
    final FreeStyleBuild build = futureBuild.get();
    Assert.assertNotNull(build);
    Assert.assertEquals("Unexpected build result", Result.SUCCESS, build.getResult());

    // check data persistence
    final BuildDetailsRepository repository = plugin.getRepository();
    final BuildDetails actual = repository.getBuildDetailsForBuild(build);
    final BuildDetails expected = new BuildDetailsImpl(build);
    Assert.assertEquals("Unexpected build details", expected, actual);
    Assert.assertNotNull("Unexpected null end date", actual.getEndDate());
    Assert.assertTrue("Unexpected duration", actual.getDuration() > 0L);
    Assert.assertEquals("Unexpected number of params", 2, actual.getParameters().size());
  }
 public void testCopyToSlave() throws Exception {
   DumbSlave node = createSlave();
   SlaveComputer c = node.getComputer();
   c.connect(false).get(); // wait until it's connected
   if (c.isOffline()) fail("Slave failed to go online: " + c.getLog());
   FreeStyleProject other = createArtifactProject(),
       p = createProject(other.getName(), "", "", false, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   p.setAssignedLabel(node.getSelfLabel());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertSame(node, b.getBuiltOn());
   assertFile(true, "foo.txt", b);
   assertFile(true, "subdir/subfoo.txt", b);
   assertFile(true, "deepfoo/a/b/c.log", b);
 }
  /**
   * Should not cause a fatal error even for an empty selector.
   *
   * @throws Exception
   */
  @Test
  public void testEmptySelector() throws Exception {
    FreeStyleProject copiee = j.createFreeStyleProject();
    FreeStyleProject copier = j.createFreeStyleProject();

    ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("SELECTOR");
    copier
        .getBuildersList()
        .add(
            CopyArtifactUtil.createCopyArtifact(
                copiee.getFullName(),
                null, // parameters
                pbs,
                "**/*", // filter
                "", // excludes
                false, // flatten
                true, // optional
                false // finterprintArtifacts
                ));
    FreeStyleBuild b =
        (FreeStyleBuild)
            copier
                .scheduleBuild2(0, new ParametersAction(new StringParameterValue("SELECTOR", "")))
                .get();
    j.assertBuildStatusSuccess(b);
  }
  @Test
  public void testTriggerName() throws Exception {
    List<RecipientProvider> recProviders = Collections.emptyList();
    PreBuildTrigger trigger =
        new PreBuildTrigger(
            recProviders,
            "$DEFAULT_RECIPIENTS",
            "$DEFAULT_REPLYTO",
            "$DEFAULT_SUBJECT",
            "$DEFAULT_CONTENT",
            "",
            0,
            "project");
    addEmailType(trigger);
    publisher.getConfiguredTriggers().add(trigger);

    FreeStyleBuild build = project.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(build);

    assertThat(
        "Email should have been triggered, so we should see it in the logs.",
        build.getLog(100),
        hasItems("Email was triggered for: " + PreBuildTrigger.TRIGGER_NAME));
    assertEquals(1, Mailbox.get("*****@*****.**").size());
    Message message = Mailbox.get("*****@*****.**").get(0);
    assertEquals(PreBuildTrigger.TRIGGER_NAME, message.getSubject());
  }
  @LocalData
  @Test
  public void setDescription() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS);

    CaseResult caseResult = build.getAction(TestResultAction.class).getFailedTests().get(0);
    String url =
        build.getUrl()
            + "/testReport/"
            + caseResult.getRelativePathFrom(caseResult.getTestResult());

    testSetDescription(url, caseResult);

    ClassResult classResult = caseResult.getParent();
    url =
        build.getUrl()
            + "/testReport/"
            + classResult.getParent().getSafeName()
            + "/"
            + classResult.getSafeName();
    testSetDescription(url, classResult);

    PackageResult packageResult = classResult.getParent();
    url = build.getUrl() + "/testReport/" + classResult.getParent().getSafeName();
    testSetDescription(url, packageResult);
  }
 @Test
 @Issue("JENKINS-25312")
 public void testMarkSuccessOnCommitNotifierFailure() throws Exception {
   FreeStyleProject prj = jRule.createFreeStyleProject();
   prj.getPublishersList().add(new GitHubCommitNotifier(Result.SUCCESS.toString()));
   Build b = prj.scheduleBuild2(0).get();
   jRule.assertBuildStatus(Result.SUCCESS, b);
 }
 public void testParameters() throws Exception {
   FreeStyleProject other = createArtifactProject(),
       p = createProject("$PROJSRC", "$BASE/*.txt", "$TARGET/bar", false, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b =
       p.scheduleBuild2(
               0,
               new UserCause(),
               new ParametersAction(
                   new StringParameterValue("PROJSRC", other.getName()),
                   new StringParameterValue("BASE", "*r"),
                   new StringParameterValue("TARGET", "foo")))
           .get();
   assertBuildStatusSuccess(b);
   assertFile(false, "foo/bar/foo.txt", b);
   assertFile(true, "foo/bar/subdir/subfoo.txt", b);
 }
  /**
   * Push the build around to different nodes via the assignment to make sure it gets where we need
   * it to.
   */
  public void testQueueBehavior2() throws Exception {
    DumbSlave s = createSlave("win", null);

    FreeStyleProject p = createFreeStyleProject();

    p.setAssignedLabel(jenkins.getLabel("!win"));
    FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertSame(jenkins, b.getBuiltOn());

    p.setAssignedLabel(jenkins.getLabel("win"));
    b = assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertSame(s, b.getBuiltOn());

    p.setAssignedLabel(jenkins.getLabel("!win"));
    b = assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertSame(jenkins, b.getBuiltOn());
  }
 protected FreeStyleBuild build(
     final FreeStyleProject project,
     final Result expectedResult,
     final String... expectedNewlyCommittedFiles)
     throws Exception {
   final FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserIdCause()).get();
   System.out.println(build.getLog(50));
   return build;
 }
  /**
   * Creates a new freestyle project and checks if the rebuild action is available on the project
   * level.
   *
   * @throws Exception Exception
   */
  public void testWhenProjectWithoutParamsThenRebuildProjectAvailable() throws Exception {
    FreeStyleProject project = createFreeStyleProject();

    FreeStyleBuild build = project.scheduleBuild2(0).get();

    RebuildLastCompletedBuildAction action =
        build.getProject().getAction(RebuildLastCompletedBuildAction.class);
    assertNotNull(action);
  }
 @Test
 @Issue("JENKINS-23641")
 public void testNoBuildData() throws Exception {
   FreeStyleProject prj = jRule.createFreeStyleProject("23641_noBuildData");
   prj.getPublishersList().add(new GitHubCommitNotifier());
   Build b = prj.scheduleBuild2(0).get();
   jRule.assertBuildStatus(Result.FAILURE, b);
   jRule.assertLogContains(BuildDataHelper_NoBuildDataError(), b);
 }
 public void testSpecificBuildSelector() throws Exception {
   FreeStyleProject other = createArtifactProject(), p = createFreeStyleProject();
   p.getBuildersList()
       .add(
           new CopyArtifact(
               other.getName(), new SpecificBuildSelector("1"), "*.txt", "", false, false));
   assertBuildStatusSuccess(
       other
           .scheduleBuild2(
               0,
               new UserCause(),
               new ParametersAction(new StringParameterValue("FOO", "buildone")))
           .get());
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()));
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(true, "foo.txt", b);
   assertFile(true, "buildone.txt", b);
   assertFile(false, "subdir/subfoo.txt", b);
 }
  @LocalData
  @Test
  public void persistence() throws Exception {
    project.scheduleBuild2(0).get(60, TimeUnit.SECONDS);

    reloadJenkins();

    FreeStyleBuild build = project.getBuildByNumber(1);

    assertTestResults(build);
  }
 /** Test copying artifacts from a particular configuration of a matrix job */
 public void testMatrixJob() throws Exception {
   MatrixProject other = createMatrixArtifactProject();
   FreeStyleProject p = createProject(other.getName() + "/FOO=two", "", "", true, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(true, "foo.txt", b);
   assertFile(true, "two.txt", b);
   assertFile(true, "subdir/subfoo.txt", b);
   assertFile(true, "deepfoo/a/b/c.log", b);
 }
 /** Test copying all artifacts from a maven job */
 public void testMavenAll() throws Exception {
   MavenModuleSet mp = setupMavenJob();
   assertBuildStatusSuccess(mp.scheduleBuild2(0, new UserCause()).get());
   FreeStyleProject p = createProject(mp.getName(), "", "", true, false, false);
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   String dir = "org.jvnet.hudson.main.test.multimod/";
   assertFile(true, dir + "moduleA/1.0-SNAPSHOT/moduleA-1.0-SNAPSHOT.jar", b);
   assertFile(true, dir + "moduleA/1.0-SNAPSHOT/pom.xml", b);
   assertFile(true, dir + "moduleB/1.0-SNAPSHOT/moduleB-1.0-SNAPSHOT.jar", b);
   assertFile(true, dir + "moduleB/1.0-SNAPSHOT/pom.xml", b);
   assertFile(true, dir + "moduleC/1.0-SNAPSHOT/moduleC-1.0-SNAPSHOT.jar", b);
   assertFile(true, dir + "moduleC/1.0-SNAPSHOT/pom.xml", b);
   // Test with filter
   p = createProject(mp.getName(), "**/*.jar", "", true, false, false);
   b = p.scheduleBuild2(0, new UserCause()).get();
   assertFile(true, dir + "moduleA/1.0-SNAPSHOT/moduleA-1.0-SNAPSHOT.jar", b);
   assertFile(false, dir + "moduleA/1.0-SNAPSHOT/pom.xml", b);
   assertFile(true, dir + "moduleB/1.0-SNAPSHOT/moduleB-1.0-SNAPSHOT.jar", b);
   assertFile(false, dir + "moduleB/1.0-SNAPSHOT/pom.xml", b);
   assertFile(true, dir + "moduleC/1.0-SNAPSHOT/moduleC-1.0-SNAPSHOT.jar", b);
   assertFile(false, dir + "moduleC/1.0-SNAPSHOT/pom.xml", b);
 }
  /** This test unit is for testing a commit hook using the UUID */
  @Bug(399165)
  @Test
  public void testPrebuiltCommitTrigger() throws Exception {
    hudson.setCrumbIssuer(null);

    // First create repository with 1 file and commit information
    SVNCommitInfo info = createSVNRepository();
    assertNull(info.getErrorMessage());
    assertEquals("Failed to create 1 revision.", 1, info.getNewRevision());

    // Create freestyle project with SVN SCM.
    FreeStyleProject project = createFreeStyleProject();
    project.setScm(new SubversionSCM("file:///tmp/399165"));
    SCMTrigger trigger = new SCMTrigger("0 */6 * * *");
    project.addTrigger(trigger);
    trigger.start(project, true);

    // Execute build (This is critical for fixing eclipse bug: 399165)
    assertBuildStatusSuccess(project.scheduleBuild2(0));

    // Commit a file again.
    info = createSecondCommit();
    assertNull(info.getErrorMessage());
    assertEquals("Failed to create second commit.", 2, info.getNewRevision());

    // Create post-commit hook
    WebClient wc = new WebClient();
    WebRequestSettings wr =
        new WebRequestSettings(
            new URL(
                getURL() + "subversion/" + repository.getRepositoryUUID(false) + "/notifyCommit"),
            HttpMethod.POST);
    wr.setRequestBody("A   dirB/file2.txt");
    wr.setAdditionalHeader("Content-Type", "text/plain;charset=UTF-8");

    wr.setAdditionalHeader("X-Hudson-Subversion-Revision", "2");

    WebConnection conn = wc.getWebConnection();
    System.out.println(wr);
    WebResponse resp = conn.getResponse(wr);
    assertTrue(isGoodHttpStatus(resp.getStatusCode()));

    waitUntilNoActivity();
    FreeStyleBuild b = project.getLastBuild();
    assertNotNull(b);

    assertBuildStatus(Result.SUCCESS, b);

    assertEquals("Failed to execute a buid.", 2, b.getNumber());
  }
  /**
   * Returns the future object for a newly created project.
   *
   * @param blockingJobName the name for the project
   * @param shell the shell command task to add
   * @param label the label to bind to master or slave
   * @return the future object for a newly created project
   * @throws IOException
   */
  private Future<FreeStyleBuild> createBlockingProject(
      String blockingJobName, Shell shell, Label label) throws IOException {
    FreeStyleProject blockingProject = this.createFreeStyleProject(blockingJobName);
    blockingProject.setAssignedLabel(label);

    blockingProject.getBuildersList().add(shell);
    Future<FreeStyleBuild> future = blockingProject.scheduleBuild2(0);

    while (!blockingProject.isBuilding()) {
      // wait until job is started
    }

    return future;
  }