use of org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType in project legend-sdlc by finos.
the class MultiModuleMavenProjectStructure method createMavenOtherModuleModel.
protected Model createMavenOtherModuleModel(String otherModuleName, BiFunction<String, VersionId, ProjectFileAccessProvider.FileAccessContext> versionFileAccessContextProvider) {
Model mavenModel = createMavenModuleModel(otherModuleName);
ArtifactType typeForConfig = otherModules.get(otherModuleName);
Map<ModuleConfigType, Method> otherModuleConfigMethods = this.moduleConfigMethods.get(getModuleConfigName(typeForConfig));
if (otherModuleConfigMethods != null) {
// Properties
Method propertiesMethod = otherModuleConfigMethods.get(ModuleConfigType.PROPERTIES);
if (propertiesMethod != null) {
try {
Properties properties = new SortedPropertiesForSerialization();
invokeConfigMethod(propertiesMethod, (BiConsumer<String, String>) properties::setProperty);
if (!properties.isEmpty()) {
mavenModel.setProperties(properties);
}
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven properties for module " + otherModuleName, e);
}
}
// Module dependencies
Method moduleDependenciesMethod = otherModuleConfigMethods.get(ModuleConfigType.MODULE_DEPENDENCIES);
if (moduleDependenciesMethod != null) {
try {
invokeConfigMethod(moduleDependenciesMethod, (Consumer<String>) m -> mavenModel.addDependency(getModuleWithNoVersionDependency(m)));
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven module dependencies for module " + otherModuleName, e);
}
}
// Dependencies
Method dependenciesMethod = otherModuleConfigMethods.get(ModuleConfigType.DEPENDENCIES);
if (dependenciesMethod != null) {
try {
invokeConfigMethod(dependenciesMethod, versionFileAccessContextProvider, (Consumer<Dependency>) mavenModel::addDependency);
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven dependencies for module " + otherModuleName, e);
}
}
// Plugins
Method pluginsMethod = otherModuleConfigMethods.get(ModuleConfigType.PLUGINS);
if (pluginsMethod != null) {
try {
Build build = new Build();
invokeConfigMethod(pluginsMethod, otherModuleName, versionFileAccessContextProvider, (Consumer<Plugin>) build::addPlugin);
if (!build.getPlugins().isEmpty()) {
mavenModel.setBuild(build);
}
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven plugins for module " + otherModuleName, e);
}
}
}
return mavenModel;
}
use of org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType in project legend-sdlc by finos.
the class TestMultiModuleMavenProjectStructure method assertStateValid.
@Override
protected void assertStateValid(T projectStructure, String projectId, String workspaceId, String revisionId) {
super.assertStateValid(projectStructure, projectId, workspaceId, revisionId);
ProjectFileAccessProvider.FileAccessContext fileAccessContext = this.fileAccessProvider.getFileAccessContext(projectId, workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, revisionId);
Model entitiesMavenModel = projectStructure.getModuleMavenModel(projectStructure.getEntitiesModuleName(), fileAccessContext);
Assert.assertNotNull(projectStructure.getEntitiesModuleName(), entitiesMavenModel);
assertMavenEntitiesModelValid(entitiesMavenModel, projectStructure);
Map<ArtifactType, List<String>> expectedArtifacts = getExpectedArtifactIdsByType(projectStructure);
expectedArtifacts.keySet().forEach(artifactType -> {
List<String> projectArtifactsForType = projectStructure.getArtifactIdsForType(artifactType).collect(Collectors.toList());
Assert.assertEquals("same size", expectedArtifacts.get(artifactType).size(), projectArtifactsForType.size());
Assert.assertTrue("projects artifacts contains all expected", projectArtifactsForType.containsAll(expectedArtifacts.get(artifactType)));
Assert.assertTrue("expected contains all project artifacts", expectedArtifacts.get(artifactType).containsAll(projectArtifactsForType));
});
Map<String, Map<ModuleConfigType, Method>> expectedConfigMethods = getExpectedConfigMethods();
for (String otherModuleName : projectStructure.getOtherModulesNames()) {
Model otherModuleMavenModel = projectStructure.getModuleMavenModel(otherModuleName, fileAccessContext);
Assert.assertNotNull(otherModuleName, otherModuleMavenModel);
assertMavenOtherModuleModelValid(otherModuleName, otherModuleMavenModel, projectStructure, expectedConfigMethods.getOrDefault(MultiModuleMavenProjectStructure.getModuleConfigName(projectStructure.getOtherModuleArtifactType(otherModuleName)), Collections.emptyMap()));
}
}
use of org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType 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.ArtifactType in project legend-sdlc by finos.
the class TestMultiGenerationProjectStructure method assertMultiformatGenerationStateValid.
@Override
protected void assertMultiformatGenerationStateValid(String projectId, String workspaceId, String revisionId, ArtifactType artifactType) {
ProjectConfiguration configuration = ProjectStructure.getProjectConfiguration(projectId, workspaceId, revisionId, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
Assert.assertNotNull(configuration);
T projectStructure = (T) ProjectStructure.getProjectStructure(configuration);
Assert.assertNotNull(projectStructure.getModuleConfig(artifactType));
List<String> generationModuleName = projectStructure.getModuleNamesForType(artifactType).collect(Collectors.toList());
Assert.assertFalse(artifactType.name() + " module does not exists", generationModuleName.isEmpty());
Assert.assertTrue(generationModuleName.stream().allMatch(name -> projectStructure.getOtherModulesNames().contains(name)));
Model mavenModel = MavenProjectStructure.getProjectMavenModel(this.fileAccessProvider.getFileAccessContext(projectId, workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, revisionId));
Assert.assertNotNull(mavenModel);
List<String> moduleNames = mavenModel.getModules();
Assert.assertFalse(moduleNames.isEmpty());
Assert.assertTrue(generationModuleName.stream().allMatch(name -> moduleNames.contains(projectStructure.getModuleFullName(name))));
projectStructure.getModuleNamesForType(artifactType).forEach(name -> moduleNames.contains(projectStructure.getModuleFullName(name)));
Map<String, Map<MultiModuleMavenProjectStructure.ModuleConfigType, Method>> expectedConfigMethods = getExpectedConfigMethods();
for (String otherModuleName : projectStructure.getModuleNamesForType(artifactType).collect(Collectors.toList())) {
Model otherModuleMavenModel = projectStructure.getModuleMavenModel(otherModuleName, this.fileAccessProvider.getFileAccessContext(projectId, workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, revisionId));
Assert.assertNotNull(otherModuleName, otherModuleMavenModel);
assertMavenOtherModuleModelValid(otherModuleName, otherModuleMavenModel, projectStructure, expectedConfigMethods.getOrDefault(MultiModuleMavenProjectStructure.getModuleConfigName(projectStructure.getOtherModuleArtifactType(otherModuleName)), Collections.emptyMap()));
}
}
Aggregations