Search in sources :

Example 1 with ArtifactType

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;
}
Also used : ProjectFileOperation(org.finos.legend.sdlc.server.project.ProjectFileOperation) ArtifactType(org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType) BiFunction(java.util.function.BiFunction) Dependency(org.apache.maven.model.Dependency) Lists(org.eclipse.collections.api.factory.Lists) Build(org.apache.maven.model.Build) Parent(org.apache.maven.model.Parent) Retention(java.lang.annotation.Retention) Maps(org.eclipse.collections.api.factory.Maps) EntitySerializer(org.finos.legend.sdlc.serialization.EntitySerializer) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Method(java.lang.reflect.Method) Sets(org.eclipse.collections.api.factory.Sets) VersionId(org.finos.legend.sdlc.domain.model.version.VersionId) Properties(java.util.Properties) ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) EnumMap(java.util.EnumMap) Set(java.util.Set) Target(java.lang.annotation.Target) ListIterate(org.eclipse.collections.impl.utility.ListIterate) ElementType(java.lang.annotation.ElementType) EntitySerializers(org.finos.legend.sdlc.serialization.EntitySerializers) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) Plugin(org.apache.maven.model.Plugin) List(java.util.List) Stream(java.util.stream.Stream) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency) TreeMap(java.util.TreeMap) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration) ProjectStructurePlatformExtensions(org.finos.legend.sdlc.server.project.ProjectStructurePlatformExtensions) ProjectPaths(org.finos.legend.sdlc.server.project.ProjectPaths) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) ArtifactGeneration(org.finos.legend.sdlc.domain.model.project.configuration.ArtifactGeneration) SortedMap(java.util.SortedMap) Model(org.apache.maven.model.Model) RetentionPolicy(java.lang.annotation.RetentionPolicy) Method(java.lang.reflect.Method) Dependency(org.apache.maven.model.Dependency) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency) Properties(java.util.Properties) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) ArtifactType(org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) Plugin(org.apache.maven.model.Plugin)

Example 2 with ArtifactType

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()));
    }
}
Also used : ArtifactType(org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType) Model(org.apache.maven.model.Model) List(java.util.List) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 3 with ArtifactType

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())));
        }
    }
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) ArtifactType(org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)

Example 4 with ArtifactType

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()));
    }
}
Also used : ArtifactType(org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType) Dependency(org.apache.maven.model.Dependency) Collectors(java.util.stream.Collectors) WorkspaceType(org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType) MultiModuleMavenProjectStructure(org.finos.legend.sdlc.server.project.maven.MultiModuleMavenProjectStructure) Consumer(java.util.function.Consumer) Plugin(org.apache.maven.model.Plugin) List(java.util.List) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration) LegendVersionPackagePluginMavenHelper(org.finos.legend.sdlc.server.project.maven.LegendVersionPackagePluginMavenHelper) Map(java.util.Map) MavenProjectStructure(org.finos.legend.sdlc.server.project.maven.MavenProjectStructure) BiConsumer(java.util.function.BiConsumer) ModuleConfig(org.finos.legend.sdlc.server.project.maven.MultiModuleMavenProjectStructure.ModuleConfig) Assert(org.junit.Assert) Method(java.lang.reflect.Method) Collections(java.util.Collections) Model(org.apache.maven.model.Model) Model(org.apache.maven.model.Model) MultiModuleMavenProjectStructure(org.finos.legend.sdlc.server.project.maven.MultiModuleMavenProjectStructure) Map(java.util.Map) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)

Aggregations

ArtifactType (org.finos.legend.sdlc.domain.model.project.configuration.ArtifactType)4 List (java.util.List)3 Map (java.util.Map)3 Model (org.apache.maven.model.Model)3 ProjectConfiguration (org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)3 ProjectDependency (org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency)3 Method (java.lang.reflect.Method)2 EnumMap (java.util.EnumMap)2 BiConsumer (java.util.function.BiConsumer)2 Consumer (java.util.function.Consumer)2 Dependency (org.apache.maven.model.Dependency)2 Plugin (org.apache.maven.model.Plugin)2 ElementType (java.lang.annotation.ElementType)1 Retention (java.lang.annotation.Retention)1 RetentionPolicy (java.lang.annotation.RetentionPolicy)1 Target (java.lang.annotation.Target)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Properties (java.util.Properties)1