Search in sources :

Example 1 with Comparison

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();
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EntityChangeType(org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType) Comparison(org.finos.legend.sdlc.domain.model.comparison.Comparison) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure) EntityDiff(org.finos.legend.sdlc.domain.model.comparison.EntityDiff)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Comparison (org.finos.legend.sdlc.domain.model.comparison.Comparison)1 EntityDiff (org.finos.legend.sdlc.domain.model.comparison.EntityDiff)1 EntityChangeType (org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType)1 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)1