Search in sources :

Example 11 with ProjectTypeDef

use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.

the class ProjectTypesTest method testGetMixins.

@Test
public void testGetMixins() throws Exception {
    Set<ProjectTypeDef> pts = new HashSet<>();
    pts.add(new PrimaryType());
    pts.add(new PersistedMixin());
    ProjectTypeRegistry reg = new ProjectTypeRegistry(pts);
    List<RegisteredProject.Problem> problems = new ArrayList<>();
    ProjectTypes projectTypes = new ProjectTypes(generate("projectPath-", 5), PrimaryType.PRIMARY_ID, Collections.singletonList(PersistedMixin.PERSISTED_MIXIN_ID), reg, problems);
    assertNotNull(projectTypes.getMixins());
    assertEquals(projectTypes.getMixins().size(), 1);
    assertTrue(projectTypes.getMixins().containsKey(PersistedMixin.PERSISTED_MIXIN_ID));
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) ArrayList(java.util.ArrayList) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with ProjectTypeDef

use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.

the class ProjectTypes method reset.

/**
     * Reset project types and atrributes after initialization
     * in case when some attributes are not valid
     * (for instance required attributes are not initialized)
     *
     * @param attributesToDel - invalid attributes
     */
void reset(Set<Attribute> attributesToDel) {
    Set<String> ptsToDel = new HashSet<>();
    for (Attribute attr : attributesToDel) {
        ptsToDel.add(attr.getProjectType());
    }
    Set<String> attrNamesToDel = new HashSet<>();
    for (String pt : ptsToDel) {
        ProjectTypeDef typeDef = all.get(pt);
        for (Attribute attrDef : typeDef.getAttributes()) {
            attrNamesToDel.add(attrDef.getName());
        }
    }
    // remove project types
    for (String typeId : ptsToDel) {
        this.all.remove(typeId);
        if (this.primary.getId().equals(typeId)) {
            this.primary = ProjectTypeRegistry.BASE_TYPE;
            this.all.put(ProjectTypeRegistry.BASE_TYPE.getId(), ProjectTypeRegistry.BASE_TYPE);
        } else {
            mixins.remove(typeId);
        }
    }
    // remove attributes
    for (String attr : attrNamesToDel) {
        this.attributeDefs.remove(attr);
    }
}
Also used : Attribute(org.eclipse.che.api.core.model.project.type.Attribute) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) HashSet(java.util.HashSet)

Example 13 with ProjectTypeDef

use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.

the class ProjectTypes method addTransient.

void addTransient(FolderEntry projectFolder) {
    for (ProjectTypeDef pt : projectTypeRegistry.getProjectTypes()) {
        // NOTE: Only mixable types allowed
        if (pt.isMixable() && !pt.isPersisted() && pt.resolveSources(projectFolder).matched()) {
            all.put(pt.getId(), pt);
            mixins.put(pt.getId(), pt);
            for (Attribute attr : pt.getAttributes()) {
                final String attrName = attr.getName();
                if (attributeDefs.containsKey(attrName)) {
                    problems.add(new Problem(ATTRIBUTE_NAME_PROBLEM, format("Attribute name conflict. Duplicated attributes detected for %s. " + "Attribute %s declared in %s already declared in %s. Skipped.", projectPath, attrName, pt.getId(), attributeDefs.get(attrName).getProjectType())));
                }
                attributeDefs.put(attrName, attr);
            }
        }
    }
}
Also used : Attribute(org.eclipse.che.api.core.model.project.type.Attribute) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem)

Example 14 with ProjectTypeDef

use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.

the class MavenProjectTypeTest method testGetProjectType.

@Test
public void testGetProjectType() throws Exception {
    ProjectTypeDef pt = ptRegistry.getProjectType("maven");
    Assert.assertTrue(pt.getAttributes().size() > 0);
    Assert.assertTrue(pt.isTypeOf("java"));
}
Also used : ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) Test(org.junit.Test)

Example 15 with ProjectTypeDef

use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.

the class MavenProjectTypeTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Set<ProjectTypeDef> projTypes = new HashSet<>();
    projTypes.add(new JavaProjectType(new JavaValueProviderFactory()));
    projTypes.add(new MavenProjectType(new MavenValueProviderFactory()));
    ptRegistry = new ProjectTypeRegistry(projTypes);
    Set<ProjectHandler> handlers = new HashSet<>();
    handlers.add(new MavenProjectGenerator(Collections.<GeneratorStrategy>emptySet()));
    httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) JavaValueProviderFactory(org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ProjectHandler(org.eclipse.che.api.project.server.handlers.ProjectHandler) GeneratorStrategy(org.eclipse.che.plugin.maven.server.projecttype.handler.GeneratorStrategy) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) MavenProjectGenerator(org.eclipse.che.plugin.maven.server.projecttype.handler.MavenProjectGenerator) JavaProjectType(org.eclipse.che.plugin.java.server.projecttype.JavaProjectType) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ProjectTypeDef (org.eclipse.che.api.project.server.type.ProjectTypeDef)16 HashSet (java.util.HashSet)10 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)9 ArrayList (java.util.ArrayList)8 Test (org.testng.annotations.Test)6 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)5 File (java.io.File)3 PathMatcher (java.nio.file.PathMatcher)3 Collections.singletonList (java.util.Collections.singletonList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Set (java.util.Set)3 Attribute (org.eclipse.che.api.core.model.project.type.Attribute)3 EventService (org.eclipse.che.api.core.notification.EventService)3 HttpJsonRequest (org.eclipse.che.api.core.rest.HttpJsonRequest)3 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)3 SelfReturningAnswer (org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer)3