use of org.finos.legend.sdlc.domain.model.comparison.Comparison in project legend-sdlc by finos.
the class GitLabComparisonApi method newComparison.
private static Comparison newComparison(String fromRevisionId, String toRevisionId, List<Diff> deltas, ProjectStructure fromProjectStructure, ProjectStructure toProjectStructure) {
List<EntityDiff> entityDiffs = Lists.mutable.empty();
AtomicBoolean isProjectConfigurationUpdated = new AtomicBoolean(false);
deltas.forEach(diff -> {
// File changes can be of three types:
// 1. entity file changes - which we should handle without any problem
// 2. project configuration changes - which we will just capture by a boolean flag to indicate if there are any changes
// 3. other files: e.g. users can go in and modify pom.xml, add some non-entity files, etc. we DO NOT keep track of these
String oldPath = diff.getOldPath().startsWith(FILE_PATH_DELIMITER) ? diff.getOldPath() : FILE_PATH_DELIMITER + diff.getOldPath();
String newPath = diff.getNewPath().startsWith(FILE_PATH_DELIMITER) ? diff.getNewPath() : FILE_PATH_DELIMITER + diff.getNewPath();
// project configuration change
if (ProjectStructure.PROJECT_CONFIG_PATH.equals(oldPath) || ProjectStructure.PROJECT_CONFIG_PATH.equals(newPath)) {
// technically, we know the only probable operation that can happen is MODIFICATION, CREATE is really an edge case
isProjectConfigurationUpdated.set(true);
return;
}
ProjectStructure.EntitySourceDirectory oldPathSourceDirectory = fromProjectStructure.findSourceDirectoryForEntityFilePath(oldPath);
ProjectStructure.EntitySourceDirectory newPathSourceDirectory = toProjectStructure.findSourceDirectoryForEntityFilePath(newPath);
// entity file change
if ((oldPathSourceDirectory != null) || (newPathSourceDirectory != null)) {
String oldEntityPath = (oldPathSourceDirectory == null) ? oldPath : oldPathSourceDirectory.filePathToEntityPath(oldPath);
String newEntityPath = (newPathSourceDirectory == null) ? newPath : newPathSourceDirectory.filePathToEntityPath(newPath);
EntityChangeType entityChangeType;
if (diff.getDeletedFile()) {
entityChangeType = EntityChangeType.DELETE;
} else if (diff.getNewFile()) {
entityChangeType = EntityChangeType.CREATE;
} else if (diff.getRenamedFile()) {
entityChangeType = EntityChangeType.RENAME;
} else {
entityChangeType = EntityChangeType.MODIFY;
}
entityDiffs.add(new EntityDiff() {
@Override
public EntityChangeType getEntityChangeType() {
return entityChangeType;
}
@Override
public String getNewPath() {
return newEntityPath;
}
@Override
public String getOldPath() {
return oldEntityPath;
}
});
}
// SKIP non-entity, non-config file
});
return new Comparison() {
@Override
public String getToRevisionId() {
return toRevisionId;
}
@Override
public String getFromRevisionId() {
return fromRevisionId;
}
@Override
public List<EntityDiff> getEntityDiffs() {
return entityDiffs;
}
@Override
public boolean isProjectConfigurationUpdated() {
return isProjectConfigurationUpdated.get();
}
};
}
Aggregations