Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-6162: Fix problem project detection procedure #6264

Merged
merged 7 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface ProjectConfig {
Map<String, List<String>> getAttributes();

SourceStorage getSource();

List<? extends ProjectProblem> getProblems();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.eclipse.che.api.core.model.project;

/** @author Vitalii Parfonov */
public interface ProjectProblem {

int getCode();

String getMessage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;
import org.eclipse.che.api.core.model.project.NewProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.machine.shared.dto.CommandDto;

Expand All @@ -35,6 +36,7 @@ public class MutableProjectConfig implements ProjectConfig {
private Map<String, String> options;
private List<NewProjectConfig> projects;
private List<CommandDto> commands;
private List<? extends ProjectProblem> problems;

public MutableProjectConfig(ProjectConfig source) {
name = source.getName();
Expand All @@ -44,6 +46,7 @@ public MutableProjectConfig(ProjectConfig source) {
mixins = newArrayList(source.getMixins());
attributes = newHashMap(source.getAttributes());
sourceStorage = new MutableSourceStorage(source.getSource());
problems = source.getProblems();
}

public MutableProjectConfig() {}
Expand Down Expand Up @@ -119,6 +122,11 @@ public MutableSourceStorage getSource() {
return sourceStorage;
}

@Override
public List<? extends ProjectProblem> getProblems() {
return problems;
}

public void setSource(SourceStorage sourceStorage) {
this.sourceStorage = new MutableSourceStorage(sourceStorage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
package org.eclipse.che.ide.api.project;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.core.model.project.NewProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.project.templates.shared.dto.ProjectTemplateDescriptor;
import org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto;
Expand Down Expand Up @@ -170,4 +172,9 @@ public void setOptions(Map<String, String> options) {
public SourceStorage getSource() {
return sourceStorage;
}

@Override
public List<ProjectProblem> getProblems() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.inject.client.multibindings.GinMultibinder;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.auth.OAuthServiceClient;
import org.eclipse.che.ide.api.auth.OAuthServiceClientImpl;
import org.eclipse.che.ide.api.oauth.OAuth2Authenticator;
import org.eclipse.che.ide.api.oauth.OAuth2AuthenticatorRegistry;

Expand All @@ -33,5 +35,7 @@ protected void configure() {
bind(OAuth2AuthenticatorRegistry.class)
.to(OAuth2AuthenticatorRegistryImpl.class)
.in(Singleton.class);

bind(OAuthServiceClient.class).to(OAuthServiceClientImpl.class).in(Singleton.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.core.model.project.ProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.project.shared.dto.SourceEstimation;
import org.eclipse.che.api.promises.client.Promise;
Expand Down Expand Up @@ -96,6 +97,11 @@ public SourceStorage getSource() {
return reference.getSource();
}

@Override
public List<ProjectProblem> getProblems() {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to return actual list of problems? reference.getProblems() WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thx

}

/** {@inheritDoc} */
@Override
public ProjectRequest update() {
Expand Down Expand Up @@ -126,7 +132,7 @@ public Promise<Project> send() {
/** {@inheritDoc} */
@Override
public boolean isProblem() {
return getMarker(ProblemProjectMarker.PROBLEM_PROJECT).isPresent();
return reference.getProblems() != null && !reference.getProblems().isEmpty();
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@
*/
package org.eclipse.che.ide.resources.tree;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Lists.newArrayListWithExpectedSize;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static org.eclipse.che.ide.api.resources.Resource.FILE;
import static org.eclipse.che.ide.api.resources.Resource.FOLDER;
import static org.eclipse.che.ide.api.resources.Resource.PROJECT;
import static org.eclipse.che.ide.api.vcs.VcsStatus.NOT_MODIFIED;

import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.web.bindery.event.shared.EventBus;
import java.util.List;
import java.util.Set;
import javax.validation.constraints.NotNull;

import org.eclipse.che.api.promises.client.Function;
import org.eclipse.che.api.promises.client.FunctionException;
import org.eclipse.che.api.promises.client.Promise;
Expand All @@ -49,8 +37,23 @@
import org.eclipse.che.ide.project.shared.NodesResources;
import org.eclipse.che.ide.ui.smartTree.presentation.HasPresentation;
import org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation;
import org.eclipse.che.ide.util.loging.Log;
import org.vectomatic.dom.svg.ui.SVGResource;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Lists.newArrayListWithExpectedSize;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static org.eclipse.che.ide.api.resources.Resource.FILE;
import static org.eclipse.che.ide.api.resources.Resource.FOLDER;
import static org.eclipse.che.ide.api.resources.Resource.PROJECT;
import static org.eclipse.che.ide.api.vcs.VcsStatus.NOT_MODIFIED;

/**
* Abstract based implementation for all resource based nodes in the IDE.
*
Expand Down Expand Up @@ -146,14 +149,15 @@ public final NodePresentation getPresentation(boolean update) {
nodePresentation = new NodePresentation();
}

updatePresentation(nodePresentation);
if (update) {
updatePresentation(nodePresentation);
}

return nodePresentation;
}

@Override
public void updatePresentation(@NotNull NodePresentation presentation) {

final StringBuilder cssBuilder = new StringBuilder();

final Optional<Marker> presentableTextMarker = getData().getMarker(PresentableTextMarker.ID);
Expand Down Expand Up @@ -189,6 +193,7 @@ public void updatePresentation(@NotNull NodePresentation presentation) {
? nodesResources.hiddenSimpleFolder()
: nodesResources.simpleFolder());
} else if (getData().getResourceType() == PROJECT) {
Log.info(getClass(), ((Project) getData()).isProblem());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-informative info log

presentation.setPresentableIcon(
((Project) getData()).isProblem()
? nodesResources.notValidProjectFolder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.stream.Collectors;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.model.project.ProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.core.model.project.type.Attribute;
import org.eclipse.che.api.project.server.importer.ProjectImporter;
Expand Down Expand Up @@ -146,7 +147,9 @@ public static SourceStorageDto asDto(SourceStorage sourceStorage) {
return storageDto;
}

public static ProjectProblemDto asDto(RegisteredProject.Problem problem) {
return newDto(ProjectProblemDto.class).withCode(problem.code).withMessage(problem.message);
public static ProjectProblemDto asDto(ProjectProblem problem) {
return newDto(ProjectProblemDto.class)
.withCode(problem.getCode())
.withMessage(problem.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import static com.google.common.collect.Maps.newHashMap;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.core.model.project.NewProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.project.server.type.BaseProjectType;
import org.eclipse.che.api.vfs.Path;
Expand Down Expand Up @@ -154,6 +156,11 @@ public SourceStorage getSource() {
return origin;
}

@Override
public List<ProjectProblem> getProblems() {
return Collections.emptyList();
}

@Override
public void setOptions(Map<String, String> options) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import org.eclipse.che.api.core.UnauthorizedException;
import org.eclipse.che.api.core.model.project.NewProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectConfig;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.core.model.project.type.ProjectType;
import org.eclipse.che.api.core.util.LineConsumerFactory;
import org.eclipse.che.api.project.server.RegisteredProject.Problem;
import org.eclipse.che.api.project.server.handlers.CreateProjectHandler;
import org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry;
import org.eclipse.che.api.project.server.importer.ProjectImporter;
Expand Down Expand Up @@ -308,9 +308,9 @@ private RegisteredProject doCreateProject(
* NewProjectConfig#setPath(String)} field. In this case Project will be created as project of
* {@link BaseProjectType} type
* <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>- a project will be created with {@link Problem#code} = 12 and without mixin project type
* when declared mixin project type is not registered
* ProjectProblem#getCode()} code} = 12 when declared primary project type is not registered,
* <li>- a project will be created with {@link ProjectProblem#getCode()} code} = 12 and without
* mixin project type when declared mixin project type is not registered
* <li>- for creating a project by generator {@link NewProjectConfig#getOptions()} should be
* specified.
*
Expand Down Expand Up @@ -377,8 +377,8 @@ public List<RegisteredProject> createBatchProjects(
} catch (Exception e) {
registeredProject =
projectRegistry.putProject(projectConfig, asFolder(pathToProject), true, false);
final Problem problem =
new Problem(
final ProjectProblem problem =
new ProjectProblemImpl(
NOT_UPDATED_PROJECT,
"The project is not updated, caused by " + e.getLocalizedMessage());
registeredProject.getProblems().add(problem);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.eclipse.che.api.project.server;

import org.eclipse.che.api.core.model.project.ProjectProblem;

/** @author Vitalii Parfonov */
public class ProjectProblemImpl implements ProjectProblem {

public ProjectProblemImpl(int code, String message) {
this.code = code;
this.message = message;
}

int code;
String message;

@Override
public int getCode() {
return code;
}

@Override
public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Map;
import java.util.Set;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.model.project.ProjectProblem;
import org.eclipse.che.api.core.model.project.type.Attribute;
import org.eclipse.che.api.project.server.RegisteredProject.Problem;
import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;

Expand All @@ -36,14 +36,14 @@ public class ProjectTypes {
private final Map<String, ProjectTypeDef> mixins;
private final Map<String, ProjectTypeDef> all;
private final Map<String, Attribute> attributeDefs;
private final List<Problem> problems;
private final List<ProjectProblem> problems;

ProjectTypes(
String projectPath,
String type,
List<String> mixinTypes,
ProjectTypeRegistry projectTypeRegistry,
List<Problem> problems) {
List<ProjectProblem> problems) {
mixins = new HashMap<>();
all = new HashMap<>();
attributeDefs = new HashMap<>();
Expand All @@ -55,7 +55,7 @@ public class ProjectTypes {
ProjectTypeDef tmpPrimary;
if (type == null) {
this.problems.add(
new Problem(
new ProjectProblemImpl(
PROJECT_TYPE_IS_NOT_REGISTERED,
"No primary type defined for " + projectPath + " Base Project Type assigned."));
tmpPrimary = ProjectTypeRegistry.BASE_TYPE;
Expand All @@ -64,7 +64,7 @@ public class ProjectTypes {
tmpPrimary = projectTypeRegistry.getProjectType(type);
} catch (NotFoundException e) {
this.problems.add(
new Problem(
new ProjectProblemImpl(
PROJECT_TYPE_IS_NOT_REGISTERED,
"Primary type "
+ type
Expand All @@ -76,7 +76,7 @@ public class ProjectTypes {

if (!tmpPrimary.isPrimaryable()) {
this.problems.add(
new Problem(
new ProjectProblemImpl(
PROJECT_TYPE_IS_NOT_REGISTERED,
"Project type "
+ tmpPrimary.getId()
Expand Down Expand Up @@ -108,15 +108,15 @@ public class ProjectTypes {
mixin = projectTypeRegistry.getProjectType(mixinFromConfig);
} catch (NotFoundException e) {
this.problems.add(
new Problem(
new ProjectProblemImpl(
PROJECT_TYPE_IS_NOT_REGISTERED,
"Project type " + mixinFromConfig + " is not registered. Skipped."));
continue;
}

if (!mixin.isMixable()) {
this.problems.add(
new Problem(
new ProjectProblemImpl(
PROJECT_TYPE_IS_NOT_REGISTERED,
"Project type "
+ mixin
Expand All @@ -134,7 +134,7 @@ public class ProjectTypes {
final Attribute attribute = attributeDefs.get(attrName);
if (attribute != null && !attribute.getProjectType().equals(attr.getProjectType())) {
this.problems.add(
new Problem(
new ProjectProblemImpl(
ATTRIBUTE_NAME_PROBLEM,
format(
"Attribute name conflict. Duplicated attributes detected for %s. "
Expand Down Expand Up @@ -219,7 +219,7 @@ void addTransient(FolderEntry projectFolder) {
// check whether it's the same attribute that comes from the common parent PT, e.g. from Base PT.
if (attribute != null && !attribute.getProjectType().equals(attr.getProjectType())) {
problems.add(
new Problem(
new ProjectProblemImpl(
ATTRIBUTE_NAME_PROBLEM,
format(
"Attribute name conflict. Duplicated attributes detected for %s. "
Expand Down
Loading