return collectables;
}
private void persistCollectables(List<Collectable> collectables,
MavenProject sonarProject) throws MojoExecutionException {
Snapshot snapshot = new Snapshot();
snapshot.setCreatedAt(runDate);
snapshot.setMavenProject(sonarProject);
snapshot.setVersion(mavenProject.getVersion());
manager.getTransaction().begin();
SnapshotGroup snapshotGroup;
try {
if (sonarProject.getParent() == null) {
snapshotGroup = new SnapshotGroup();
snapshotGroup.setCreatedAt(runDate);
snapshotGroup.setMavenProject(sonarProject);
manager.persist(snapshotGroup);
setCurrentSnapshotGroupId(snapshotGroup.getId());
} else {
Integer groupId = getCurrentSnapshotGroupId();
if (groupId != null) {
snapshotGroup = manager.find(SnapshotGroup.class, groupId);
if (snapshotGroup == null) {
throw new NoResultException();
}
} else {
SnapshotGroupService service = new SnapshotGroupService(manager);
MavenProject parent = sonarProject.getParent();
int maxDept = 100;
while (maxDept > 0) {
if (parent.getParent() == null) {
break;
}
parent = parent.getParent();
maxDept--;
}
// look for the last snapshot group created within the last 60 mins
snapshotGroup = service.getLastUnprocessedGroup(parent.getId(), (long) 60 * 60 * 1000, runDate.getTime());
}
}
} catch (NoResultException e) {
throw new MojoExecutionException("Unable to find the last snapshot group");
}
snapshot.setSnapshotGroup(snapshotGroup);
manager.persist(snapshot);
CollectableService collectableService = new CollectableService(manager);
collectableService.persistCollectables(snapshot, collectables);