Skip to content

Commit

Permalink
CHE-5335: Add Git branch/revision link to project name (eclipse-che#5817
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vinokurig authored Aug 14, 2017
1 parent 4a1f5ac commit 03f7e01
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,8 @@ public interface Theme {

String projectExplorerHoverRowBorder();

String projectExplorerVcsHead();

/********************************************************************************************
*
* Loader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.che.ide.part.explorer.project;

import com.google.common.base.Optional;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
Expand All @@ -29,14 +30,15 @@
import org.eclipse.che.ide.api.data.tree.HasAttributes;
import org.eclipse.che.ide.api.data.tree.Node;
import org.eclipse.che.ide.api.data.tree.NodeInterceptor;
import org.eclipse.che.ide.api.data.tree.settings.HasSettings;
import org.eclipse.che.ide.api.parts.PerspectiveManager;
import org.eclipse.che.ide.api.parts.base.BaseView;
import org.eclipse.che.ide.api.parts.base.ToolButton;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.menu.ContextMenu;
import org.eclipse.che.ide.project.node.SyntheticNode;
import org.eclipse.che.ide.resources.tree.ContainerNode;
import org.eclipse.che.ide.resources.tree.ResourceNode;
import org.eclipse.che.ide.resources.tree.SkipHiddenNodesInterceptor;
import org.eclipse.che.ide.FontAwesome;
Expand Down Expand Up @@ -331,10 +333,8 @@ public Element render(Node node, String domID, Tree.Joint joint, int depth) {
final Resource resource = ((ResourceNode)node).getData();
element.setAttribute("path", resource.getLocation().toString());

final Optional<Project> project = resource.getRelatedProject();
if (project.isPresent()) {
element.setAttribute("project", project.get().getLocation().toString());
}
Project project = resource.getProject();
element.setAttribute("project", project.getLocation().toString());
}

if (node instanceof HasAction) {
Expand All @@ -351,6 +351,19 @@ public Element render(Node node, String domID, Tree.Joint joint, int depth) {
.setBackgroundColor(((HasAttributes)node).getAttributes().get(CUSTOM_BACKGROUND_FILL).get(0));
}

if (node instanceof ContainerNode) {
Container container = ((ContainerNode)node).getData();
if (container instanceof Project) {
String head = container.getProject().getAttribute("git.current.head.name");
if (head != null) {
Element nodeContainer = element.getFirstChildElement();
DivElement divElement = Document.get().createDivElement();
divElement.setInnerText("(" + head + ")");
divElement.setClassName(treeStyles.styles().vcsHeadContainer());
nodeContainer.insertBefore(divElement, nodeContainer.getLastChild());
}
}
}
return element;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.lang.System.arraycopy;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.stream;
import static org.eclipse.che.ide.api.resources.Resource.FILE;
import static org.eclipse.che.ide.api.resources.ResourceDelta.ADDED;
import static org.eclipse.che.ide.api.resources.ResourceDelta.COPIED_FROM;
Expand All @@ -84,6 +85,7 @@
import static org.eclipse.che.ide.api.resources.ResourceDelta.SYNCHRONIZED;
import static org.eclipse.che.ide.api.resources.ResourceDelta.UPDATED;
import static org.eclipse.che.ide.util.Arrays.add;
import static org.eclipse.che.ide.util.Arrays.contains;
import static org.eclipse.che.ide.util.Arrays.removeAll;
import static org.eclipse.che.ide.util.NameUtils.checkFileName;
import static org.eclipse.che.ide.util.NameUtils.checkFolderName;
Expand Down Expand Up @@ -681,7 +683,7 @@ public void visit(Resource resource) {
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, REMOVED)));
}

final Resource[] updated = removeAll(outdated, reloaded, true);
final Resource[] updated = stream(reloaded).filter(resource -> contains(outdated, resource)).toArray(Resource[]::new);
for (Resource resource : updated) {
store.register(resource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,11 @@ public String projectExplorerHoverRowBorder() {
return "#dbdbdb";
}

@Override
public String projectExplorerVcsHead() {
return "#c3bfbf";
}

@Override
public String loaderExpanderColor() {
return "#e3e3e3";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,11 @@ public String projectExplorerHoverRowBorder() {
return "#7b7b7b";
}

@Override
public String projectExplorerVcsHead() {
return "#7A8088";
}

@Override
public String loaderExpanderColor() {
return "#555555";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface CSS extends CssResource {

String infoTextContainer();

String vcsHeadContainer();

String descendantsContainer();

String selected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@eval projectExplorerSelectedRowBorder org.eclipse.che.ide.api.theme.Style.theme.projectExplorerSelectedRowBorder();
@eval projectExplorerHoverRowBackground org.eclipse.che.ide.api.theme.Style.theme.projectExplorerHoverRowBackground();
@eval projectExplorerHoverRowBorder org.eclipse.che.ide.api.theme.Style.theme.projectExplorerHoverRowBorder();
@eval projectExplorerVcsHead org.eclipse.che.ide.api.theme.Style.theme.projectExplorerVcsHead();


.noFocusOutline {
Expand Down Expand Up @@ -62,6 +63,18 @@
text-shadow: projectExplorerInfoTextShadow;
}

.vcsHeadContainer {
white-space: nowrap;
vertical-align: middle;
display: inline-block;
margin-top: -10px;
font-size: 1em;
font-style: italic;
padding-left: 2px;
text-shadow: projectExplorerPresentableTextShadow;
color: projectExplorerVcsHead;
}

.nodeContainer {
white-space: nowrap;
height: 20px;
Expand All @@ -73,13 +86,6 @@

.selected {
background-color: projectExplorerSelectedRowBackground !important;
/* Set default text color to selected item */
color: projectExplorerJointContainerFill !important;
}

/* Set default text color to nested elements of selected item */
.selected * {
color: projectExplorerJointContainerFill !important;
}

.hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
import org.eclipse.che.api.project.shared.dto.event.GitCheckoutEventDto;
import org.eclipse.che.api.project.shared.dto.event.GitCheckoutEventDto.Type;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.resources.impl.ResourceManager;
import org.eclipse.che.ide.util.loging.Log;

import javax.inject.Inject;
Expand All @@ -27,22 +29,26 @@
/**
* Receives git checkout notifications caught by server side VFS file watching system.
* Support two type of notifications: git branch checkout and git revision checkout.
* After a notification is received it is processed and passed to and instance of
* {@link NotificationManager}.
* After a notification is received it is processed and passed to an instance of
* {@link NotificationManager}. Updates attributes of the project from server to load
* new HEAD value to project attributes that are held in {@link ResourceManager}.
*/
@Singleton
public class GitCheckoutStatusNotificationHandler {
private final Provider<NotificationManager> notificationManagerProvider;
public class GitCheckoutHandler {
private final Provider<NotificationManager> notificationManagerProvider;
private final AppContext appContext;

@Inject
public GitCheckoutStatusNotificationHandler(Provider<NotificationManager> notificationManagerProvider,
RequestHandlerConfigurator configurator) {
public GitCheckoutHandler(Provider<NotificationManager> notificationManagerProvider,
RequestHandlerConfigurator configurator,
AppContext appContext) {
this.notificationManagerProvider = notificationManagerProvider;
this.appContext = appContext;

configureHandler(configurator);
}

public void configureHandler(RequestHandlerConfigurator configurator) {
private void configureHandler(RequestHandlerConfigurator configurator) {
configurator.newConfiguration()
.methodName("event:git-checkout")
.paramsAsDto(GitCheckoutEventDto.class)
Expand Down Expand Up @@ -76,5 +82,8 @@ public void apply(String endpointId, GitCheckoutEventDto dto) {
break;
}
}

//Update project attributes from server.
appContext.getWorkspaceRoot().synchronize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public void onCheckoutClicked() {

service.checkout(project.getLocation(), checkoutRequest)
.then(ignored -> {
getBranches();
project.synchronize();
view.close();
})
.catchError(error -> {
handleError(error.getCause(), BRANCH_CHECKOUT_COMMAND_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.che.ide.api.extension.ExtensionGinModule;
import org.eclipse.che.ide.api.preferences.PreferencePagePresenter;
import org.eclipse.che.ide.api.project.wizard.ImportWizardRegistrar;
import org.eclipse.che.ide.ext.git.client.GitCheckoutStatusNotificationHandler;
import org.eclipse.che.ide.ext.git.client.GitCheckoutHandler;
import org.eclipse.che.ide.ext.git.client.add.AddToIndexView;
import org.eclipse.che.ide.ext.git.client.add.AddToIndexViewImpl;
import org.eclipse.che.ide.ext.git.client.branch.BranchView;
Expand Down Expand Up @@ -92,6 +92,6 @@ protected void configure() {
install(new GinFactoryModuleBuilder().implement(GitOutputConsole.class, GitOutputConsolePresenter.class)
.build(GitOutputConsoleFactory.class));

bind(GitCheckoutStatusNotificationHandler.class).asEagerSingleton();
bind(GitCheckoutHandler.class).asEagerSingleton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
*******************************************************************************/
package org.eclipse.che.api.git;

import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
import org.eclipse.che.api.project.server.ProjectRegistry;
import org.eclipse.che.api.project.shared.dto.event.GitCheckoutEventDto;
import org.eclipse.che.api.project.shared.dto.event.GitCheckoutEventDto.Type;
import org.eclipse.che.api.vfs.Path;
Expand Down Expand Up @@ -51,16 +54,21 @@ public class GitCheckoutDetector {
private final VirtualFileSystemProvider vfsProvider;
private final RequestTransmitter transmitter;
private final FileWatcherManager manager;
private final ProjectRegistry projectRegistry;

private final Set<String> endpointIds = newConcurrentHashSet();

private int id;

@Inject
public GitCheckoutDetector(VirtualFileSystemProvider vfsProvider, RequestTransmitter transmitter, FileWatcherManager manager) {
public GitCheckoutDetector(VirtualFileSystemProvider vfsProvider,
RequestTransmitter transmitter,
FileWatcherManager manager,
ProjectRegistry projectRegistry) {
this.vfsProvider = vfsProvider;
this.transmitter = transmitter;
this.manager = manager;
this.projectRegistry = projectRegistry;
}

@Inject
Expand Down Expand Up @@ -111,10 +119,15 @@ private Consumer<String> fsEventConsumer() {
Type type = content.contains("ref:") ? BRANCH : REVISION;
String name = type == REVISION ? content : PATTERN.split(content)[1];

//Update project attributes with new git values
projectRegistry.setProjectType(it.split("/")[1], GitProjectType.TYPE_ID, true);

endpointIds.forEach(transmitConsumer(type, name));

} catch (ServerException | ForbiddenException e) {
LOG.error("Error trying to read {} file and broadcast it", it, e);
} catch (NotFoundException | ConflictException e) {
LOG.error("Error trying to update project attributes", it, e);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
@Singleton
public class GitProjectType extends TransientMixin {

public static final String TYPE_ID = "git";
public static final String DISPLAY_NAME = "git";
public static final String VCS_PROVIDER_NAME = "vcs.provider.name";
public static final String GIT_CURRENT_BRANCH_NAME = "git.current.branch.name";
public static final String GIT_REPOSITORY_REMOTES = "git.repository.remotes";
public static final String TYPE_ID = "git";
public static final String DISPLAY_NAME = "git";
public static final String VCS_PROVIDER_NAME = "vcs.provider.name";
public static final String GIT_CURRENT_HEAD_NAME = "git.current.head.name";
public static final String GIT_REPOSITORY_REMOTES = "git.repository.remotes";

@Inject
public GitProjectType(GitValueProviderFactory gitRepositoryValueProviderFactory) {
super(TYPE_ID, DISPLAY_NAME);
addVariableDefinition(VCS_PROVIDER_NAME, "Is this git repo or not?", true,
gitRepositoryValueProviderFactory);
addVariableDefinition(GIT_CURRENT_BRANCH_NAME, "Name of current git branch", false,
addVariableDefinition(GIT_CURRENT_HEAD_NAME, "Name of current git branch or revision", false,
gitRepositoryValueProviderFactory);
addVariableDefinition(GIT_REPOSITORY_REMOTES, "List of git repository remote addresses", false,
gitRepositoryValueProviderFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.inject.Inject;

import org.eclipse.che.api.core.ApiException;
import org.eclipse.che.api.git.params.LogParams;
import org.eclipse.che.api.git.shared.Remote;
import org.eclipse.che.api.project.server.FolderEntry;
import org.eclipse.che.api.project.server.type.ReadonlyValueProvider;
Expand All @@ -25,7 +26,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.eclipse.che.api.git.GitProjectType.GIT_CURRENT_BRANCH_NAME;
import static java.util.Collections.singletonList;
import static org.eclipse.che.api.git.GitProjectType.GIT_CURRENT_HEAD_NAME;
import static org.eclipse.che.api.git.GitProjectType.GIT_REPOSITORY_REMOTES;
import static org.eclipse.che.api.git.GitProjectType.VCS_PROVIDER_NAME;

Expand Down Expand Up @@ -54,9 +56,14 @@ public List<String> getValues(String attributeName) throws ValueStorageException

switch (attributeName) {
case VCS_PROVIDER_NAME:
return Collections.singletonList("git");
case GIT_CURRENT_BRANCH_NAME:
return Collections.singletonList(gitConnection.getCurrentBranch());
return singletonList("git");
case GIT_CURRENT_HEAD_NAME:
String currentBranch = gitConnection.getCurrentBranch();
return singletonList("HEAD".equals(currentBranch) ? gitConnection.log(LogParams.create().withMaxCount(1))
.getCommits()
.get(0)
.getId()
: currentBranch);
case GIT_REPOSITORY_REMOTES:
return gitConnection.remoteList(null, false)
.stream()
Expand Down

0 comments on commit 03f7e01

Please sign in to comment.