Search in sources :

Example 16 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet 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 17 with ChangeLogSet

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

the class ChangeLogReport method writeChangelogXml.

private void writeChangelogXml(List<ChangeLogSet> changelogList) throws IOException {
    StringBuilder changelogXml = new StringBuilder();
    changelogXml.append("<?xml version=\"1.0\" encoding=\"").append(getOutputEncoding()).append("\"?>\n");
    changelogXml.append("<changelog>");
    for (ChangeLogSet changelogSet : changelogList) {
        changelogXml.append("\n  ");
        String changeset = changelogSet.toXML(getOutputEncoding());
        // remove xml header
        if (changeset.startsWith("<?xml")) {
            int idx = changeset.indexOf("?>") + 2;
            changeset = changeset.substring(idx);
        }
        changelogXml.append(changeset);
    }
    changelogXml.append("\n</changelog>");
    outputXML.getParentFile().mkdirs();
    // PrintWriter pw = new PrintWriter( new BufferedOutputStream( new FileOutputStream( outputXML ) ) );
    // pw.write( changelogXml.toString() );
    // pw.flush();
    // pw.close();
    // MCHANGELOG-86
    Writer writer = WriterFactory.newWriter(new BufferedOutputStream(new FileOutputStream(outputXML)), getOutputEncoding());
    writer.write(changelogXml.toString());
    writer.flush();
    writer.close();
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer)

Example 18 with ChangeLogSet

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

the class ChangeLogReport method getChangedSets.

/**
 * populates the changedSets field by either connecting to the SCM or using an existing XML generated in a previous
 * run of the report
 *
 * @throws MavenReportException
 */
protected List<ChangeLogSet> getChangedSets() throws MavenReportException {
    List<ChangeLogSet> changelogList = null;
    if (!outputXML.isAbsolute()) {
        outputXML = new File(project.getBasedir(), outputXML.getPath());
    }
    if (outputXML.exists()) {
        // CHECKSTYLE_OFF: MagicNumber
        if (outputXMLExpiration > 0 && outputXMLExpiration * 60000 > System.currentTimeMillis() - outputXML.lastModified()) // CHECKSTYLE_ON: MagicNumber
        {
            try {
                // ReaderFactory.newReader( outputXML, getOutputEncoding() );
                // FileInputStream fIn = new FileInputStream( outputXML );
                getLog().info("Using existing changelog.xml...");
                changelogList = ChangeLog.loadChangedSets(ReaderFactory.newReader(outputXML, getOutputEncoding()));
            } catch (FileNotFoundException e) {
            // do nothing, just regenerate
            } catch (Exception e) {
                throw new MavenReportException("An error occurred while parsing " + outputXML.getAbsolutePath(), e);
            }
        }
    }
    if (changelogList == null) {
        if (offline) {
            throw new MavenReportException("This report requires online mode.");
        }
        getLog().info("Generating changed sets xml to: " + outputXML.getAbsolutePath());
        changelogList = generateChangeSetsFromSCM();
        try {
            writeChangelogXml(changelogList);
        } catch (FileNotFoundException e) {
            throw new MavenReportException("Can't create " + outputXML.getAbsolutePath(), e);
        } catch (UnsupportedEncodingException e) {
            throw new MavenReportException("Can't create " + outputXML.getAbsolutePath(), e);
        } catch (IOException e) {
            throw new MavenReportException("Can't create " + outputXML.getAbsolutePath(), e);
        }
    }
    return changelogList;
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) ScmException(org.apache.maven.scm.ScmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MavenReportException(org.apache.maven.reporting.MavenReportException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 19 with ChangeLogSet

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

the class ChangeLogHandler method startElement.

/**
 * {@inheritDoc}
 */
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    bufData = "";
    if ("file".equals(qName)) {
        bufFile = new ChangeFile("");
    } else if ("changelog-entry".equals(qName)) {
        bufEntry = new ChangeSet();
    } else if ("date".equals(qName)) {
        currentPattern = attributes.getValue("pattern");
        if (currentPattern == null) {
            currentPattern = "yyyy-MM-dd";
        }
    } else if ("time".equals(qName)) {
        currentPattern = attributes.getValue("pattern");
        if (currentPattern == null) {
            currentPattern = "HH:mm:ss";
        }
    } else if ("changeset".equals(qName)) {
        bufEntries = new LinkedList<ChangeSet>();
        currentPattern = attributes.getValue("datePattern");
        if (currentPattern == null) {
            currentPattern = "yyyy-MM-dd";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(currentPattern);
        String start = attributes.getValue("start");
        String end = attributes.getValue("end");
        Date startDate = null;
        Date endDate = null;
        if (start != null) {
            try {
                startDate = formatter.parse(start);
            } catch (ParseException e) {
                throw new SAXException("Can't parse start date '" + start + "'.", e);
            }
        }
        if (end != null) {
            try {
                endDate = formatter.parse(end);
            } catch (ParseException e) {
                throw new SAXException("Can't parse end date '" + end + "'.", e);
            }
        }
        bufSet = new ChangeLogSet(bufEntries, startDate, endDate);
        String startVersion = attributes.getValue("startVersion");
        if (startVersion != null) {
            bufSet.setStartVersion(new ScmTag(startVersion));
        }
        String endVersion = attributes.getValue("endVersion");
        if (endVersion != null) {
            bufSet.setEndVersion(new ScmTag(endVersion));
        }
    }
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ChangeFile(org.apache.maven.scm.ChangeFile) ScmTag(org.apache.maven.scm.ScmTag) ParseException(java.text.ParseException) ChangeSet(org.apache.maven.scm.ChangeSet) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SAXException(org.xml.sax.SAXException)

Example 20 with ChangeLogSet

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

the class FileActivityReport method doGenerateReport.

/**
 * {@inheritDoc}
 */
protected void doGenerateReport(List<ChangeLogSet> changeLogSets, ResourceBundle bundle, Sink sink) {
    sink.head();
    sink.title();
    sink.text(bundle.getString("report.file-activity.header"));
    sink.title_();
    sink.head_();
    sink.body();
    sink.section1();
    sink.sectionTitle1();
    sink.text(bundle.getString("report.file-activity.mainTitle"));
    sink.sectionTitle1_();
    for (ChangeLogSet set : changeLogSets) {
        doChangedSets(set, bundle, sink);
    }
    sink.section1_();
    sink.body_();
    sink.flush();
    sink.close();
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet)

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