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());
   }
 }
Exemplo n.º 2
0
  public void run() throws SVNException {
    List targets = getSVNEnvironment().combineTargets(null, true);
    if (targets.size() < 2) {
      SVNErrorManager.error(
          SVNErrorMessage.create(SVNErrorCode.CL_INSUFFICIENT_ARGS), SVNLogType.CLIENT);
    }
    SVNPath dst = new SVNPath((String) targets.remove(targets.size() - 1));
    if (!dst.isURL()) {
      if (getSVNEnvironment().getMessage() != null
          || getSVNEnvironment().getFileData() != null
          || getSVNEnvironment().getRevisionProperties() != null) {
        SVNErrorManager.error(
            SVNErrorMessage.create(
                SVNErrorCode.CL_UNNECESSARY_LOG_MESSAGE,
                "Local, non-commit operations do not take a log message or revision properties"),
            SVNLogType.CLIENT);
      }
    }

    Collection sources = new ArrayList();
    boolean sourceIsURL = false;
    for (int i = 0; i < targets.size(); i++) {
      String targetName = (String) targets.get(i);
      SVNPath source = new SVNPath(targetName, true);
      if (i == 0) {
        sourceIsURL = source.isURL();
      }
      if (source.isURL()) {
        sources.add(
            new SVNCopySource(
                source.getPegRevision(), getSVNEnvironment().getStartRevision(), source.getURL()));
      } else {
        sources.add(
            new SVNCopySource(
                source.getPegRevision(), getSVNEnvironment().getStartRevision(), source.getFile()));
      }
    }

    SVNCopyClient client = getSVNEnvironment().getClientManager().getCopyClient();
    if (!sourceIsURL && !dst.isURL()) {
      if (!getSVNEnvironment().isQuiet()) {
        client.setEventHandler(new SVNNotifyPrinter(getSVNEnvironment()));
      }
    } else if (!sourceIsURL && dst.isURL()) {
      // skip
    } else if (sourceIsURL && !dst.isURL()) {
      if (!getSVNEnvironment().isQuiet()) {
        client.setEventHandler(new SVNNotifyPrinter(getSVNEnvironment(), true, false, false));
      }
    }
    client.setCommitHandler(getSVNEnvironment());
    SVNCopySource[] copySources =
        (SVNCopySource[]) sources.toArray(new SVNCopySource[sources.size()]);
    if (dst.isURL()) {
      SVNCommitInfo info =
          client.doCopy(
              copySources,
              dst.getURL(),
              false,
              getSVNEnvironment().isParents(),
              false,
              getSVNEnvironment().getMessage(),
              getSVNEnvironment().getRevisionProperties());

      if (!getSVNEnvironment().isQuiet()) {
        getSVNEnvironment().printCommitInfo(info);
      }
    } else {
      client.doCopy(copySources, dst.getFile(), false, getSVNEnvironment().isParents(), false);
    }
  }
Exemplo n.º 3
0
  /**
   * Pass the absolute path of the base directory where all example data will be created in arg[0].
   * The sample will create:
   *
   * <p>- arg[0]/exampleRepository - repository with some test data - arg[0]/exampleWC - working
   * copy checked out from exampleRepository
   */
  public static void main(String[] args) {
    // initialize SVNKit to work through file:/// protocol
    SamplesUtility.initializeFSFSprotocol();

    File baseDirectory = new File(args[0]);
    File reposRoot = new File(baseDirectory, "exampleRepository");
    File wcRoot = new File(baseDirectory, "exampleWC");

    try {
      // first create a repository and fill it with data
      SamplesUtility.createRepository(reposRoot);
      SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot);
      // print out new revision info
      System.out.println(info);

      SVNClientManager clientManager = SVNClientManager.newInstance();
      clientManager.setEventHandler(new EventHandler());

      SVNURL reposURL = SVNURL.fromFile(reposRoot);

      // copy A to A_copy in repository (url-to-url copy)
      SVNCopyClient copyClient = clientManager.getCopyClient();
      SVNURL A_URL = reposURL.appendPath("A", true);
      SVNURL copyTargetURL = reposURL.appendPath("A_copy", true);
      SVNCopySource copySource = new SVNCopySource(SVNRevision.UNDEFINED, SVNRevision.HEAD, A_URL);
      info =
          copyClient.doCopy(
              new SVNCopySource[] {copySource},
              copyTargetURL,
              false,
              false,
              true,
              "copy A to A_copy",
              null);
      // print out new revision info
      System.out.println(info);

      // checkout the entire repository tree
      SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);

      // now make some changes to the A tree
      SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
      SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);

      SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
      wcClient.doSetProperty(
          new File(wcRoot, "A/B"),
          "spam",
          SVNPropertyValue.create("egg"),
          false,
          SVNDepth.EMPTY,
          null,
          null);

      // commit local changes
      SVNCommitClient commitClient = clientManager.getCommitClient();
      commitClient.doCommit(
          new File[] {wcRoot},
          false,
          "committing changes",
          null,
          null,
          false,
          false,
          SVNDepth.INFINITY);

      // now diff the base revision of the working copy against the repository
      SVNDiffClient diffClient = clientManager.getDiffClient();
      SVNRevisionRange rangeToMerge = new SVNRevisionRange(SVNRevision.create(1), SVNRevision.HEAD);

      diffClient.doMerge(
          A_URL,
          SVNRevision.HEAD,
          Collections.singleton(rangeToMerge),
          new File(wcRoot, "A_copy"),
          SVNDepth.UNKNOWN,
          true,
          false,
          false,
          false);

      // now make some changes to the A tree again
      // change file contents of iota and A/D/gamma
      SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text2 appended to 'iota'", true);
      SamplesUtility.writeToFile(new File(wcRoot, "A/D/gamma"), "New text in 'gamma'", false);
      // remove A/C from version control
      wcClient.doDelete(new File(wcRoot, "A/C"), false, true, false);

      // commit local changes
      commitClient.doCommit(
          new File[] {wcRoot},
          false,
          "committing changes again",
          null,
          null,
          false,
          false,
          SVNDepth.INFINITY);

      /* do the same merge call, merge-tracking feature will merge only those revisions
       * which were not still merged.
       */
      diffClient.doMerge(
          A_URL,
          SVNRevision.HEAD,
          Collections.singleton(rangeToMerge),
          new File(wcRoot, "A_copy"),
          SVNDepth.UNKNOWN,
          true,
          false,
          false,
          false);

    } catch (SVNException svne) {
      System.out.println(svne.getErrorMessage());
      System.exit(1);
    } catch (IOException ioe) {
      ioe.printStackTrace();
      System.exit(1);
    }
  }