use of com.github.difflib.algorithm.DiffException in project indy by Commonjava.
the class RepoChangeHandler method handleRepoChange.
private void handleRepoChange(DiffStoreFetcher fetcher, boolean isDelete) {
if (!config.isEnabled()) {
logger.info("Repository changelog module is not enabled. Will ignore all change logs for propagation.");
return;
}
ChangeSummary changeSummary = fetcher.getSummary();
Collection<ArtifactStore> stores = fetcher.getStores();
String user = ChangeSummary.SYSTEM_USER;
String summary = "";
String version = "";
Date timeStamp = new Date();
if (changeSummary != null) {
if (changeSummary.getUser() != null) {
user = changeSummary.getUser();
}
if (changeSummary.getSummary() != null) {
summary = changeSummary.getSummary();
}
if (changeSummary.getRevisionId() != null) {
version = changeSummary.getRevisionId();
} else {
// FIXME: we need version not null here to let it be a key, not sure if timestamp is good here
version = String.format("%s", timeStamp.getTime());
}
}
for (ArtifactStore store : stores) {
try {
ArtifactStore origin = fetcher.getOriginal(store);
ArtifactStore changed = fetcher.getChanged(store);
String patchString = diffRepoChanges(changed, origin);
ChangeEvent changeLog = new ChangeEvent();
changeLog.setEventId(UUID.randomUUID().toString().replace("-", ""));
changeLog.setStoreKey(store.getKey().toString());
changeLog.setChangeTime(new Date());
changeLog.setDiffContent(patchString);
if (isDelete) {
changeLog.setChangeType(ChangeType.DELETE);
} else {
changeLog.setChangeType(origin == null ? ChangeType.CREATE : ChangeType.UPDATE);
}
changeLog.setUser(user);
changeLog.setSummary(summary);
changeLog.setVersion(version);
String key = changeLog.getStoreKey() + "_" + changeLog.getVersion();
repoChangelogCache.put(key, changeLog);
} catch (JsonProcessingException | DiffException e) {
String error = String.format("Something wrong happened when doing repo change log generation for store %s", store.getKey());
logger.error(error, e);
}
}
}
use of com.github.difflib.algorithm.DiffException in project page-factory-2 by sbtqa.
the class DiffUtils method diff.
public static String diff(String string1, String string2) {
DiffRowGenerator generator = DiffRowGenerator.create().showInlineDiffs(true).mergeOriginalRevised(true).oldTag(f -> "|").newTag(f -> "|").build();
List<DiffRow> rows = new ArrayList<>();
try {
rows = generator.generateDiffRows(Collections.singletonList(string1), Collections.singletonList(string2));
} catch (DiffException e) {
LOG.info("There is an error in string diff", e);
}
return !rows.isEmpty() ? rows.get(0).getOldLine() : "";
}
use of com.github.difflib.algorithm.DiffException in project closure-compiler by google.
the class TextDiffFactsBuilder method build.
/**
* Returns one or more Fact objects representing the difference between the expected and actual
* text strings, which must be specified by calling their methods before calling this one.
*/
public ImmutableList<Fact> build() {
try {
// The diff algorithm expects to work on a list, so we need to split the text into
// lines.
final Splitter lineSplitter = Splitter.on('\n');
final List<String> expectedLines = lineSplitter.splitToList(checkNotNull(expectedText));
final List<String> actualLines = lineSplitter.splitToList(checkNotNull(actualText));
final Patch<String> patch = DiffUtils.diff(expectedLines, actualLines);
final List<String> unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff("expected", "actual", expectedLines, patch, /* contextSize= */
10);
return ImmutableList.of(fact(title, unifiedDiff.stream().collect(joining("\n"))));
} catch (DiffException e) {
// It may indicate a bug in the diff library itself.
throw new IllegalStateException(e);
}
}
Aggregations