use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class GitManager method getChangelog.
public List<ChangeSummary> getChangelog(final File f, final int start, final int length) throws GitSubsystemException {
return lockAnd(me -> {
if (length == 0) {
return Collections.emptyList();
}
try {
final ObjectId oid = repo.resolve(Constants.HEAD);
final PlotWalk pw = new PlotWalk(repo);
final RevCommit rc = pw.parseCommit(oid);
toChangeSummary(rc);
pw.markStart(rc);
final String filepath = relativize(f);
logger.info("Getting changelog for: {} (start: {}, length: {})", filepath, start, length);
if (!isEmpty(filepath) && !filepath.equals("/")) {
pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));
} else {
pw.setTreeFilter(TreeFilter.ANY_DIFF);
}
final List<ChangeSummary> changelogs = new ArrayList<ChangeSummary>();
int count = 0;
final int stop = length > 0 ? length + 1 : 0;
RevCommit commit = null;
while ((commit = pw.next()) != null && (stop < 1 || count < stop)) {
if (count < start) {
count++;
continue;
}
changelogs.add(toChangeSummary(commit));
count++;
}
if (length < -1) {
final int remove = (-1 * length) - 1;
for (int i = 0; i < remove; i++) {
changelogs.remove(changelogs.size() - 1);
}
}
return changelogs;
} catch (RevisionSyntaxException | IOException e) {
throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f, e.getMessage());
}
});
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class PromotionValidator method validate.
public void validate(PromoteRequest request, ValidationResult result, String baseUrl) throws PromotionValidationException {
ValidationRuleSet set = validationsManager.getRuleSetMatching(request.getTargetKey());
Logger logger = LoggerFactory.getLogger(getClass());
if (set != null) {
logger.debug("Running validation rule-set for promotion: {}", set.getName());
result.setRuleSet(set.getName());
List<String> ruleNames = set.getRuleNames();
if (ruleNames != null && !ruleNames.isEmpty()) {
final ArtifactStore store = getRequestStore(request, baseUrl);
try {
final ValidationRequest req = new ValidationRequest(request, set, validationTools, store);
for (String ruleRef : ruleNames) {
String ruleName = // flatten in case some path fragment leaks in...
new File(ruleRef).getName();
ValidationRuleMapping rule = validationsManager.getRuleMappingNamed(ruleName);
if (rule != null) {
try {
logger.debug("Running promotion validation rule: {}", rule.getName());
String error = rule.getRule().validate(req);
if (StringUtils.isNotEmpty(error)) {
logger.debug("{} failed", rule.getName());
result.addValidatorError(rule.getName(), error);
} else {
logger.debug("{} succeeded", rule.getName());
}
} catch (Exception e) {
if (e instanceof PromotionValidationException) {
throw (PromotionValidationException) e;
}
throw new PromotionValidationException("Failed to run validation rule: {} for request: {}. Reason: {}", e, rule.getName(), request, e);
}
}
}
} finally {
if (needTempRepo(request)) {
try {
final String changeSum = String.format("Removes the temp remote repo [%s] after promote operation.", store);
storeDataMgr.deleteArtifactStore(store.getKey(), new ChangeSummary(ChangeSummary.SYSTEM_USER, changeSum), new EventMetadata().set(ContentManager.SUPPRESS_EVENTS, true));
logger.info("Promotion temporary repo {} has been deleted for {}", store.getKey(), request.getSource());
} catch (IndyDataException e) {
logger.warn("StoreDataManager can not remove artifact stores correctly.", e);
}
}
}
}
} else {
logger.info("No validation rule-sets are defined for: {}", request.getTargetKey());
}
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class PromotionManagerTest method rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource.
@Test
public void rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource() throws Exception {
final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final String first = "/first/path";
final String second = "/second/path";
contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()).setPurgeSource(true), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(2));
assertThat(result.getError(), nullValue());
result = manager.rollbackPathsPromote(result);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
pending = result.getPendingPaths();
assertThat(pending, notNullValue());
assertThat(pending.size(), equalTo(2));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, first);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(target, second);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(source, first);
assertThat(ref.exists(), equalTo(true));
ref = downloadManager.getStorageReference(source, second);
assertThat(ref.exists(), equalTo(true));
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class RevisionsManagerTest method commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem_LimitToOldestEvent.
@Test
public void commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem_LimitToOldestEvent() throws Exception {
lcEvents.fireStarted();
final DataFile f1 = dfManager.getDataFile("test/foo.txt");
f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for first file."));
final DataFile f2 = dfManager.getDataFile("test/bar.txt");
final String testSummary = "test for second file.";
f2.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", testSummary));
f2.writeString("this is another test", "UTF-8", new ChangeSummary("test-user", "test (2) for second file."));
listener.waitForEvents(3);
final List<ChangeSummary> changeLog = revManager.getDataChangeLog(f2.getPath(), 1, 1);
assertThat(changeLog, notNullValue());
assertThat(changeLog.size(), equalTo(1));
final ChangeSummary summary = changeLog.get(0);
assertThat(summary.getSummary().startsWith(testSummary), equalTo(true));
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class RevisionsManagerTest method commitOneFileTwice_NoChangeSecondTime_RetrieveOneChangelog.
@Test
public void commitOneFileTwice_NoChangeSecondTime_RetrieveOneChangelog() throws Exception {
lcEvents.fireStarted();
revManager.setup();
final DataFile f1 = dfManager.getDataFile("test/foo.txt");
f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for first write of file."));
List<DataFileEvent> events = listener.waitForEvents(1);
System.out.println("Got events:\n " + join(events, "\n "));
f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for second write of file."));
events = listener.waitForEvents(1);
System.out.println("Got events:\n " + join(events, "\n "));
final List<ChangeSummary> changeLog = revManager.getDataChangeLog(f1.getPath(), 0, -1);
assertThat(changeLog, notNullValue());
assertThat(changeLog.size(), equalTo(1));
assertThat(changeLog.get(0).getSummary().contains("test for first write of file."), equalTo(true));
}
Aggregations