Search in sources :

Example 1 with MutableProjectConfig

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);
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 2 with 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);
    }
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 3 with MutableProjectConfig

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");
                        }
                    });
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List) ArrayList(java.util.ArrayList) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 4 with MutableProjectConfig

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());
            }
        }
    });
}
Also used : Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) ProjectNotificationSubscriber(org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Map(java.util.Map)

Example 5 with MutableProjectConfig

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);
        }
    });
}
Also used : MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) PromiseError(org.eclipse.che.api.promises.client.PromiseError) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Aggregations

MutableProjectConfig (org.eclipse.che.ide.api.project.MutableProjectConfig)13 List (java.util.List)3 Function (org.eclipse.che.api.promises.client.Function)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 Promise (org.eclipse.che.api.promises.client.Promise)3 Project (org.eclipse.che.ide.api.resources.Project)3 Resource (org.eclipse.che.ide.api.resources.Resource)3 Provider (com.google.inject.Provider)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 WizardPage (org.eclipse.che.ide.api.wizard.WizardPage)2 ImportWizard (org.eclipse.che.ide.projectimport.wizard.ImportWizard)2 Path (org.eclipse.che.ide.resource.Path)2 Optional (com.google.common.base.Optional)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)1 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)1 AttributeDto (org.eclipse.che.api.project.shared.dto.AttributeDto)1