Search in sources :

Example 11 with AttributeValue

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

the class ProjectManagerWriteTest method testUpdateProjectWithPersistedAttributes.

@Test
public void testUpdateProjectWithPersistedAttributes() throws Exception {
    Map<String, List<String>> attributes = new HashMap<>();
    ProjectConfig pc = new NewProjectConfigImpl("/testUpdateProject", BaseProjectType.ID, null, "name", "descr", null, null, null);
    RegisteredProject p = pm.createProject(pc, null);
    assertEquals(BaseProjectType.ID, p.getType());
    assertEquals("name", p.getName());
    attributes.put("pt2-var2", new AttributeValue("updated").getList());
    ProjectConfig pc1 = new NewProjectConfigImpl("/testUpdateProject", "pt2", null, "updatedName", "descr", attributes, null, null);
    p = pm.updateProject(pc1);
    assertEquals("pt2", p.getType());
    assertEquals("updated", p.getAttributes().get("pt2-var2").get(0));
    assertEquals("updatedName", p.getName());
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 12 with AttributeValue

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

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProjectWhenInnerProjectContainsSource.

@Test
public void testCreateBatchProjectsWithInnerProjectWhenInnerProjectContainsSource() throws Exception {
    final String rootProjectPath = "/rootProject";
    final String innerProjectPath = "/rootProject/innerProject";
    final String rootImportType = "rootImportType";
    final String innerImportType = "innerImportType";
    final String innerProjectType = "pt2";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final List<String> children1 = new ArrayList<>(Arrays.asList(paths1));
    registerImporter(rootImportType, prepareZipArchiveBasedOn(children1));
    final String[] paths2 = { "folder2/", "folder2/file2.txt" };
    final List<String> children2 = new ArrayList<>(Arrays.asList(paths2));
    registerImporter(innerImportType, prepareZipArchiveBasedOn(children2));
    final SourceStorageDto source1 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(rootImportType);
    final NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(innerImportType);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", innerProjectPath, innerProjectType, source2);
    config2.setAttributes(attributes);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config2);
    configs.add(config1);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    checkProjectExist(rootProjectPath);
    checkChildrenFor(rootProjectFolder, children1);
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(innerProjectFolder, children2);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) List(java.util.List) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 13 with AttributeValue

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

the class ProjectManagerWriteTest method testUpdateProjectWithProvidedAttributes.

@Test
public void testUpdateProjectWithProvidedAttributes() throws Exception {
    // SPECS: Project should be updated with problem code = 13 when value for required attribute is not initialized
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    ProjectConfig pc = new NewProjectConfigImpl("/testUpdateProject", "pt2", null, "name", "descr", attributes, null, null);
    pm.createProject(pc, null);
    pc = new NewProjectConfigImpl("/testUpdateProject", "pt3", null, "updatedName", "descr", attributes, null, null);
    RegisteredProject project = pm.updateProject(pc);
    final List<Problem> problems = project.getProblems();
    assertNotNull(problems);
    assertFalse(problems.isEmpty());
    assertEquals(1, problems.size());
    assertEquals(13, problems.get(0).code);
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) Test(org.junit.Test)

Example 14 with AttributeValue

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

the class PlainJavaProjectGeneratorTest method projectShouldBeCreatedWithCustomSourceFolders.

@Test
public void projectShouldBeCreatedWithCustomSourceFolders() throws Exception {
    attributes = new HashMap<>();
    options = new HashMap<>();
    attributes.put(Constants.SOURCE_FOLDER, new AttributeValue("src2"));
    PlainJavaProjectGenerator generator = new PlainJavaProjectGenerator(vfsProvider, classpathBuilder);
    generator.onCreateProject(Path.of("project"), attributes, options);
    VirtualFile project1 = vfsProvider.getVirtualFileSystem().getRoot().getChild(Path.of("project"));
    IJavaProject project = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject("project");
    VirtualFile mainClass = project1.getChild(Path.of("/src2/Main.java"));
    assertNotNull(mainClass);
    assertTrue(project.exists());
    verify(classpathBuilder).generateClasspath(project, singletonList("src2"), singletonList(DEFAULT_LIBRARY_FOLDER_VALUE));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) IJavaProject(org.eclipse.jdt.core.IJavaProject) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest) Test(org.testng.annotations.Test)

Example 15 with AttributeValue

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

the class ProjectManager method doCreateProject.

/** Note: Use {@link FileWatcherManager#suspend()} and {@link FileWatcherManager#resume()} while creating a project */
private RegisteredProject doCreateProject(ProjectConfig projectConfig, Map<String, String> options) throws ConflictException, ForbiddenException, ServerException, NotFoundException {
    final String path = ProjectRegistry.absolutizePath(projectConfig.getPath());
    final CreateProjectHandler generator = handlers.getCreateProjectHandler(projectConfig.getType());
    FolderEntry projectFolder;
    if (generator != null) {
        Map<String, AttributeValue> valueMap = new HashMap<>();
        Map<String, List<String>> attributes = projectConfig.getAttributes();
        if (attributes != null) {
            for (Map.Entry<String, List<String>> entry : attributes.entrySet()) {
                valueMap.put(entry.getKey(), new AttributeValue(entry.getValue()));
            }
        }
        if (options == null) {
            options = new HashMap<>();
        }
        Path projectPath = Path.of(path);
        generator.onCreateProject(projectPath, valueMap, options);
        projectFolder = new FolderEntry(vfs.getRoot().getChild(projectPath), projectRegistry);
    } else {
        projectFolder = new FolderEntry(vfs.getRoot().createFolder(path), projectRegistry);
    }
    final RegisteredProject project = projectRegistry.putProject(projectConfig, projectFolder, true, false);
    workspaceProjectsHolder.sync(projectRegistry);
    projectRegistry.fireInitHandlers(project);
    return project;
}
Also used : Path(org.eclipse.che.api.vfs.Path) CreateProjectHandler(org.eclipse.che.api.project.server.handlers.CreateProjectHandler) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)16 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)8 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)7 ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)5 File (java.io.File)2 Map (java.util.Map)2 ServerException (org.eclipse.che.api.core.ServerException)2 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)2 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)2 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1