Search in sources :

Example 26 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class SvnChangeLogCommand method executeChangeLogCommand.

private ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion, Integer limit) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate, endDate, startVersion, endVersion, limit);
    SvnChangeLogConsumer consumer = new SvnChangeLogConsumer(getLogger(), datePattern);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            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 svn command.", ex);
    }
    if (exitCode != 0) {
        return new ChangeLogScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
    changeLogSet.setStartVersion(startVersion);
    changeLogSet.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 27 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class AccuRevChangeLogCommand method getChangeLog.

private ChangeLogSet getChangeLog(Stream stream, List<FileDifference> streamDifferences, List<Transaction> streamHistory, List<Transaction> workspaceHistory, Date startDate, Date endDate) {
    // Collect all the "to" versions from the streamDifferences into a Map by element id
    // If that version is seen in the promote/keep history then we move it from the map
    // At the end we create a pseudo ChangeSet for any remaining entries in the map as
    // representing "upstream changes"
    Map<Long, FileDifference> differencesMap = new HashMap<Long, FileDifference>();
    for (FileDifference fileDifference : streamDifferences) {
        differencesMap.put(fileDifference.getElementId(), fileDifference);
    }
    List<Transaction> mergedHistory = new ArrayList<Transaction>(streamHistory);
    // will never match a version
    String streamPrefix = "/";
    mergedHistory.addAll(workspaceHistory);
    streamPrefix = stream.getId() + "/";
    List<ChangeSet> entries = new ArrayList<ChangeSet>(streamHistory.size());
    for (Transaction t : mergedHistory) {
        if ((startDate != null && t.getWhen().before(startDate)) || (endDate != null && t.getWhen().after(endDate))) {
            // This is possible if dates and transactions are mixed in the time spec.
            continue;
        }
        // the history of this stream.
        if ("mkstream".equals(t.getTranType())) {
            continue;
        }
        Collection<Version> versions = t.getVersions();
        List<ChangeFile> files = new ArrayList<ChangeFile>(versions.size());
        for (Version v : versions) {
            // Remove diff representing this promote
            FileDifference difference = differencesMap.get(v.getElementId());
            // TODO: how are defuncts shown in the version history?
            if (difference != null) {
                String newVersionSpec = difference.getNewVersionSpec();
                if (newVersionSpec != null && newVersionSpec.equals(v.getRealSpec())) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Removing difference for " + v);
                    }
                    differencesMap.remove(v.getElementId());
                }
            }
            // to its basis stream, and is therefore NOT a change
            if (v.getRealSpec().startsWith(streamPrefix) && !v.getVirtualSpec().startsWith(streamPrefix)) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Skipping workspace to basis stream promote " + v);
                }
            } else {
                ChangeFile f = new ChangeFile(v.getElementName(), v.getVirtualSpec() + " (" + v.getRealSpec() + ")");
                files.add(f);
            }
        }
        if (versions.isEmpty() || !files.isEmpty()) {
            ChangeSet changeSet = new ChangeSet(t.getWhen(), t.getComment(), t.getAuthor(), files);
            entries.add(changeSet);
        } else {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("All versions removed for " + t);
            }
        }
    }
    // detect these for CI tools like Continuum
    if (!differencesMap.isEmpty()) {
        List<ChangeFile> upstreamFiles = new ArrayList<ChangeFile>();
        for (FileDifference difference : differencesMap.values()) {
            if (difference.getNewVersionSpec() != null) {
                upstreamFiles.add(new ChangeFile(difference.getNewFile().getPath(), difference.getNewVersionSpec()));
            } else {
                // difference is a deletion
                upstreamFiles.add(new ChangeFile(difference.getOldFile().getPath(), null));
            }
        }
        entries.add(new ChangeSet(endDate, "Upstream changes", "various", upstreamFiles));
    }
    return new ChangeLogSet(entries, startDate, endDate);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Transaction(org.apache.maven.scm.provider.accurev.Transaction) Version(org.apache.maven.scm.provider.accurev.Transaction.Version) AccuRevVersion(org.apache.maven.scm.provider.accurev.AccuRevVersion) ScmVersion(org.apache.maven.scm.ScmVersion) ChangeFile(org.apache.maven.scm.ChangeFile) FileDifference(org.apache.maven.scm.provider.accurev.FileDifference) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 28 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class LocalChangeLogCommand method executeChangeLogCommand.

/**
 * {@inheritDoc}
 */
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
    LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
    if (branch != null) {
        throw new ScmException("The local scm doesn't support tags.");
    }
    File root = new File(repo.getRoot());
    String module = repo.getModule();
    File source = new File(root, module);
    File baseDestination = fileSet.getBasedir();
    if (!baseDestination.exists()) {
        throw new ScmException("The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ").");
    }
    if (!root.exists()) {
        throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
    }
    if (!source.exists()) {
        throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
    }
    List<ChangeSet> changeLogList = new ArrayList<ChangeSet>();
    try {
        File repoRoot = new File(repo.getRoot(), repo.getModule());
        List<File> files = fileSet.getFileList();
        if (files.isEmpty()) {
            @SuppressWarnings("unchecked") List<File> fileList = FileUtils.getFiles(baseDestination, "**", null, false);
            files = fileList;
        }
        for (File file : files) {
            String path = file.getPath().replace('\\', '/');
            File repoFile = new File(repoRoot, path);
            file = new File(baseDestination, path);
            ChangeSet changeSet = new ChangeSet();
            int chop = repoRoot.getAbsolutePath().length();
            String fileName = "/" + repoFile.getAbsolutePath().substring(chop + 1);
            changeSet.addFile(new ChangeFile(fileName, null));
            if (repoFile.exists()) {
                long lastModified = repoFile.lastModified();
                Date modifiedDate = new Date(lastModified);
                if (startDate != null) {
                    if (startDate.before(modifiedDate) || startDate.equals(modifiedDate)) {
                        if (endDate != null) {
                            if (endDate.after(modifiedDate) || endDate.equals(modifiedDate)) {
                            // nop
                            } else {
                                continue;
                            }
                        }
                    } else {
                        continue;
                    }
                }
                changeSet.setDate(modifiedDate);
                changeLogList.add(changeSet);
            } else {
                // This file is deleted
                changeLogList.add(changeSet);
            }
        }
    } catch (IOException ex) {
        throw new ScmException("Error while getting change logs.", ex);
    }
    return new ChangeLogScmResult(null, new ChangeLogSet(changeLogList, startDate, endDate));
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 29 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class GitChangeLogCommand method executeChangeLogCommand.

protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion, Integer limit) throws ScmException {
    Commandline cl = createCommandLine((GitScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate, endDate, startVersion, endVersion, limit);
    GitChangeLogConsumer consumer = new GitChangeLogConsumer(getLogger(), datePattern);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    exitCode = GitCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    if (exitCode != 0) {
        return new ChangeLogScmResult(cl.toString(), "The git-log command failed.", stderr.getOutput(), false);
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
    changeLogSet.setStartVersion(startVersion);
    changeLogSet.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult)

Example 30 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-plugins by apache.

the class ChangeLog method loadChangedSets.

public static List<ChangeLogSet> loadChangedSets(Reader reader) throws ParserConfigurationException, SAXException, IOException {
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    List<ChangeLogSet> changeLogSets = new ArrayList<ChangeLogSet>();
    // CHECKSTYLE_OFF: MagicNumber
    BufferedReader br = new BufferedReader(reader, 8192);
    // CHECKSTYLE_ON: MagicNumber
    parser.parse(new InputSource(br), new ChangeLogHandler(changeLogSets));
    return changeLogSets;
}
Also used : InputSource(org.xml.sax.InputSource) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) SAXParser(javax.xml.parsers.SAXParser)

Aggregations

ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)34 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)22 ChangeSet (org.apache.maven.scm.ChangeSet)16 ScmException (org.apache.maven.scm.ScmException)14 ArrayList (java.util.ArrayList)13 Date (java.util.Date)9 ChangeFile (org.apache.maven.scm.ChangeFile)7 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 Commandline (org.codehaus.plexus.util.cli.Commandline)6 File (java.io.File)4 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ScmVersion (org.apache.maven.scm.ScmVersion)4 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ScmBranch (org.apache.maven.scm.ScmBranch)3 ScmResult (org.apache.maven.scm.ScmResult)3 ScmRevision (org.apache.maven.scm.ScmRevision)3 FileDifference (org.apache.maven.scm.provider.accurev.FileDifference)3 BufferedReader (java.io.BufferedReader)2