Package org.tmatesoft.svn.core.io

Examples of org.tmatesoft.svn.core.io.SVNRepository


      /*
       * 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 is provided via an
     * ISVNAuthenticationManager instance. SVNWCUtil creates a default
     * usre's authentication manager given user's name and password.
     */
    ISVNAuthenticationManager authManager = SVNWCUtil
        .createDefaultAuthenticationManager(name, password);

    /*
     * Sets the manager of the user's authentication information that will
     * be used to authenticate the user to the server (if needed) during
     * operations handled by the SVNRepository.
     */
    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
       */
      System.out.println("Repository Root: "
          + repository.getRepositoryRoot(true));
      /*
       * getRepositoryUUID returns Universal Unique IDentifier (UUID) - an
       * identifier of the repository
       */
      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);
View Full Code Here


            /*
             * 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);
View Full Code Here

                  SwingWorker<SVNRepository, Void> worker = new SwingWorker<SVNRepository, Void>() {
                    @Override
                    protected SVNRepository doInBackground()
                        throws Exception {
                      try {
                        SVNRepository repository = SVNRepositoryFactory
                            .create(SVNURL
                                .parseURIEncoded(repoInfo.url));
                        ISVNAuthenticationManager authManager = SVNWCUtil
                            .createDefaultAuthenticationManager(
                                repoInfo.user,
                                repoInfo.password);
                        repository
                            .setAuthenticationManager(authManager);
                        return repository;
                      } catch (SVNException svne) {
                        List<BreadcrumbBarExceptionHandler> handlers = getExceptionHandlers();
                        for (BreadcrumbBarExceptionHandler handler : handlers) {
View Full Code Here

      /*
       * 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);
View Full Code Here

      /*
       * Obtains a password
       */
      password = (args.length >= 4) ? args[3] : 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 the location '"
              + url + "': " + svne.getMessage());
      svne.printStackTrace();
      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);

    /*
     * This Map will be used to get the file properties. Each Map key is a
     * property name and the value associated with the key is the property
     * value.
     */
    Map fileProperties = new HashMap();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {
      /*
       * Checks up if the specified path really corresponds to a file. 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(filePath, -1);

      if (nodeKind == SVNNodeKind.NONE) {
        System.err.println("There is no entry at '" + url + "'.");
        System.exit(1);
      } else if (nodeKind == SVNNodeKind.DIR) {
        System.err.println("The entry at '" + url
            + "' is a directory while a file was expected.");
        System.exit(1);
      }
      /*
       * Gets the contents and properties of the file located at filePath
       * in the repository at the latest revision (which is meant by a
       * negative revision number).
       */
      repository.getFile(filePath, -1,
          SVNProperties.wrap(fileProperties), baos);

    } catch (SVNException svne) {
      System.err
          .println("error while fetching the file contents and properties: "
              + svne.getMessage());
      svne.printStackTrace();
      System.exit(1);
    }

    /*
     * Here the SVNProperty class is used to get the value of the
     * svn:mime-type property (if any). SVNProperty is used to facilitate
     * the work with versioned properties.
     */
    String mimeType = (String) fileProperties.get(SVNProperty.MIME_TYPE);

    /*
     * SVNProperty.isTextMimeType(..) method checks up the value of the
     * mime-type file property and says if the file is a text (true) or not
     * (false).
     */
    boolean isTextType = SVNProperty.isTextMimeType(mimeType);

    Iterator iterator = fileProperties.keySet().iterator();
    /*
     * Displays file properties.
     */
    while (iterator.hasNext()) {
      String propertyName = (String) iterator.next();
      String propertyValue = (String) fileProperties.get(propertyName);
      System.out.println("File property: " + propertyName + "="
          + propertyValue);
    }
    /*
     * Displays the file contents in the console if the file is a text.
     */
    if (isTextType) {
      System.out.println("File contents:");
      System.out.println();
      try {
        baos.writeTo(System.out);
      } catch (IOException ioe) {
        ioe.printStackTrace();
      }
    } else {
      System.out
          .println("File contents can not be displayed in the console since the mime-type property says that it's not a kind of a text file.");
    }
    /*
     * 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);
View Full Code Here

        DAVRepositoryFactory.setup();
        String url = "http://engsvn.fnfr.com/";
        String user = "mhuang";
        String password = "mil&momo";

        SVNRepository repository = null;
        try {
            repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(user, password);
            repository.setAuthenticationManager(authManager);
            System.out.println("Root: " + repository.getRepositoryRoot(true));
        } catch (SVNAuthenticationException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
View Full Code Here

        boolean isDirectory = info.getKind() != NodeKind.FILE;
        final long currentRevision = committedRevision.getNumber();
        String repoRoot = info.getRepositoryRootURL().toString();
        final String relPath = info.getURL().toString().substring(repoRoot.length());

        SVNRepository repo = svn.getSvnKitManager().createRepository(repoRoot);
        boolean mergeInfoAvailable = repo.hasCapability(SVNCapability.MERGE_INFO);

        showProgressInfo(progressIndicator, "Getting latest repository revision");
        long latestRevision = repo.getLatestRevision();

        ExtendedScanManager esm = new ExtendedScanManager(repo, latestRevision, progressIndicator);
        final Deque<Task> pathsToProcess = new LinkedList<Task>();
        boolean retryWithoutMergeInfo = false;

        pathsToProcess.add(new Task(relPath, currentRevision, true));
        while (!pathsToProcess.isEmpty()) {
            checkCancelled(progressIndicator);
            final Task task = pathsToProcess.remove();
            if (revisions.contain(task.relPath, task.revision)) {
                continue;
            }

            if (scanMode != ScanMode.ONLY_IMPACTING_PATHS) {
                pathsToProcess.addAll(esm.getPotentialTargets(task.relPath, scanMode == ScanMode.INCLUDE_CURRENT_BRANCHES_AND_TAGS));
                checkCancelled(progressIndicator);
            }

            try {
                showProgressInfo(progressIndicator, "Obtaining log info for " + task.relPath);
                final List<Revision> revisionChain = new ArrayList<Revision>();
                final List<Task> newTasks = new ArrayList<Task>();
                // find deleted revision for current scan point to determine limits of log request
                long deletedRevision = (task.revision == latestRevision) ? INVALID_REVISION
                        : repo.getDeletedRevision(task.relPath, task.revision, latestRevision);
                if (deletedRevision >= 0) {
                    checkCancelled(progressIndicator);
                    SVNProperties p = repo.getRevisionProperties(deletedRevision, null);
                    revisionChain.add(new Revision(task.relPath, deletedRevision,
                            p.getStringValue(SVNRevisionProperty.AUTHOR),
                            SVNDate.parseDateString(p.getStringValue(SVNRevisionProperty.DATE)),
                            p.getStringValue(SVNRevisionProperty.LOG),
                            Collections.<Revision>emptyList(), null, SVNLogEntryPath.TYPE_DELETED));
                }

                // request log for current scan point
                MergeInfoProcessor handler = new MergeInfoProcessor(task.relPath, new LogEntryWithMergeInfoHandler() {
                    @Override
                    public void handleLogEntry(SVNLogEntry logEntry, @NotNull List<Revision> mergedRevisions)
                            throws SVNCancelException {
                        checkCancelled(progressIndicator);
                        Revision.LinkType linkType = null;
                        // check copy sources
                        Revision copyFromRevision = getCopyFromRevision(logEntry, task.relPath);
                        if (copyFromRevision != null) {
                            linkType = Revision.LinkType.COPY;
                            mergedRevisions = Arrays.asList(copyFromRevision);
                        } else if (!mergedRevisions.isEmpty()) {
                            linkType = Revision.LinkType.MERGE;
                        }
                        long revision = logEntry.getRevision();
                        char changeType = getChangeType(logEntry, task.relPath);
                        Revision rgRev = new Revision(task.relPath, revision,
                                logEntry.getAuthor(), logEntry.getDate(), logEntry.getMessage(),
                                mergedRevisions, linkType, changeType);
                        revisionChain.add(rgRev);
                        if (!mergedRevisions.isEmpty()) {
                            Revision linkRev = mergedRevisions.get(0);
                            newTasks.add(new Task(linkRev.getRelPath(), linkRev.getRevisionNumber(), true));
                        }
                        if (changeType == SVNLogEntryPath.TYPE_REPLACED) {
                            newTasks.add(new Task(task.relPath, revision - 1, true));
                        }
                        showProgressInfo(progressIndicator, rgRev + " processed");
                    }
                });
                repo.log(new String[]{task.relPath}, deletedRevision < 0 ? INVALID_REVISION : (deletedRevision - 1), 0,
                        true, true, 0, mergeInfoAvailable && !retryWithoutMergeInfo , null, handler);
                handler.checkFinalState();
                revisions.addRevisionChain(revisionChain);
                pathsToProcess.addAll(newTasks);
                retryWithoutMergeInfo = false;
View Full Code Here

        Info info = svn.getInfo(file);
        if (info == null) {
            throw new SVNException(SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Error retrieving SVN information for file"));
        }
        String repoRoot = info.getRepositoryRootURL().toString();
        SVNRepository repo = svn.getSvnKitManager().createRepository(repoRoot);
        SVNProperties properties = new SVNProperties();
        if (info.getKind() == NodeKind.FILE) {
            repo.getFile(revision.getRelPath(), revision.getRevisionNumber(), properties, null);
        } else {
            repo.getDir(revision.getRelPath(), revision.getRevisionNumber(), properties, (Collection) null);
        }
        return properties.getRegularProperties();
    }
View Full Code Here

        // For using over svn:// and svn+xxx://
        SVNRepositoryFactoryImpl.setup();
        // For using over file:///
        FSRepositoryFactory.setup();

        SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(sSVNUrl));

        // Create Authentication manager
        ISVNAuthenticationManager authManager;
        if ((sSVNUser == null) && (sSVNPwd == null)) {
            authManager = SVNWCUtil.createDefaultAuthenticationManager();
        } else {
            authManager = SVNWCUtil.createDefaultAuthenticationManager(sSVNUser, sSVNPwd);
        }
        repository.setAuthenticationManager(authManager);

        return repository;
    }
View Full Code Here

                SVNRevision startRevision = source.getRevision();
                if (!startRevision.isValid()) {
                    startRevision = pegRevision;
                }
                SVNRepositoryLocation[] locations = getLocations(source.getURL(), null, null, pegRevision, startRevision, SVNRevision.UNDEFINED);
                SVNRepository repository = createRepository(locations[0].getURL(), null, null, true);
                long revision = locations[0].getRevisionNumber();
                Collection entries = new ArrayList();
                repository.getDir("", revision, null, 0, entries);
                for (Iterator ents = entries.iterator(); ents.hasNext();) {
                    SVNDirEntry entry = (SVNDirEntry) ents.next();
                    // add new copy source.
                    expanded.add(new SVNCopySource(SVNRevision.UNDEFINED, source.getRevision(), entry.getURL()));
                }
View Full Code Here

TOP

Related Classes of org.tmatesoft.svn.core.io.SVNRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.