Search in sources :

Example 6 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class ChangeLogReport method generateChangeSetsFromSCM.

/**
     * creates a ChangeLog object and then connects to the SCM to generate the changed sets
     *
     * @return changedlogsets generated from the SCM
     * @throws MavenReportException
     */
protected List<ChangeLogSet> generateChangeSetsFromSCM() throws MavenReportException {
    try {
        List<ChangeLogSet> changeSets = new ArrayList<ChangeLogSet>();
        ScmRepository repository = getScmRepository();
        ScmProvider provider = manager.getProviderByRepository(repository);
        ChangeLogScmResult result;
        if ("range".equals(type)) {
            result = provider.changeLog(repository, new ScmFileSet(basedir), null, null, range, (ScmBranch) null, dateFormat);
            checkResult(result);
            changeSets.add(result.getChangeLog());
        } else if ("tag".equals(type)) {
            Iterator<String> tagsIter = tags.iterator();
            String startTag = tagsIter.next();
            String endTag = null;
            if (tagsIter.hasNext()) {
                while (tagsIter.hasNext()) {
                    endTag = tagsIter.next();
                    String endRevision = getRevisionForTag(endTag, repository, provider);
                    String startRevision = getRevisionForTag(startTag, repository, provider);
                    result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
                    checkResult(result);
                    result.getChangeLog().setStartVersion(new ScmRevision(startTag));
                    result.getChangeLog().setEndVersion(new ScmRevision(endTag));
                    changeSets.add(result.getChangeLog());
                    startTag = endTag;
                }
            } else {
                String startRevision = getRevisionForTag(startTag, repository, provider);
                String endRevision = getRevisionForTag(endTag, repository, provider);
                result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
                checkResult(result);
                result.getChangeLog().setStartVersion(new ScmRevision(startTag));
                result.getChangeLog().setEndVersion(null);
                changeSets.add(result.getChangeLog());
            }
        } else if ("date".equals(type)) {
            Iterator<String> dateIter = dates.iterator();
            String startDate = dateIter.next();
            String endDate = null;
            if (dateIter.hasNext()) {
                while (dateIter.hasNext()) {
                    endDate = dateIter.next();
                    result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
                    checkResult(result);
                    changeSets.add(result.getChangeLog());
                    startDate = endDate;
                }
            } else {
                result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
                checkResult(result);
                changeSets.add(result.getChangeLog());
            }
        } else {
            throw new MavenReportException("The type '" + type + "' isn't supported.");
        }
        filter(changeSets);
        return changeSets;
    } catch (ScmException e) {
        throw new MavenReportException("Cannot run changelog command : ", e);
    } catch (MojoExecutionException e) {
        throw new MavenReportException("An error has occurred during changelog command : ", e);
    }
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ScmRevision(org.apache.maven.scm.ScmRevision) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 7 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class SvnInfoCommandExpanded method executeInfoCommand.

private InfoScmResult executeInfoCommand(final Commandline cl) throws ScmException {
    SvnInfoConsumer consumer = new SvnInfoConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new InfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new InfoScmResult(cl.toString(), consumer.getInfoItems());
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 8 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class AbstractScmPublishMojo method deleteFiles.

protected void deleteFiles(Collection<File> deleted) throws MojoExecutionException {
    if (skipDeletedFiles) {
        logInfo("Deleting files is skipped.");
        return;
    }
    List<File> deletedList = new ArrayList<File>();
    for (File f : deleted) {
        deletedList.add(relativize(checkoutDirectory, f));
    }
    ScmFileSet deletedFileSet = new ScmFileSet(checkoutDirectory, deletedList);
    try {
        getLog().info("Deleting files: " + deletedList);
        checkScmResult(scmProvider.remove(scmRepository, deletedFileSet, "Deleting obsolete site files."), "delete files from SCM");
    } catch (ScmException e) {
        throw new MojoExecutionException("Failed to delete removed files to SCM", e);
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 9 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class AbstractScmPublishMojo method checkoutExisting.

protected void checkoutExisting() throws MojoExecutionException {
    if (scmProvider instanceof AbstractSvnScmProvider) {
        checkCreateRemoteSvnPath();
    }
    logInfo("%s the pub tree from %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)

Example 10 with ScmException

use of org.apache.maven.scm.ScmException 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)

Aggregations

ScmException (org.apache.maven.scm.ScmException)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ScmFileSet (org.apache.maven.scm.ScmFileSet)7 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ScmBranch (org.apache.maven.scm.ScmBranch)3 MavenReportException (org.apache.maven.reporting.MavenReportException)2 CommandParameters (org.apache.maven.scm.CommandParameters)2 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 InfoScmResult (org.apache.maven.scm.command.info.InfoScmResult)2 AbstractSvnScmProvider (org.apache.maven.scm.provider.svn.AbstractSvnScmProvider)2 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)2 ScmRepository (org.apache.maven.scm.repository.ScmRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1