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

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

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

import org.tmatesoft.svn.core.SVNCommitInfo;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.*;

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

class CopySvn extends BaseSvn {

    private static final long serialVersionUID = -6504391246130847233L;

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

    public void copy(URL urlOrigem, URL urlDestino, String comentario) throws Exception {
        if (!existeRepositorio(urlOrigem)) {
            throw new Exception("Repositório " + urlOrigem.toString() + " NÃO Localizado ");
        }

        if (existeRepositorio(urlDestino)) {
            throw new Exception("Repositório " + urlDestino.toString() + " JÁ existe ");
        }

        SVNCopySource svnCopySource = new SVNCopySource(SVNRevision.UNDEFINED, SVNRevision.HEAD, SVNURL.parseURIEncoded(urlOrigem.toString()));

        SVNCopySource[] svnCopySources = new SVNCopySource[]{svnCopySource};

        SVNCopyClient svnCopyClient = getCopyClient();

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

            @Override
            public void handleEvent(SVNEvent svnEvent, double arg1) {
                if (svnEvent == null || svnEvent.getFile() == null)
                    return;
                else
                    svnEvent.getFile();

                String mensagem = "COPY: " + svnEvent.getFile().getPath();
                logUtil.formatMiddle(log, mensagem);
            }
        });

        SVNCommitInfo svnCommiInfo = svnCopyClient.doCopy(svnCopySources, SVNURL.parseURIEncoded(urlDestino.toString()), false, false, true,
                comentario, null);

        logUtil.formatBeginMiddleEnd(log, "COPY", new String[]{"URL ORIGEM: " + urlOrigem.toString(), "URL DESTINO: " + urlDestino.toString(),
                "REVISÃO: " + svnCommiInfo.getNewRevision()});
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy