use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.
the class HistoryConsumerTest method testConsumeStreamHistory.
@Test
public void testConsumeStreamHistory() throws IOException {
List<Transaction> transactions = new ArrayList<Transaction>();
XppStreamConsumer consumer = new HistoryConsumer(new DefaultLog(), transactions);
AccuRevJUnitUtil.consume("/streamHistory.xml", consumer);
assertThat(transactions.size(), is(4));
Transaction t = transactions.get(0);
assertThat(t.getTranType(), is("promote"));
assertThat(t.getWhen(), is(new Date(1233782838000L)));
assertThat(t.getAuthor(), is("ggardner"));
assertThat(t.getId(), is(50L));
assertThat(t.getVersions().size(), is(2));
assertThat(t.getVersions(), Matchers.<Transaction.Version>hasItem(version(8L, "/./tcktests/src/main/java/Application.java", "1/1", "2/3")));
t = transactions.get(1);
assertThat(t.getComment(), is("hpromoting"));
}
use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.
the class AccuRevChangeLogCommandTest method testChangeLogToNow.
@Test
public void testChangeLogToNow() throws Exception {
final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
// start tran (35)
List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, new Date(), "sometran", "anyone"));
when(accurev.history("aStream", "12", null, 1, true, true)).thenReturn(startTransaction);
// end tran (42)
List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, new Date(), "sometran", "anyone"));
when(accurev.history("aStream", "now", null, 1, true, true)).thenReturn(endTransaction);
Stream basisStream = new Stream("aStream", 10, "myDepot", 1, "myDepot", getDate(2008, 1, 1), "normal");
when(accurev.showStream("aStream")).thenReturn(basisStream);
List<FileDifference> emptyList = Collections.emptyList();
when(accurev.diff("myStream", "12", "42")).thenReturn(emptyList);
List<Transaction> noTransactions = Collections.emptyList();
when(accurev.history("aStream", "13", "42", 0, false, false)).thenReturn(noTransactions);
AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
CommandParameters params = new CommandParameters();
params.setScmVersion(CommandParameter.START_SCM_VERSION, new ScmRevision("aStream/12"));
assertThat(command.changelog(repo, testFileSet, params), not(nullValue()));
}
use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.
the class AccuRevChangeLogCommandTest method testChangeLogFailed.
@Test
public void testChangeLogFailed() throws Exception {
// Workspace to root stream, keeps and promotes
// Setup test data so that the checkin area is the repo's project path.
final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
final Date dateFrom = getDate(2009, 0, 01, 10, 00, 00, null);
final Date dateTo = getDate(2009, 0, 12, 13, 00, 00, null);
// start tran (35)
List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, new Date(), "sometran", "anyone"));
when(accurev.history("myStream", "2009/01/01 10:00:00", null, 1, true, true)).thenReturn(startTransaction);
// end tran (42)
List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, new Date(), "sometran", "anyone"));
when(accurev.history("myStream", "2009/01/12 13:00:00", null, 1, true, true)).thenReturn(endTransaction);
when(accurev.history(eq("myStream"), any(String.class), any(String.class), eq(0), eq(false), eq(false))).thenReturn(null);
AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
CommandParameters commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.MESSAGE, "A commit message");
commandParameters.setDate(CommandParameter.START_DATE, dateFrom);
commandParameters.setDate(CommandParameter.END_DATE, dateTo);
ChangeLogScmResult result = command.changelog(repo, testFileSet, commandParameters);
assertThat(result.isSuccess(), is(false));
assertThat(result.getProviderMessage(), notNullValue());
}
use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.
the class AccuRevChangeLogCommand method executeAccurevCommand.
@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
// Do we have a supplied branch. If not we default to the URL stream.
ScmBranch branch = (ScmBranch) parameters.getScmVersion(CommandParameter.BRANCH, null);
AccuRevVersion branchVersion = repository.getAccuRevVersion(branch);
String stream = branchVersion.getBasisStream();
String fromSpec = branchVersion.getTimeSpec();
String toSpec = "highest";
// Versions
ScmVersion startVersion = parameters.getScmVersion(CommandParameter.START_SCM_VERSION, null);
ScmVersion endVersion = parameters.getScmVersion(CommandParameter.END_SCM_VERSION, null);
if (startVersion != null && StringUtils.isNotEmpty(startVersion.getName())) {
AccuRevVersion fromVersion = repository.getAccuRevVersion(startVersion);
// if no end version supplied then use same basis as startVersion
AccuRevVersion toVersion = endVersion == null ? new AccuRevVersion(fromVersion.getBasisStream(), "now") : repository.getAccuRevVersion(endVersion);
if (!StringUtils.equals(fromVersion.getBasisStream(), toVersion.getBasisStream())) {
throw new AccuRevException("Not able to provide change log between different streams " + fromVersion + "," + toVersion);
}
stream = fromVersion.getBasisStream();
fromSpec = fromVersion.getTimeSpec();
toSpec = toVersion.getTimeSpec();
}
Date startDate = parameters.getDate(CommandParameter.START_DATE, null);
Date endDate = parameters.getDate(CommandParameter.END_DATE, null);
int numDays = parameters.getInt(CommandParameter.NUM_DAYS, 0);
if (numDays > 0) {
if ((startDate != null || endDate != null)) {
throw new ScmException("Start or end date cannot be set if num days is set.");
}
// Last x days.
int day = 24 * 60 * 60 * 1000;
startDate = new Date(System.currentTimeMillis() - (long) numDays * day);
endDate = new Date(System.currentTimeMillis() + day);
}
if (endDate != null && startDate == null) {
throw new ScmException("The end date is set but the start date isn't.");
}
// Date parameters override transaction ids in versions
if (startDate != null) {
fromSpec = AccuRevScmProviderRepository.formatTimeSpec(startDate);
} else if (fromSpec == null) {
fromSpec = "1";
}
// Convert the fromSpec to both a date AND a transaction id by looking up
// the nearest transaction in the depot.
Transaction fromTransaction = getDepotTransaction(repository, stream, fromSpec);
long fromTranId = 1;
if (fromTransaction != null) {
// This tran id is less than or equal to the date/tranid we requested.
fromTranId = fromTransaction.getTranId();
if (startDate == null) {
startDate = fromTransaction.getWhen();
}
}
if (endDate != null) {
toSpec = AccuRevScmProviderRepository.formatTimeSpec(endDate);
} else if (toSpec == null) {
toSpec = "highest";
}
Transaction toTransaction = getDepotTransaction(repository, stream, toSpec);
long toTranId = 1;
if (toTransaction != null) {
toTranId = toTransaction.getTranId();
if (endDate == null) {
endDate = toTransaction.getWhen();
}
}
startVersion = new ScmRevision(repository.getRevision(stream, fromTranId));
endVersion = new ScmRevision(repository.getRevision(stream, toTranId));
// TODO Split this method in two here. above to convert params to start and end (stream,tranid,date) and test independantly
List<Transaction> streamHistory = Collections.emptyList();
List<Transaction> workspaceHistory = Collections.emptyList();
List<FileDifference> streamDifferences = Collections.emptyList();
StringBuilder errorMessage = new StringBuilder();
AccuRev accurev = repository.getAccuRev();
Stream changelogStream = accurev.showStream(stream);
if (changelogStream == null) {
errorMessage.append("Unknown accurev stream -").append(stream).append(".");
} else {
String message = "Changelog on stream " + stream + "(" + changelogStream.getStreamType() + ") from " + fromTranId + " (" + startDate + "), to " + toTranId + " (" + endDate + ")";
if (startDate != null && startDate.after(endDate) || fromTranId >= toTranId) {
getLogger().warn("Skipping out of range " + message);
} else {
getLogger().info(message);
// In 4.7.2 and higher we have a diff command that will list all the file differences in a stream
// and thus can be used to detect upstream changes
// Unfortunately diff -v -V -t does not work in workspaces.
Stream diffStream = changelogStream;
if (changelogStream.isWorkspace()) {
workspaceHistory = accurev.history(stream, Long.toString(fromTranId + 1), Long.toString(toTranId), 0, false, false);
if (workspaceHistory == null) {
errorMessage.append("history on workspace " + stream + " from " + fromTranId + 1 + " to " + toTranId + " failed.");
}
// do the diff/hist on the basis stream instead.
stream = changelogStream.getBasis();
diffStream = accurev.showStream(stream);
}
if (AccuRevCapability.DIFF_BETWEEN_STREAMS.isSupported(accurev.getClientVersion())) {
if (startDate.before(diffStream.getStartDate())) {
getLogger().warn("Skipping diff of " + stream + " due to start date out of range");
} else {
streamDifferences = accurev.diff(stream, Long.toString(fromTranId), Long.toString(toTranId));
if (streamDifferences == null) {
errorMessage.append("Diff " + stream + "- " + fromTranId + " to " + toTranId + "failed.");
}
}
}
// History needs to start from the transaction after our starting transaction
streamHistory = accurev.history(stream, Long.toString(fromTranId + 1), Long.toString(toTranId), 0, false, false);
if (streamHistory == null) {
errorMessage.append("history on stream " + stream + " from " + fromTranId + 1 + " to " + toTranId + " failed.");
}
}
}
String errorString = errorMessage.toString();
if (StringUtils.isBlank(errorString)) {
ChangeLogSet changeLog = getChangeLog(changelogStream, streamDifferences, streamHistory, workspaceHistory, startDate, endDate);
changeLog.setEndVersion(endVersion);
changeLog.setStartVersion(startVersion);
return new ChangeLogScmResult(accurev.getCommandLines(), changeLog);
} else {
return new ChangeLogScmResult(accurev.getCommandLines(), "AccuRev errors: " + errorMessage, accurev.getErrorOutput(), false);
}
}
use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.
the class HistoryConsumer method startTag.
@Override
protected void startTag(List<String> tagPath, Map<String, String> attributes) {
String tagName = getTagName(tagPath);
if ("transaction".equals(tagName)) {
Long id = Long.parseLong(attributes.get("id"));
Date when = new Date(Long.parseLong(attributes.get("time")) * 1000);
String tranType = attributes.get("type");
String user = attributes.get("user");
currentTran = new Transaction(id, when, tranType, user);
transactions.add(currentTran);
} else if ("version".equals(tagName)) {
if (currentTran != null) {
if (attributes.containsKey("eid")) {
elementId = Long.parseLong(attributes.get("eid"));
elementName = attributes.get("path");
}
String virtualSpec = attributes.get("virtual");
String realSpec = attributes.get("real");
String ancestor = attributes.get("ancestor");
currentTran.addVersion(elementId, elementName, virtualSpec, realSpec, ancestor);
}
} else if ("element".equals(tagName)) {
elementId = Long.parseLong(attributes.get("eid"));
elementName = attributes.get("name");
}
}
Aggregations