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-998. Add 'Reimport' action for maven project #1277

Merged
merged 1 commit into from
May 24, 2016
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -32,7 +32,6 @@ public interface IdeActions {
String GROUP_RIGHT_TOOLBAR = "rightToolBar";

String GROUP_MAIN_CONTEXT_MENU = "mainContextMenu";
String GROUP_BUILD_CONTEXT_MENU = "buildGroupContextMenu";
String GROUP_RUN_CONTEXT_MENU = "runGroupContextMenu";
String GROUP_DEBUG_CONTEXT_MENU = "debugGroupContextMenu";
String GROUP_PROJECT_EXPLORER_CONTEXT_MENU = "projectExplorerContextMenu";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ private void registerDefaultActionGroups() {
DefaultActionGroup mainContextMenuGroup = new DefaultActionGroup(IdeActions.GROUP_MAIN_CONTEXT_MENU, false, this);
registerAction(IdeActions.GROUP_MAIN_CONTEXT_MENU, mainContextMenuGroup);

DefaultActionGroup buildContextMenuGroup = new DefaultActionGroup(IdeActions.GROUP_BUILD_CONTEXT_MENU, false, this);
registerAction(IdeActions.GROUP_BUILD_CONTEXT_MENU, buildContextMenuGroup);

DefaultActionGroup runContextMenuGroup = new DefaultActionGroup(IdeActions.GROUP_RUN_CONTEXT_MENU, false, this);
registerAction(IdeActions.GROUP_RUN_CONTEXT_MENU, runContextMenuGroup);
mainContextMenuGroup.add(runContextMenuGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.DefaultActionGroup;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.constraints.Constraints;
import org.eclipse.che.ide.api.editor.EditorRegistry;
import org.eclipse.che.ide.api.editor.texteditor.EditorResources;
import org.eclipse.che.ide.api.filetypes.FileType;
Expand Down Expand Up @@ -538,7 +539,7 @@ public void initialize() {
resourceOperation.add(convertFolderToProjectAction);

DefaultActionGroup mainContextMenuGroup = (DefaultActionGroup)actionManager.getAction(IdeActions.GROUP_MAIN_CONTEXT_MENU);
mainContextMenuGroup.add(newGroup);
mainContextMenuGroup.add(newGroup, Constraints.FIRST);
mainContextMenuGroup.addSeparator();
mainContextMenuGroup.add(resourceOperation);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.DefaultActionGroup;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.constraints.Constraints;
import org.eclipse.che.ide.api.editor.EditorRegistry;
import org.eclipse.che.ide.api.extension.Extension;
import org.eclipse.che.ide.api.filetypes.FileType;
import org.eclipse.che.ide.api.filetypes.FileTypeRegistry;
import org.eclipse.che.ide.api.project.type.wizard.PreSelectedProjectTypeManager;
import org.eclipse.che.plugin.maven.client.actions.GetEffectivePomAction;
import org.eclipse.che.plugin.maven.client.actions.MavenActionsConstants;
import org.eclipse.che.plugin.maven.client.actions.ReimportMavenDependenciesAction;
import org.eclipse.che.plugin.maven.client.comunnication.MavenMessagesHandler;
import org.eclipse.che.plugin.maven.client.comunnication.progressor.background.DependencyResolverAction;
import org.eclipse.che.plugin.maven.client.editor.ClassFileSourcesDownloader;
Expand All @@ -32,8 +33,10 @@
import java.util.Arrays;
import java.util.List;

import static org.eclipse.che.ide.api.action.IdeActions.GROUP_BUILD_CONTEXT_MENU;
import static org.eclipse.che.ide.api.action.IdeActions.GROUP_ASSISTANT;
import static org.eclipse.che.ide.api.action.IdeActions.GROUP_RIGHT_STATUS_PANEL;
import static org.eclipse.che.plugin.maven.client.actions.MavenActionsConstants.MAVEN_GROUP_CONTEXT_MENU_ID;
import static org.eclipse.che.plugin.maven.client.actions.MavenActionsConstants.MAVEN_GROUP_CONTEXT_MENU_NAME;

/**
* Maven extension entry point.
Expand All @@ -44,11 +47,14 @@
@Extension(title = "Maven", version = "3.0.0")
public class MavenExtension {
private static List<MavenArchetype> archetypes;
private final MavenResources resources;

@Inject
public MavenExtension(PreSelectedProjectTypeManager preSelectedProjectManager,
MavenMessagesHandler messagesHandler,
ClassFileSourcesDownloader downloader) {
ClassFileSourcesDownloader downloader,
MavenResources resources) {
this.resources = resources;

preSelectedProjectManager.setProjectTypeIdToPreselect(MavenAttributes.MAVEN_ID, 100);

Expand All @@ -65,17 +71,29 @@ public static List<MavenArchetype> getAvailableArchetypes() {
@Inject
private void prepareActions(ActionManager actionManager,
DependencyResolverAction dependencyResolverAction,
GetEffectivePomAction getEffectivePomAction) {
GetEffectivePomAction getEffectivePomAction,
ReimportMavenDependenciesAction reimportMavenDependenciesAction) {
// register actions
actionManager.registerAction("getEffectivePom", getEffectivePomAction);
actionManager.registerAction("reimportMavenDependenciesAction", reimportMavenDependenciesAction);

// add actions in main menu
DefaultActionGroup assistantGroup = (DefaultActionGroup)actionManager.getAction(IdeActions.GROUP_ASSISTANT);
DefaultActionGroup assistantGroup = (DefaultActionGroup)actionManager.getAction(GROUP_ASSISTANT);
assistantGroup.add(getEffectivePomAction, Constraints.LAST);

// create maven context menu
DefaultActionGroup mavenContextMenuGroup = new DefaultActionGroup(MAVEN_GROUP_CONTEXT_MENU_NAME, true, actionManager);
actionManager.registerAction(MAVEN_GROUP_CONTEXT_MENU_ID, mavenContextMenuGroup);
mavenContextMenuGroup.getTemplatePresentation().setSVGResource(resources.maven());

// add maven context menu to main context menu
DefaultActionGroup mainContextMenuGroup = (DefaultActionGroup)actionManager.getAction("resourceOperation");
mainContextMenuGroup.addSeparator();
mainContextMenuGroup.add(mavenContextMenuGroup, Constraints.LAST);

// add actions in context menu
DefaultActionGroup buildContextMenuGroup = (DefaultActionGroup)actionManager.getAction(GROUP_BUILD_CONTEXT_MENU);
buildContextMenuGroup.addSeparator();
mavenContextMenuGroup.add(reimportMavenDependenciesAction);
mavenContextMenuGroup.addSeparator();

// add resolver widget on right part of bottom panel
final DefaultActionGroup rightStatusPanelGroup = (DefaultActionGroup)actionManager.getAction(GROUP_RIGHT_STATUS_PANEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public interface MavenLocalizationConstant extends Messages {
@Key("action.effectivePom.description")
String actionGetEffectivePomDescription();

@Key("action.reimportDependencies.title")
String actionReimportDependenciesTitle();

@Key("action.reimportDependencies.description")
String actionReimportDependenciesDescription();

@Key("action.createMavenModule.description")
String actionCreateMavenModuleDescription();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.maven.client.actions;

/** @author Roman Nikitenko */
public final class MavenActionsConstants {
private MavenActionsConstants() {
}

public static final String MAVEN_GROUP_CONTEXT_MENU_NAME = "Maven";
public static final String MAVEN_GROUP_CONTEXT_MENU_ID = "mavenGroupContextMenu";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.maven.client.actions;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.ide.Resources;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.selection.Selection;
import org.eclipse.che.ide.api.selection.SelectionAgent;
import org.eclipse.che.ide.project.node.ProjectNode;
import org.eclipse.che.plugin.maven.client.MavenLocalizationConstant;
import org.eclipse.che.plugin.maven.client.service.MavenServerServiceClient;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;
import static org.eclipse.che.plugin.maven.shared.MavenAttributes.MAVEN_ID;

/**
* Action for reimport maven dependencies.
*
* @author Roman Nikitenko
*/
@Singleton
public class ReimportMavenDependenciesAction extends AbstractPerspectiveAction {

private final SelectionAgent selectionAgent;
private final NotificationManager notificationManager;
private final MavenServerServiceClient mavenServerServiceClient;

@Inject
public ReimportMavenDependenciesAction(MavenLocalizationConstant constant,
SelectionAgent selectionAgent,
NotificationManager notificationManager,
Resources resources,
MavenServerServiceClient mavenServerServiceClient) {
super(Collections.singletonList(PROJECT_PERSPECTIVE_ID),
constant.actionReimportDependenciesTitle(),
constant.actionReimportDependenciesDescription(),
null,
resources.refresh());
this.selectionAgent = selectionAgent;
this.notificationManager = notificationManager;
this.mavenServerServiceClient = mavenServerServiceClient;
}


@Override
public void updateInPerspective(@NotNull ActionEvent event) {
event.getPresentation().setEnabledAndVisible(isMavenProjectSelected());
}

@Override
public void actionPerformed(ActionEvent e) {
mavenServerServiceClient.reimportDependencies(getPathsToSelectedMavenProject()).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify("Problem with reimporting maven dependencies", arg.getMessage(), FAIL, EMERGE_MODE);
}
});
}

private boolean isMavenProjectSelected() {
return !getPathsToSelectedMavenProject().isEmpty();
}

private List<String> getPathsToSelectedMavenProject() {
List<String> paths = new ArrayList<>();
Selection<?> selection = selectionAgent.getSelection();
for (Object aSelection: selection.getAllElements()) {
if (!(aSelection instanceof ProjectNode)) {
continue;
}

ProjectConfigDto projectConfig = ((ProjectNode)aSelection).getProjectConfig();
if (MAVEN_ID.equals(projectConfig.getType())) {
paths.add(projectConfig.getPath());
}
}
return paths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public interface MavenServerServiceClient {
*/
Promise<Boolean> downloadSources(String projectPath, String fqn);

/**
* Invokes reimporting maven dependencies.
*
* @param projectsPaths
* the paths to projects which need to be reimported dependencies
*/
Promise<Void> reimportDependencies(List<String> projectsPaths);

/**
* Invokes reconciling for pom.xml file
* @param pomPath tha path to pom.xml file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.che.ide.rest.Unmarshallable;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;

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

/**
Expand Down Expand Up @@ -81,6 +82,17 @@ public Boolean getPayload() {
});
}

@Override
public Promise<Void> reimportDependencies(@NotNull List<String> projectsPaths) {
StringBuilder queryParameters = new StringBuilder();
for (String path : projectsPaths) {
queryParameters.append("&projectPath=").append(path);
}
final String url = appContext.getDevMachine().getWsAgentBaseUrl() + servicePath + "reimport" +
queryParameters.toString().replaceFirst("&", "?");
return asyncRequestFactory.createPutRequest(url, null).send();
}

@Override
public Promise<List<Problem>> reconcilePom(String pomPath) {
final String url = appContext.getDevMachine().getWsAgentBaseUrl() + servicePath + "pom/reconsile?pompath=" + pomPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ action.createMavenModule.text = Maven Module
action.createMavenModule.description = Create new Maven module
action.effectivePom.title = Generate Effective Pom
action.effectivePom.description = Generate effective pom for current project
action.reimportDependencies.title = Reimport
action.reimportDependencies.description = Reimport maven dependencies

##### MavenCommandPageView #####
view.mavenCommandPage.commandLine.text = Command line
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion plugins/plugin-maven/che-plugin-maven-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
Expand Down Expand Up @@ -287,4 +291,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Loading