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

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

There is a newer version: 24.8.0
Show newest version
package br.com.jarch.svn;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.wc.*;

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

class MergeSvn extends BaseSvn {

    private static final long serialVersionUID = 7512633402234527489L;

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

    public void merge(URL url, File pastaTrabalho) throws Exception {

        if (!existeRepositorio(url)) {
            throw new Exception("Repositório " + url.toString() + " NÃO localizado");
        }

        if (!pastaTrabalho.exists()) {
            throw new Exception("Pasta de trabalho " + pastaTrabalho.getAbsolutePath() + " NÃO localizado");
        }

        logUtil.formatBegin(log, "MERGE");
        logUtil.formatMiddle(log, "FOLDER: " + pastaTrabalho.getAbsolutePath() + " URL: " + url);

        SVNDiffClient diffClient = getDiffClient();

//        DefaultSVNOptions options = (DefaultSVNOptions) diffClient.getOptions();
//        options.setConflictHandler(new ISVNConflictHandler() {
//
//            @Override
//            public SVNConflictResult handleConflict(SVNConflictDescription svnConflictDescription) throws SVNException {
//                SVNConflictReason reason = svnConflictDescription.getConflictReason();
//                SVNMergeFileSet mergeFiles = svnConflictDescription.getMergeFiles();
//
//                File arquivo = mergeFiles.getWCFile() == null ? mergeFiles.getLocalFile() : mergeFiles.getWCFile();
//
//                SVNConflictChoice choice;
////                if (SvnUtil.ignora(arquivo))
////                    choice = SVNConflictChoice.THEIRS_FULL;
////                else
//                    choice = SVNConflictChoice.POSTPONE;
//
//                logUtil.formatMiddle(log, "CONFLICT: " + arquivo.getAbsolutePath());
//                logUtil.formatMiddle(log, "REASON: " + reason);
//
//                return new SVNConflictResult(choice, mergeFiles.getLocalFile());
//            }
//        });

        diffClient.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 = "MERGE: " + svnEvent.getFile().getPath();
                logUtil.formatMiddle(log, mensagem);
            }
        });

        diffClient.doMergeReIntegrate(SVNURL.parseURIEncoded(url.toString()), SVNRevision.HEAD, pastaTrabalho, false);

        logUtil.formatMiddle(log, "URL: " + url);
        logUtil.formatMiddle(log, "PASTA: " + pastaTrabalho);

        logUtil.formatEnd(log, "MERGE");

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy