Package org.tmatesoft.svn.core.io

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


         * 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);
        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 latest repository revision. We will export repository contents at this very revision.
         */
        long latestRevision = repository.getLatestRevision();

        /*
         * Create reporterBaton. This class is responsible for reporting 'wc state' to the server.
         *
         * In this example it will always report that working copy is empty to receive update
         * instructions that are sufficient to create complete directories hierarchy and get full
         * files contents.
         */
        ISVNReporterBaton reporterBaton = new ExportReporterBaton(latestRevision);

        /*
         * Create editor. This class will process update instructions received from the server and
         * will create directories and files accordingly.
         *
         * As we've reported 'emtpy working copy', server will only send 'addDir/addFile' instructions
         * and will never ask our editor implementation to modify a file or directory properties.
         */
        ISVNEditor exportEditor = new ExportEditor(exportDir);

        /*
         * Now ask SVNKit to perform generic 'update' operation using our reporter and editor.
         *
         * We are passing:
         *
         * - revision from which we would like to export
         * - null as "target" name, to perform export from the URL SVNRepository was created for,
         *   not from some child directory.
         * - reporterBaton
         * - exportEditor.
         */
        repository.update(latestRevision, null, true, reporterBaton, exportEditor);

        //System.out.println("Exported revision: " + latestRevision);
    }
View Full Code Here


       
        if (!revision.isValid()) {
            revision = SVNRevision.HEAD;
        }
       
        SVNRepository repos = createRepository(url, null, null, pegRevision, revision, null);
        url = repos.getLocation();
        long revNumber = getRevisionNumber(revision, repos, null);
        SVNNodeKind targetNodeKind = repos.checkPath("", revNumber);
        if (targetNodeKind == SVNNodeKind.FILE) {
            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE, "URL ''{0}'' refers to a file, not a directory", url);
            SVNErrorManager.error(err, SVNLogType.WC);
        } else if (targetNodeKind == SVNNodeKind.NONE) {
            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_ILLEGAL_URL, "URL ''{0}'' doesn''t exist", url);
            SVNErrorManager.error(err, SVNLogType.WC);
        }
        String uuid = repos.getRepositoryUUID(true);
        SVNURL repositoryRoot = repos.getRepositoryRoot(true);

        long result = -1;
        depth = depth == null ? SVNDepth.UNKNOWN : depth;
        SVNWCAccess wcAccess = createWCAccess();
        SVNFileType kind = SVNFileType.getType(dstPath);
View Full Code Here

     * @since  1.2, SVN 1.5
     */
    public long doExport(SVNURL url, File dstPath, SVNRevision pegRevision, SVNRevision revision, String eolStyle,
            boolean overwrite, SVNDepth depth) throws SVNException {
        long[] revNum = { SVNRepository.INVALID_REVISION };
        SVNRepository repository = createRepository(url, null, null, pegRevision, revision, revNum);
        long exportedRevision = doRemoteExport(repository, revNum[0], dstPath, eolStyle, overwrite, depth);
        dispatchEvent(SVNEventFactory.createSVNEvent(null, SVNNodeKind.NONE, null, exportedRevision,
                SVNEventAction.UPDATE_COMPLETED, null, null, null));
        return exportedRevision;
    }
View Full Code Here

     */
    public long doExport(File srcPath, final File dstPath, SVNRevision pegRevision, SVNRevision revision,
            String eolStyle, final boolean overwrite, SVNDepth depth) throws SVNException {
        long exportedRevision = -1;
        if (revision != SVNRevision.BASE && revision != SVNRevision.WORKING && revision != SVNRevision.COMMITTED && revision != SVNRevision.UNDEFINED) {
            SVNRepository repository = createRepository(null, srcPath, null, pegRevision, revision, null);
            long revisionNumber = getRevisionNumber(revision, repository, srcPath);
            exportedRevision = doRemoteExport(repository, revisionNumber, dstPath, eolStyle, overwrite, depth);
        } else {
            if (revision == SVNRevision.UNDEFINED) {
                revision = SVNRevision.WORKING;
View Full Code Here

        }
       
        externalRevision = revs.length > 0 && revs[0] != null ? revs[0] : externalRevision;
        externalPegRevision = revs.length > 1 && revs[1] != null ? revs[1] : externalPegRevision;
       
        SVNRepository repository = null;
        SVNNodeKind kind = null;
        SVNURL reposRootURL = null;
        if (newURL != null) {
            long[] rev = { SVNRepository.INVALID_REVISION };
            repository = createRepository(newURL, null, null, externalPegRevision, externalRevision, rev);
            reposRootURL = repository.getRepositoryRoot(false);
            kind = repository.checkPath("", rev[0]);
            if (kind == SVNNodeKind.NONE) {
                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_ILLEGAL_URL, "URL ''{0}'' at revision {1} doesn''t exist",
                        new Object[] { repository.getLocation(), String.valueOf(rev[0]) });
                SVNErrorManager.error(err, SVNLogType.WC);
            }
           
            if (kind != SVNNodeKind.DIR && kind != SVNNodeKind.FILE) {
                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_ILLEGAL_URL, "URL ''{0}'' at revision {1} is not a file or a directory",
                        new Object[] { repository.getLocation(), String.valueOf(rev[0]) });
                SVNErrorManager.error(err, SVNLogType.WC);
            }
        }
       
        try {
            setEventPathPrefix("path");
            if (oldURL == null) {
                if (kind == SVNNodeKind.DIR) {
                    target.mkdirs();
                    dispatchEvent(SVNEventFactory.createSVNEvent(target, SVNNodeKind.DIR, null, SVNRepository.INVALID_REVISION,
                            SVNEventAction.UPDATE_EXTERNAL, null, null, null));
                    if (externalDiff.isExport) {
                        doExport(newURL, target, externalPegRevision, externalRevision, null, true, SVNDepth.INFINITY);
                    } else {
                        doCheckout(newURL, target, externalPegRevision, externalRevision, SVNDepth.INFINITY, false);
                    }
                } else if (kind == SVNNodeKind.FILE) {
                    dispatchEvent(SVNEventFactory.createSVNEvent(target, SVNNodeKind.FILE, null, SVNRepository.INVALID_REVISION,
                            SVNEventAction.UPDATE_EXTERNAL, null, null, null));

                    if (externalDiff.isExport) {
                        boolean ignoreExternals = isIgnoreExternals();
                        setIgnoreExternals(true);
                        doExport(newURL, target, externalPegRevision, externalRevision, null, false, SVNDepth.INFINITY);
                        setIgnoreExternals(ignoreExternals);
                    } else {
                        switchFileExternal(access, target, newURL, externalPegRevision, externalRevision, reposRootURL);
                    }
                }
            } else if (newURL == null) {
                SVNWCAccess wcAccess = createWCAccess();
                SVNAdminArea area = wcAccess.open(target, true, SVNWCAccess.INFINITE_DEPTH);
                SVNException error = null;
                try {
                    area.removeFromRevisionControl(area.getThisDirName(), true, false);
                } catch (SVNException svne) {
                    error = svne;
                }
                if (error == null || error.getErrorMessage().getErrorCode() == SVNErrorCode.WC_LEFT_LOCAL_MOD) {
                    try {
                        wcAccess.close();
                    } catch (SVNException svne) {
                        error = error == null ? svne : error;
                    }
                }
                if (error != null && error.getErrorMessage().getErrorCode() != SVNErrorCode.WC_LEFT_LOCAL_MOD) {
                    throw error;
                }
            } else if (externalDiff.isUpdateUnchanged || !externalDiff.compareExternals(oldURL, newURL)) {
                if (kind == SVNNodeKind.DIR) {
                    SVNFileType fileType = SVNFileType.getType(target);
                    boolean empty = false;
                    if (fileType == SVNFileType.DIRECTORY) {
                        File[] children = target.listFiles();
                        if (children != null && children.length == 0) {
                            empty = true;
                        }
                    }
                   
                    if (fileType == SVNFileType.DIRECTORY && !empty) {
                        dispatchEvent(SVNEventFactory.createSVNEvent(target, SVNNodeKind.DIR, null, SVNRepository.INVALID_REVISION, SVNEventAction.UPDATE_EXTERNAL, null, null, null));
                        SVNWCAccess wcAccess = createWCAccess();
                        SVNAdminArea area = wcAccess.open(target, true, 0);
                        SVNEntry entry = area.getEntry(area.getThisDirName(), false);
                        wcAccess.close();
                        String url = entry.getURL();
       
                        if (entry != null && entry.getURL() != null) {
                            if (newURL.toString().equals(url)) {
                                doUpdate(target, externalRevision, SVNDepth.UNKNOWN, true, false);
                                return;
                            } else if (entry.getRepositoryRoot() != null) {
                                if (!SVNPathUtil.isAncestor(entry.getRepositoryRoot(), newURL.toString())) {
                                    SVNRepository repos = createRepository(newURL, null, null, true);
                                    SVNURL reposRoot = repos.getRepositoryRoot(true);
                                    try {
                                        doRelocate(target, entry.getSVNURL(), reposRoot, true);
                                    } catch (SVNException svne) {
                                        if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.WC_INVALID_RELOCATION ||
                                                svne.getErrorMessage().getErrorCode() == SVNErrorCode.CLIENT_INVALID_RELOCATION) {
View Full Code Here

                    SVNErrorManager.error(err, SVNLogType.WC);
                }
                return validatedURLs;
            }
        }
        SVNRepository repos = createRepository(targetURL, null, null, false);
        try {
            SVNURL actualRoot = repos.getRepositoryRoot(true);
            if (isRoot && !targetURL.equals(actualRoot)) {
                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.CLIENT_INVALID_RELOCATION, "''{0}'' is not the root of the repository", targetURL);
                SVNErrorManager.error(err, SVNLogType.WC);
            }
   
            String actualUUID = repos.getRepositoryUUID(true);
            if (expectedUUID != null && !expectedUUID.equals(actualUUID)) {
                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.CLIENT_INVALID_RELOCATION, "The repository at ''{0}'' has uuid ''{1}'', but the WC has ''{2}''",
                        new Object[] { targetURL, actualUUID, expectedUUID });
                SVNErrorManager.error(err, SVNLogType.WC);
            }
            validatedURLs.put(targetURL, actualUUID);
        } finally {
            repos.closeSession();
        }
        return validatedURLs;
    }
View Full Code Here

                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_MISSING_URL, "Directory ''{0}'' has no URL", anchorArea.getRoot());
                SVNErrorManager.error(err, SVNLogType.WC);
            }
            long[] revs = new long[1];
            // should fail on missing repository.
            SVNRepository repository = createRepository(url, null, anchorArea, pegRevision, revision, revs);
            long revNumber = revs[0];
            url = repository.getLocation();
            // root of the switched repos.
            SVNURL sourceRoot = repository.getRepositoryRoot(true);
            if (!SVNPathUtil.isAncestor(sourceRoot.toString(), sourceURL.toString())) {
                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_INVALID_SWITCH, "''{0}''\nis not the same repository as\n''{1}''",
                        new Object[] {url.toString(), sourceRoot.toString()});
                SVNErrorManager.error(err, SVNLogType.WC);
            }
            if (depthIsSticky && depth.compareTo(SVNDepth.INFINITY) < 0) {
                SVNEntry targetEntry = anchorArea.getEntry(info.getTargetName(), true);
                if (targetEntry != null && targetEntry.isDirectory()) {
                    SVNWCManager.crop(info, depth);
                }
            }

            // reparent to the sourceURL
            repository.setLocation(sourceURL, false);
            String[] preservedExts = getOptions().getPreservedConflictFileExtensions();
            ISVNUpdateEditor editor = wcAccess.createUpdateEditor(info, url.toString(),
                    allowUnversionedObstructions, depthIsSticky, depth, preservedExts, null, false);

            ISVNEditor filterEditor = SVNAmbientDepthFilterEditor.wrap(editor, info, depthIsSticky);
           
            String target = "".equals(info.getTargetName()) ? null : info.getTargetName();
            repository.update(url, revNumber, target, depth, reporter, SVNCancellableEditor.newInstance(filterEditor, this, getDebugLog()));

            long targetRevision = editor.getTargetRevision();
            if (targetRevision >= 0 && !isIgnoreExternals() && depth.isRecursive()) {
                url = target == null ? url : url.removePathTail();
                handleExternals(wcAccess, info.getAnchor().getRoot(), info.getOldExternals(), info.getNewExternals(),
View Full Code Here

                }
            }
 
            String[] preservedExts = getOptions().getPreservedConflictFileExtensions();
           
            SVNRepository repos = createRepository(url, anchorArea.getRoot(), wcAccess, true);
            boolean serverSupportsDepth = repos.hasCapability(SVNCapability.DEPTH);
            final SVNReporter reporter = new SVNReporter(adminInfo, path, true, !serverSupportsDepth,
                    depth, isUpdateLocksOnDemand(), false, !depthIsSticky, getDebugLog());
           
            String target = "".equals(adminInfo.getTargetName()) ? null : adminInfo.getTargetName();
            long revNumber = getRevisionNumber(revision, repos, path);
            SVNURL reposRoot = repos.getRepositoryRoot(true);
            wcAccess.setRepositoryRoot(path, reposRoot);
           
            final SVNRepository repos2 = createRepository(reposRoot, null, null, false);
            ISVNFileFetcher fileFetcher = new ISVNFileFetcher() {
                public long fetchFile(String path, long revision, OutputStream os, SVNProperties properties) throws SVNException {
                    return repos2.getFile(path, revision, properties, os);
                }
            };
           
            ISVNUpdateEditor editor = wcAccess.createUpdateEditor(adminInfo, null, allowUnversionedObstructions,
                    depthIsSticky, depth, preservedExts, fileFetcher, isUpdateLocksOnDemand());

            ISVNEditor filterEditor = SVNAmbientDepthFilterEditor.wrap(editor, adminInfo, depthIsSticky);

            try {
                repos.update(revNumber, target, depth, sendCopyFrom, reporter, SVNCancellableEditor.newInstance(filterEditor, this, getDebugLog()));
            } finally {
                repos2.closeSession();
            }

            long targetRevision = editor.getTargetRevision();
           
            if (targetRevision >= 0) {
View Full Code Here

      svnurl = SVNURL.fromFile(new File(new File(System.getProperty("user.dir")).getParentFile(), "demorepo"));
    } else {
      svnurl = SVNURL.parseURIEncoded(svnUriString);
    }
    logger.info("Connecting to subversion repository at: " + svnUriString);
    SVNRepository repository = SVNRepositoryFactory.create(svnurl);

    // credentials for access
    repository.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager(
        configuration.getValue("account"),
        configuration.getValue("password"))
    );
    return repository;
  }
View Full Code Here

     * 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 mya be
     * used to specify HEAD (latest) revision.
     */
    SVNNodeKind nodeKind = repository.checkPath("", -1);
    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 latest repository revision. We will export repository contents at
     * this very revision.
     */
    long latestRevision = repository.getLatestRevision();

    /*
     * Create reporterBaton. This class is responsible for reporting 'wc
     * state' to the server.
     *
     * In this example it will always report that working copy is empty to
     * receive update instructions that are sufficient to create complete
     * directories hierarchy and get full files contents.
     */
    ISVNReporterBaton reporterBaton = new ExportReporterBaton(
        latestRevision);

    /*
     * Create editor. This class will process update instructions received
     * from the server and will create directories and files accordingly.
     *
     * As we've reported 'emtpy working copy', server will only send
     * 'addDir/addFile' instructions and will never ask our editor
     * implementation to modify a file or directory properties.
     */
    ISVNEditor exportEditor = new ExportEditor(exportDir);

    /*
     * Now ask JavaSVN to perform generic 'update' operation using our
     * reporter and editor.
     *
     * We are passing: - revision from which we would like to export - null
     * as "target" name, to perform export from the URL SVNRepository was
     * created for, not from some child directory. - reporterBaton -
     * exportEditor.
     */
    repository.update(latestRevision, null, true, reporterBaton,
        exportEditor);

    System.out.println("Exported revision: " + latestRevision);
  }
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.