/**
   * 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;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  private SVNRepository getRepository(SVNURL svnUrl, ISVNAuthenticationManager authManager)
      throws SVNException {
    SVNRepository repository = SVNRepositoryFactory.create(svnUrl, null);
    repository.setAuthenticationManager(authManager);

    return repository;
  }
    protected SVNRepository getRepository(
        SCMSourceOwner context,
        SVNURL repoURL,
        StandardCredentials credentials,
        Map<String, Credentials> additionalCredentials,
        ISVNSession session)
        throws SVNException {
      SVNRepository repository = SVNRepositoryFactory.create(repoURL, session);

      ISVNAuthenticationManager sam =
          SubversionSCM.createSvnAuthenticationManager(
              new CredentialsSVNAuthenticationProviderImpl(credentials, additionalCredentials));
      sam =
          new FilterSVNAuthenticationManager(sam) {
            // If there's no time out, the blocking read operation may hang forever, because TCP
            // itself
            // has no timeout. So always use some time out. If the underlying implementation gives
            // us some
            // value (which may come from ~/.subversion), honor that, as long as it sets some
            // timeout value.
            @Override
            public int getReadTimeout(SVNRepository repository) {
              int r = super.getReadTimeout(repository);
              if (r <= 0) r = SubversionSCM.DEFAULT_TIMEOUT;
              return r;
            }
          };
      repository.setTunnelProvider(SubversionSCM.createDefaultSVNOptions());
      repository.setAuthenticationManager(sam);

      return repository;
    }
  @NotNull
  public SVNRepository createRepository(@NotNull SVNURL url) throws SVNException {
    SVNRepository repository = SVNRepositoryFactory.create(url);
    repository.setAuthenticationManager(getAuthenticationManager());
    repository.setTunnelProvider(getSvnOptions());

    return repository;
  }
Ejemplo n.º 6
0
 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();
   }
 }
Ejemplo n.º 7
0
 private void getLogEntry() {
   SVNRepositoryFactoryImpl.setup();
   DAVRepositoryFactory.setup();
   SVNRepository repository = null;
   try {
     repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(this.url));
     revision = repository.getLatestRevision();
     repository.log(null, svnlogEntries, 0, revision, true, false);
   } catch (Exception e) {
     this.status = 2;
   }
 }
Ejemplo n.º 8
0
  @Override
  public Commit getCommit(String revNumber) throws IOException, SVNException {
    long rev = Integer.parseInt(revNumber);
    String[] paths = {"/"};
    SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName));
    org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL);

    for (Object entry : repository.log(paths, null, rev, rev, false, false)) {
      return new SvnCommit((SVNLogEntry) entry);
    }

    return null;
  }
  public boolean connect() {

    if (connected) return true;

    setupLibrary();

    try {
      repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    } catch (SVNException svne) {
      LOG.error(
          "error while creating an SVNRepository for location '" + url + "': " + svne.getMessage());
      return false;
    }

    ISVNAuthenticationManager authManager = new BasicAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);

    try {
      SVNNodeKind nodeKind = repository.checkPath("", -1);
      if (nodeKind == SVNNodeKind.NONE) {
        LOG.error("There is no entry at '" + url + "'.");
        return false;
      } else if (nodeKind == SVNNodeKind.FILE) {
        LOG.error("The entry at '" + url + "' is a file while a directory was expected.");
        return false;
      }

      System.out.println("Repository Root: " + repository.getRepositoryRoot(true));
      System.out.println("Repository UUID: " + repository.getRepositoryUUID(true));
      System.out.println("");

    } catch (SVNException svne) {
      LOG.error("error while listing entries: " + svne.getMessage());
      return false;
    }

    try {
      latestRevision = repository.getLatestRevision();
    } catch (SVNException svne) {
      LOG.error("error while fetching the latest repository revision: " + svne.getMessage());
      return false;
    }

    System.out.println("");
    System.out.println("---------------------------------------------");
    System.out.println("Repository latest revision: " + latestRevision);

    connected = true;

    return true;
  }
  /**
   * I take no credit for the below code. The creation of the svn repository is provided by the
   * svnkit library guys at: http://wiki.svnkit.com/Setting_Up_A_Subversion_Repository
   *
   * @throws SVNException
   */
  private SVNCommitInfo createSVNRepository() throws Exception {
    FSRepositoryFactory.setup();
    String repoDir = "/tmp/399165/svn";
    SVNRepositoryFactoryImpl.setup();
    SVNURL repo = SVNRepositoryFactory.createLocalRepository(new File("/tmp/399165"), true, true);
    repository = SVNRepositoryFactory.create(repo);
    String logMessage = "test commit message";

    ISVNWorkspaceMediator mediator = new PostCommitWorkspaceMediator();

    ISVNEditor editor = repository.getCommitEditor(logMessage, mediator);

    editor.openRoot(-1);
    editor.addDir("dirB", null, -1);
    editor.addFile("dirB/file1.txt", null, -1);
    editor.applyTextDelta("dirB/file1.txt", null);

    OutputStream os = editor.textDeltaChunk("dirB/file1.txt", SVNDiffWindow.EMPTY);

    editor.textDeltaEnd("dirB/file1.txt");
    editor.closeFile("dirB/file1.txt", null);
    return editor.closeEdit();
  }
Ejemplo n.º 11
0
  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();
    }
  }
Ejemplo n.º 12
0
 @Override
 public boolean isEmpty() {
   SVNURL svnURL;
   org.tmatesoft.svn.core.io.SVNRepository repository = null;
   try {
     svnURL = SVNURL.fromFile(getDirectory());
     repository = SVNRepositoryFactory.create(svnURL);
     return repository.getLatestRevision() == 0;
   } catch (SVNException e) {
     throw new RuntimeException(e);
   } finally {
     if (repository != null) {
       repository.closeSession();
     }
   }
 }
Ejemplo n.º 13
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());
  }
Ejemplo n.º 14
0
  @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());
    }
  }
Ejemplo n.º 15
0
  private boolean testUrl(String url2) {
    SVNRepositoryFactoryImpl.setup();
    DAVRepositoryFactory.setup();
    SVNRepository repository = null;
    try {
      repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url2));
    } catch (SVNException e) {
      this.status = 1;
      return false;
    }

    if (repository != null) {
      // TEST IF CONNECTION OK
      try {
        repository.testConnection();
      } catch (SVNException e) {
        return false;
      }
      return true;
    } else this.status = 3;
    // GET LATEST REVISION
    return false;
  }
Ejemplo n.º 16
0
  /*
   * 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);
  }
Ejemplo n.º 17
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);
  }
Ejemplo n.º 19
0
  private org.tmatesoft.svn.core.io.SVNRepository getSVNRepository() throws SVNException {
    SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName));

    return SVNRepositoryFactory.create(svnURL);
  }
  /**
   * Returns a list of Subversion dirs to be displayed in {@code
   * ListSubversionTagsParameterDefinition/index.jelly}.
   *
   * <p>This method plainly reuses settings that must have been preivously defined when configuring
   * the Subversion SCM.
   *
   * <p>This method never returns {@code null}. In case an error happens, the returned list contains
   * an error message surrounded by &lt; and &gt;.
   */
  public List<String> getTags() {
    AbstractProject context = null;
    List<AbstractProject> jobs = Hudson.getInstance().getItems(AbstractProject.class);

    // which project is this parameter bound to? (I should take time to move
    // this code to Hudson core one day)
    for (AbstractProject project : jobs) {
      ParametersDefinitionProperty property =
          (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class);
      if (property != null) {
        List<ParameterDefinition> parameterDefinitions = property.getParameterDefinitions();
        if (parameterDefinitions != null) {
          for (ParameterDefinition pd : parameterDefinitions) {
            if (pd instanceof ListSubversionTagsParameterDefinition
                && ((ListSubversionTagsParameterDefinition) pd).compareTo(this) == 0) {
              context = project;
              break;
            }
          }
        }
      }
    }

    SimpleSVNDirEntryHandler dirEntryHandler = new SimpleSVNDirEntryHandler(tagsFilter);
    List<String> dirs = new ArrayList<String>();

    try {
      ISVNAuthenticationProvider authProvider =
          getDescriptor().createAuthenticationProvider(context);
      ISVNAuthenticationManager authManager =
          SubversionSCM.createSvnAuthenticationManager(authProvider);
      SVNURL repoURL = SVNURL.parseURIDecoded(getTagsDir());

      SVNRepository repo = SVNRepositoryFactory.create(repoURL);
      repo.setAuthenticationManager(authManager);
      SVNLogClient logClient = new SVNLogClient(authManager, null);

      if (isSVNRepositoryProjectRoot(repo)) {
        dirs = this.getSVNRootRepoDirectories(logClient, repoURL);
      } else {
        logClient.doList(
            repoURL, SVNRevision.HEAD, SVNRevision.HEAD, false, false, dirEntryHandler);
        dirs = dirEntryHandler.getDirs(isReverseByDate(), isReverseByName());
      }
    } catch (SVNException e) {
      // logs are not translated (IMO, this is a bad idea to translate logs)
      LOGGER.log(
          Level.SEVERE,
          "An SVN exception occurred while listing the directory entries at " + getTagsDir(),
          e);
      return new ArrayList() {
        {
          add(
              "&lt;"
                  + ResourceBundleHolder.get(ListSubversionTagsParameterDefinition.class)
                      .format("SVNException")
                  + "&gt;");
        }
      };
    }

    // SVNKit's doList() method returns also the parent dir, so we need to remove it
    if (dirs != null) {
      removeParentDir(dirs);
    } else {
      LOGGER.log(
          Level.INFO,
          "No directory entries were found for the following SVN repository: {0}",
          getTagsDir());
      return new ArrayList() {
        {
          add(
              "&lt;"
                  + ResourceBundleHolder.get(ListSubversionTagsParameterDefinition.class)
                      .format("NoDirectoryEntriesFound")
                  + "&gt;");
        }
      };
    }

    // Conform list to the maxTags option.
    Integer max = (isInt(this.maxTags) ? Integer.parseInt(this.maxTags) : null);
    if ((max != null) && (dirs.size() > max)) {
      dirs = dirs.subList(0, max);
    }

    return dirs;
  }
Ejemplo n.º 21
0
 public SVNRepository createRepository(SVNURL url) throws SVNException {
   SVNRepository repos = SVNRepositoryFactory.create(url);
   repos.setAuthenticationManager(myConfiguration.getAuthenticationManager(this));
   repos.setTunnelProvider(myConfiguration.getOptions(myProject));
   return repos;
 }
  @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 "";
  }
Ejemplo n.º 23
0
  private org.tmatesoft.svn.core.io.SVNRepository getSVNRepository() throws SVNException {
    SVNURL svnURL = SVNURL.fromFile(getDirectory());

    return SVNRepositoryFactory.create(svnURL);
  }
Ejemplo n.º 24
0
 @Override
 public void create() throws SVNException {
   SVNRepositoryFactory.createLocalRepository(getDirectory(), true, false);
 }