use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.
the class ProjectListeners method isJavaProject.
private boolean isJavaProject(String projectPath) {
ProjectConfig project = projectRegistry.getProject(projectPath);
String type = project.getType();
try {
return projectTypeRegistry.getProjectType(type).isTypeOf("java");
} catch (NotFoundException e) {
LOG.error("Can't find project " + projectPath, e);
return false;
}
}
use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.
the class ProjectManager method createBatchProjects.
/**
* Create batch of projects according to their configurations.
* <p/>
* Notes: - a project will be created by importing when project configuration contains {@link SourceStorage} object,
* otherwise this one will be created corresponding its {@link NewProjectConfig}:
* <li> - {@link NewProjectConfig} object contains only one mandatory {@link NewProjectConfig#setPath(String)} field.
* In this case Project will be created as project of {@link BaseProjectType} type </li>
* <li> - a project will be created as project of {@link BaseProjectType} type with {@link Problem#code} = 12
* when declared primary project type is not registered, </li>
* <li> - a project will be created with {@link Problem#code} = 12 and without mixin project type
* when declared mixin project type is not registered</li>
* <li> - for creating a project by generator {@link NewProjectConfig#getOptions()} should be specified.</li>
*
* @param projectConfigList
* the list of configurations to create projects
* @param rewrite
* whether rewrite or not (throw exception otherwise) if such a project exists
* @return the list of new projects
* @throws BadRequestException
* when {@link NewProjectConfig} object not contains mandatory {@link NewProjectConfig#setPath(String)} field.
* @throws ConflictException
* when the same path project exists and {@code rewrite} is {@code false}
* @throws ForbiddenException
* when trying to overwrite the project and this one contains at least one locked file
* @throws NotFoundException
* when parent folder does not exist
* @throws UnauthorizedException
* if user isn't authorized to access to location at importing source code
* @throws ServerException
* if other error occurs
*/
public List<RegisteredProject> createBatchProjects(List<? extends NewProjectConfig> projectConfigList, boolean rewrite, ProjectOutputLineConsumerFactory lineConsumerFactory) throws BadRequestException, ConflictException, ForbiddenException, NotFoundException, ServerException, UnauthorizedException, IOException {
fileWatcherManager.suspend();
try {
final List<RegisteredProject> projects = new ArrayList<>(projectConfigList.size());
validateProjectConfigurations(projectConfigList, rewrite);
final List<NewProjectConfig> sortedConfigList = projectConfigList.stream().sorted((config1, config2) -> config1.getPath().compareTo(config2.getPath())).collect(Collectors.toList());
for (NewProjectConfig projectConfig : sortedConfigList) {
RegisteredProject registeredProject;
final String pathToProject = projectConfig.getPath();
//creating project(by config or by importing source code)
try {
final SourceStorage sourceStorage = projectConfig.getSource();
if (sourceStorage != null && !isNullOrEmpty(sourceStorage.getLocation())) {
doImportProject(pathToProject, sourceStorage, rewrite, lineConsumerFactory.setProjectName(projectConfig.getPath()));
} else if (!isVirtualFileExist(pathToProject)) {
registeredProject = doCreateProject(projectConfig, projectConfig.getOptions());
projects.add(registeredProject);
continue;
}
} catch (Exception e) {
if (!isVirtualFileExist(pathToProject)) {
//project folder is absent
rollbackCreatingBatchProjects(projects);
throw e;
}
}
//update project
if (isVirtualFileExist(pathToProject)) {
try {
registeredProject = updateProject(projectConfig);
} catch (Exception e) {
registeredProject = projectRegistry.putProject(projectConfig, asFolder(pathToProject), true, false);
final Problem problem = new Problem(NOT_UPDATED_PROJECT, "The project is not updated, caused by " + e.getLocalizedMessage());
registeredProject.getProblems().add(problem);
}
} else {
registeredProject = projectRegistry.putProject(projectConfig, null, true, false);
}
projects.add(registeredProject);
}
return projects;
} finally {
fileWatcherManager.resume();
}
}
use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.
the class ProjectRegistry method initProjects.
@PostConstruct
public void initProjects() throws ConflictException, NotFoundException, ServerException, ForbiddenException {
List<? extends ProjectConfig> projectConfigs = workspaceHolder.getProjects();
// take all the projects from ws's config
for (ProjectConfig projectConfig : projectConfigs) {
final String path = projectConfig.getPath();
final VirtualFile vf = vfs.getRoot().getChild(Path.of(path));
final FolderEntry projectFolder = ((vf == null) ? null : new FolderEntry(vf, this));
putProject(projectConfig, projectFolder, false, false);
}
initUnconfiguredFolders();
initialized = true;
for (RegisteredProject project : projects.values()) {
// only for projects with sources
if (project.getBaseFolder() != null) {
fireInitHandlers(project);
}
}
}
use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.
the class ResourceManager method update.
/**
* Update state of specific properties in project and save this state on the server.
* As the result method should return the {@link Promise} with new {@link Project} object.
* <p/>
* During the update method have to iterate on children of updated resource and if any of
* them has changed own type, e.g. folder -> project, project -> folder, specific event
* has to be fired.
* <p/>
* Method is not intended to be called in third party components. It is the service method
* for {@link Project}.
*
* @param path
* the path to project which should be updated
* @param request
* the update request
* @return the {@link Promise} with new {@link Project} object.
* @see ResourceChangedEvent
* @see ProjectRequest
* @see Project#update()
* @since 4.4.0
*/
protected Promise<Project> update(final Path path, final ProjectRequest request) {
final ProjectConfig projectConfig = request.getBody();
final SourceStorage source = projectConfig.getSource();
final SourceStorageDto sourceDto = dtoFactory.createDto(SourceStorageDto.class);
if (source != null) {
sourceDto.setLocation(source.getLocation());
sourceDto.setType(source.getType());
sourceDto.setParameters(source.getParameters());
}
final ProjectConfigDto dto = dtoFactory.createDto(ProjectConfigDto.class).withName(projectConfig.getName()).withPath(path.toString()).withDescription(projectConfig.getDescription()).withType(projectConfig.getType()).withMixins(projectConfig.getMixins()).withAttributes(projectConfig.getAttributes()).withSource(sourceDto);
return ps.updateProject(dto).thenPromise(new Function<ProjectConfigDto, Promise<Project>>() {
@Override
public Promise<Project> apply(ProjectConfigDto reference) throws FunctionException {
/* Note: After update, project may become to be other type,
e.g. blank -> java or maven, or ant, or etc. And this may
cause sub-project creations. Simultaneously on the client
side there is outdated information about sub-projects, so
we need to get updated project list. */
//dispose outdated resource
final Optional<Resource> outdatedResource = store.getResource(path);
checkState(outdatedResource.isPresent(), "Outdated resource wasn't found");
final Resource resource = outdatedResource.get();
checkState(resource instanceof Container, "Outdated resource is not a container");
Container container = (Container) resource;
if (resource instanceof Folder) {
Container parent = resource.getParent();
checkState(parent != null, "Parent of the resource wasn't found");
container = parent;
}
return synchronize(container).then(new Function<Resource[], Project>() {
@Override
public Project apply(Resource[] synced) throws FunctionException {
final Optional<Resource> updatedProject = store.getResource(path);
checkState(updatedProject.isPresent(), "Updated resource is not present");
checkState(updatedProject.get().isProject(), "Updated resource is not a project");
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(updatedProject.get(), UPDATED)));
return (Project) updatedProject.get();
}
});
}
});
}
use of org.eclipse.che.api.core.model.project.ProjectConfig in project che by eclipse.
the class ProjectManagerWriteTest method testDeleteProject.
@Test
public void testDeleteProject() throws Exception {
ProjectConfig pc = new NewProjectConfigImpl("/testDeleteProject", BaseProjectType.ID, null, "name", "descr", null, null, null);
pm.createProject(pc, null);
pc = new NewProjectConfigImpl("/testDeleteProject/inner", BaseProjectType.ID, null, "name", "descr", null, null, null);
pm.createProject(pc, null);
assertNotNull(projectRegistry.getProject("/testDeleteProject/inner"));
pm.delete("/testDeleteProject");
assertNull(projectRegistry.getProject("/testDeleteProject/inner"));
assertNull(projectRegistry.getProject("/testDeleteProject"));
assertNull(pm.getProjectsRoot().getChild("/testDeleteProject/inner"));
//assertNull(projectRegistry.folder("/testDeleteProject/inner"));
}
Aggregations