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());
}
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);
}
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);
}
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));
}
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;
}
Aggregations