use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class ResourceManager method createProject.
Promise<Project> createProject(final Project.ProjectRequest createRequest) {
checkArgument(checkProjectName(createRequest.getBody().getName()), "Invalid project name");
checkArgument(typeRegistry.getProjectType(createRequest.getBody().getType()) != null, "Invalid project type");
final Path path = Path.valueOf(createRequest.getBody().getPath());
return findResource(path, true).thenPromise(new Function<Optional<Resource>, Promise<Project>>() {
@Override
public Promise<Project> apply(Optional<Resource> resource) throws FunctionException {
if (resource.isPresent()) {
if (resource.get().isProject()) {
throw new IllegalStateException("Project already exists");
} else if (resource.get().isFile()) {
throw new IllegalStateException("File can not be converted to project");
}
return update(path, createRequest);
}
final MutableProjectConfig projectConfig = (MutableProjectConfig) createRequest.getBody();
final List<NewProjectConfig> projectConfigList = projectConfig.getProjects();
projectConfigList.add(asDto(projectConfig));
final List<NewProjectConfigDto> configDtoList = asDto(projectConfigList);
return ps.createBatchProjects(configDtoList).thenPromise(new Function<List<ProjectConfigDto>, Promise<Project>>() {
@Override
public Promise<Project> apply(final List<ProjectConfigDto> configList) throws FunctionException {
return ps.getProjects().then(new Function<List<ProjectConfigDto>, Project>() {
@Override
public Project apply(List<ProjectConfigDto> updatedConfiguration) throws FunctionException {
//cache new configs
cachedConfigs = updatedConfiguration.toArray(new ProjectConfigDto[updatedConfiguration.size()]);
for (ProjectConfigDto projectConfigDto : configList) {
if (projectConfigDto.getPath().equals(path.toString())) {
final Project newResource = resourceFactory.newProjectImpl(projectConfigDto, ResourceManager.this);
store.register(newResource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(newResource, ADDED | DERIVED)));
return newResource;
}
}
throw new IllegalStateException("Created project is not found");
}
});
}
});
}
});
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class ProjectImporter method importProject.
public void importProject(final CompleteCallback callback, MutableProjectConfig projectConfig) {
final Path path = !isNullOrEmpty(projectConfig.getPath()) ? Path.valueOf(projectConfig.getPath()) : !isNullOrEmpty(projectConfig.getName()) ? Path.valueOf(projectConfig.getName()).makeAbsolute() : null;
checkState(path != null, "Import path is undefined");
startImport(path, projectConfig.getSource()).then(new Operation<Project>() {
@Override
public void apply(Project arg) throws OperationException {
if (callback != null) {
callback.onCompleted();
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (callback != null) {
callback.onFailure(arg.getCause());
}
}
});
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class ProjectImporter method doImport.
private Promise<Project> doImport(final Path path, final SourceStorage sourceStorage) {
final ProjectNotificationSubscriber subscriber = subscriberFactory.createSubscriber();
subscriber.subscribe(path.lastSegment());
MutableProjectConfig importConfig = new MutableProjectConfig();
importConfig.setPath(path.toString());
importConfig.setSource(sourceStorage);
return appContext.getWorkspaceRoot().importProject().withBody(importConfig).send().thenPromise(new Function<Project, Promise<Project>>() {
@Override
public Promise<Project> apply(Project project) throws FunctionException {
subscriber.onSuccess();
return projectResolver.resolve(project);
}
}).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {
@Override
public Promise<Project> apply(PromiseError exception) throws FunctionException {
subscriber.onFailure(exception.getCause().getMessage());
switch(getErrorCode(exception.getCause())) {
case UNABLE_GET_PRIVATE_SSH_KEY:
throw new IllegalStateException(localizationConstant.importProjectMessageUnableGetSshKey());
case UNAUTHORIZED_SVN_OPERATION:
return recallImportWithCredentials(sourceStorage, path);
case UNAUTHORIZED_GIT_OPERATION:
final Map<String, String> attributes = ExceptionUtils.getAttributes(exception.getCause());
final String providerName = attributes.get(PROVIDER_NAME);
final String authenticateUrl = attributes.get(AUTHENTICATE_URL);
if (!Strings.isNullOrEmpty(providerName) && !Strings.isNullOrEmpty(authenticateUrl)) {
return authUserAndRecallImport(providerName, authenticateUrl, path, sourceStorage, subscriber);
} else {
throw new IllegalStateException(localizationConstant.oauthFailedToGetAuthenticatorText());
}
default:
throw new IllegalStateException(exception.getCause());
}
}
});
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class ProjectResolver method resolve.
public Promise<Project> resolve(final Project project) {
return project.resolve().thenPromise(new Function<List<SourceEstimation>, Promise<Project>>() {
@Override
public Promise<Project> apply(List<SourceEstimation> estimations) throws FunctionException {
if (estimations == null || estimations.isEmpty()) {
return promiseProvider.resolve(project);
}
final List<String> primeTypes = newArrayList();
for (SourceEstimation estimation : estimations) {
if (projectTypeRegistry.getProjectType(estimation.getType()).isPrimaryable()) {
primeTypes.add(estimation.getType());
}
}
final MutableProjectConfig config = new MutableProjectConfig(project);
final SourceStorage source = project.getSource();
if (source != null && source.getParameters() != null && source.getParameters().containsKey("keepDir")) {
config.setType(Constants.BLANK_ID);
} else if (primeTypes.isEmpty()) {
return promiseProvider.resolve(project);
} else if (primeTypes.size() == 1) {
config.setType(primeTypes.get(0));
} else {
config.setType(Constants.BLANK_ID);
projectWizard.show(config);
return promiseProvider.resolve(project);
}
return project.update().withBody(config).send();
}
}).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {
@Override
public Promise<Project> apply(PromiseError error) throws FunctionException {
Log.warn(ProjectResolver.class, error.getMessage());
return promiseProvider.resolve(project);
}
});
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class ShowRemoteAction method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
final Project project = appContext.getRootProject();
checkState(project != null, "Null project occurred");
presenter.showDialog(project);
}
Aggregations