Search in sources :

Example 1 with ScmFileSet

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

the class AbstractScmPublishMojo method checkinFiles.

/**
     * Check-in content from scm checkout.
     *
     * @throws MojoExecutionException
     */
protected void checkinFiles() throws MojoExecutionException {
    if (skipCheckin) {
        return;
    }
    ScmFileSet updatedFileSet = new ScmFileSet(checkoutDirectory);
    try {
        long start = System.currentTimeMillis();
        CheckInScmResult checkinResult = checkScmResult(scmProvider.checkIn(scmRepository, updatedFileSet, new ScmBranch(scmBranch), checkinComment), "check-in files to SCM");
        logInfo("Checked in %d file(s) to revision %s in %s", checkinResult.getCheckedInFiles().size(), checkinResult.getScmRevision(), DurationFormatUtils.formatPeriod(start, System.currentTimeMillis(), "H' h 'm' m 's' s'"));
    } catch (ScmException e) {
        throw new MojoExecutionException("Failed to perform SCM checkin", 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) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 2 with ScmFileSet

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

the class AbstractScmPublishMojo method addFiles.

/**
     * Add files to scm.
     *
     * @param added files to be added
     * @throws MojoFailureException
     * @throws MojoExecutionException
     */
protected void addFiles(Collection<File> added) throws MojoFailureException, MojoExecutionException {
    List<File> addedList = new ArrayList<File>();
    Set<File> createdDirs = new HashSet<File>();
    Set<File> dirsToAdd = new TreeSet<File>();
    createdDirs.add(relativize(checkoutDirectory, checkoutDirectory));
    for (File f : added) {
        for (File dir = f.getParentFile(); !dir.equals(checkoutDirectory); dir = dir.getParentFile()) {
            File relativized = relativize(checkoutDirectory, dir);
            //  we do the best we can with the directories
            if (createdDirs.add(relativized)) {
                dirsToAdd.add(relativized);
            } else {
                break;
            }
        }
        addedList.add(relativize(checkoutDirectory, f));
    }
    if (addUniqueDirectory) {
        // add one directory at a time
        for (File relativized : dirsToAdd) {
            try {
                ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, relativized);
                getLog().info("scm add directory: " + relativized);
                AddScmResult addDirResult = scmProvider.add(scmRepository, fileSet, "Adding directory");
                if (!addDirResult.isSuccess()) {
                    getLog().warn(" Error adding directory " + relativized + ": " + addDirResult.getCommandOutput());
                }
            } catch (ScmException e) {
            //
            }
        }
    } else {
        // add all directories in one command
        try {
            List<File> dirs = new ArrayList<File>(dirsToAdd);
            ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, dirs);
            getLog().info("scm add directories: " + dirs);
            AddScmResult addDirResult = scmProvider.add(scmRepository, fileSet, "Adding directories");
            if (!addDirResult.isSuccess()) {
                getLog().warn(" Error adding directories " + dirs + ": " + addDirResult.getCommandOutput());
            }
        } catch (ScmException e) {
        //
        }
    }
    // remove directories already added !
    addedList.removeAll(dirsToAdd);
    ScmFileSet addedFileSet = new ScmFileSet(checkoutDirectory, addedList);
    getLog().info("scm add files: " + addedList);
    try {
        CommandParameters commandParameters = new CommandParameters();
        commandParameters.setString(CommandParameter.MESSAGE, "Adding new site files.");
        commandParameters.setString(CommandParameter.FORCE_ADD, Boolean.TRUE.toString());
        checkScmResult(scmProvider.add(scmRepository, addedFileSet, commandParameters), "add new files to SCM");
    } catch (ScmException e) {
        throw new MojoExecutionException("Failed to add new files to SCM", e);
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeSet(java.util.TreeSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with ScmFileSet

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

the class ChangeLogReport method getRevisionForTag.

/**
     * Resolves the given tag to the revision number.
     *
     * @param tag
     * @param repository
     * @param provider
     * @return
     * @throws ScmException
     */
private String getRevisionForTag(final String tag, final ScmRepository repository, final ScmProvider provider) throws ScmException {
    if (repository.getProvider().equals("svn")) {
        if (tag == null) {
            return "HEAD";
        }
        SvnInfoCommandExpanded infoCommand = new SvnInfoCommandExpanded();
        infoCommand.setLogger(new DefaultLog());
        InfoScmResult infoScmResult = infoCommand.executeInfoTagCommand((SvnScmProviderRepository) repository.getProviderRepository(), new ScmFileSet(basedir), tag, null, false, null);
        if (infoScmResult.getInfoItems().size() == 0) {
            throw new ScmException("There is no tag named '" + tag + "' in the Subversion repository.");
        }
        InfoItem infoItem = infoScmResult.getInfoItems().get(0);
        String revision = infoItem.getLastChangedRevision();
        getLog().info(String.format("Resolved tag '%s' to revision '%s'", tag, revision));
        return revision;
    }
    return tag;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) InfoItem(org.apache.maven.scm.command.info.InfoItem) ScmException(org.apache.maven.scm.ScmException) DefaultLog(org.apache.maven.scm.log.DefaultLog) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) SvnInfoCommandExpanded(org.apache.maven.scm.provider.svn.svnexe.command.info.SvnInfoCommandExpanded)

Example 4 with ScmFileSet

use of org.apache.maven.scm.ScmFileSet 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 5 with ScmFileSet

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

Aggregations

ScmException (org.apache.maven.scm.ScmException)7 ScmFileSet (org.apache.maven.scm.ScmFileSet)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ScmBranch (org.apache.maven.scm.ScmBranch)3 IOException (java.io.IOException)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 AbstractSvnScmProvider (org.apache.maven.scm.provider.svn.AbstractSvnScmProvider)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 ScmResult (org.apache.maven.scm.ScmResult)1 ScmRevision (org.apache.maven.scm.ScmRevision)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1 InfoItem (org.apache.maven.scm.command.info.InfoItem)1