private static void copySVNURL(String fileName) {
    File file = new File(fileName);

    SVNClientManager clientManager = SVNClientManager.newInstance();

    SVNStatusClient statusClient = clientManager.getStatusClient();
    SVNStatus status = null;
    try {
      status = statusClient.doStatus(file, false);
    } catch (SVNException e) {
      logger.error("SVN Status was not possible", e);
      String message = "Some error with SVN. Probably the file selected is not in SVN.";
      String title = "Error";
      JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
      System.exit(ERROR_END);
    }
    if (status != null) {
      SVNURL fileSVNUrl = status.getRemoteURL();
      logger.info("SVN URL " + fileSVNUrl);
      Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
      StringSelection stringSelection = new StringSelection(fileSVNUrl.toString());
      clpbrd.setContents(stringSelection, null);
      String message = "Remote SVN URL has been coppied to the clipboard";
      String title = "Success!";
      JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE);
    } else {
      String message = "File " + fileName + " cannot be found in SVN";
      String title = "File not found in Repository";
      JOptionPane.showMessageDialog(null, message, title, JOptionPane.WARNING_MESSAGE);
    }
  }
 public void linkPath(SVNURL url, String path, String lockToken, long revison, boolean startEmpty)
     throws SVNException {
   assertValidRevision(revison);
   if (lockToken == null) {
     write(
         "(w(ssnw))",
         new Object[] {
           "link-path",
           path,
           url.toString(),
           getRevisionObject(revison),
           Boolean.valueOf(startEmpty)
         });
   } else {
     write(
         "(w(ssnw(s)))",
         new Object[] {
           "link-path",
           path,
           url.toString(),
           getRevisionObject(revison),
           Boolean.valueOf(startEmpty),
           lockToken
         });
   }
 }
  private boolean reparent(SVNURL url) throws SVNException {
    if (myConnection != null) {
      if (getLocation().equals(url)) {
        return true;
      }
      try {
        Object[] buffer = new Object[] {"reparent", url.toString()};
        write("(w(s))", buffer);
        authenticate();
        read("[()]", null, true);

        String newLocation = url.toString();
        String rootLocation = myRepositoryRoot.toString();

        if (!(newLocation.startsWith(rootLocation)
            && (newLocation.length() == rootLocation.length()
                || (newLocation.length() > rootLocation.length()
                    && newLocation.charAt(rootLocation.length()) == '/')))) {
          return false;
        }

        return true;
      } catch (SVNException e) {
        closeSession();
        if (e instanceof SVNCancelException || e instanceof SVNAuthenticationException) {
          throw e;
        }
      }
    }
    return false;
  }
  private void onStateChangedToSuccess(final AuthenticationRequest obj) {
    myCopiesPassiveResults.put(getKey(obj), true);
    myVcs.invokeRefreshSvnRoots(false);

    final List<SVNURL> outdatedRequests = new LinkedList<SVNURL>();
    final Collection<SVNURL> keys = getAllCurrentKeys();
    for (SVNURL key : keys) {
      final SVNURL commonURLAncestor = SVNURLUtil.getCommonURLAncestor(key, obj.getUrl());
      if ((commonURLAncestor != null)
          && (!StringUtil.isEmptyOrSpaces(commonURLAncestor.getHost()))
          && (!StringUtil.isEmptyOrSpaces(commonURLAncestor.getPath()))) {
        // final AuthenticationRequest currObj = getObj(key);
        // if ((currObj != null) && passiveValidation(myVcs.getProject(), key, true,
        // currObj.getRealm(), currObj.getKind())) {
        outdatedRequests.add(key);
        // }
      }
    }
    log("on state changed ");
    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              public void run() {
                for (SVNURL key : outdatedRequests) {
                  removeLazyNotificationByKey(key);
                }
              }
            },
            ModalityState.NON_MODAL);
  }
 /**
  * Gets the URL (repository location) of the ancestor from which the item was copied. That is when
  * the item is added with history.
  *
  * @return the item ancestor's URL
  */
 @Override
 public String getCopyFromURL() {
   if (!isCopied()) return null;
   final SVNInfo info = initInfo();
   if (info == null) return null;
   SVNURL url = initInfo().getCopyFromURL();
   return url == null ? null : url.toString();
 }
Esempio n. 6
0
  /**
   * 获取 path2/revision2 相对于path1/revision1的变更日志
   *
   * @param svnClientManager svn客服端管理
   * @param path1
   * @param revision1
   * @param path2
   * @param revision2
   * @return 变更列表
   * @throws Exception
   */
  public static Collection<SVNLog> diff(
      SVNClientManager svnClientManager,
      final String path1,
      final long revision1,
      final String path2,
      final long revision2)
      throws Exception {

    final Collection<SVNLog> diffs = new LinkedList<SVNLog>();

    SVNURL url1 = SVNURL.parseURIEncoded(Constants.CRS_REPOS + path1);
    SVNURL url2 = SVNURL.parseURIEncoded(Constants.CRS_REPOS + path2);

    svnClientManager
        .getDiffClient()
        .doDiffStatus(
            url1,
            SVNRevision.HEAD,
            url2,
            SVNRevision.HEAD,
            SVNDepth.UNKNOWN,
            false,
            new ISVNDiffStatusHandler() {

              @Override
              public void handleDiffStatus(SVNDiffStatus diffStatus) throws SVNException {

                boolean logging = false;
                SVNLog svnLog = new SVNLog();
                SVNStatusType svnStatusType = diffStatus.getModificationType();
                if (svnStatusType == SVNStatusType.CHANGED
                    || svnStatusType == SVNStatusType.STATUS_ADDED
                    || svnStatusType == SVNStatusType.STATUS_MODIFIED) {
                  svnLog.setType(SVNLog.TYPE_ADD);
                  svnLog.setRevision(revision2);
                  logging = true;
                }

                if (svnStatusType == SVNStatusType.STATUS_DELETED) {
                  svnLog.setType(SVNLog.TYPE_DEL);
                  logging = true;
                }

                if (logging) {
                  if (diffStatus.getKind() == SVNNodeKind.DIR) {
                    svnLog.setEntryKind(SVNLog.ENTRY_DIR);
                  }
                  if (diffStatus.getKind() == SVNNodeKind.FILE) {
                    svnLog.setEntryKind(SVNLog.ENTRY_FILE);
                  }
                  svnLog.setPath("/" + diffStatus.getPath());
                  diffs.add(svnLog);
                }
              }
            });

    return diffs;
  }
 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);
 }
Esempio n. 8
0
 public static void createVersionedDirectory(
     File path, SVNURL url, SVNURL rootURL, String uuid, long revNumber, SVNDepth depth)
     throws SVNException {
   createVersionedDirectory(
       path,
       url != null ? url.toString() : null,
       rootURL != null ? rootURL.toString() : null,
       uuid,
       revNumber,
       depth);
 }
Esempio n. 9
0
 @Override
 protected SvnFileRevision createRevision(
     final LogEntry logEntry, final String copyPath, LogEntryPath entryPath)
     throws SVNException {
   final SVNURL url =
       entryPath == null
           ? myRepositoryRoot.appendPath(myLastPathCorrector.getBefore(), false)
           : myRepositoryRoot.appendPath(entryPath.getPath(), true);
   return new SvnFileRevision(
       myVcs, SVNRevision.UNDEFINED, logEntry, url.toString(), copyPath, null);
 }
Esempio n. 10
0
  private HTTPSSLKeyManager createKeyManager() {
    if (!myIsSecured) {
      return null;
    }

    SVNURL location = myRepository.getLocation();
    ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();
    String sslRealm =
        "<" + location.getProtocol() + "://" + location.getHost() + ":" + location.getPort() + ">";
    return new HTTPSSLKeyManager(authManager, sslRealm, location);
  }
  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()));
  }
 public SVNURL ask(final SVNURL url) {
   for (SVNURL root : myRoots) {
     if (root.equals(SVNURLUtil.getCommonURLAncestor(root, url))) {
       return root;
     }
   }
   final SVNURL newUrl = SvnUtil.getRepositoryRoot(myVcs, url);
   if (newUrl != null) {
     myRoots.add(newUrl);
     return newUrl;
   }
   return null;
 }
Esempio n. 13
0
 public DefaultSVNSSLTrustManager(
     File authDir,
     SVNURL url,
     File[] serverCertFiles,
     boolean useKeyStore,
     DefaultSVNAuthenticationManager authManager) {
   myURL = url;
   myAuthDirectory = authDir;
   myRealm = "https://" + url.getHost() + ":" + url.getPort();
   myAuthManager = authManager;
   myIsUseKeyStore = useKeyStore;
   myServerCertFiles = serverCertFiles;
 }
Esempio n. 14
0
 @Override
 public void run(ContinuationContext continuationContext) {
   final SVNURL branch =
       SvnBranchConfigurationManager.getInstance(myProject)
           .getSvnBranchConfigManager()
           .getWorkingBranchWithReload(myWcInfo.getUrl(), myRoot);
   if (branch != null && (!myWcInfo.getUrl().equals(branch))) {
     final String branchString = branch.toString();
     if (SVNPathUtil.isAncestor(branchString, myWcInfo.getRootUrl())) {
       final String subPath = SVNPathUtil.getRelativePath(branchString, myWcInfo.getRootUrl());
       mySourceUrl = SVNPathUtil.append(mySourceUrl, subPath);
     }
   }
 }
 public void diff(
     SVNURL url,
     long tRevision,
     long revision,
     String target,
     boolean ignoreAncestry,
     boolean recursive,
     boolean getContents,
     ISVNReporterBaton reporter,
     ISVNEditor editor)
     throws SVNException {
   target = target == null ? "" : target;
   if (url == null) {
     SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.BAD_URL, "URL can not be NULL"));
   }
   Object[] buffer =
       getContents
           ? new Object[] {
             "diff",
             getRevisionObject(tRevision),
             target,
             Boolean.valueOf(recursive),
             Boolean.valueOf(ignoreAncestry),
             url.toString()
           }
           : new Object[] {
             "diff",
             getRevisionObject(tRevision),
             target,
             Boolean.valueOf(recursive),
             Boolean.valueOf(ignoreAncestry),
             url.toString(),
             Boolean.valueOf(getContents)
           };
   try {
     openConnection();
     write(getContents ? "(w((n)swws))" : "(w((n)swwsw))", buffer);
     authenticate();
     reporter.report(this);
     authenticate();
     read("*E", new Object[] {editor}, true);
     write("(w())", new Object[] {"success"});
     read("[()]", null, true);
   } catch (SVNException e) {
     closeSession();
     throw e;
   } finally {
     closeConnection();
   }
 }
  /**
   * Returns a list of contents from the trunk, branches, and tags directories.
   *
   * @param logClient
   * @param repoURL
   * @return List of directories.
   * @throws SVNException
   */
  private List<String> getSVNRootRepoDirectories(SVNLogClient logClient, SVNURL repoURL)
      throws SVNException {
    // Get the branches repository contents
    List<String> dirs = null;
    SVNURL branchesRepo = repoURL.appendPath(SVN_BRANCHES, true);
    SimpleSVNDirEntryHandler branchesEntryHandler = new SimpleSVNDirEntryHandler(null);
    logClient.doList(
        branchesRepo, SVNRevision.HEAD, SVNRevision.HEAD, false, false, branchesEntryHandler);
    List<String> branches = branchesEntryHandler.getDirs(isReverseByDate(), isReverseByName());
    branches.remove(SVN_BRANCHES);
    appendTargetDir(SVN_BRANCHES, branches);

    // Get the tags repository contents
    SVNURL tagsRepo = repoURL.appendPath(SVN_TAGS, true);
    SimpleSVNDirEntryHandler tagsEntryHandler = new SimpleSVNDirEntryHandler(null);
    logClient.doList(tagsRepo, SVNRevision.HEAD, SVNRevision.HEAD, false, false, tagsEntryHandler);
    List<String> tags = tagsEntryHandler.getDirs(isReverseByDate(), isReverseByName());
    tags.remove(SVN_TAGS);
    appendTargetDir(SVN_TAGS, tags);

    // Merge trunk with the contents of branches and tags.
    dirs = new ArrayList<String>();
    dirs.add(SVN_TRUNK);

    if (branches != null) {
      dirs.addAll(branches);
    }

    if (tags != null) {
      dirs.addAll(tags);
    }

    // Filter out any unwanted repository locations.
    if (StringUtils.isNotBlank(tagsFilter)) {
      Pattern filterPattern = Pattern.compile(tagsFilter);

      if ((dirs != null) && (dirs.size() > 0) && (filterPattern != null)) {
        List<String> temp = new ArrayList<String>();
        for (String dir : dirs) {
          if (filterPattern.matcher(dir).matches()) {
            temp.add(dir);
          }
        }
        dirs = temp;
      }
    }

    return dirs;
  }
  @Nullable
  private String getLastMergedRevision(final SVNRevision rev2, final SVNURL svnURL2) {
    if (!rev2.isValid() || rev2.isLocal()) {
      return null;
    } else {
      final long number = rev2.getNumber();
      if (number > 0) {
        return String.valueOf(number);
      } else {

        SVNRepository repos = null;
        try {
          repos = myVcs.createRepository(svnURL2.toString());
          final long latestRev = repos.getLatestRevision();
          return String.valueOf(latestRev);
        } catch (SVNException e) {
          return null;
        } finally {
          if (repos != null) {
            repos.closeSession();
          }
        }
      }
    }
  }
 public static String getRelativePath(SVNURL repoURL, SVNRepository repository)
     throws SVNException {
   String repoPath =
       repoURL.getPath().substring(repository.getRepositoryRoot(true).getPath().length());
   if (!repoPath.startsWith("/")) repoPath = "/" + repoPath;
   return repoPath;
 }
Esempio n. 19
0
  /**
   * 从svn上获取变更
   *
   * @param path svn目录
   * @param datumRevision 基准版本
   * @param expectRevision 目标版本
   * @param localPath 保存路径
   * @throws Exception
   */
  public static void getDelta(
      String path, long datumRevision, long expectRevision, String localPath) throws Exception {
    DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(
            Constants.CRS_REPOS_USER, Constants.CRS_REPOS_PWD);
    SVNClientManager svnClientManager = null;
    try {
      svnClientManager = SVNClientManager.newInstance(options, authManager);

      SVNRepository repository =
          svnClientManager.createRepository(SVNURL.parseURIEncoded(Constants.CRS_REPOS), true);

      Collection<SVNLog> logs = getLog(repository, path, datumRevision, expectRevision);

      // 创建本地目录
      File localDict = new File(localPath);
      if (!localDict.exists()) {
        localDict.mkdirs();
      } else {
        FileUtils.cleanDirectory(localDict);
      }

      // 获取添加、替换项
      getDelta4Add(repository, path, logs, localPath + Constants.UPDPKG_CODEDIR);

      // 将日志写入文件
      writeLogToFile(logs, new File(localPath + Constants.UPDPKG_UPDTXT));

    } finally {
      if (svnClientManager != null) {
        svnClientManager.dispose();
      }
    }
  }
  /** {@inheritDoc} */
  @NonNull
  @Override
  protected void retrieve(@NonNull final SCMHeadObserver observer, @NonNull TaskListener listener)
      throws IOException {
    SVNRepositoryView repository = null;
    try {
      listener.getLogger().println("Opening conection to " + remoteBase);
      SVNURL repoURL = SVNURL.parseURIEncoded(remoteBase);
      repository = openSession(repoURL);

      String repoPath =
          SubversionSCM.DescriptorImpl.getRelativePath(repoURL, repository.getRepository());
      List<String> prefix = Collections.emptyList();
      fetch(
          listener,
          repository,
          -1,
          repoPath,
          toPaths(splitCludes(includes)),
          prefix,
          prefix,
          toPaths(splitCludes(excludes)),
          getCriteria(),
          observer);
    } catch (SVNException e) {
      e.printStackTrace(listener.error("Could not communicate with Subversion server"));
      throw new IOException(e);
    } finally {
      closeSession(repository);
    }
  }
 /** {@inheritDoc} */
 @Override
 protected SCMRevision retrieve(String unparsedRevision, TaskListener listener)
     throws IOException, InterruptedException {
   try {
     listener.getLogger().println("Opening connection to " + remoteBase);
     SVNURL repoURL = SVNURL.parseURIEncoded(remoteBase);
     SVNRepositoryView repository = openSession(repoURL);
     String repoPath =
         SubversionSCM.DescriptorImpl.getRelativePath(repoURL, repository.getRepository());
     String base;
     long revision;
     Matcher pathAtRev = Pattern.compile("(.+)@(\\d+)").matcher(unparsedRevision);
     if (pathAtRev.matches()) {
       base = pathAtRev.group(1);
       revision = Long.parseLong(pathAtRev.group(2));
     } else {
       base = unparsedRevision;
       revision = -1;
     }
     String path = SVNPathUtil.append(repoPath, base);
     long resolvedRevision = repository.getNode(path, -1).getRevision();
     if (resolvedRevision == -1) {
       listener.getLogger().println("Could not find " + path);
       return null;
     }
     return new SCMRevisionImpl(new SCMHead(base), revision == -1 ? resolvedRevision : revision);
   } catch (SVNException e) {
     throw new IOException(e);
   }
 }
Esempio n. 22
0
  @Override
  public List<Commit> getHistory(int page, int limit, String until)
      throws AmbiguousObjectException, IOException, NoHeadException, GitAPIException, SVNException {
    // Get the repository
    SVNURL svnURL = SVNURL.fromFile(new File(repoPrefix + ownerName + "/" + projectName));
    org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL);

    // path to get log
    String[] paths = {"/"};

    // Determine revisions
    long startRevision = repository.getLatestRevision() - page * limit;
    long endRevision = startRevision - limit;
    if (endRevision < 1) {
      endRevision = 1;
    }

    // No log to return.
    if (startRevision < endRevision) {
      return new ArrayList<>();
    }

    // Get the logs
    List<Commit> result = new ArrayList<>();
    for (Object entry : repository.log(paths, null, startRevision, endRevision, false, false)) {
      result.add(new SvnCommit((SVNLogEntry) entry));
    }

    return result;
  }
 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());
   }
 }
  /**
   * SVNリポジトリの全ツリーを取得します。
   *
   * @param bean リポジトリBean
   * @return リポジトリルート
   * @throws LrdException Lrd共通例外
   */
  public static LrdNode getRepositoryRootNode(RepositoryBean bean) throws LrdException {

    RepositoryInfo repositoryInfo = bean.getRepositoryInfo();

    //        SVNLogClient logClient = SVNClientManager.newInstance(
    //                SVNWCUtil.createDefaultOptions(true),
    //                repositoryInfo.getAuthUser(),
    //                repositoryInfo.getAuthPass()).getLogClient();
    //        SVNRepositoryFactoryImpl.setup();

    LrdNode root = new LrdNode(new LrdPath(bean.getProject(), ""), true);

    //        boolean recursive = true;
    //
    //        LrdSVNDirEntryHandler handler = new LrdSVNDirEntryHandler(bean.getProject());
    try {
      SVNRepository repository =
          SVNRepositoryFactory.create(SVNURL.parseURIDecoded(repositoryInfo.getRepositoryUrl()));
      ISVNAuthenticationManager authManager =
          SVNWCUtil.createDefaultAuthenticationManager(
              repositoryInfo.getAuthUser(), repositoryInfo.getAuthPass());
      repository.setAuthenticationManager(authManager);
      listEntries(repository, "", root);
      repository.closeSession();
      //            logClient.doList(
      //                    SVNURL.parseURIEncoded(
      //                            repositoryInfo.getRepositoryUrl()),
      //                    SVNRevision.UNDEFINED,
      //                    SVNRevision.HEAD, recursive,
      //                    handler);
    } catch (SVNException e) {
      throw new LrdException(e);
    }
    return root;
  }
Esempio n. 25
0
    @Override
    public void run(ContinuationContext context) {
      final SVNURL sourceUrlUrl;
      try {
        sourceUrlUrl = SVNURL.parseURIEncoded(mySourceUrl);
      } catch (SVNException e) {
        finishWithError(context, "Cannot merge: " + e.getMessage(), true);
        return;
      }

      context.next(
          new TaskDescriptor(getName(), Where.POOLED) {
            @Override
            public void run(ContinuationContext context) {
              final SvnIntegrateChangesTask task =
                  new SvnIntegrateChangesTask(
                      SvnVcs.getInstance(myProject),
                      new WorkingCopyInfo(myWcInfo.getPath(), true),
                      myFactory,
                      sourceUrlUrl,
                      getName(),
                      false,
                      myBranchName);
              RunBackgroundable.run(task);
            }
          });
      createChangelist(context);
    }
  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;
  }
Esempio n. 27
0
  @Test
  public void testRecursiveInfoGetsFileLock() throws Exception {
    final TestOptions options = TestOptions.getInstance();

    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    final Sandbox sandbox =
        Sandbox.createWithCleanup(getTestName() + ".testRecursiveInfoGetsFileLock", options);
    try {
      final SVNURL url = sandbox.createSvnRepository();

      final CommitBuilder commitBuilder = new CommitBuilder(url);
      commitBuilder.addFile("directory/file");
      commitBuilder.commit();

      final SVNURL fileUrl = url.appendPath("directory/file", false);

      final String lockMessage = "lock message";

      final SvnSetLock setLock = svnOperationFactory.createSetLock();
      setLock.setSingleTarget(SvnTarget.fromURL(fileUrl));
      setLock.setLockMessage(lockMessage);
      setLock.run();

      final SVNLock[] lock = new SVNLock[1];

      final SvnGetInfo getInfo = svnOperationFactory.createGetInfo();
      getInfo.setDepth(SVNDepth.INFINITY);
      getInfo.setSingleTarget(SvnTarget.fromURL(url));
      getInfo.setReceiver(
          new ISvnObjectReceiver<SvnInfo>() {
            public void receive(SvnTarget target, SvnInfo info) throws SVNException {
              if (target.getPathOrUrlDecodedString().endsWith("file")) {
                lock[0] = info.getLock();
              }
            }
          });
      getInfo.run();

      Assert.assertNotNull(lock[0]);
      Assert.assertEquals("/directory/file", lock[0].getPath());
      Assert.assertEquals(lockMessage, lock[0].getComment());
    } finally {
      svnOperationFactory.dispose();
      sandbox.dispose();
    }
  }
Esempio n. 28
0
  @Test
  public void testCommitOfLockedFile() throws SVNException {
    final String fullFilePath = "Project/Prueba/Modify/prueba.txt";
    final String filePath = "Prueba/Modify/prueba.txt";

    final TestOptions options = TestOptions.getInstance();
    final Sandbox sandbox =
        Sandbox.createWithCleanup(getClass().getSimpleName() + ".testModifyLocked", options);
    final SVNURL url = sandbox.createSvnRepository();
    final CommitBuilder commitBuilder = new CommitBuilder(url);
    commitBuilder.addFile(fullFilePath);
    commitBuilder.commit();

    // user paths relative to Project directory.

    SVNRepository repository = SVNRepositoryFactory.create(url.appendPath("Project", false));
    repository.setAuthenticationManager(new BasicAuthenticationManager("user", "password"));
    final Map<String, Long> pathsToRevisions = new HashMap<String, Long>();
    pathsToRevisions.put(filePath, 1l);
    repository.lock(pathsToRevisions, null, false, null);

    repository.closeSession();
    // same user as one who owns the lock.
    repository.setAuthenticationManager(new BasicAuthenticationManager("user", "password"));

    final SVNLock lock = repository.getLock(filePath);
    Assert.assertNotNull(lock);
    Assert.assertNotNull(lock.getID());
    Assert.assertEquals("user", lock.getOwner());

    final Map<String, String> locks = new HashMap<String, String>();

    try {
      tryCommit(filePath, repository, locks);
      Assert.fail();
    } catch (SVNException e) {
      // no lock token.
    }

    locks.put(filePath, lock.getID());
    SVNCommitInfo info = tryCommit(filePath, repository, locks);
    Assert.assertNotNull(info);
    Assert.assertEquals(2, info.getNewRevision());
  }
Esempio n. 29
0
  public void checkout(String url, File folder) throws SVNException {
    SVNURL svnUrl = SVNURL.parseURIDecoded(url);
    SVNRepository repository = getRepository(svnUrl, getAuthManager(username, password));
    SVNClientManager ourClientManager =
        SVNClientManager.newInstance(null, repository.getAuthenticationManager());

    SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
    updateClient.setIgnoreExternals(false);
    updateClient.doCheckout(svnUrl, folder, SVNRevision.HEAD, SVNRevision.HEAD, true);
  }
 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);
 }