Exemple #1
0
  public static void getDeta4UpdateAll(final String path, final long revision, 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 {
      // 创建本地目录
      File localDict = new File(localPath);
      if (!localDict.exists()) {
        localDict.mkdirs();
      } else {
        FileUtils.cleanDirectory(localDict);
      }

      svnClientManager = SVNClientManager.newInstance(options, authManager);

      Collection<SVNLog> logs = new LinkedList<SVNLog>();
      logs.add(new SVNLog4All());

      // 更新所有文件
      export(svnClientManager, path, revision, localPath + Constants.UPDPKG_CODEDIR);

      // 将日志写入文件
      writeLogToFile(logs, new File(localPath + Constants.UPDPKG_UPDTXT));
    } finally {
      if (svnClientManager != null) {
        svnClientManager.dispose();
      }
    }
  }
Exemple #2
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();
      }
    }
  }
  /**
   * 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;
  }
 public Object invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException {
   File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile();
   try {
     ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
     sam.setAuthenticationProvider(authProvider);
     SVNCommitClient commitClient = new SVNCommitClient(sam, null);
     buildListener.getLogger().println("[RELEASE] " + commitMessage);
     debuggingLogger.fine(String.format("Committing working copy: '%s'", workingCopy));
     SVNCommitInfo commitInfo =
         commitClient.doCommit(
             new File[] {workingCopy},
             true,
             commitMessage,
             null,
             null,
             true,
             true,
             SVNDepth.INFINITY);
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       throw new IOException("Failed to commit working copy: " + errorMessage.getFullMessage());
     }
     return null;
   } catch (SVNException e) {
     throw new IOException(e.getMessage());
   }
 }
 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());
   }
 }
 public ISVNOptions getOptions(Project project) {
   if (myOptions == null) {
     File path = new File(getConfigurationDirectory());
     myOptions = SVNWCUtil.createDefaultOptions(path.getAbsoluteFile(), true);
   }
   return myOptions;
 }
  public static void clone(String URL, String repoPath) throws SVNException {
    SVNURL svnurl = SVNURL.parseURIDecoded(URL);
    SVNRepository srcRepository = SVNRepositoryFactory.create(svnurl);
    srcRepository.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager());
    SVNClientManager ourClientManager = SVNClientManager.newInstance();
    ourClientManager.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager());
    SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
    updateClient.setIgnoreExternals(true);

    long latestRevision = srcRepository.getLatestRevision();
    if (updateClient.doCheckout(
            svnurl, new File(repoPath), SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true)
        == latestRevision) {
      ourClientManager.dispose();
    }
  }
 public VCSModule(final String url) {
   try {
     this.url = SVNURL.fromFile(new File(url));
     this.authManager = SVNWCUtil.createDefaultAuthenticationManager("", "");
     this.repository = SVNRepositoryFactory.create(this.url);
     this.repository.setAuthenticationManager(this.authManager);
     this.latestRevision = this.repository.getLatestRevision();
   } catch (final SVNException e) {
     e.printStackTrace();
   }
 }
 public Object invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException {
   File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile();
   try {
     log(listener, "Cleanup working copy: " + workingCopy);
     ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
     sam.setAuthenticationProvider(authProvider);
     SVNWCClient wcClient = new SVNWCClient(sam, null);
     wcClient.doCleanup(workingCopy);
     return null;
   } catch (SVNException e) {
     throw new IOException(e.getMessage());
   }
 }
  @Test
  public void testGetInfo2() {
    DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    SVNClientManager clientManager = SVNClientManager.newInstance(options, "", "");
    SVNWCClient wcClient = clientManager.getWCClient();

    /*
     * For using over http:// and https://
     */
    DAVRepositoryFactory.setup();

    // Create configuration file in current folder
    File configFile = new File(".rockysvn");
    String username = "******";
    String password = "******";
    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(configFile, username, password);
    // String url = "https://open-ones.googlecode.com/svn/trunk/ProjectList/RockySVN";
    String url = "https://hcm-svn.fsoft.fpt.vn/svn/F15-HCAM/trunk";

    SVNRevision revision = SVNRevision.HEAD;
    File path = new File("D:/Project/MyProject/Open-Ones/RockySVN");
    try {
      SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
      repository.setAuthenticationManager(authManager);
      repository.getDatedRevision(new Date());
      long latestRev = repository.getLatestRevision();

      assertEquals(634, latestRev);
      SVNInfo svnInfo = wcClient.doInfo(path, revision);
      assertEquals("ThachLN", svnInfo.getAuthor());
      assertEquals(123, svnInfo.getRevision().getID());
      assertEquals(new Date(), svnInfo.getRevision().getDate());
    } catch (SVNException ex) {
      ex.printStackTrace();
      fail(ex.getMessage());
    }
  }
Exemple #11
0
 public WorkingCopy(String name, String password, String svnPath, String localPath) {
   try {
     repositoryURL = SVNURL.parseURIEncoded(svnPath);
   } catch (SVNException e) {
     //
   }
   myUpdateEventHandler = new UpdateEventHandler(this);
   myWCEventHandler = new WCEventHandler(this);
   DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
   ourClientManager = SVNClientManager.newInstance(options, name, password);
   ourClientManager.getCommitClient().setEventHandler(myCommitEventHandler);
   ourClientManager.getUpdateClient().setEventHandler(myUpdateEventHandler);
   ourClientManager.getWCClient().setEventHandler(myWCEventHandler);
   //
   destPath = new File(localPath);
 }
Exemple #12
0
  private static void commitExample() throws SVNException {
    /*
     * URL that points to repository.
     */
    SVNURL url = SVNURL.parseURIEncoded("svn://localhost/rep");
    /*
     * Credentials to use for authentication.
     */
    String userName = "******";
    String userPassword = "******";

    /*
     * Sample file contents.
     */
    byte[] contents = "This is a new file".getBytes();
    byte[] modifiedContents = "This is the same file but modified a little.".getBytes();

    /*
     * Create an instance of SVNRepository class. This class is the main entry point
     * for all "low-level" Subversion operations supported by Subversion protocol.
     *
     * These operations includes browsing, update and commit operations. See
     * SVNRepository methods javadoc for more details.
     */
    SVNRepository repository = SVNRepositoryFactory.create(url);

    /*
     * User's authentication information (name/password) is provided via  an
     * ISVNAuthenticationManager  instance.  SVNWCUtil  creates  a   default
     * authentication manager given user's name and password.
     *
     * Default authentication manager first attempts to use provided user name
     * and password and then falls back to the credentials stored in the
     * default Subversion credentials storage that is located in Subversion
     * configuration area. If you'd like to use provided user name and password
     * only you may use BasicAuthenticationManager class instead of default
     * authentication manager:
     *
     *  authManager = new BasicAuthenticationsManager(userName, userPassword);
     *
     * You may also skip this point - anonymous access will be used.
     */
    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(userName, userPassword);
    repository.setAuthenticationManager(authManager);

    /*
     * Get type of the node located at URL we used to create SVNRepository.
     *
     * "" (empty string) is path relative to that URL,
     * -1 is value that may be used to specify HEAD (latest) revision.
     */
    SVNNodeKind nodeKind = repository.checkPath("", -1);

    /*
     * Checks  up  if the current path really corresponds to a directory. If
     * it doesn't, the program exits. SVNNodeKind is that one who says  what
     * is located at a path in a revision.
     */
    if (nodeKind == SVNNodeKind.NONE) {
      SVNErrorMessage err =
          SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "No entry at URL ''{0}''", url);
      throw new SVNException(err);
    } else if (nodeKind == SVNNodeKind.FILE) {
      SVNErrorMessage err =
          SVNErrorMessage.create(
              SVNErrorCode.UNKNOWN,
              "Entry at URL ''{0}'' is a file while directory was expected",
              url);
      throw new SVNException(err);
    }

    /*
     * Get exact value of the latest (HEAD) revision.
     */
    long latestRevision = repository.getLatestRevision();
    System.out.println("Repository latest revision (before committing): " + latestRevision);

    /*
     * Gets an editor for committing the changes to  the  repository.  NOTE:
     * you  must not invoke methods of the SVNRepository until you close the
     * editor with the ISVNEditor.closeEdit() method.
     *
     * commitMessage will be applied as a log message of the commit.
     *
     * ISVNWorkspaceMediator instance will be used to store temporary files,
     * when 'null' is passed, then default system temporary directory will be used to
     * create temporary files.
     */
    ISVNEditor editor = repository.getCommitEditor("directory and file added", null);

    /*
     * Add a directory and a file within that directory.
     *
     * SVNCommitInfo object contains basic information on the committed revision, i.e.
     * revision number, author name, commit date and commit message.
     */
    SVNCommitInfo commitInfo = addDir(editor, "test", "test/file.txt", contents);
    System.out.println("The directory was added: " + commitInfo);

    /*
     * Modify file added at the previous revision.
     */
    editor = repository.getCommitEditor("file contents changed", null);
    commitInfo = modifyFile(editor, "test", "test/file.txt", contents, modifiedContents);
    System.out.println("The file was changed: " + commitInfo);

    /*
     * Copy recently added directory to another location. This operation
     * will create new directory "test2" taking its properties and contents
     * from the directory "test". Revisions history will be preserved.
     *
     * Copy is usually used to create tags or branches in repository or to
     * rename files or directories.
     */

    /*
     * To make a copy of a repository entry, absolute path of that entry
     * and revision from which to make a copy are needed.
     *
     * Absolute path is the path relative to repository root URL and
     * such paths always start with '/'. Relative paths are relative
     * to SVNRepository instance location.
     *
     * For more information see SVNRepository.getRepositoryRoot(...) and
     * SVNRepository.getLocation() methods. Utility method getRepositoryPath(...)
     * converts relative path to the absolute one.
     */
    String absoluteSrcPath = repository.getRepositoryPath("test");
    long srcRevision = repository.getLatestRevision();

    editor = repository.getCommitEditor("directory copied", null);

    commitInfo = copyDir(editor, absoluteSrcPath, "test2", srcRevision);
    System.out.println("The directory was copied: " + commitInfo);

    /*
     * Delete directory "test".
     */
    editor = repository.getCommitEditor("directory deleted", null);
    commitInfo = deleteDir(editor, "test");
    System.out.println("The directory was deleted: " + commitInfo);

    /*
     * And directory "test2".
     */
    editor = repository.getCommitEditor("copied directory deleted", null);
    commitInfo = deleteDir(editor, "test2");
    System.out.println("The copied directory was deleted: " + commitInfo);

    latestRevision = repository.getLatestRevision();
    System.out.println("Repository latest revision (after committing): " + latestRevision);
  }
  public static void getData(String murl) throws SVNException {
    url = murl;
    /*
     * default values:
     */

    /*
     * initializes the library (it must be done before ever using the
     * library itself)
     */
    setupLibrary();
    SVNRepository repository = null;

    /*
     * Creates an instance of SVNRepository to work with the repository. All
     * user's requests to the repository are relative to the repository
     * location used to create this SVNRepository. SVNURL is a wrapper for
     * URL strings that refer to repository locations.
     */
    repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));

    /*
     * User's authentication information (name/password) is provided via an
     * ISVNAuthenticationManager instance. SVNWCUtil creates a default
     * authentication manager given user's name and password.
     *
     * Default authentication manager first attempts to use provided user
     * name and password and then falls back to the credentials stored in
     * the default Subversion credentials storage that is located in
     * Subversion configuration area. If you'd like to use provided user
     * name and password only you may use BasicAuthenticationManager class
     * instead of default authentication manager:
     *
     * authManager = new BasicAuthenticationsManager(userName,
     * userPassword);
     *
     * You may also skip this point - anonymous access will be used.
     */
    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);

    /*
     * Checks up if the specified path/to/repository part of the URL really
     * corresponds to a directory. If doesn't the program exits. SVNNodeKind
     * is that one who says what is located at a path in a revision. -1
     * means the latest revision.
     */
    SVNNodeKind nodeKind = repository.checkPath("", -1);
    if (nodeKind == SVNNodeKind.NONE) {
      System.err.println("There is no entry at '" + url + "'.");

    } else if (nodeKind == SVNNodeKind.FILE) {
      System.err.println("The entry at '" + url + "' is a file while a directory was expected.");
    }
    /*
     * getRepositoryRoot() returns the actual root directory where the
     * repository was created. 'true' forces to connect to the repository if
     * the root url is not cached yet.
     */
    // System.out.println("Repository Root: " +
    // repository.getRepositoryRoot(true));
    /*
     * getRepositoryUUID() returns Universal Unique IDentifier (UUID) of the
     * repository. 'true' forces to connect to the repository if the UUID is
     * not cached yet.
     */
    // System.out.println("Repository UUID: " +
    // repository.getRepositoryUUID(true));
    // System.out.println("");

    /*
     * Displays the repository tree at the current path - "" (what means the
     * path/to/repository directory)
     */
    listEntries(repository, "");

    /*
     * Gets the latest revision number of the repository
     */
    long latestRevision = -1;

    latestRevision = repository.getLatestRevision();

    // System.out.println("");
    // System.out.println("---------------------------------------------");
    // System.out.println("Repository latest revision: " + latestRevision);
    // System.exit(0);
  }
  @Override
  protected String getChangeFileNames(String lastFinishDateTimeString) throws Exception {
    /*
     * Default values:
     */
    String url = Globals.getProperty("svn.url");
    String name = Globals.getProperty("svn.user");
    String password = Globals.getProperty("svn.password");

    long startRevision = 0;
    long endRevision = -1; // HEAD (the latest) revision

    setupLibrary();

    SVNRepository repository = null;

    try {
      repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    } catch (SVNException svne) {
      /*
       * Perhaps a malformed URL is the cause of this exception.
       */
      System.err.println(
          "error while creating an SVNRepository for the location '"
              + url
              + "': "
              + svne.getMessage());
      System.exit(1);
    }

    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);

    /*
     * Gets the latest revision number of the repository
     */
    try {
      endRevision = repository.getLatestRevision();
      startRevision = endRevision;
    } catch (SVNException svne) {
      System.err.println(
          "error while fetching the latest repository revision: " + svne.getMessage());
      System.exit(1);
    }

    Collection logEntries = null;
    try {
      /*
       * Collects SVNLogEntry objects for all revisions in the range
       * defined by its start and end points [startRevision, endRevision].
       * For each revision commit information is represented by
       * SVNLogEntry.
       *
       * the 1st parameter (targetPaths - an array of path strings) is set
       * when restricting the [startRevision, endRevision] range to only
       * those revisions when the paths in targetPaths were changed.
       *
       * the 2nd parameter if non-null - is a user's Collection that will
       * be filled up with found SVNLogEntry objects; it's just another
       * way to reach the scope.
       *
       * startRevision, endRevision - to define a range of revisions you are
       * interested in; by default in this program - startRevision=0, endRevision=
       * the latest (HEAD) revision of the repository.
       *
       * the 5th parameter - a boolean flag changedPath - if true then for
       * each revision a corresponding SVNLogEntry will contain a map of
       * all paths which were changed in that revision.
       *
       * the 6th parameter - a boolean flag strictNode - if false and a
       * changed path is a copy (branch) of an existing one in the repository
       * then the history for its origin will be traversed; it means the
       * history of changes of the target URL (and all that there's in that
       * URL) will include the history of the origin path(s).
       * Otherwise if strictNode is true then the origin path history won't be
       * included.
       *
       * The return value is a Collection filled up with SVNLogEntry Objects.
       */
      logEntries = repository.log(new String[] {""}, null, startRevision, endRevision, true, true);

    } catch (SVNException svne) {
      System.out.println(
          "error while collecting log information for '" + url + "': " + svne.getMessage());
      System.exit(1);
    }
    for (Iterator entries = logEntries.iterator(); entries.hasNext(); ) {
      /*
       * gets a next SVNLogEntry
       */
      SVNLogEntry logEntry = (SVNLogEntry) entries.next();
      System.out.println("---------------------------------------------");
      /*
       * gets the revision number
       */
      System.out.println("revision: " + logEntry.getRevision());
      /*
       * gets the author of the changes made in that revision
       */
      System.out.println("author: " + logEntry.getAuthor());
      /*
       * gets the time moment when the changes were committed
       */
      System.out.println("date: " + logEntry.getDate());
      /*
       * gets the commit log message
       */
      System.out.println("log message: " + logEntry.getMessage());
      /*
       * displaying all paths that were changed in that revision; cahnged
       * path information is represented by SVNLogEntryPath.
       */
      if (logEntry.getChangedPaths().size() > 0) {
        System.out.println();
        System.out.println("changed paths:");
        /*
         * keys are changed paths
         */
        Set changedPathsSet = logEntry.getChangedPaths().keySet();

        for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext(); ) {
          /*
           * obtains a next SVNLogEntryPath
           */
          SVNLogEntryPath entryPath =
              (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
          /*
           * SVNLogEntryPath.getPath returns the changed path itself;
           *
           * SVNLogEntryPath.getType returns a charecter describing
           * how the path was changed ('A' - added, 'D' - deleted or
           * 'M' - modified);
           *
           * If the path was copied from another one (branched) then
           * SVNLogEntryPath.getCopyPath &
           * SVNLogEntryPath.getCopyRevision tells where it was copied
           * from and what revision the origin path was at.
           */
          System.out.println(
              " "
                  + entryPath.getType()
                  + "	"
                  + entryPath.getPath()
                  + ((entryPath.getCopyPath() != null)
                      ? " (from "
                          + entryPath.getCopyPath()
                          + " revision "
                          + entryPath.getCopyRevision()
                          + ")"
                      : ""));
        }
      }
    }
    return "";
  }
Exemple #15
0
  /**
   * 获取path2相对与path1的变更
   *
   * @param path1
   * @param revision1 path1版本号
   * @param path2
   * @param revision2 path2版本号
   * @param localPath 保存变更内容的临时路径路径
   * @param deployPath 正式部署代码的路径
   * @throws Exception
   */
  public static void getDelta(
      final String path1,
      final long revision1,
      final String path2,
      final long revision2,
      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 {
      // 创建本地目录
      File localDict = new File(localPath);
      if (!localDict.exists()) {
        localDict.mkdirs();
      } else {
        FileUtils.cleanDirectory(localDict);
      }

      svnClientManager = SVNClientManager.newInstance(options, authManager);

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

      Collection<SVNLog> logs = null;

      boolean update4All = false;

      // 没有正在使用的版本或前后版本相同
      if (path1 == null || path1.equals("") || path1.equals(path2)) {
        update4All = true;
      }

      if (update4All) {
        // 更新所有文件
        export(svnClientManager, path2, revision2, localPath + Constants.UPDPKG_CODEDIR);
        logs = new LinkedList<SVNLog>();
        logs.add(new SVNLog4All());
      } else {
        // 增量获取俩个版本的变更
        logs = diff(svnClientManager, path1, revision1, path2, revision2);

        if (logs != null && !logs.isEmpty()) {
          // 获取添加、替换项
          getDelta4Add(repository, path2, logs, localPath + Constants.UPDPKG_CODEDIR);
        } else {
          // 没有变更项目时 已更新全部处理
          export(svnClientManager, path2, revision2, localPath + Constants.UPDPKG_CODEDIR);
          logs = new LinkedList<SVNLog>();
          logs.add(new SVNLog4All());
        }
      }

      // 将日志写入文件
      writeLogToFile(logs, new File(localPath + Constants.UPDPKG_UPDTXT));
    } finally {
      if (svnClientManager != null) {
        svnClientManager.dispose();
      }
    }
  }
 private ISVNAuthenticationManager createAuthenticationManager() {
   ISVNAuthenticationProvider sap = getSvnAuthenticationProvider();
   ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
   sam.setAuthenticationProvider(sap);
   return sam;
 }
  /*
   * args parameter is used to obtain a repository location URL, user's
   * account name & password to authenticate him to the server.
   */
  public static void main(String[] args) {
    /*
     * default values:
     */
    String url = "http://svn.svnkit.com/repos/svnkit/trunk/doc";
    String name = "anonymous";
    String password = "******";

    /*
     * initializes the library (it must be done before ever using the
     * library itself)
     */
    setupLibrary();
    if (args != null) {
      /*
       * obtains a repository location URL
       */
      url = (args.length >= 1) ? args[0] : url;
      /*
       * obtains an account name (will be used to authenticate the user to
       * the server)
       */
      name = (args.length >= 2) ? args[1] : name;
      /*
       * obtains a password
       */
      password = (args.length >= 3) ? args[2] : password;
    }
    SVNRepository repository = null;
    try {
      /*
       * Creates an instance of SVNRepository to work with the repository.
       * All user's requests to the repository are relative to the
       * repository location used to create this SVNRepository.
       * SVNURL is a wrapper for URL strings that refer to repository locations.
       */
      repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    } catch (SVNException svne) {
      /*
       * Perhaps a malformed URL is the cause of this exception
       */
      System.err.println(
          "error while creating an SVNRepository for location '" + url + "': " + svne.getMessage());
      System.exit(1);
    }

    /*
     * User's authentication information (name/password) is provided via  an
     * ISVNAuthenticationManager  instance.  SVNWCUtil  creates  a   default
     * authentication manager given user's name and password.
     *
     * Default authentication manager first attempts to use provided user name
     * and password and then falls back to the credentials stored in the
     * default Subversion credentials storage that is located in Subversion
     * configuration area. If you'd like to use provided user name and password
     * only you may use BasicAuthenticationManager class instead of default
     * authentication manager:
     *
     *  authManager = new BasicAuthenticationsManager(userName, userPassword);
     *
     * You may also skip this point - anonymous access will be used.
     */
    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);

    try {
      /*
       * Checks up if the specified path/to/repository part of the URL
       * really corresponds to a directory. If doesn't the program exits.
       * SVNNodeKind is that one who says what is located at a path in a
       * revision. -1 means the latest revision.
       */
      SVNNodeKind nodeKind = repository.checkPath("", -1);
      if (nodeKind == SVNNodeKind.NONE) {
        System.err.println("There is no entry at '" + url + "'.");
        System.exit(1);
      } else if (nodeKind == SVNNodeKind.FILE) {
        System.err.println("The entry at '" + url + "' is a file while a directory was expected.");
        System.exit(1);
      }
      /*
       * getRepositoryRoot() returns the actual root directory where the
       * repository was created. 'true' forces to connect to the repository
       * if the root url is not cached yet.
       */
      System.out.println("Repository Root: " + repository.getRepositoryRoot(true));
      /*
       * getRepositoryUUID() returns Universal Unique IDentifier (UUID) of the
       * repository. 'true' forces to connect to the repository
       * if the UUID is not cached yet.
       */
      System.out.println("Repository UUID: " + repository.getRepositoryUUID(true));
      System.out.println("");

      /*
       * Displays the repository tree at the current path - "" (what means
       * the path/to/repository directory)
       */
      listEntries(repository, "");
    } catch (SVNException svne) {
      System.err.println("error while listing entries: " + svne.getMessage());
      System.exit(1);
    }
    /*
     * Gets the latest revision number of the repository
     */
    long latestRevision = -1;
    try {
      latestRevision = repository.getLatestRevision();
    } catch (SVNException svne) {
      System.err.println(
          "error while fetching the latest repository revision: " + svne.getMessage());
      System.exit(1);
    }
    System.out.println("");
    System.out.println("---------------------------------------------");
    System.out.println("Repository latest revision: " + latestRevision);
    System.exit(0);
  }