@Override
  public void execute(final SmtpMessage message) throws IOException {
    final SVNWCClient svnWCClient = svnClientManager.getWCClient();

    try {
      final SVNPropertyData svnPropData =
          svnWCClient.doGetProperty(
              svnRepositoryURL,
              propName,
              SVNRevision.create(revision),
              SVNRevision.create(revision));

      LOG.info(
          "PROPCHANGE: getName()="
              + svnPropData.getName()
              + " getValue()="
              + svnPropData.getValue());
      System.out.println(svnPropData.getName() + ":" + svnPropData.getValue());

      // TODO write the prop change to the OutputStream

      // TODO dont forget old prop value
    } catch (final SVNException se) {
      throw new IOException("SVN communication error: " + se.getMessage(), se);
    }
  }
 /**
  * Parses an input string and be it a representation of either a revision number, or a timestamp,
  * or a revision keyword, constructs an <b>SVNRevision</b> representation of the revision.
  *
  * @param value a string to be parsed
  * @return an <b>SVNRevision</b> object that holds the revision information parsed from <code>
  *     value</code>; however if an input string is not a valid one which can be successfully
  *     transformed to an <b>SVNRevision</b> the return value is {@link SVNRevision#UNDEFINED}
  */
 public static SVNRevision parse(String value) {
   if (value == null) {
     return SVNRevision.UNDEFINED;
   }
   if (value.startsWith("-r")) {
     value = value.substring("-r".length());
   }
   value = value.trim();
   if (value.startsWith("{") && value.endsWith("}")) {
     value = value.substring(1);
     value = value.substring(0, value.length() - 1);
     try {
       Date date = DateFormat.getDateInstance().parse(value);
       return SVNRevision.create(date);
     } catch (ParseException e) {
       return SVNRevision.UNDEFINED;
     }
   }
   try {
     long number = Long.parseLong(value);
     return SVNRevision.create(number);
   } catch (NumberFormatException nfe) {
   }
   SVNRevision revision = (SVNRevision) ourValidRevisions.get(value.toUpperCase());
   if (revision == null) {
     return UNDEFINED;
   }
   return revision;
 }
  private boolean buildModule(String url, SVNLogClient svnlc, SVNXMLLogHandler logHandler)
      throws IOException2 {
    PrintStream logger = listener.getLogger();
    Long prevRev = previousRevisions.get(url);
    if (prevRev == null) {
      logger.println("no revision recorded for " + url + " in the previous build");
      return false;
    }
    Long thisRev = thisRevisions.get(url);
    if (thisRev == null) {
      listener.error(
          "No revision found for URL: "
              + url
              + " in "
              + SubversionSCM.getRevisionFile(build)
              + ". Revision file contains: "
              + thisRevisions.keySet());
      return false;
    }
    if (thisRev.equals(prevRev)) {
      logger.println("no change for " + url + " since the previous build");
      return false;
    }

    try {
      if (debug)
        listener
            .getLogger()
            .printf(
                "Computing changelog of %1s from %2s to %3s\n",
                SVNURL.parseURIEncoded(url), prevRev + 1, thisRev);
      svnlc.doLog(
          SVNURL.parseURIEncoded(url),
          null,
          SVNRevision.UNDEFINED,
          SVNRevision.create(prevRev + 1),
          SVNRevision.create(thisRev),
          false, // Don't stop on copy.
          true, // Report paths.
          0, // Retrieve log entries for unlimited number of revisions.
          debug ? new DebugSVNLogHandler(logHandler) : logHandler);
      if (debug) listener.getLogger().println("done");
    } catch (SVNException e) {
      throw new IOException2("revision check failed on " + url, e);
    }
    return true;
  }
 @Override
 protected void updateStatus(Attributes attributes, PortableStatus status, Lock.Builder lock)
     throws SAXException {
   final String revision = attributes.getValue("revision");
   if (!StringUtil.isEmpty(revision)) {
     status.setCommittedRevision(SVNRevision.create(Long.valueOf(revision)));
   }
 }
Example #5
0
  /**
   * Method getSelectedRevisions
   *
   * @return
   */
  public List<SVNRevisionRange> getSelectedRevisions() {
    List<SVNRevisionRange> revisions = new LinkedList<SVNRevisionRange>();

    if ((jTable1.getSelectedRowCount() == 0)
        || (jTable1.getSelectedRowCount() == jTable1.getRowCount())) {
      revisions.add(
          new SVNRevisionRange(SVNRevision.create(minRevision), SVNRevision.create(maxRevision)));
    } else {
      for (int i : jTable1.getSelectedRows()) {
        int selected = jTable1.getRowSorter().convertRowIndexToModel(i);
        long r = data.get(selected).getRevision();

        revisions.add(new SVNRevisionRange(SVNRevision.create(r - 1), SVNRevision.create(r)));
      }
    }

    return revisions;
  }
 protected SvnFileRevision createRevision(final SVNLogEntry logEntry, final String copyPath)
     throws SVNException {
   Date date = logEntry.getDate();
   String author = logEntry.getAuthor();
   String message = logEntry.getMessage();
   SVNRevision rev = SVNRevision.create(logEntry.getRevision());
   final SVNURL url = myRepositoryRoot.appendPath(myLastPath, true);
   return new SvnFileRevision(
       myVcs, myPegRevision, rev, url.toString(), author, date, message, copyPath, myCharset);
 }
 private File dump(SVNURL url) throws SVNException {
   final File repositoryRoot = new File(url.getPath());
   final SVNAdminClient adminClient = SVNClientManager.newInstance().getAdminClient();
   adminClient.doDump(
       repositoryRoot,
       SVNDebugLog.getDefaultLog().createOutputLogStream(),
       SVNRevision.create(0),
       SVNRevision.HEAD,
       false,
       false);
   return repositoryRoot;
 }
  private void collectLogEntries(
      final ProgressIndicator indicator,
      FilePath file,
      VcsException[] exception,
      final Consumer<VcsFileRevision> result,
      final Ref<Boolean> supports15Ref)
      throws SVNException, VcsException {
    SVNWCClient wcClient = myVcs.createWCClient();
    SVNInfo info =
        wcClient.doInfo(new File(file.getIOFile().getAbsolutePath()), SVNRevision.UNDEFINED);
    wcClient.setEventHandler(
        new ISVNEventHandler() {
          public void handleEvent(SVNEvent event, double progress) throws SVNException {}

          public void checkCancelled() throws SVNCancelException {
            indicator.checkCanceled();
          }
        });
    if (info == null || info.getRepositoryRootURL() == null) {
      exception[0] =
          new VcsException("File ''{0}'' is not under version control" + file.getIOFile());
      return;
    }
    final String url = info.getURL() == null ? null : info.getURL().toString();
    String relativeUrl = url;
    final SVNURL repoRootURL = info.getRepositoryRootURL();

    final String root = repoRootURL.toString();
    if (url != null && url.startsWith(root)) {
      relativeUrl = url.substring(root.length());
    }
    if (indicator != null) {
      indicator.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", url));
    }
    final SVNRevision pegRevision = info.getRevision();
    SVNLogClient client = myVcs.createLogClient();

    final boolean supports15 = SvnUtil.checkRepositoryVersion15(myVcs, url);
    supports15Ref.set(supports15);
    client.doLog(
        new File[] {new File(file.getIOFile().getAbsolutePath())},
        SVNRevision.HEAD,
        SVNRevision.create(1),
        SVNRevision.UNDEFINED,
        false,
        true,
        supports15,
        0,
        null,
        new MyLogEntryHandler(
            myVcs, url, pegRevision, relativeUrl, result, repoRootURL, file.getCharset()));
  }
Example #9
0
  private String getPatch(long revA, long revB) throws SVNException, UnsupportedEncodingException {
    // Prepare required arguments.
    SVNURL svnURL = SVNURL.fromFile(getDirectory());

    // Get diffClient.
    SVNClientManager clientManager = SVNClientManager.newInstance();
    SVNDiffClient diffClient = clientManager.getDiffClient();

    // Using diffClient, write the changes by commitId into
    // byteArrayOutputStream, as unified format.
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    diffClient.doDiff(
        svnURL,
        null,
        SVNRevision.create(revA),
        SVNRevision.create(revB),
        SVNDepth.INFINITY,
        true,
        byteArrayOutputStream);

    return byteArrayOutputStream.toString(Config.getCharset().name());
  }
Example #10
0
  public void mergeNext() throws SVNException, VcsException {
    myAtStart = false;

    File destination = new File(myTargetPath);
    MergeClient client = myVcs.getFactory(destination).createMergeClient();

    if (myReintegrate) {
      client.merge(
          SvnTarget.fromURL(mySourceUrl), destination, false, createDiffOptions(), myHandler);
    } else {
      client.merge(
          SvnTarget.fromURL(mySourceUrl, SVNRevision.create(mySourceCopyRevision)),
          SvnTarget.fromURL(mySourceUrl, SVNRevision.create(mySourceLatestRevision)),
          destination,
          SVNDepth.INFINITY,
          true,
          false,
          false,
          true,
          createDiffOptions(),
          myHandler);
    }
  }
 public SvnFileRevision(
     SvnVcs vcs, SVNRevision pegRevision, LogEntry logEntry, String url, String copyFromPath) {
   final SVNRevision revision = SVNRevision.create(logEntry.getRevision());
   myRevisionNumber = new SvnRevisionNumber(revision);
   myPegRevision = pegRevision;
   myRevision = revision;
   myAuthor = logEntry.getAuthor();
   myDate = logEntry.getDate();
   myCommitMessage = logEntry.getMessage();
   myCopyFromPath = copyFromPath;
   myVCS = vcs;
   myURL = url;
   myMergeSources = new ArrayList<>();
 }
Example #12
0
  @Override
  public String getPatch(String commitId) throws SVNException {
    // Prepare required arguments.
    SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName));
    long rev = Integer.parseInt(commitId);

    // Get diffClient.
    SVNClientManager clientManager = SVNClientManager.newInstance();
    SVNDiffClient diffClient = clientManager.getDiffClient();

    // Using diffClient, write the changes by commitId into
    // byteArrayOutputStream, as unified format.
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    diffClient.doDiff(
        svnURL,
        null,
        SVNRevision.create(rev - 1),
        SVNRevision.create(rev),
        SVNDepth.INFINITY,
        true,
        byteArrayOutputStream);

    return byteArrayOutputStream.toString();
  }
Example #13
0
    @Override
    protected void load() {
      String relativeUrl = myUrl;
      final SVNURL repoRootURL = myInfo.getRepositoryRootURL();

      final String root = repoRootURL.toString();
      if (myUrl != null && myUrl.startsWith(root)) {
        relativeUrl = myUrl.substring(root.length());
      }
      if (myPI != null) {
        myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl));
      }
      final SVNRevision pegRevision = myInfo.getRevision();
      final SvnTarget target = SvnTarget.fromFile(myFile.getIOFile(), myPeg);
      try {
        myVcs
            .getFactory(target)
            .createHistoryClient()
            .doLog(
                target,
                myFrom == null ? SVNRevision.HEAD : myFrom,
                myTo == null ? SVNRevision.create(1) : myTo,
                false,
                true,
                myShowMergeSources && mySupport15,
                myLimit + 1,
                null,
                new MyLogEntryHandler(
                    myVcs,
                    myUrl,
                    pegRevision,
                    relativeUrl,
                    createConsumerAdapter(myConsumer),
                    repoRootURL,
                    myFile.getCharset()));
      } catch (SVNCancelException e) {
        //
      } catch (SVNException e) {
        myException = new VcsException(e);
      } catch (VcsException e) {
        myException = e;
      }
    }
 private static Pair<SVNRevision, SVNURL> createRemoteFolder(
     final SvnVcs17 vcs, final SVNURL parent, final String folderName) throws SVNException {
   SVNURL url = parent.appendPath(folderName, false);
   final String urlText = url.toString();
   final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
   if (indicator != null) {
     indicator.checkCanceled();
     indicator.setText(SvnBundle.message("share.directory.create.dir.progress.text", urlText));
   }
   final SVNCommitInfo info =
       vcs.createCommitClient()
           .doMkDir(
               new SVNURL[] {url},
               SvnBundle.message(
                   "share.directory.commit.message",
                   folderName,
                   ApplicationNamesInfo.getInstance().getFullProductName()));
   return new Pair<SVNRevision, SVNURL>(SVNRevision.create(info.getNewRevision()), url);
 }
 @Override
 protected void load() {
   if (myPI != null) {
     myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl));
   }
   SVNWCClient wcClient = myVcs.createWCClient();
   try {
     final SVNURL svnurl = SVNURL.parseURIEncoded(myUrl);
     SVNInfo info = null;
     info = wcClient.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD);
     final String root = info.getRepositoryRootURL().toString();
     String relativeUrl = myUrl;
     if (myUrl.startsWith(root)) {
       relativeUrl = myUrl.substring(root.length());
     }
     SVNLogClient client = myVcs.createLogClient();
     client.doLog(
         svnurl,
         new String[] {},
         SVNRevision.UNDEFINED,
         SVNRevision.HEAD,
         SVNRevision.create(1),
         false,
         true,
         mySupport15,
         0,
         null,
         new RepositoryLogEntryHandler(
             myVcs,
             myUrl,
             SVNRevision.UNDEFINED,
             relativeUrl,
             myConsumer,
             info.getRepositoryRootURL()));
   } catch (SVNCancelException e) {
     //
   } catch (SVNException e) {
     myException = new VcsException(e);
   } catch (VcsException e) {
     myException = e;
   }
 }
    @Override
    protected void updateStatus(Attributes attributes, PortableStatus status, Lock.Builder lock)
        throws SAXException {
      final StatusType propertiesStatus = parsePropertiesStatus(attributes);
      status.setPropertiesStatus(propertiesStatus);
      final StatusType contentsStatus = parseContentsStatus(attributes);
      status.setContentsStatus(contentsStatus);

      if (StatusType.STATUS_CONFLICTED.equals(propertiesStatus)
          || StatusType.STATUS_CONFLICTED.equals(contentsStatus)) {
        status.setIsConflicted(true);
      }

      // optional
      final String locked = attributes.getValue("wc-locked");
      if (locked != null && Boolean.parseBoolean(locked)) {
        status.setIsLocked(true);
      }
      final String copied = attributes.getValue("copied");
      if (copied != null && Boolean.parseBoolean(copied)) {
        status.setIsCopied(true);
      }
      final String treeConflicted = attributes.getValue("tree-conflicted");
      if (treeConflicted != null && Boolean.parseBoolean(treeConflicted)) {
        status.setIsConflicted(true);
      }

      final String switched = attributes.getValue("switched");
      if (switched != null && Boolean.parseBoolean(switched)) {
        status.setIsSwitched(true);
      }

      final String revision = attributes.getValue("revision");
      if (!StringUtil.isEmptyOrSpaces(revision)) {
        try {
          final long number = Long.parseLong(revision);
          status.setRevision(SVNRevision.create(number));
        } catch (NumberFormatException e) {
          throw new SAXException(e);
        }
      }
    }
Example #17
0
    private void loadBackwards(SVNURL svnurl) throws SVNException, VcsException {
      // this method is called when svnurl does not exist in latest repository revision - thus
      // concrete old revision is used for "info"
      // command to get repository url
      Info info = myVcs.getInfo(svnurl, myPeg, myPeg);
      final SVNURL rootURL = info != null ? info.getRepositoryRootURL() : null;
      final String root = rootURL != null ? rootURL.toString() : "";
      String relativeUrl = myUrl;
      if (myUrl.startsWith(root)) {
        relativeUrl = myUrl.substring(root.length());
      }

      final RepositoryLogEntryHandler repositoryLogEntryHandler =
          new RepositoryLogEntryHandler(
              myVcs,
              myUrl,
              SVNRevision.UNDEFINED,
              relativeUrl,
              new ThrowableConsumer<VcsFileRevision, SVNException>() {
                @Override
                public void consume(VcsFileRevision revision) throws SVNException {
                  myConsumer.consume(revision);
                }
              },
              rootURL);
      repositoryLogEntryHandler.setThrowCancelOnMeetPathCreation(true);

      SvnTarget target = SvnTarget.fromURL(rootURL, myFrom);
      myVcs
          .getFactory(target)
          .createHistoryClient()
          .doLog(
              target,
              myFrom,
              myTo == null ? SVNRevision.create(1) : myTo,
              false,
              true,
              myShowMergeSources && mySupport15,
              1,
              null,
              repositoryLogEntryHandler);
    }
Example #18
0
  /**
   * 将svn上removePath路径下的内容导出到本地的localPath路径下 支持文件下载及目录导出
   *
   * @param svnClientManager svn客户端操作对象
   * @param remotePath svn远程目录
   * @param revision 目标版本
   * @param localPath 本地保存目录
   */
  public static void export(
      SVNClientManager svnClientManager, String remotePath, long revision, String localPath)
      throws Exception {
    File localF = new File(localPath);
    if (!localF.exists()) {
      localF.mkdirs();
    } else {
      FileUtils.cleanDirectory(localF);
    }

    SVNUpdateClient svnUpdateClient = svnClientManager.getUpdateClient();
    svnUpdateClient.doExport(
        SVNURL.parseURIEncoded(Constants.CRS_REPOS + remotePath),
        new File(localPath),
        SVNRevision.HEAD,
        SVNRevision.create(revision),
        null,
        true,
        SVNDepth.INFINITY);
  }
    @Override
    protected void load() {
      String relativeUrl = myUrl;
      final SVNURL repoRootURL = myInfo.getRepositoryRootURL();

      final String root = repoRootURL.toString();
      if (myUrl != null && myUrl.startsWith(root)) {
        relativeUrl = myUrl.substring(root.length());
      }
      if (myPI != null) {
        myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl));
      }
      final SVNRevision pegRevision = myInfo.getRevision();
      SVNLogClient client = myVcs.createLogClient();
      try {
        client.doLog(
            new File[] {new File(myFile.getIOFile().getAbsolutePath())},
            SVNRevision.HEAD,
            SVNRevision.create(1),
            SVNRevision.UNDEFINED,
            false,
            true,
            mySupport15,
            0,
            null,
            new MyLogEntryHandler(
                myVcs,
                myUrl,
                pegRevision,
                relativeUrl,
                myConsumer,
                repoRootURL,
                myFile.getCharset()));
      } catch (SVNCancelException e) {
        //
      } catch (SVNException e) {
        myException = new VcsException(e);
      } catch (VcsException e) {
        myException = e;
      }
    }
 @Override
 public void run(ContinuationContext context) {
   final SvnContentRevision base =
       SvnContentRevision.createBaseRevision(
           myVcs, myNewFilePath, myCommittedRevision.getRevision());
   final SvnContentRevision remote =
       SvnContentRevision.createRemote(
           myVcs,
           myOldFilePath,
           SVNRevision.create(myDescription.getSourceRightVersion().getPegRevision()));
   try {
     final ContentRevision newBase =
         new SimpleContentRevision(
             base.getContent(), myNewFilePath, base.getRevisionNumber().asString());
     final ContentRevision newRemote =
         new SimpleContentRevision(
             remote.getContent(), myNewFilePath, remote.getRevisionNumber().asString());
     myTheirsChanges.add(new Change(newBase, newRemote));
   } catch (VcsException e) {
     context.handleException(e, true);
   }
 }
 private void collectLogEntriesForRepository(
     final ProgressIndicator indicator,
     FilePath file,
     final Consumer<VcsFileRevision> result,
     final Ref<Boolean> supports15Ref)
     throws SVNException, VcsException {
   final String url = file.getPath().replace('\\', '/');
   if (indicator != null) {
     indicator.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", url));
   }
   SVNWCClient wcClient = myVcs.createWCClient();
   final SVNURL svnurl = SVNURL.parseURIEncoded(url);
   SVNInfo info = wcClient.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD);
   final String root = info.getRepositoryRootURL().toString();
   String relativeUrl = url;
   if (url.startsWith(root)) {
     relativeUrl = url.substring(root.length());
   }
   SVNLogClient client = myVcs.createLogClient();
   final boolean supports15 = SvnUtil.checkRepositoryVersion15(myVcs, root);
   supports15Ref.set(supports15);
   // todo log in history provider
   client.doLog(
       svnurl,
       new String[] {},
       SVNRevision.UNDEFINED,
       SVNRevision.HEAD,
       SVNRevision.create(1),
       false,
       true,
       supports15,
       0,
       null,
       new RepositoryLogEntryHandler(
           myVcs, url, SVNRevision.UNDEFINED, relativeUrl, result, info.getRepositoryRootURL()));
 }
Example #22
0
  @Override
  public MergeResult execute() throws ScmException {
    try {
      // set up client
      SVNDiffClient client = getClientManager().getDiffClient();
      // set up intermediate lists for result
      final ArrayList<String> addedFiles = new ArrayList<String>();
      final ArrayList<String> mergedFiles = new ArrayList<String>();
      final ArrayList<String> deletedFiles = new ArrayList<String>();
      client.setEventHandler(
          new EventHandler() {
            @Override
            public void handleEvent(SVNEvent paramSVNEvent, double paramDouble)
                throws SVNException {
              if (paramSVNEvent.getAction() != null) {
                int actionId = paramSVNEvent.getAction().getID();

                if (actionId == SVNEventAction.UPDATE_ADD.getID()) {
                  addedFiles.add(paramSVNEvent.getFile().getPath());
                } else if (actionId == SVNEventAction.UPDATE_DELETE.getID()) {
                  deletedFiles.add(paramSVNEvent.getFile().getPath());
                } else if (actionId == SVNEventAction.UPDATE_UPDATE.getID()) {
                  mergedFiles.add(paramSVNEvent.getFile().getPath());
                } else if (actionId == SVNEventAction.UPDATE_REPLACE.getID()) {
                  mergedFiles.add(paramSVNEvent.getFile().getPath());
                  // else do nothing
                }
              }
            }
          });

      // set up parameters
      SVNURL repositoryUrl = getRepositoryUrl();
      SVNURL branchesUrl = repositoryUrl.appendPath(AbstractSvnCommand.BRANCHES, true);
      SVNURL branchUrl = branchesUrl.appendPath(this.branchName, true);
      File destinationPath = getWorkingCopy();
      SVNDepth depth = SVNDepth.INFINITY;
      boolean useAncestry = true;
      boolean force = false;
      boolean dryRun = false;
      boolean recordOnly = false;

      SVNRevisionRange rangeToMerge = new SVNRevisionRange(SVNRevision.create(1), SVNRevision.HEAD);

      // perform merge
      client.doMerge(
          branchUrl,
          SVNRevision.HEAD,
          Collections.singleton(rangeToMerge),
          destinationPath,
          depth,
          useAncestry,
          force,
          dryRun,
          recordOnly);

      // assemble mergeResult
      MergeResult result = new MergeResult();
      result.setAdds(addedFiles.toArray(new String[addedFiles.size()]));
      result.setDeletions(deletedFiles.toArray(new String[deletedFiles.size()]));
      result.setMerges(mergedFiles.toArray(new String[mergedFiles.size()]));

      // TODO find out how to collect conflicting files...
      return result;

    } catch (SVNException exception) {
      throw new ScmException(exception);
    }
  }
  private void getDiff(long rev, String path, char type, int nbatt) {

    // http://old.nabble.com/file/p31961153/Comparision.java
    String durl = "";

    // System.out.println(path);
    switch (urlType) {
      case 0:
        durl = this.serverUrl + path;
        break;
      case 1:
        try {
          SVNURL serverUrl = SVNURL.parseURIDecoded(this.url);
          durl = serverUrl.getProtocol() + "://" + serverUrl.getHost() + path;
        } catch (SVNException e2) {
          e2.printStackTrace();
        }
        break;
      case 2:
        durl = mergeUrls(this.serverUrl, path);
        break;
    }

    //	System.out.println("Type:"+this.urlType+", Url:"+durl);
    SVNURL svnurl = null;
    try {
      svnurl = SVNURL.parseURIEncoded(durl);
    } catch (SVNException e1) {
      System.out.println(
          "Error 3:" + durl + "-" + urlType + "ser:" + this.serverUrl + "path: " + path);
    }
    int plus = 0;
    int minus = 0;

    // if(type =='M'){
    SVNRevision previous = SVNRevision.create(rev - 1);
    SVNRevision current = SVNRevision.create(rev);
    OutputStream os = new MyOutputStream();

    try {
      if (type == 'M') {
        this.svnDiffCl.doDiff(svnurl, previous, svnurl, current, SVNDepth.EMPTY, false, os);
        int[] c = ((MyOutputStream) os).count();
        plus = c[0];
        minus = c[1];
      } else if (type == 'A') {
        this.svnWcClient.doGetFileContents(svnurl, current, current, true, os);
        plus = ((MyOutputStream) os).counLines();
      } else if (type == 'D' || type == 'R') {
        this.svnWcClient.doGetFileContents(svnurl, previous, previous, true, os);
        minus = ((MyOutputStream) os).counLines();

      } else System.out.println("#################Type chelou ! " + type);

    } catch (SVNException e) {
      if (nbatt < 2) {
        this.urlType = (this.urlType + 1) % 3;
        getDiff(rev, path, type, nbatt + 1);
        return;
      } else {
        // System.out.println("Error 4: "+ this.serverUrl+"-"+this.url+"-"+path);
        // e.printStackTrace();
        // System.out.println(e.getMessage());
      }
    }
    // }
    String daCl = sdf.format(new Date(this.date.getTimeInMillis()));
    if (type == 'D') type = 'R';
    commits.add(
        this.revision
            + ","
            + this.author
            + ","
            + daCl
            + ","
            + this.date.getTimeInMillis()
            + ","
            + type
            + ","
            + path
            + ","
            + plus
            + ","
            + minus);
    System.out.print(".");
  }
Example #24
0
    @Override
    protected void load() {
      if (myPI != null) {
        myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl));
      }

      try {
        if (myForceBackwards) {
          SVNURL svnurl = SVNURL.parseURIEncoded(myUrl);
          if (!existsNow(svnurl)) {
            loadBackwards(svnurl);
            return;
          }
        }

        final SVNURL svnurl = SVNURL.parseURIEncoded(myUrl);
        SVNRevision operationalFrom = myFrom == null ? SVNRevision.HEAD : myFrom;
        // TODO: try to rewrite without separately retrieving repository url by item url - as this
        // command could require authentication
        // TODO: and it is not "clear enough/easy to implement" with current design (for some cases)
        // how to cache credentials (if in
        // TODO: non-interactive mode)
        final SVNURL rootURL = SvnUtil.getRepositoryRoot(myVcs, svnurl);
        if (rootURL == null) {
          throw new VcsException("Could not find repository root for URL: " + myUrl);
        }
        final String root = rootURL.toString();
        String relativeUrl = myUrl;
        if (myUrl.startsWith(root)) {
          relativeUrl = myUrl.substring(root.length());
        }
        SvnTarget target = SvnTarget.fromURL(svnurl, myPeg == null ? myFrom : myPeg);
        RepositoryLogEntryHandler handler =
            new RepositoryLogEntryHandler(
                myVcs,
                myUrl,
                SVNRevision.UNDEFINED,
                relativeUrl,
                createConsumerAdapter(myConsumer),
                rootURL);

        myVcs
            .getFactory(target)
            .createHistoryClient()
            .doLog(
                target,
                operationalFrom,
                myTo == null ? SVNRevision.create(1) : myTo,
                false,
                true,
                myShowMergeSources && mySupport15,
                myLimit + 1,
                null,
                handler);
      } catch (SVNCancelException e) {
        //
      } catch (SVNException e) {
        myException = new VcsException(e);
      } catch (VcsException e) {
        myException = e;
      }
    }
  @Override
  public Pair<SvnChangeList, FilePath> getOneList(final VirtualFile file, VcsRevisionNumber number)
      throws VcsException {
    final RootUrlInfo rootUrlInfo =
        myVcs.getSvnFileUrlMapping().getWcRootForFilePath(new File(file.getPath()));
    if (rootUrlInfo == null) return null;
    final VirtualFile root = rootUrlInfo.getVirtualFile();
    if (root == null) return null;
    final SvnRepositoryLocation svnRootLocation =
        (SvnRepositoryLocation) getLocationFor(new FilePathImpl(root));
    if (svnRootLocation == null) return null;
    final String url = svnRootLocation.getURL();
    final long revision;
    try {
      revision = Long.parseLong(number.asString());
    } catch (NumberFormatException e) {
      throw new VcsException(e);
    }

    final SvnChangeList[] result = new SvnChangeList[1];
    final SVNLogClient logger;
    final SVNRevision revisionBefore;
    final SVNURL repositoryUrl;
    final SVNURL svnurl;
    final SVNInfo targetInfo;
    try {
      logger = myVcs.createLogClient();
      revisionBefore = SVNRevision.create(revision);

      svnurl = SVNURL.parseURIEncoded(url);
      final SVNWCClient client = myVcs.createWCClient();
      final SVNInfo info = client.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD);
      targetInfo = client.doInfo(new File(file.getPath()), SVNRevision.UNDEFINED);
      if (info == null) {
        throw new VcsException("Can not get repository URL");
      }
      repositoryUrl = info.getRepositoryRootURL();
    } catch (SVNException e) {
      LOG.info(e);
      throw new VcsException(e);
    }

    tryExactHit(svnRootLocation, result, logger, revisionBefore, repositoryUrl, svnurl);
    if (result[0] == null) {
      tryByRoot(result, logger, revisionBefore, repositoryUrl);
      if (result[0] == null) {
        FilePath path =
            tryStepByStep(svnRootLocation, result, logger, revisionBefore, targetInfo, svnurl);
        path = path == null ? new FilePathImpl(file) : path;
        // and pass & take rename context there
        return new Pair<SvnChangeList, FilePath>(result[0], path);
      }
    }
    if (result[0].getChanges().size() == 1) {
      final Collection<Change> changes = result[0].getChanges();
      final Change change = changes.iterator().next();
      final ContentRevision afterRevision = change.getAfterRevision();
      if (afterRevision != null) {
        return new Pair<SvnChangeList, FilePath>(result[0], afterRevision.getFile());
      } else {
        return new Pair<SvnChangeList, FilePath>(result[0], new FilePathImpl(file));
      }
    }
    String relativePath =
        SVNPathUtil.getRelativePath(
            targetInfo.getRepositoryRootURL().toString(), targetInfo.getURL().toString());
    relativePath = relativePath.startsWith("/") ? relativePath : "/" + relativePath;
    final Change targetChange = result[0].getByPath(relativePath);
    if (targetChange == null) {
      FilePath path =
          tryStepByStep(svnRootLocation, result, logger, revisionBefore, targetInfo, svnurl);
      path = path == null ? new FilePathImpl(file) : path;
      // and pass & take rename context there
      return new Pair<SvnChangeList, FilePath>(result[0], path);
    }
    return new Pair<SvnChangeList, FilePath>(result[0], new FilePathImpl(file));
  }
  private void getCommittedChangesImpl(
      ChangeBrowserSettings settings,
      final String url,
      final String[] filterUrls,
      final int maxCount,
      final Consumer<SVNLogEntry> resultConsumer,
      final boolean includeMergedRevisions,
      final boolean filterOutByDate)
      throws VcsException {
    final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
    if (progress != null) {
      progress.setText(SvnBundle.message("progress.text.changes.collecting.changes"));
      progress.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", url));
    }
    try {
      SVNLogClient logger = myVcs.createLogClient();

      final String author = settings.getUserFilter();
      final Date dateFrom = settings.getDateAfterFilter();
      final Long changeFrom = settings.getChangeAfterFilter();
      final Date dateTo = settings.getDateBeforeFilter();
      final Long changeTo = settings.getChangeBeforeFilter();

      final SVNRevision revisionBefore;
      if (dateTo != null) {
        revisionBefore = SVNRevision.create(dateTo);
      } else if (changeTo != null) {
        revisionBefore = SVNRevision.create(changeTo.longValue());
      } else {
        SVNRepository repository = null;
        final long revision;
        try {
          repository = myVcs.createRepository(url);
          revision = repository.getLatestRevision();
        } finally {
          if (repository != null) {
            repository.closeSession();
          }
        }
        revisionBefore = SVNRevision.create(revision);
      }
      final SVNRevision revisionAfter;
      if (dateFrom != null) {
        revisionAfter = SVNRevision.create(dateFrom);
      } else if (changeFrom != null) {
        revisionAfter = SVNRevision.create(changeFrom.longValue());
      } else {
        revisionAfter = SVNRevision.create(1);
      }

      logger.doLog(
          SVNURL.parseURIEncoded(url),
          filterUrls,
          revisionBefore,
          revisionBefore,
          revisionAfter,
          settings.STOP_ON_COPY,
          true,
          includeMergedRevisions,
          maxCount,
          null,
          new ISVNLogEntryHandler() {
            public void handleLogEntry(SVNLogEntry logEntry) {
              if (myProject.isDisposed()) throw new ProcessCanceledException();
              if (progress != null) {
                progress.setText2(
                    SvnBundle.message(
                        "progress.text2.processing.revision", logEntry.getRevision()));
                progress.checkCanceled();
              }
              if (filterOutByDate && logEntry.getDate() == null) {
                // do not add lists without info - this situation is possible for lists where there
                // are paths that user has no rights to observe
                return;
              }
              if (author == null || author.equalsIgnoreCase(logEntry.getAuthor())) {
                resultConsumer.consume(logEntry);
              }
            }
          });
    } catch (SVNException e) {
      throw new VcsException(e);
    }
  }
Example #27
0
 public void setPegRevision(long pegRevision) {
   this.pegRevision = SVNRevision.create(pegRevision);
 }
Example #28
0
  /**
   * Parses an input string and be it a representation of either a revision number, or a timestamp,
   * or a revision keyword, constructs an <b>SVNRevision</b> representation of the revision.
   *
   * @param value a string to be parsed
   * @return an <b>SVNRevision</b> object that holds the revision information parsed from <code>
   *     value</code>; however if an input string is not a valid one which can be successfully
   *     transformed to an <b>SVNRevision</b> the return value is {@link SVNRevision#UNDEFINED}
   */
  public static SVNRevision parse(String value) {
    if (value == null) {
      return SVNRevision.UNDEFINED;
    }
    if (value.startsWith("-r")) {
      value = value.substring("-r".length());
    }
    value = value.trim();
    if (value.startsWith("{") && value.endsWith("}")) {
      value = value.substring(1);
      value = value.substring(0, value.length() - 1);

      try {
        Calendar date = Calendar.getInstance();
        for (Iterator patterns = ourTimeFormatPatterns.iterator(); patterns.hasNext(); ) {
          Pattern pattern = (Pattern) patterns.next();
          Matcher matcher = pattern.matcher(value);
          if (matcher.matches()) {
            if (pattern == ISO_8601_EXTENDED_DATE_ONLY_PATTERN
                || pattern == ISO_8601_BASIC_DATE_ONLY_PATTERN) {
              int year = Integer.parseInt(matcher.group(1));
              int month = Integer.parseInt(matcher.group(2));
              int day = Integer.parseInt(matcher.group(3));
              date.clear();
              date.set(year, month - 1, day);
            } else if (pattern == ISO_8601_EXTENDED_UTC_PATTERN
                || pattern == ISO_8601_EXTENDED_OFFSET_PATTERN
                || pattern == ISO_8601_BASIC_UTC_PATTERN
                || pattern == ISO_8601_BASIC_OFFSET_PATTERN
                || pattern == ISO_8601_GNU_FORMAT_PATTERN
                || pattern == SVN_LOG_DATE_FORMAT_PATTERN) {
              int year = Integer.parseInt(matcher.group(1));
              int month = Integer.parseInt(matcher.group(2));
              int day = Integer.parseInt(matcher.group(3));
              int hours = Integer.parseInt(matcher.group(4));
              int minutes = Integer.parseInt(matcher.group(5));
              int seconds = 0;
              int milliseconds = 0;
              if (matcher.group(6) != null) {
                seconds = Integer.parseInt(matcher.group(7));
                if (matcher.group(8) != null) {
                  String millis = matcher.group(9);
                  millis = millis.length() <= 3 ? millis : millis.substring(0, 3);
                  milliseconds = Integer.parseInt(millis);
                }
              }
              date.clear();
              date.set(year, month - 1, day, hours, minutes, seconds);
              date.set(Calendar.MILLISECOND, milliseconds);

              if (pattern == ISO_8601_EXTENDED_OFFSET_PATTERN
                  || pattern == ISO_8601_BASIC_OFFSET_PATTERN
                  || pattern == ISO_8601_GNU_FORMAT_PATTERN) {
                int zoneOffsetInMillis = "+".equals(matcher.group(10)) ? +1 : -1;
                int hoursOffset = Integer.parseInt(matcher.group(11));
                int minutesOffset =
                    matcher.group(12) != null ? Integer.parseInt(matcher.group(13)) : 0;
                zoneOffsetInMillis =
                    zoneOffsetInMillis * ((hoursOffset * 3600 + minutesOffset * 60) * 1000);
                date.set(Calendar.ZONE_OFFSET, zoneOffsetInMillis);
                date.set(Calendar.DST_OFFSET, 0);
              } else if (pattern == SVN_LOG_DATE_FORMAT_PATTERN && matcher.group(10) != null) {
                int zoneOffsetInMillis = "+".equals(matcher.group(11)) ? +1 : -1;
                int hoursOffset = Integer.parseInt(matcher.group(12));
                int minutesOffset =
                    matcher.group(13) != null ? Integer.parseInt(matcher.group(13)) : 0;
                zoneOffsetInMillis =
                    zoneOffsetInMillis * ((hoursOffset * 3600 + minutesOffset * 60) * 1000);
                date.set(Calendar.ZONE_OFFSET, zoneOffsetInMillis);
                date.set(Calendar.DST_OFFSET, 0);
              } else if (((pattern == ISO_8601_EXTENDED_UTC_PATTERN)
                      || (pattern == ISO_8601_BASIC_UTC_PATTERN))
                  && "Z".equals(matcher.group(10))) {
                date.set(Calendar.ZONE_OFFSET, 0);
                date.set(Calendar.DST_OFFSET, 0);
              }
            } else if (pattern == TIME_ONLY_PATTERN) {
              int hours = Integer.parseInt(matcher.group(1));
              int minutes = Integer.parseInt(matcher.group(2));
              int seconds = 0;
              int milliseconds = 0;
              if (matcher.group(3) != null) {
                seconds = Integer.parseInt(matcher.group(4));
                if (matcher.group(5) != null) {
                  String millis = matcher.group(6);
                  millis = millis.length() <= 3 ? millis : millis.substring(0, 3);
                  milliseconds = Integer.parseInt(millis);
                }
              }
              date.set(Calendar.HOUR_OF_DAY, hours);
              date.set(Calendar.MINUTE, minutes);
              date.set(Calendar.SECOND, seconds);
              date.set(Calendar.MILLISECOND, milliseconds);
            }
            return SVNRevision.create(date.getTime());
          }
        }
        return SVNRevision.UNDEFINED;
      } catch (NumberFormatException e) {
        return SVNRevision.UNDEFINED;
      }
    }
    try {
      long number = Long.parseLong(value);
      return SVNRevision.create(number);
    } catch (NumberFormatException nfe) {
    }
    SVNRevision revision = (SVNRevision) ourValidRevisions.get(value.toUpperCase());
    if (revision == null) {
      return UNDEFINED;
    }
    return revision;
  }
Example #29
0
 public void setRevision(long revision) {
   this.revision = SVNRevision.create(revision);
 }
Example #30
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);
    }
  }