/** 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());
  }
 public Object invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException {
   File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile();
   try {
     SVNURL svnUrl = SVNURL.parseURIEncoded(tagUrl);
     ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
     sam.setAuthenticationProvider(authProvider);
     SVNCopyClient copyClient = new SVNCopyClient(sam, null);
     buildListener.getLogger().println("[RELEASE] Creating subversion tag: " + tagUrl);
     SVNCopySource source =
         new SVNCopySource(SVNRevision.WORKING, SVNRevision.WORKING, workingCopy);
     SVNCommitInfo commitInfo =
         copyClient.doCopy(
             new SVNCopySource[] {source},
             svnUrl,
             false,
             true,
             true,
             commitMessage,
             new SVNProperties());
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       throw new IOException("Failed to create tag: " + errorMessage.getFullMessage());
     }
     return null;
   } catch (SVNException e) {
     throw new IOException("Subversion tag creation failed: " + e.getMessage());
   }
 }
 public Object invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException {
   File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile();
   try {
     ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
     sam.setAuthenticationProvider(authProvider);
     SVNCommitClient commitClient = new SVNCommitClient(sam, null);
     buildListener.getLogger().println("[RELEASE] " + commitMessage);
     debuggingLogger.fine(String.format("Committing working copy: '%s'", workingCopy));
     SVNCommitInfo commitInfo =
         commitClient.doCommit(
             new File[] {workingCopy},
             true,
             commitMessage,
             null,
             null,
             true,
             true,
             SVNDepth.INFINITY);
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       throw new IOException("Failed to commit working copy: " + errorMessage.getFullMessage());
     }
     return null;
   } catch (SVNException e) {
     throw new IOException(e.getMessage());
   }
 }
 public void safeRevertTag(String tagUrl, String commitMessageSuffix) {
   try {
     log("Reverting subversion tag: " + tagUrl);
     SVNURL svnUrl = SVNURL.parseURIEncoded(tagUrl);
     SVNCommitClient commitClient = new SVNCommitClient(createAuthenticationManager(), null);
     SVNCommitInfo commitInfo =
         commitClient.doDelete(new SVNURL[] {svnUrl}, COMMENT_PREFIX + commitMessageSuffix);
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       log("Failed to revert '" + tagUrl + "': " + errorMessage.getFullMessage());
     }
   } catch (SVNException e) {
     log("Failed to revert '" + tagUrl + "': " + e.getLocalizedMessage());
   }
 }