/**
   * 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;
  }
コード例 #2
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);
 }
コード例 #3
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();
    }
  }
コード例 #4
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());
  }
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: SvnMergeCommand.java プロジェクト: grumpo/openengsb
  @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);
    }
  }
コード例 #7
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);
    }
  }
コード例 #8
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);
      }
    }
  }
コード例 #9
0
ファイル: Merge.java プロジェクト: BillVelasquez/exist
  /**
   * 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);
    }
  }