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);
}
}
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();
}
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;
}
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));
}
}
}
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();
}
Aggregations