All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.svn.CheckoutSvn Maven / Gradle / Ivy

The newest version!
package br.com.jarch.svn;

import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNEventHandler;
import org.tmatesoft.svn.core.wc.SVNEvent;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;

import java.io.File;
import java.net.URL;
import java.util.List;

class CheckoutSvn extends BaseSvn {

    private static final long serialVersionUID = -8759154546425267411L;

    public CheckoutSvn(List log, String login, String senha) {
        super(log, login, senha);
    }

    public void checkout(URL urlOrigem, File pastaTrabalho) throws SVNException {
        checkout(urlOrigem, pastaTrabalho, 0);
    }

    public void checkout(URL urlOrigem, File pastaTrabalho, long revisaoDesejada) throws SVNException {
        System.out.println("CHECKOUT: " + urlOrigem.toString() + " em " + pastaTrabalho.getAbsolutePath());
        logUtil.formatBegin(log, "CHECKOUT");
        logUtil.formatMiddle(log, "FOLDER: " + pastaTrabalho.getAbsolutePath() + " URL: " + urlOrigem);

        SVNUpdateClient updateClient = getUpdateClient();
        updateClient.setIgnoreExternals(false);

        updateClient.setEventHandler(new ISVNEventHandler() {
            @Override
            public void checkCancelled() {
            }

            @Override
            public void handleEvent(SVNEvent svnEvent, double arg1) {
                String mensagem = "CHECKOUT: " + svnEvent.getFile().getPath();
                logUtil.formatMiddle(log, mensagem);
            }
        });

        SVNRevision revisao;

        if (revisaoDesejada == 0) {
            revisao = SVNRevision.HEAD;
        } else {
            revisao = SVNRevision.create(revisaoDesejada);
        }

        long revision = updateClient.doCheckout(SVNURL.parseURIEncoded(urlOrigem.toString()), pastaTrabalho, revisao, revisao, SVNDepth.INFINITY,
                false);

        logUtil.formatMiddle(log, "Revisão: " + revision);
        logUtil.formatEnd(log, "CHECKOUT");

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy