use of org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency in project legend-sdlc by finos.
the class ProjectStructure method updateProjectConfiguration.
private static Revision updateProjectConfiguration(ProjectConfigurationUpdateBuilder updateBuilder, boolean requireRevisionId) {
ProjectFileAccessProvider projectFileAccessProvider = CachingProjectFileAccessProvider.wrap(updateBuilder.getProjectFileAccessProvider());
ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = updateBuilder.getWorkspaceAccessType();
WorkspaceType workspaceType = updateBuilder.getWorkspaceType();
if (updateBuilder.hasGroupId() && !isValidGroupId(updateBuilder.getGroupId())) {
throw new LegendSDLCServerException("Invalid groupId: " + updateBuilder.getGroupId(), Status.BAD_REQUEST);
}
if (updateBuilder.hasArtifactId() && !isValidArtifactId(updateBuilder.getArtifactId())) {
throw new LegendSDLCServerException("Invalid artifactId: " + updateBuilder.getArtifactId(), Status.BAD_REQUEST);
}
ProjectType projectType = updateBuilder.getProjectType();
String projectId = updateBuilder.getProjectId();
String workspaceId = updateBuilder.getWorkspaceId();
String revisionId = updateBuilder.getRevisionId();
// if revisionId not specified, get the current revision
if (revisionId == null) {
Revision currentRevision = projectFileAccessProvider.getRevisionAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType).getCurrentRevision();
if (currentRevision != null) {
revisionId = currentRevision.getId();
} else if (requireRevisionId) {
StringBuilder builder = new StringBuilder("Could not find current revision for ");
if (workspaceId != null) {
builder.append(workspaceType.getLabel() + " " + workspaceAccessType.getLabel()).append(" ").append(workspaceId).append("in ");
}
builder.append("project ").append(projectId).append(": it may be corrupt");
throw new LegendSDLCServerException(builder.toString());
}
}
// find out what we need to update for project structure
FileAccessContext fileAccessContext = CachingFileAccessContext.wrap(projectFileAccessProvider.getFileAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, revisionId));
ProjectFile configFile = getProjectConfigurationFile(fileAccessContext);
ProjectConfiguration currentConfig = (configFile == null) ? getDefaultProjectConfiguration(projectId, projectType) : readProjectConfiguration(configFile);
if (projectType != currentConfig.getProjectType()) {
throw new LegendSDLCServerException("Project type mismatch for project " + projectId + ": got " + projectType + ", found " + currentConfig.getProjectType(), Status.BAD_REQUEST);
}
boolean updateProjectStructureVersion = updateBuilder.hasProjectStructureVersion() && (updateBuilder.getProjectStructureVersion() != currentConfig.getProjectStructureVersion().getVersion());
boolean updateProjectStructureExtensionVersion = updateBuilder.hasProjectStructureExtensionVersion() && !updateBuilder.getProjectStructureExtensionVersion().equals(currentConfig.getProjectStructureVersion().getExtensionVersion());
boolean updateGroupId = updateBuilder.hasGroupId() && !updateBuilder.getGroupId().equals(currentConfig.getGroupId());
boolean updateArtifactId = updateBuilder.hasArtifactId() && !updateBuilder.getArtifactId().equals(currentConfig.getArtifactId());
// find out which dependencies we need to update
boolean updateProjectDependencies = false;
Set<ProjectDependency> projectDependencies = Sets.mutable.withAll(currentConfig.getProjectDependencies());
Set<ProjectDependency> toUpdateProjectDependencies = projectDependencies.stream().filter(dep -> ProjectDependency.isLegacyProjectDependency(dep) && !(updateBuilder.hasProjectDependenciesToRemove() && updateBuilder.getProjectDependenciesToRemove().contains(dep))).collect(Collectors.toSet());
if (toUpdateProjectDependencies.size() > 0) {
updateProjectDependencies = true;
updateOrAddDependencies(toUpdateProjectDependencies, projectFileAccessProvider, projectDependencies, true);
}
if (updateBuilder.hasProjectDependenciesToRemove()) {
updateProjectDependencies |= projectDependencies.removeAll(updateBuilder.getProjectDependenciesToRemove());
}
// add new dependencies to the list of dependencies while also validate that there are no unknown/non-prod dependencies
if (updateBuilder.hasProjectDependenciesToAdd()) {
updateProjectDependencies = true;
updateOrAddDependencies(updateBuilder.getProjectDependenciesToAdd(), projectFileAccessProvider, projectDependencies, false);
}
// validate if there are any conflicts between the dependencies
if (updateProjectDependencies) {
validateDependencyConflicts(projectDependencies, ProjectDependency::getProjectId, (id, deps) -> {
if ((deps.size() <= 1) || deps.stream().allMatch(dep -> getProjectStructure(projectFileAccessProvider.getFileAccessContext(dep.getProjectId(), dep.getVersionId())).isSupportedArtifactType(ArtifactType.versioned_entities))) {
return null;
}
List<ProjectDependency> supported = Lists.mutable.empty();
List<ProjectDependency> unsupported = Lists.mutable.empty();
deps.forEach(dep -> (getProjectStructure(projectFileAccessProvider.getFileAccessContext(dep.getProjectId(), dep.getVersionId())).isSupportedArtifactType(ArtifactType.versioned_entities) ? supported : unsupported).add(dep));
StringBuilder message = new StringBuilder();
unsupported.forEach(dep -> dep.appendVersionIdString((message.length() == 0) ? message : message.append(", ")));
message.append((unsupported.size() == 1) ? " does" : " do").append(" not support multi-version dependency");
if (!supported.isEmpty()) {
int startLen = message.length();
supported.forEach(dep -> dep.appendVersionIdString(message.append((message.length() == startLen) ? "; " : ", ")));
message.append((supported.size() == 1) ? " does" : " do");
}
return message.toString();
}, "projects");
}
// check if we need to update any metamodel dependencies
boolean updateMetamodelDependencies = false;
Set<MetamodelDependency> metamodelDependencies = Sets.mutable.withAll(currentConfig.getMetamodelDependencies());
if (updateBuilder.hasMetamodelDependenciesToRemove()) {
updateMetamodelDependencies |= metamodelDependencies.removeAll(updateBuilder.getMetamodelDependenciesToRemove());
}
// add new metamodel dependencies to the list of metamodel dependencies while also validate that there are no unknown metamodel dependencies
if (updateBuilder.hasMetamodelDependenciesToAdd()) {
List<MetamodelDependency> unknownDependencies = Lists.mutable.empty();
for (MetamodelDependency metamodelDependency : updateBuilder.getMetamodelDependenciesToAdd()) {
if (metamodelDependencies.add(metamodelDependency)) {
updateMetamodelDependencies = true;
if (!isKnownMetamodel(metamodelDependency)) {
unknownDependencies.add(metamodelDependency);
}
}
}
if (!unknownDependencies.isEmpty()) {
StringBuilder builder = new StringBuilder("There were issues with one or more added metamodel dependencies");
builder.append("; unknown ").append((unknownDependencies.size() == 1) ? "dependency" : "dependencies").append(": ");
unknownDependencies.sort(Comparator.naturalOrder());
unknownDependencies.forEach(d -> d.appendDependencyString((d == unknownDependencies.get(0)) ? builder : builder.append(", ")));
throw new LegendSDLCServerException(builder.toString(), Status.BAD_REQUEST);
}
}
// validate that there are no conflicts between the metamodel dependencies
if (updateMetamodelDependencies) {
validateDependencyConflicts(metamodelDependencies, MetamodelDependency::getMetamodel, (id, deps) -> (deps.size() > 1) ? deps.stream().collect(StringBuilder::new, (builder, dep) -> dep.appendVersionIdString(builder.append((builder.length() == 0) ? "multiple versions not allowed: " : ", ")), StringBuilder::append).toString() : null, "metamodels");
}
boolean updateGeneration = false;
Map<String, ArtifactGeneration> generationsByName = currentConfig.getArtifactGenerations().stream().collect(Collectors.toMap(ArtifactGeneration::getName, Function.identity()));
if (updateBuilder.hasArtifactGenerationsToRemove()) {
updateGeneration = generationsByName.keySet().stream().anyMatch(updateBuilder.getArtifactGenerationToRemove()::contains);
updateBuilder.getArtifactGenerationToRemove().forEach(generationsByName::remove);
}
if (updateBuilder.hasArtifactGenerationsToAdd()) {
validateArtifactGenerations(generationsByName, updateBuilder.getArtifactGenerationToAdd());
updateGeneration = updateBuilder.getArtifactGenerationToAdd().stream().noneMatch(generationsByName.values()::contains);
updateBuilder.getArtifactGenerationToAdd().forEach(art -> generationsByName.put(art.getName(), art));
}
// abort if there is no change to make
if (!updateProjectStructureVersion && !updateProjectStructureExtensionVersion && !updateGroupId && !updateArtifactId && !updateProjectDependencies && !updateMetamodelDependencies && !updateGeneration) {
return null;
}
// Collect operations
List<ProjectFileOperation> operations = Lists.mutable.empty();
// New configuration
SimpleProjectConfiguration newConfig = new SimpleProjectConfiguration(currentConfig);
if (updateProjectStructureVersion) {
if (updateBuilder.hasProjectStructureExtensionVersion()) {
newConfig.setProjectStructureVersion(updateBuilder.getProjectStructureVersion(), updateBuilder.getProjectStructureExtensionVersion());
} else if (updateBuilder.hasProjectStructureExtensionProvider()) {
newConfig.setProjectStructureVersion(updateBuilder.getProjectStructureVersion(), updateBuilder.getProjectStructureExtensionProvider().getLatestVersionForProjectStructureVersion(updateBuilder.getProjectStructureVersion()));
} else {
newConfig.setProjectStructureVersion(updateBuilder.getProjectStructureVersion(), null);
}
} else if (updateProjectStructureExtensionVersion) {
newConfig.setProjectStructureVersion(currentConfig.getProjectStructureVersion().getVersion(), updateBuilder.getProjectStructureExtensionVersion());
}
if (updateGroupId) {
newConfig.setGroupId(updateBuilder.getGroupId());
}
if (updateArtifactId) {
newConfig.setArtifactId(updateBuilder.getArtifactId());
}
if (updateProjectDependencies) {
List<ProjectDependency> projectDependencyList = Lists.mutable.withAll(projectDependencies);
projectDependencyList.sort(Comparator.naturalOrder());
newConfig.setProjectDependencies(projectDependencyList);
}
if (updateMetamodelDependencies) {
List<MetamodelDependency> metamodelDependencyList = Lists.mutable.withAll(metamodelDependencies);
metamodelDependencyList.sort(Comparator.naturalOrder());
newConfig.setMetamodelDependencies(metamodelDependencyList);
}
if (updateGeneration) {
List<ArtifactGeneration> artifactGenerationsList = Lists.mutable.withAll(generationsByName.values());
artifactGenerationsList.sort(Comparator.comparing(ArtifactGeneration::getName));
newConfig.setArtifactGeneration(artifactGenerationsList);
}
// prevent downgrading project
if (newConfig.getProjectStructureVersion().compareTo(currentConfig.getProjectStructureVersion()) < 0) {
throw new LegendSDLCServerException("Cannot change project " + projectId + " from project structure version " + currentConfig.getProjectStructureVersion().toVersionString() + " to version " + newConfig.getProjectStructureVersion().toVersionString(), Status.BAD_REQUEST);
}
String serializedNewConfig = serializeProjectConfiguration(newConfig);
operations.add((configFile == null) ? ProjectFileOperation.addFile(PROJECT_CONFIG_PATH, serializedNewConfig) : ProjectFileOperation.modifyFile(PROJECT_CONFIG_PATH, serializedNewConfig));
ProjectStructure currentProjectStructure = getProjectStructure(currentConfig, updateBuilder.getProjectStructurePlatformExtensions());
ProjectStructure newProjectStructure = getProjectStructure(newConfig, updateBuilder.getProjectStructurePlatformExtensions());
// Move or re-serialize entities if necessary
List<EntitySourceDirectory> currentEntityDirectories = currentProjectStructure.getEntitySourceDirectories();
List<EntitySourceDirectory> newEntityDirectories = newProjectStructure.getEntitySourceDirectories();
if (!currentEntityDirectories.equals(newEntityDirectories)) {
currentEntityDirectories.forEach(currentSourceDirectory -> fileAccessContext.getFilesInDirectory(currentSourceDirectory.getDirectory()).forEach(file -> {
String currentPath = file.getPath();
if (currentSourceDirectory.isPossiblyEntityFilePath(currentPath)) {
byte[] currentBytes = file.getContentAsBytes();
Entity entity;
try {
entity = currentSourceDirectory.deserialize(currentBytes);
} catch (Exception e) {
StringBuilder builder = new StringBuilder("Error deserializing entity from file \"").append(currentPath).append('"');
StringTools.appendThrowableMessageIfPresent(builder, e);
throw new LegendSDLCServerException(builder.toString(), e);
}
EntitySourceDirectory newSourceDirectory = Iterate.detectWith(newEntityDirectories, EntitySourceDirectory::canSerialize, entity);
if (newSourceDirectory == null) {
throw new LegendSDLCServerException("Could not find a new source directory for entity " + entity.getPath() + ", currently in " + currentPath);
}
if (!currentSourceDirectory.equals(newSourceDirectory)) {
String newPath = newSourceDirectory.entityPathToFilePath(entity.getPath());
byte[] newBytes = newSourceDirectory.serializeToBytes(entity);
if (!newPath.equals(currentPath)) {
operations.add(ProjectFileOperation.moveFile(currentPath, newPath, newBytes));
} else if (!Arrays.equals(currentBytes, newBytes)) {
operations.add(ProjectFileOperation.modifyFile(currentPath, newBytes));
}
}
}
}));
}
// Collect any further update operations
newProjectStructure.collectUpdateProjectConfigurationOperations(currentProjectStructure, fileAccessContext, projectFileAccessProvider::getFileAccessContext, operations::add);
// Collect update operations from any project structure extension
if (updateBuilder.hasProjectStructureExtensionProvider() && (newConfig.getProjectStructureVersion().getExtensionVersion() != null)) {
ProjectStructureExtension projectStructureExtension = updateBuilder.getProjectStructureExtensionProvider().getProjectStructureExtension(newConfig.getProjectStructureVersion().getVersion(), newConfig.getProjectStructureVersion().getExtensionVersion());
projectStructureExtension.collectUpdateProjectConfigurationOperations(currentConfig, newConfig, fileAccessContext, operations::add);
}
// Submit changes
return projectFileAccessProvider.getFileModificationContext(projectId, workspaceId, workspaceType, workspaceAccessType, revisionId).submit(updateBuilder.getMessage(), operations);
}
use of org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency in project legend-sdlc by finos.
the class TestProjectStructure method testUpdateOldProjectDependencies.
protected void testUpdateOldProjectDependencies(ProjectType projectType) {
ProjectDependency oldProjectDependency = ProjectDependency.parseProjectDependency("TestProject3:2.0.1");
ProjectDependency oldProjectDependencyToRemove = ProjectDependency.parseProjectDependency("TestProject0:0.0.1");
List<ProjectDependency> oldProjectDependencyList = Arrays.asList(oldProjectDependency, oldProjectDependencyToRemove);
ProjectDependency updatedProjectDependency = ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject3:2.0.1");
ProjectStructure projectStructure = buildProjectStructure(projectType);
createProjectWithVersions(oldProjectDependency.getProjectId(), GROUP_ID, "testproject3", oldProjectDependency.getVersionId());
ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId());
Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, beforeProjectConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, beforeProjectConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getMetamodelDependencies());
Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, null, null);
SimpleProjectConfiguration newConfig = new SimpleProjectConfiguration(beforeProjectConfig);
newConfig.setProjectDependencies(oldProjectDependencyList);
String serializedConfig = serializeConfig(newConfig);
List<ProjectFileOperation> operations = Lists.mutable.empty();
operations.add(ProjectFileOperation.modifyFile("/project.json", serializedConfig));
this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("set dependencies", operations);
ProjectConfiguration afterUpdateProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterUpdateProjectConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterUpdateProjectConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterUpdateProjectConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterUpdateProjectConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterUpdateProjectConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), afterUpdateProjectConfig.getMetamodelDependencies());
Assert.assertEquals(oldProjectDependencyList, afterUpdateProjectConfig.getProjectDependencies());
String updateOldDependenciesId = "UpdateOldDependencies";
this.fileAccessProvider.createWorkspace(PROJECT_ID, updateOldDependenciesId);
ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(updateOldDependenciesId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Update Old Dependencies").withProjectDependenciesToRemove(Collections.singletonList(oldProjectDependencyToRemove)).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
ProjectConfiguration afterUpdateWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, updateOldDependenciesId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterUpdateWorkspaceConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterUpdateWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterUpdateWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterUpdateWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterUpdateWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), afterUpdateWorkspaceConfig.getMetamodelDependencies());
// asserting after deleting one of the old form dependency and updating one of the dependency
Assert.assertEquals(Collections.singletonList(updatedProjectDependency), afterUpdateWorkspaceConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, updateOldDependenciesId, null);
}
use of org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency in project legend-sdlc by finos.
the class TestProjectStructure method testMultiformatArtifactGeneration.
private void testMultiformatArtifactGeneration(ProjectType projectType) {
ProjectStructure projectStructure = buildProjectStructure(projectType);
Set<ArtifactType> configs = projectStructure.getAvailableGenerationConfigurations().stream().map(ArtifactTypeGenerationConfiguration::getType).collect(Collectors.toSet());
Assert.assertEquals(getExpectedSupportedArtifactConfigurationTypes(), configs);
Assert.assertEquals(Collections.emptySet(), configs.stream().filter(t -> !projectStructure.isSupportedArtifactType(t)).collect(Collectors.toSet()));
if (!configs.isEmpty()) {
List<Entity> testEntities = getTestEntities();
List<ProjectFileOperation> addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure);
this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations);
ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId());
Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, beforeProjectConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, beforeProjectConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertTrue(beforeProjectConfig.getArtifactGenerations().isEmpty());
assertStateValid(PROJECT_ID, null, null);
String addGenerationsWorkspaceId = "AddGeneration";
this.fileAccessProvider.createWorkspace(PROJECT_ID, addGenerationsWorkspaceId);
ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId());
Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, beforeWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, beforeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertTrue(beforeWorkspaceConfig.getMetamodelDependencies().isEmpty());
Assert.assertTrue(beforeWorkspaceConfig.getProjectDependencies().isEmpty());
Assert.assertTrue(beforeWorkspaceConfig.getArtifactGenerations().isEmpty());
assertStateValid(PROJECT_ID, addGenerationsWorkspaceId, null);
List<ProjectDependency> projectDependencies = Arrays.asList(ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject0:0.0.1"), ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject1:1.0.0"), ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject3:2.0.1"));
projectDependencies.sort(Comparator.naturalOrder());
for (ProjectDependency projectDependency : projectDependencies) {
String artifactId = projectDependency.getProjectId().substring(GROUP_ID.length() + 1);
createProjectWithVersions(artifactId, GROUP_ID, artifactId, projectDependency.getVersionId());
}
ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Add multi generation").withProjectDependenciesToAdd(projectDependencies).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, addGenerationsWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(projectDependencies, afterWorkspaceConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, addGenerationsWorkspaceId, null);
this.fileAccessProvider.commitWorkspace(PROJECT_ID, addGenerationsWorkspaceId);
for (ArtifactType type : configs) {
testMultiformatFormatGeneration(projectType, type, Collections.singletonList(new SimpleArtifactGeneration().withType(type).withName("test-" + type.name()).withParameters(Collections.emptyMap())));
}
}
}
use of org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency in project legend-sdlc by finos.
the class TestProjectStructure method testUpdateProjectDependencies.
protected void testUpdateProjectDependencies(ProjectType projectType) {
List<ProjectDependency> projectDependencies = Arrays.asList(ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject0:0.0.1"), ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject1:1.0.0"), ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject3:2.0.1"));
projectDependencies.sort(Comparator.naturalOrder());
for (ProjectDependency projectDependency : projectDependencies) {
String artifactId = projectDependency.getProjectId().substring(GROUP_ID.length() + 1);
createProjectWithVersions(artifactId, GROUP_ID, artifactId, projectDependency.getVersionId());
}
ProjectStructure projectStructure = buildProjectStructure(projectType);
List<Entity> testEntities = getTestEntities();
List<ProjectFileOperation> addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure);
this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations);
ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId());
Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, beforeProjectConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, beforeProjectConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getMetamodelDependencies());
Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, null, null);
String addDependenciesWorkspaceId = "AddDependencies";
this.fileAccessProvider.createWorkspace(PROJECT_ID, addDependenciesWorkspaceId);
ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId());
Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, beforeWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, beforeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), beforeWorkspaceConfig.getMetamodelDependencies());
Assert.assertEquals(Collections.emptyList(), beforeWorkspaceConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, addDependenciesWorkspaceId, null);
ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Add dependencies").withProjectDependenciesToAdd(projectDependencies).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, addDependenciesWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), afterWorkspaceConfig.getMetamodelDependencies());
Assert.assertEquals(projectDependencies, afterWorkspaceConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, addDependenciesWorkspaceId, null);
this.fileAccessProvider.commitWorkspace(PROJECT_ID, addDependenciesWorkspaceId);
ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterProjectConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterProjectConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), afterProjectConfig.getMetamodelDependencies());
Assert.assertEquals(projectDependencies, afterProjectConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, null, null);
String noChangeWorkspaceId = "NoChangeToDependencies";
this.fileAccessProvider.createWorkspace(PROJECT_ID, noChangeWorkspaceId);
Revision newRevision = ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("No change to dependencies").withGroupId("temp.group.id").withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
Assert.assertNotNull(newRevision);
ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, noChangeWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, noChangeWorkspaceConfig.getProjectId());
Assert.assertEquals("temp.group.id", noChangeWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, noChangeWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, noChangeWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, noChangeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), noChangeWorkspaceConfig.getMetamodelDependencies());
Assert.assertEquals(projectDependencies, noChangeWorkspaceConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, noChangeWorkspaceId, null);
this.fileAccessProvider.deleteWorkspace(PROJECT_ID, noChangeWorkspaceId);
for (int i = 0; i < projectDependencies.size(); i++) {
String removeDependencyWorkspaceId = "RemoveDependency" + 0;
this.fileAccessProvider.createWorkspace(PROJECT_ID, removeDependencyWorkspaceId);
ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, beforeRemovalConfig.getProjectId());
Assert.assertEquals(GROUP_ID, beforeRemovalConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, beforeRemovalConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, beforeRemovalConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, beforeRemovalConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), beforeRemovalConfig.getMetamodelDependencies());
Assert.assertEquals(projectDependencies.subList(i, projectDependencies.size()), beforeRemovalConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, removeDependencyWorkspaceId, null);
ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Remove dependencies").withProjectDependenciesToRemove(Collections.singletonList(projectDependencies.get(i))).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, removeDependencyWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterRemovalWorkspaceConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterRemovalWorkspaceConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterRemovalWorkspaceConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterRemovalWorkspaceConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterRemovalWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), afterRemovalWorkspaceConfig.getMetamodelDependencies());
Assert.assertEquals(projectDependencies.subList(i + 1, projectDependencies.size()), afterRemovalWorkspaceConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, removeDependencyWorkspaceId, null);
this.fileAccessProvider.commitWorkspace(PROJECT_ID, removeDependencyWorkspaceId);
ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, afterRemovalProjectConfig.getProjectId());
Assert.assertEquals(GROUP_ID, afterRemovalProjectConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, afterRemovalProjectConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, afterRemovalProjectConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, afterRemovalProjectConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), afterRemovalProjectConfig.getMetamodelDependencies());
Assert.assertEquals(projectDependencies.subList(i + 1, projectDependencies.size()), afterRemovalProjectConfig.getProjectDependencies());
assertStateValid(PROJECT_ID, null, null);
}
ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId());
Assert.assertEquals(GROUP_ID, projectConfigUpdateRevisionConfig.getGroupId());
Assert.assertEquals(ARTIFACT_ID, projectConfigUpdateRevisionConfig.getArtifactId());
Assert.assertEquals(this.projectStructureVersion, projectConfigUpdateRevisionConfig.getProjectStructureVersion().getVersion());
Assert.assertEquals(this.projectStructureExtensionVersion, projectConfigUpdateRevisionConfig.getProjectStructureVersion().getExtensionVersion());
Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getMetamodelDependencies());
Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getProjectDependencies());
assertEntitiesEquivalent(testEntities, getActualEntities(PROJECT_ID));
}
use of org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency in project legend-sdlc by finos.
the class TestMultiModuleMavenProjectStructure method collectExpectedProjectModelDependencyManagement.
@Override
protected void collectExpectedProjectModelDependencyManagement(T projectStructure, Consumer<Dependency> dependencyManagementConsumer) {
ProjectConfiguration projectConfig = projectStructure.getProjectConfiguration();
if (projectStructure.usesDependencyManagement()) {
List<ProjectDependency> projectDependencies = projectConfig.getProjectDependencies();
if (projectDependencies != null) {
projectDependencies.stream().flatMap(pd -> MavenProjectStructure.projectDependencyToAllMavenDependencies(pd, this.fileAccessProvider::getFileAccessContext, true)).forEach(dependencyManagementConsumer);
}
projectStructure.addJunitDependency(dependencyManagementConsumer, true);
projectStructure.addJacksonDependency(dependencyManagementConsumer, true);
}
dependencyManagementConsumer.accept(MavenProjectStructure.newMavenDependency(projectConfig.getGroupId(), projectStructure.getModuleFullName(projectStructure.getEntitiesModuleName()), "0.0.1-SNAPSHOT"));
projectStructure.getOtherModulesNames().stream().map(m -> MavenProjectStructure.newMavenDependency(projectConfig.getGroupId(), projectStructure.getModuleFullName(m), "0.0.1-SNAPSHOT")).forEach(dependencyManagementConsumer);
}
Aggregations