diff --git a/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java b/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java index a7a2546565..f306ef201c 100644 --- a/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java +++ b/core/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java @@ -34,4 +34,5 @@ public class ErrorCodes { public static final int PROJECT_TYPE_IS_NOT_REGISTERED = 12; public static final int ATTRIBUTE_NAME_PROBLEM = 13; public static final int NOT_UPDATED_PROJECT = 14; + public static final int ITEM_NOT_FOUND = 15; } diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java index e88d8754cb..262d1fdc7b 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java @@ -69,6 +69,12 @@ public interface MavenLocalizationConstant extends Messages { @Key("maven.page.errorDialog.title") String mavenPageErrorDialogTitle(); + @Key("maven.page.archetype.disabled.title") + String mavenPageArchetypeDisabledTitle(); + + @Key("maven.page.archetype.disabled.message") + String mavenPageArchetypeDisabledMessage(); + /* Preferences page*/ @Key("maven.preferences.title") String mavenPreferencesTitle(); diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/wizard/MavenPagePresenter.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/wizard/MavenPagePresenter.java index 2e2d697d65..06e45035b6 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/wizard/MavenPagePresenter.java +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/wizard/MavenPagePresenter.java @@ -13,6 +13,8 @@ package org.eclipse.che.plugin.maven.client.wizard; import static com.google.common.base.MoreObjects.firstNonNull; import static java.util.Collections.singletonList; +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.WARNING; import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode.CREATE; import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode.UPDATE; import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar.WIZARD_MODE_KEY; @@ -46,10 +48,13 @@ 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.ide.api.app.AppContext; +import org.eclipse.che.ide.api.notification.NotificationManager; import org.eclipse.che.ide.api.project.MutableProjectConfig; import org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode; import org.eclipse.che.ide.api.resources.Container; import org.eclipse.che.ide.api.wizard.AbstractWizardPage; +import org.eclipse.che.ide.project.ProjectServiceClient; +import org.eclipse.che.ide.resource.Path; import org.eclipse.che.ide.ui.dialogs.DialogFactory; import org.eclipse.che.ide.util.loging.Log; import org.eclipse.che.plugin.maven.client.MavenArchetype; @@ -67,18 +72,24 @@ public class MavenPagePresenter extends AbstractWizardPage private final DialogFactory dialogFactory; private final AppContext appContext; private final MavenLocalizationConstant localization; + private final NotificationManager notificationManager; + private final ProjectServiceClient projectService; @Inject public MavenPagePresenter( MavenPageView view, DialogFactory dialogFactory, AppContext appContext, - MavenLocalizationConstant localization) { + MavenLocalizationConstant localization, + NotificationManager notificationManager, + ProjectServiceClient projectService) { super(); this.view = view; this.dialogFactory = dialogFactory; this.appContext = appContext; this.localization = localization; + this.notificationManager = notificationManager; + this.projectService = projectService; view.setDelegate(this); } @@ -197,7 +208,6 @@ public class MavenPagePresenter extends AbstractWizardPage @Override public void go(AcceptsOneWidget container) { - container.setWidget(view); final ProjectWizardMode wizardMode = ProjectWizardMode.parse(context.get(WIZARD_MODE_KEY)); final String projectName = dataObject.getName(); @@ -212,11 +222,34 @@ public class MavenPagePresenter extends AbstractWizardPage } updateDelegate.updateControls(); } + if (CREATE == wizardMode) { + projectService + .getItem(Path.valueOf(dataObject.getPath()).parent().append("pom.xml")) + .then( + result -> { + notificationManager.notify( + localization.mavenPageArchetypeDisabledTitle(), + localization.mavenPageArchetypeDisabledMessage(), + WARNING, + EMERGE_MODE); + updateView(container, false); + }) + .catchError( + error -> { + updateView(container, true); + }); + } else { + updateView(container, false); + } + } + + private void updateView(AcceptsOneWidget container, boolean showArchetype) { + container.setWidget(view); updateView(); validateCoordinates(); - view.setArchetypeSectionVisibility(CREATE == wizardMode); + view.setArchetypeSectionVisibility(showArchetype); view.enableArchetypes(view.isGenerateFromArchetypeSelected()); } diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties b/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties index bdd6c2be8c..dde59afd43 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties @@ -41,6 +41,9 @@ window.loader.title=Resolving dependencies maven.page.errorDialog.title=Not valid Maven project maven.page.estimate.errorMessage=Source code not matches Maven project type requirements +maven.page.archetype.disabled.title=Maven project configuration +maven.page.archetype.disabled.message=''From Archetype'' section is disabled because selected parent contains ''pom.xml'' file + ##### Preferences page ##### maven.preferences.title=Maven maven.preferences.show.artifact.id.checkbox.text=Show artifact id in project explorer diff --git a/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/server/projecttype/handler/ArchetypeGenerationStrategy.java b/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/server/projecttype/handler/ArchetypeGenerationStrategy.java index 608ab7bb74..469771c73e 100644 --- a/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/server/projecttype/handler/ArchetypeGenerationStrategy.java +++ b/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/server/projecttype/handler/ArchetypeGenerationStrategy.java @@ -20,7 +20,9 @@ import static org.eclipse.che.plugin.maven.shared.MavenAttributes.DEFAULT_VERSIO import static org.eclipse.che.plugin.maven.shared.MavenAttributes.GROUP_ID; import static org.eclipse.che.plugin.maven.shared.MavenAttributes.VERSION; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -101,6 +103,11 @@ public class ArchetypeGenerationStrategy implements GeneratorStrategy { "Missed some required option (archetypeGroupId, archetypeArtifactId or archetypeVersion)"); } + Path projectsParentPath = Paths.get(rootDirPathProvider.get(), projectPath).getParent(); + if (Files.exists(projectsParentPath.resolve("pom.xml"))) { + throw new ServerException("Parent path witch contains 'pom.xml' file is not allowed"); + } + MavenArchetype mavenArchetype = new MavenArchetypeImpl( archetypeGroupId, @@ -115,6 +122,6 @@ public class ArchetypeGenerationStrategy implements GeneratorStrategy { mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectName)); mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION)); archetypeGenerator.generateFromArchetype( - projectName, new File(rootDirPathProvider.get()), mavenArchetype, mavenArtifact); + projectName, projectsParentPath.toFile(), mavenArchetype, mavenArtifact); } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Wizard.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Wizard.java index 8aa3065f80..2ee420d10f 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Wizard.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Wizard.java @@ -11,6 +11,7 @@ */ package org.eclipse.che.selenium.pageobject; +import static java.util.Collections.singletonList; import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.ELEMENT_TIMEOUT_SEC; import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC; import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC; @@ -514,6 +515,14 @@ public class Wizard { .until(ExpectedConditions.visibilityOf(archetypeDropDown)); } + /** wait for the archetype section in the import widget to be invisible */ + public void waitInvisibilityOfAchetypeSection() { + new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until(ExpectedConditions.invisibilityOfAllElements(singletonList(fromArchetypeChkBox))); + new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until(ExpectedConditions.invisibilityOfAllElements(singletonList(archetypeDropDown))); + } + public void selectArcheTypeFromList(Archetypes type) { clickOnFromArchetypeChkBox(); waitArcheTypeDropdawn(); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/mavenplugin/CheckGeneratingMavenArchetypeTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/mavenplugin/CheckGeneratingMavenArchetypeTest.java index f433f98920..e2155a021e 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/mavenplugin/CheckGeneratingMavenArchetypeTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/mavenplugin/CheckGeneratingMavenArchetypeTest.java @@ -18,9 +18,11 @@ import org.eclipse.che.selenium.core.constant.TestBuildConstants; import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants; import org.eclipse.che.selenium.core.workspace.TestWorkspace; import org.eclipse.che.selenium.pageobject.CodenvyEditor; +import org.eclipse.che.selenium.pageobject.ConfigureClasspath; import org.eclipse.che.selenium.pageobject.Consoles; import org.eclipse.che.selenium.pageobject.Ide; import org.eclipse.che.selenium.pageobject.Menu; +import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel; import org.eclipse.che.selenium.pageobject.ProjectExplorer; import org.eclipse.che.selenium.pageobject.Wizard; import org.testng.annotations.Test; @@ -37,6 +39,8 @@ public class CheckGeneratingMavenArchetypeTest { @Inject private CodenvyEditor editor; @Inject private Ide ide; @Inject private TestWorkspace workspace; + @Inject private ConfigureClasspath selectPath; + @Inject private NotificationsPopupPanel notificationsPopupPanel; @Test public void createMavenArchetypeStartProjectByWizard() throws Exception { @@ -74,4 +78,21 @@ public class CheckGeneratingMavenArchetypeTest { projectExplorer.openItemByPath(PROJECT_NAME + "/pom.xml"); editor.waitTextIntoEditor(expectedContnetInPomXml); } + + @Test(priority = 1) + public void shouldHideTheArchetypeFieldIfProjectPathHasPomXml() { + menu.runCommand( + TestMenuCommandsConstants.Workspace.WORKSPACE, + TestMenuCommandsConstants.Workspace.CREATE_PROJECT); + projectWizard.selectTypeProject(Wizard.TypeProject.MAVEN); + projectWizard.clickOnSelectPathForParentBtn(); + selectPath.openItemInSelectPathForm("Workspace"); + selectPath.selectItemInSelectPathForm(PROJECT_NAME); + selectPath.clickSelectBtnSelectPathForm(); + projectWizard.typeProjectNameOnWizard(PROJECT_NAME); + projectWizard.clickNextButton(); + projectWizard.waitInvisibilityOfAchetypeSection(); + notificationsPopupPanel.waitExpectedMessageOnProgressPanelAndClosed( + "'From Archetype' section is disabled because selected parent contains 'pom.xml' file"); + } } diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/fs/server/impl/SimpleFsDtoConverter.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/fs/server/impl/SimpleFsDtoConverter.java index d710b6d919..a014286ef4 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/fs/server/impl/SimpleFsDtoConverter.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/fs/server/impl/SimpleFsDtoConverter.java @@ -20,8 +20,10 @@ import java.util.List; import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; +import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.core.NotFoundException; import org.eclipse.che.api.core.model.workspace.config.ProjectConfig; +import org.eclipse.che.api.core.rest.shared.dto.ExtendedError; import org.eclipse.che.api.fs.server.FsDtoConverter; import org.eclipse.che.api.fs.server.FsManager; import org.eclipse.che.api.project.server.ProjectManager; @@ -43,7 +45,10 @@ public class SimpleFsDtoConverter implements FsDtoConverter { @Override public ItemReference asDto(String wsPath) throws NotFoundException { if (!fsManager.exists(wsPath)) { - throw new NotFoundException("Can't find item " + wsPath); + throw new NotFoundException( + newDto(ExtendedError.class) + .withMessage("Can't find item " + wsPath) + .withErrorCode(ErrorCodes.ITEM_NOT_FOUND)); } String name = nameOf(wsPath);