use of org.eclipse.che.ide.api.project.MutableProjectConfig in project che by eclipse.
the class ConvertFolderToProjectAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
Resource folder = getSelectedItem();
if (folder == null) {
return;
}
Path location = folder.getLocation();
if (location == null) {
return;
}
MutableProjectConfig mutableProjectConfig = new MutableProjectConfig();
mutableProjectConfig.setPath(location.toString());
mutableProjectConfig.setName(folder.getName());
projectConfigWizard.show(mutableProjectConfig);
}
use of org.eclipse.che.ide.api.project.MutableProjectConfig in project che by eclipse.
the class ProjectConfigurationAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final Resource[] resources = appContext.getResources();
checkState(resources != null && resources.length == 1);
final Resource resource = resources[0];
checkState(resource instanceof Container);
if (resource.getResourceType() == PROJECT) {
final MutableProjectConfig config = new MutableProjectConfig((Project) resource);
projectWizard.show(config);
}
}
use of org.eclipse.che.ide.api.project.MutableProjectConfig 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.project.MutableProjectConfig 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.project.MutableProjectConfig 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);
}
});
}
Aggregations