Package org.tmatesoft.svn.core.wc

Examples of org.tmatesoft.svn.core.wc.SVNClientManager


      /*
       * Creates an instance of SVNClientManager providing authentication
       * information (name, password) and an options driver
       */
      SVNClientManager ourClientManager = SVNClientManager
          .newInstance(options);
      SVNUpdateClient updateClient = ourClientManager.getUpdateClient();

      /*
       * Creates the event handler to display information
       */
      ourClientManager.setEventHandler(new SVNEventAdapter() {
        public void handleEvent(SVNEvent event, double progress) {
          SVNEventAction action = event.getAction();
          File curFile = event.getFile();

          String path = curFile.getAbsolutePath();
          path = path.substring(path.indexOf(FOLDER_NAME));

          if (action == SVNEventAction.ADD
              || action == SVNEventAction.UPDATE_ADD) {
            m_taskOutput.append("Downloading " + path + " \n");

            m_taskOutput.setCaretPosition(m_taskOutput
                .getDocument().getLength());
            System.out.println("Downloading " + curFile.getName());
          }
          if (action == SVNEventAction.STATUS_COMPLETED
              || action == SVNEventAction.UPDATE_COMPLETED) {
            setProgress(100);
            m_taskOutput.append("Download completed. ");
            m_taskOutput.setCaretPosition(m_taskOutput
                .getDocument().getLength());
            System.out.println("Download completed. ");

          }
        }
      });

      /*
       * sets externals not to be ignored during the checkout
       */
      updateClient.setIgnoreExternals(false);

      /*
       * A url of a repository to check out
       */
      SVNURL url = null;
      try {
        url = SVNURL.parseURIDecoded("http://" + SVN_URL);
      } catch (SVNException e2) {
        e2.printStackTrace();
      }
      /*
       * A revision to check out
       */
      SVNRevision revision = SVNRevision.HEAD;

      /*
       * A revision for which you're sure that the url you specify is
       * exactly what you need
       */
      SVNRevision pegRevision = SVNRevision.HEAD;

      /*
       * A local path where a Working Copy will be ckecked out
       */
      File destPath = new File(m_installpath);

      /*
       * returns the number of the revision at which the working copy is
       */
      try {
        System.out.println(m_installpath);
        m_taskOutput.append("Game folder: " + m_installpath + "\n");
        boolean exists = destPath.exists();
        if (!exists) {
          m_taskOutput
              .append("Installing...\nPlease be patient while PokeNet is downloaded...\n");
          System.out.println("Installing...");
          updateClient.doCheckout(url, destPath, pegRevision,
              revision, SVNDepth.INFINITY, true);

        } else {
          ourClientManager.getWCClient().doCleanup(destPath);
          m_taskOutput.append("Updating...\n");
          System.out.println("Updating...\n");
          updateClient.doUpdate(destPath, revision,
              SVNDepth.INFINITY, true, true);
        }
      } catch (SVNException e1) {
        // It's probably locked, lets cleanup and resume.
        e1.printStackTrace();
        try {
          ourClientManager.getWCClient().doCleanup(destPath);
          m_taskOutput.append("Resuming Download...\n");
          System.out.println("Resuming Download...\n");
          updateClient.doUpdate(destPath, revision,
              SVNDepth.INFINITY, true, true);
        } catch (SVNException e) {
View Full Code Here


    DAVRepositoryFactory.setup();
  }

  private void initClientManager(String url, String username, String password) {
    // 1# instantiate a new object of type SVNClientManager and
    SVNClientManager manager = SVNClientManager.newInstance(defaultOpts, username, password);
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
        username, password);
    manager.setAuthenticationManager(authManager);

    // 2# add the client manager to the pool, for later use
    clientManagers.put(url, manager);
  }
View Full Code Here

            return new DefaultPooledObject<SVNClientManager>(obj);
        }

        @Override
        public void destroyObject(final PooledObject<SVNClientManager> p) throws Exception {
            final SVNClientManager m = p.getObject();
            m.dispose();
        }
View Full Code Here

    }

    @Override
    public <T> T doWithClientAndRepository(final SvnOperation<T> operation) throws StoreException {
        checkShutdownState();
        SVNClientManager clientManager = null;
        try {
            clientManager = clientManagerPool.borrowObject();
            if (clientManager == null) {
                throw new StoreException.ReadException("Failed to acquire SVNClientManager");
            }
            // do not explicitly close the session because mayReuse=true
            final SVNRepository repository = clientManager.createRepository(svnUrl, true);

            return operation.execute(repository, clientManager);
        } catch (Exception e) {
            Throwables.propagateIfInstanceOf(e, StoreException.class);
            throw operation.handleException(e);
View Full Code Here

        final String password,
        final SVNURL svnUrl,
        final FileBasedProctorStore.ProctorUpdater updater,
        final String comment) throws IOException, SVNException, Exception {
        final BasicAuthenticationManager authManager = new BasicAuthenticationManager(username, password);
        final SVNClientManager userClientManager = SVNClientManager.newInstance(null, authManager);
        final SVNWCClient wcClient = userClientManager.getWCClient();

        try {
            // Clean up the UserDir
            SvnProctorUtils.cleanUpWorkingDir(logger, userDir, svnUrl, userClientManager);

            /*
                if (previousVersion != 0) {
                    final Collection<?> changesSinceGivenVersion = repo.log(new String[] { "" }, null, previousVersion, -1, false, false);
                    if (! changesSinceGivenVersion.isEmpty()) {
                        //  TODO: the baseline version is out of date, so need to go back to the user
                    }
                }
                updateClient.doCheckout(checkoutUrl, workingDir, null, SVNRevision.HEAD, SVNDepth.INFINITY, false);
            */

            final FileBasedProctorStore.RcsClient rcsClient = new SvnPersisterCoreImpl.SvnRcsClient(wcClient);
            final boolean thingsChanged = updater.doInWorkingDirectory(rcsClient, userDir);

            if (thingsChanged) {
                final SVNCommitClient commitClient = userClientManager.getCommitClient();
                final SVNCommitPacket commit = commitClient.doCollectCommitItems(new File[]{userDir}, false, false, SVNDepth.INFINITY, new String[0]);
                long elapsed = -System.currentTimeMillis();
                final SVNCommitInfo info = commitClient.doCommit(commit, /* keepLocks */ false, comment);
                elapsed += System.currentTimeMillis();
                if (logger.isDebugEnabled()) {
                    final StringBuilder changes = new StringBuilder("Committed " + commit.getCommitItems().length + " changes: ");
                    for (final SVNCommitItem item : commit.getCommitItems()) {
                        changes.append(item.getKind() + " - " + item.getPath() + ", ");
                    }
                    changes.append(String.format(" in %d ms new revision: r%d", elapsed, info.getNewRevision()));
                    logger.debug(changes.toString());
                }
            }
        } finally {
            userClientManager.dispose();
        }
    }
View Full Code Here

            SamplesUtility.createRepository(reposRoot);
            SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot);
            //print out new revision info
            System.out.println(info);

            SVNClientManager clientManager = SVNClientManager.newInstance();
            clientManager.setEventHandler(new EventHandler());
           
            SVNURL reposURL = SVNURL.fromFile(reposRoot);

            //copy A to A_copy in repository (url-to-url copy)
            SVNCopyClient copyClient = clientManager.getCopyClient();
            SVNURL A_URL = reposURL.appendPath("A", true);
            SVNURL copyTargetURL = reposURL.appendPath("A_copy", true);
            SVNCopySource copySource = new SVNCopySource(SVNRevision.UNDEFINED, SVNRevision.HEAD, A_URL);
            info = copyClient.doCopy(new SVNCopySource[] { copySource }, copyTargetURL, false, false, true,
                    "copy A to A_copy", null);
            //print out new revision info
            System.out.println(info);
           
            //checkout the entire repository tree
            SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);

           
            //now make some changes to the A tree
            SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
            SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
           
            SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
            wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false,
                    SVNDepth.EMPTY, null, null);

            //commit local changes
            SVNCommitClient commitClient = clientManager.getCommitClient();
            commitClient.doCommit(new File[] { wcRoot }, false, "committing changes", null, null, false, false, SVNDepth.INFINITY);
           
            //now diff the base revision of the working copy against the repository
            SVNDiffClient diffClient = clientManager.getDiffClient();
            SVNRevisionRange rangeToMerge = new SVNRevisionRange(SVNRevision.create(1), SVNRevision.HEAD);
           
            diffClient.doMerge(A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge),
                    new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false);
           
View Full Code Here

           
            //now make some changes to the working copy
            SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
            SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
           
            SVNClientManager clientManager = SVNClientManager.newInstance();
            SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
            wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false,
                    SVNDepth.EMPTY, null, null);

            //commit local changes
            SVNCommitClient commitClient = clientManager.getCommitClient();
            commitClient.doCommit(new File[] { wcRoot }, false, "committing changes", null, null, false, false, SVNDepth.INFINITY);
           
            //roll back changes in the working copy - update to revision 1
            SVNUpdateClient updateClient = clientManager.getUpdateClient();
            updateClient.doUpdate(wcRoot, SVNRevision.create(1), SVNDepth.INFINITY, false, false);
           
            //now diff the base revision of the working copy against the repository
            SVNDiffClient diffClient = clientManager.getDiffClient();

            /*
             * This corresponds to 'svn diff -rBASE:HEAD'.
             */
            diffClient.doDiff(wcRoot, SVNRevision.UNDEFINED, SVNRevision.BASE, SVNRevision.HEAD,
View Full Code Here

            SVNURL reposURL = SVNURL.fromFile(reposRoot);
            //checkout the entire repository tree
            SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);

            SVNClientManager clientManager = SVNClientManager.newInstance();
            SVNStatusClient statusClient = clientManager.getStatusClient();
            ISVNStatusHandler handler = new StatusHandler();

            statusClient.doStatus(wcRoot, SVNRevision.WORKING, SVNDepth.INFINITY, true, true, false, false,
                    handler, null);
           
            SVNWCClient wcClient = clientManager.getWCClient();
            wcClient.doSetWCFormat(wcRoot, 4);
           
            statusClient.doStatus(wcRoot, SVNRevision.WORKING, SVNDepth.INFINITY, false, true, false, false,
                    handler, null);
           
View Full Code Here

           
            //now make some changes to the working copy
            SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
            SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
           
            SVNClientManager clientManager = SVNClientManager.newInstance();
            SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
            wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false,
                    SVNDepth.EMPTY, null, null);
           
            //now run diff the working copy against the repository
            SVNDiffClient diffClient = clientManager.getDiffClient();

            /*
             * This corresponds to 'svn diff -rHEAD'.
             */
            diffClient.doDiff(wcRoot, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD,
View Full Code Here

        FileUtils.deleteDirectory(LOCAL_REPO);
        FileUtils.deleteDirectory(WORKING_COPY);
    }

    public void testConversion() throws SVNException, IOException {
        SVNClientManager ourClientManager = SVNClientManager.newInstance();
        // checkout working copy
        SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
        updateClient.setIgnoreExternals(false);
        updateClient.doCheckout(tgtURL, WORKING_COPY, SVNRevision.UNDEFINED, SVNRevision.HEAD, SVNDepth.INFINITY, true);
        // add file under version control
        int id1 = 45;
        create(ourClientManager, id1);
        modify(ourClientManager, id1);
        int id2 = 2;
        create(ourClientManager, id2);
        modify(ourClientManager, id2);

        delete(ourClientManager, id1);
        delete(ourClientManager, id2);

        final SVNRepository repository = SVNRepositoryFactory.create(tgtURL);
        MyLogEntryHandler logEntryHandler = new MyLogEntryHandler();
        repository.log(new String[]{""}, 0, -1, true, true, logEntryHandler);
        final List<MetadataAction> metadataActionList = logEntryHandler.getMetadataActionList();
        // only partial assertion of entered data
        for (MetadataAction metadataAction : metadataActionList) {
            Assert.assertEquals("admin", metadataAction.getUsername());
            Assert.assertEquals("0:0:0:0:0:0:0:1", metadataAction.getIp());
        }
        final MetadataAction firstEntry = metadataActionList.get(0);
        Assert.assertEquals("all", firstEntry.getSubject());
        Assert.assertEquals(id1, firstEntry.getId());
        Assert.assertEquals('A', firstEntry.getAction());
        Assert.assertNotNull(firstEntry.getDate());
        final MetadataAction lastEntry = metadataActionList.get(metadataActionList.size() - 1);
        Assert.assertEquals('D', lastEntry.getAction());
        Assert.assertEquals("all", lastEntry.getSubject());

        ourClientManager.dispose();
    }
View Full Code Here

TOP

Related Classes of org.tmatesoft.svn.core.wc.SVNClientManager

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.