コード例 #1
0
 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);
 }
コード例 #2
0
ファイル: SvnLockTest.java プロジェクト: kstarsinic/svnkit
  @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();
    }
  }
コード例 #3
0
ファイル: SvnLockTest.java プロジェクト: kstarsinic/svnkit
  @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());
  }
コード例 #4
0
ファイル: SvnRemoteList.java プロジェクト: centic9/svnkit
  private void doList(
      SVNRepository repos,
      long rev,
      final ISVNDirEntryHandler handler,
      boolean fetchLocks,
      SVNDepth depth,
      int entryFields,
      SVNURL externalParentUrl,
      String externalTarget)
      throws SVNException {
    boolean includeExternals = !getOperation().isIgnoreExternals();
    Map<SVNURL, SVNPropertyValue> externals =
        includeExternals ? new HashMap<SVNURL, SVNPropertyValue>() : null;
    SVNURL url = repos.getLocation();
    SVNURL reposRoot = repos.getRepositoryRoot(false);
    SVNDirEntry entry = null;
    SVNException error = null;
    try {
      entry = repos.info("", rev);
    } catch (SVNException svne) {
      if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED) {
        error = svne;
      } else {
        throw svne;
      }
    }
    if (error != null) {
      SVNNodeKind kind = repos.checkPath("", rev);
      if (kind != SVNNodeKind.NONE) {
        if (!url.equals(reposRoot)) {
          String name = SVNPathUtil.tail(repos.getLocation().getPath());
          repos.setLocation(repos.getLocation().removePathTail(), false);
          Collection<SVNDirEntry> dirEntries =
              repos.getDir("", rev, null, entryFields, (Collection) null);
          repos.setLocation(url, false);
          for (Iterator<SVNDirEntry> ents = dirEntries.iterator(); ents.hasNext(); ) {
            SVNDirEntry dirEntry = (SVNDirEntry) ents.next();
            if (name.equals(dirEntry.getName())) {
              entry = dirEntry;
              break;
            }
          }
          if (entry != null) {
            entry.setRelativePath(kind == SVNNodeKind.FILE ? name : "");
          }
        } else {
          SVNProperties props = new SVNProperties();
          repos.getDir("", rev, props, entryFields, (Collection<SVNDirEntry>) null);
          SVNProperties revProps = repos.getRevisionProperties(rev, null);
          String author = revProps.getStringValue(SVNRevisionProperty.AUTHOR);
          String dateStr = revProps.getStringValue(SVNRevisionProperty.DATE);
          Date datestamp = null;
          if (dateStr != null) {
            datestamp = SVNDate.parseDateString(dateStr);
          }
          entry =
              new SVNDirEntry(
                  url, reposRoot, "", kind, 0, !props.isEmpty(), rev, datestamp, author);
          entry.setRelativePath("");
        }
      }
    } else if (entry != null) {
      if (entry.getKind() == SVNNodeKind.DIR) {
        entry.setName("");
      }
      entry.setRelativePath(entry.getKind() == SVNNodeKind.DIR ? "" : entry.getName());
    }
    if (entry == null) {
      SVNErrorMessage err =
          SVNErrorMessage.create(
              SVNErrorCode.FS_NOT_FOUND, "URL ''{0}'' non-existent in that revision", url);
      SVNErrorManager.error(err, SVNLogType.WC);
    }
    final Map locksMap = new SVNHashMap();
    if (fetchLocks) {
      SVNLock[] locks = new SVNLock[0];
      try {
        locks = repos.getLocks("");
      } catch (SVNException e) {
        if (!(e.getErrorMessage() != null
            && e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED)) {
          throw e;
        }
      }
      if (locks != null && locks.length > 0) {
        SVNURL root = repos.getRepositoryRoot(true);
        for (int i = 0; i < locks.length; i++) {
          String repositoryPath = locks[i].getPath();
          locksMap.put(root.appendPath(repositoryPath, false), locks[i]);
        }
      }
    }
    ISVNDirEntryHandler nestedHandler =
        new ISVNDirEntryHandler() {

          public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
            dirEntry.setLock((SVNLock) locksMap.get(dirEntry.getURL()));
            handler.handleDirEntry(dirEntry);
          }
        };
    entry.setExternalParentUrl(externalParentUrl);
    entry.setExternalTarget(externalTarget);
    nestedHandler.handleDirEntry(entry);
    if (entry.getKind() == SVNNodeKind.DIR
        && (depth == SVNDepth.FILES
            || depth == SVNDepth.IMMEDIATES
            || depth == SVNDepth.INFINITY)) {
      list(
          repos,
          "",
          rev,
          depth,
          entryFields,
          externals,
          externalParentUrl,
          externalTarget,
          nestedHandler);
    }

    if (includeExternals && externals != null && externals.size() > 0) {
      listExternals(repos, externals, depth, entryFields, fetchLocks, handler);
    }
  }
コード例 #5
0
ファイル: SvnRemoteList.java プロジェクト: centic9/svnkit
  private static void list(
      SVNRepository repository,
      String path,
      long rev,
      SVNDepth depth,
      int entryFields,
      Map<SVNURL, SVNPropertyValue> externals,
      SVNURL externalParentUrl,
      String externalTarget,
      ISVNDirEntryHandler handler)
      throws SVNException {
    if (depth == SVNDepth.EMPTY) {
      return;
    }
    Collection entries = new TreeSet();
    SVNProperties properties;
    try {
      properties = externals == null ? null : new SVNProperties();
      entries = repository.getDir(path, rev, properties, entryFields, entries);
    } catch (SVNAuthenticationException e) {
      return;
    } catch (SVNException e) {
      if (e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_AUTHORIZED) {
        return;
      }
      throw e;
    }

    SVNPropertyValue svnExternalsVaule =
        properties == null ? null : properties.getSVNPropertyValue(SVNProperty.EXTERNALS);
    if (svnExternalsVaule != null) {
      SVNURL location = repository.getLocation();
      externals.put(location.appendPath(path, false), svnExternalsVaule);
    }

    for (Iterator iterator = entries.iterator(); iterator.hasNext(); ) {
      SVNDirEntry entry = (SVNDirEntry) iterator.next();
      String childPath = SVNPathUtil.append(path, entry.getName());
      entry.setRelativePath(childPath);
      if (entry.getKind() == SVNNodeKind.FILE
          || depth == SVNDepth.IMMEDIATES
          || depth == SVNDepth.INFINITY) {
        entry.setExternalParentUrl(externalParentUrl);
        entry.setExternalTarget(externalTarget);
        handler.handleDirEntry(entry);
      }
      if (entry.getKind() == SVNNodeKind.DIR
          && entry.getDate() != null
          && depth == SVNDepth.INFINITY) {
        list(
            repository,
            childPath,
            rev,
            depth,
            entryFields,
            externals,
            externalParentUrl,
            externalTarget,
            handler);
      }
    }
  }