Search in sources :

Example 1 with AbstractSvnScmProvider

use of org.apache.maven.scm.provider.svn.AbstractSvnScmProvider in project maven-plugins by apache.

the class AbstractScmPublishMojo method checkCreateRemoteSvnPath.

private void checkCreateRemoteSvnPath() throws MojoExecutionException {
    getLog().debug("AbstractSvnScmProvider used, so we can check if remote url exists and eventually create it.");
    AbstractSvnScmProvider svnScmProvider = (AbstractSvnScmProvider) scmProvider;
    try {
        boolean remoteExists = svnScmProvider.remoteUrlExist(scmRepository.getProviderRepository(), null);
        if (remoteExists) {
            return;
        }
    } catch (ScmException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    String remoteUrl = ((SvnScmProviderRepository) scmRepository.getProviderRepository()).getUrl();
    if (!automaticRemotePathCreation) {
        // olamy: return ?? that will fail during checkout IMHO :-)
        logWarn("Remote svn url %s does not exist and automatic remote path creation disabled.", remoteUrl);
        return;
    }
    logInfo("Remote svn url %s does not exist: creating.", remoteUrl);
    File baseDir = null;
    try {
        // create a temporary directory for svnexec
        baseDir = File.createTempFile("scm", "tmp");
        baseDir.delete();
        baseDir.mkdirs();
        // to prevent fileSet cannot be empty
        ScmFileSet scmFileSet = new ScmFileSet(baseDir, new File(""));
        CommandParameters commandParameters = new CommandParameters();
        commandParameters.setString(CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL, Boolean.FALSE.toString());
        commandParameters.setString(CommandParameter.MESSAGE, "Automatic svn path creation: " + remoteUrl);
        svnScmProvider.mkdir(scmRepository.getProviderRepository(), scmFileSet, commandParameters);
        // new remote url so force checkout!
        if (checkoutDirectory.exists()) {
            FileUtils.deleteDirectory(checkoutDirectory);
        }
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ScmException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        if (baseDir != null) {
            try {
                FileUtils.forceDeleteOnExit(baseDir);
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractSvnScmProvider(org.apache.maven.scm.provider.svn.AbstractSvnScmProvider) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) IOException(java.io.IOException) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File)

Example 2 with AbstractSvnScmProvider

use of org.apache.maven.scm.provider.svn.AbstractSvnScmProvider in project maven-plugins by apache.

the class AbstractScmPublishMojo method checkoutExisting.

protected void checkoutExisting() throws MojoExecutionException {
    if (scmProvider instanceof AbstractSvnScmProvider) {
        checkCreateRemoteSvnPath();
    }
    logInfo(MessageUtils.buffer().strong("%s") + " the pub tree from " + MessageUtils.buffer().strong("%s") + " into %s", (tryUpdate ? "Updating" : "Checking out"), pubScmUrl, checkoutDirectory);
    if (checkoutDirectory.exists() && !tryUpdate) {
        try {
            FileUtils.deleteDirectory(checkoutDirectory);
        } catch (IOException e) {
            logError(e.getMessage());
            throw new MojoExecutionException("Unable to remove old checkout directory: " + e.getMessage(), e);
        }
    }
    boolean forceCheckout = false;
    if (!checkoutDirectory.exists()) {
        if (tryUpdate) {
            logInfo("TryUpdate is configured but no local copy currently available: forcing checkout.");
        }
        checkoutDirectory.mkdirs();
        forceCheckout = true;
    }
    try {
        ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, includes, excludes);
        ScmBranch branch = (scmBranch == null) ? null : new ScmBranch(scmBranch);
        ScmResult scmResult = null;
        if (tryUpdate && !forceCheckout) {
            scmResult = scmProvider.update(scmRepository, fileSet, branch);
        } else {
            int attempt = 0;
            while (scmResult == null) {
                try {
                    scmResult = scmProvider.checkOut(scmRepository, fileSet, branch);
                } catch (ScmException e) {
                    // give it max 2 times to retry
                    if (attempt++ < 2) {
                        try {
                            // wait 3 seconds
                            Thread.sleep(3 * 1000);
                        } catch (InterruptedException ie) {
                        // noop
                        }
                    } else {
                        throw e;
                    }
                }
            }
        }
        checkScmResult(scmResult, "check out from SCM");
    } catch (ScmException e) {
        logError(e.getMessage());
        throw new MojoExecutionException("An error occurred during the checkout process: " + e.getMessage(), e);
    } catch (IOException e) {
        logError(e.getMessage());
        throw new MojoExecutionException("An error occurred during the checkout process: " + e.getMessage(), e);
    }
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmResult(org.apache.maven.scm.ScmResult) AbstractSvnScmProvider(org.apache.maven.scm.provider.svn.AbstractSvnScmProvider) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ScmException (org.apache.maven.scm.ScmException)2 ScmFileSet (org.apache.maven.scm.ScmFileSet)2 AbstractSvnScmProvider (org.apache.maven.scm.provider.svn.AbstractSvnScmProvider)2 File (java.io.File)1 CommandParameters (org.apache.maven.scm.CommandParameters)1 ScmBranch (org.apache.maven.scm.ScmBranch)1 ScmResult (org.apache.maven.scm.ScmResult)1 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)1