diff --git a/plugins/plugin-maven/che-plugin-maven-generator-archetype/pom.xml b/plugins/plugin-maven/che-plugin-maven-generator-archetype/pom.xml
index 60bb1b6908..23a0770500 100644
--- a/plugins/plugin-maven/che-plugin-maven-generator-archetype/pom.xml
+++ b/plugins/plugin-maven/che-plugin-maven-generator-archetype/pom.xml
@@ -46,10 +46,6 @@
javax.inject
javax.inject
-
- javax.validation
- validation-api
-
org.eclipse.che.core
che-core-api-core
@@ -58,6 +54,10 @@
org.eclipse.che.core
che-core-api-dto
+
+ org.eclipse.che.core
+ che-core-api-project
+
org.eclipse.che.plugin
che-plugin-java-maven-tools
diff --git a/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/main/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGenerator.java b/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/main/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGenerator.java
index 7919647120..393ee97625 100644
--- a/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/main/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGenerator.java
+++ b/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/main/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGenerator.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.che.plugin.maven.generator.archetype;
+import static java.io.File.separator;
import static org.eclipse.che.plugin.maven.shared.dto.ArchetypeOutput.State.DONE;
import static org.eclipse.che.plugin.maven.shared.dto.ArchetypeOutput.State.ERROR;
@@ -22,7 +23,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import javax.inject.Singleton;
-import javax.validation.constraints.NotNull;
+import org.eclipse.che.api.core.ConflictException;
+import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.core.util.AbstractLineConsumer;
@@ -31,6 +33,7 @@ import org.eclipse.che.api.core.util.LineConsumer;
import org.eclipse.che.api.core.util.ProcessUtil;
import org.eclipse.che.api.core.util.ValueHolder;
import org.eclipse.che.api.core.util.Watchdog;
+import org.eclipse.che.api.fs.server.FsManager;
import org.eclipse.che.ide.maven.tools.MavenArtifact;
import org.eclipse.che.ide.maven.tools.MavenUtils;
import org.eclipse.che.plugin.maven.shared.MavenArchetype;
@@ -48,22 +51,25 @@ public class ArchetypeGenerator {
private static final Logger LOG = LoggerFactory.getLogger(ArchetypeGenerator.class);
private EventService eventService;
+ private final FsManager fsManager;
@Inject
- public ArchetypeGenerator(EventService eventService) {
+ public ArchetypeGenerator(EventService eventService, FsManager fsManager) {
this.eventService = eventService;
+ this.fsManager = fsManager;
}
/**
* Generates a new project from the specified archetype by given maven artifact descriptor.
*
+ * @param projectName name of the project
* @param workDir folder where command will execute in common use root dir of workspace
* @param archetype archetype from which need to generate new project
* @param mavenArtifact maven artifact descriptor
* @throws ServerException if an error occurs while generating project
*/
public void generateFromArchetype(
- @NotNull File workDir, @NotNull MavenArchetype archetype, MavenArtifact mavenArtifact)
+ String projectName, File workDir, MavenArchetype archetype, MavenArtifact mavenArtifact)
throws ServerException {
Map archetypeProperties = new HashMap<>();
archetypeProperties.put(
@@ -74,6 +80,7 @@ public class ArchetypeGenerator {
archetypeProperties.put("-DgroupId", mavenArtifact.getGroupId());
archetypeProperties.put("-DartifactId", mavenArtifact.getArtifactId());
archetypeProperties.put("-Dversion", mavenArtifact.getVersion());
+ archetypeProperties.put("-Dbasedir", workDir.toPath().resolve(projectName).toString());
if (archetype.getRepository() != null) {
archetypeProperties.put("-DarchetypeRepository", archetype.getRepository());
}
@@ -83,11 +90,18 @@ public class ArchetypeGenerator {
final CommandLine commandLine = createCommandLine(archetypeProperties);
try {
execute(commandLine.toShellCommand(), workDir);
- } catch (TimeoutException e) {
- LOG.error(e.getMessage());
- } catch (IOException e) {
- LOG.error(e.getMessage());
- } catch (InterruptedException e) {
+ // TODO Remove this block and use 'basedir' option of the Maven Archetype Plugin when the
+ // related issue will be solved: https://issues.apache.org/jira/browse/ARCHETYPE-311.
+ // Maven Archetype Plugin creates project directory with 'artifact-id' name, so need to rename
+ // it to specified project name.
+ if (!fsManager.exists(projectName) && fsManager.exists(mavenArtifact.getArtifactId())) {
+ fsManager.move(separator + mavenArtifact.getArtifactId(), separator + projectName);
+ }
+ } catch (TimeoutException
+ | IOException
+ | InterruptedException
+ | ConflictException
+ | NotFoundException e) {
LOG.error(e.getMessage());
}
}
diff --git a/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/test/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGeneratorTest.java b/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/test/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGeneratorTest.java
index d7fde9f64a..aae2d59b0a 100644
--- a/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/test/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGeneratorTest.java
+++ b/plugins/plugin-maven/che-plugin-maven-generator-archetype/src/test/java/org/eclipse/che/plugin/maven/generator/archetype/ArchetypeGeneratorTest.java
@@ -18,6 +18,7 @@ import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import org.eclipse.che.api.core.notification.EventService;
+import org.eclipse.che.api.fs.server.FsManager;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.ide.maven.tools.MavenArtifact;
import org.eclipse.che.plugin.maven.shared.MavenArchetype;
@@ -41,14 +42,15 @@ public class ArchetypeGeneratorTest {
when(mavenArchetype.getGroupId()).thenReturn("org.apache.openejb.maven");
when(mavenArchetype.getVersion()).thenReturn("1.7.1");
File workDir = Files.createTempDirectory("workDir").toFile();
- ArchetypeGenerator archetypeGenerator = new ArchetypeGenerator(eventService);
+ ArchetypeGenerator archetypeGenerator =
+ new ArchetypeGenerator(eventService, mock(FsManager.class));
String artifactId = NameGenerator.generate("artifactId", 5);
String groupId = NameGenerator.generate("groupId", 5);
MavenArtifact mavenArtifact = new MavenArtifact();
mavenArtifact.setArtifactId(artifactId);
mavenArtifact.setGroupId(groupId);
mavenArtifact.setVersion("1.0-SNAPSHOT");
- archetypeGenerator.generateFromArchetype(workDir, mavenArchetype, mavenArtifact);
+ archetypeGenerator.generateFromArchetype("projectName", workDir, mavenArchetype, mavenArtifact);
String[] list = workDir.list();
List strings = Arrays.asList(list);
Assert.assertTrue(strings.contains(artifactId));
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 df32d6d1de..280f9ece0e 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
@@ -25,9 +25,8 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.eclipse.che.api.core.ConflictException;
-import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.ServerException;
+import org.eclipse.che.api.project.server.impl.RootDirPathProvider;
import org.eclipse.che.api.project.server.type.AttributeValue;
import org.eclipse.che.ide.maven.tools.MavenArtifact;
import org.eclipse.che.plugin.maven.generator.archetype.ArchetypeGenerator;
@@ -43,10 +42,13 @@ import org.eclipse.che.plugin.maven.shared.MavenArchetype;
public class ArchetypeGenerationStrategy implements GeneratorStrategy {
private final ArchetypeGenerator archetypeGenerator;
+ private final RootDirPathProvider rootDirPathProvider;
@Inject
- public ArchetypeGenerationStrategy(ArchetypeGenerator archetypeGenerator) throws ServerException {
+ public ArchetypeGenerationStrategy(
+ ArchetypeGenerator archetypeGenerator, RootDirPathProvider rootDirPathProvider) {
this.archetypeGenerator = archetypeGenerator;
+ this.rootDirPathProvider = rootDirPathProvider;
}
public String getId() {
@@ -56,7 +58,7 @@ public class ArchetypeGenerationStrategy implements GeneratorStrategy {
@Override
public void generateProject(
String projectPath, Map attributes, Map options)
- throws ForbiddenException, ConflictException, ServerException {
+ throws ServerException {
AttributeValue artifactId = attributes.get(ARTIFACT_ID);
AttributeValue groupId = attributes.get(GROUP_ID);
@@ -106,11 +108,12 @@ public class ArchetypeGenerationStrategy implements GeneratorStrategy {
archetypeRepository,
archetypeProperties);
- String projectName = projectPath.substring(projectPath.lastIndexOf(separator));
+ String projectName = projectPath.substring(projectPath.lastIndexOf(separator) + 1);
final MavenArtifact mavenArtifact = new MavenArtifact();
mavenArtifact.setGroupId(getFirst(groupId.getList(), projectName));
mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectName));
mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION));
- archetypeGenerator.generateFromArchetype(new File("/projects"), mavenArchetype, mavenArtifact);
+ archetypeGenerator.generateFromArchetype(
+ projectName, new File(rootDirPathProvider.get()), mavenArchetype, mavenArtifact);
}
}
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 b60ef4d923..cd300ceec1 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
@@ -26,7 +26,9 @@ import org.testng.annotations.Test;
/** @author Musienko Maxim */
public class CheckGeneratingMavenArchetypeTest {
- private static final String NAME_OF_ARTIFACT = NameGenerator.generate("quickStart", 4);
+ private static final String PROJECT_NAME = NameGenerator.generate("quickStart", 4);
+ private static final String ARTIFACT_ID = "artifact";
+ private static final String GROUP_ID = "group";
@Inject private Wizard projectWizard;
@Inject private Menu menu;
@Inject private ProjectExplorer projectExplorer;
@@ -42,31 +44,33 @@ public class CheckGeneratingMavenArchetypeTest {
" %s\n"
+ " %s\n"
+ " 1.0-SNAPSHOT",
- NAME_OF_ARTIFACT, NAME_OF_ARTIFACT);
+ GROUP_ID, ARTIFACT_ID);
Stream expectedItems =
Stream.of(
- NAME_OF_ARTIFACT + "/src/main/java/" + NAME_OF_ARTIFACT + "/App.java",
- NAME_OF_ARTIFACT + "/src/test/java/" + NAME_OF_ARTIFACT + "/AppTest.java",
- NAME_OF_ARTIFACT + "/pom.xml");
+ PROJECT_NAME + "/src/main/java/" + GROUP_ID + "/App.java",
+ PROJECT_NAME + "/src/test/java/" + GROUP_ID + "/AppTest.java",
+ PROJECT_NAME + "/pom.xml");
ide.open(workspace);
menu.runCommand(
TestMenuCommandsConstants.Workspace.WORKSPACE,
TestMenuCommandsConstants.Workspace.CREATE_PROJECT);
projectWizard.selectTypeProject(Wizard.TypeProject.MAVEN);
- projectWizard.typeProjectNameOnWizard(NAME_OF_ARTIFACT);
+ projectWizard.typeProjectNameOnWizard(PROJECT_NAME);
projectWizard.clickNextButton();
projectWizard.waitOpenProjectConfigForm();
projectWizard.selectArcheTypeFromList(Wizard.Archetypes.QUICK_START);
- projectWizard.checkArtifactIdOnWizardContainsText(NAME_OF_ARTIFACT);
- projectWizard.checkGroupIdOnWizardContainsText(NAME_OF_ARTIFACT);
+ projectWizard.setArtifactIdOnWizard(ARTIFACT_ID);
+ projectWizard.checkArtifactIdOnWizardContainsText(ARTIFACT_ID);
+ projectWizard.setGroupIdOnWizard(GROUP_ID);
+ projectWizard.checkGroupIdOnWizardContainsText(GROUP_ID);
projectWizard.checkVersionOnWizardContainsText("1.0-SNAPSHOT");
projectWizard.clickCreateButton();
- projectExplorer.waitItem(NAME_OF_ARTIFACT);
+ projectExplorer.waitItem(PROJECT_NAME);
console.waitExpectedTextIntoConsole(TestBuildConstants.BUILD_SUCCESS);
projectExplorer.quickExpandWithJavaScript();
expectedItems.forEach(projectExplorer::waitItem);
- projectExplorer.openItemByPath(NAME_OF_ARTIFACT + "/pom.xml");
+ projectExplorer.openItemByPath(PROJECT_NAME + "/pom.xml");
editor.waitTextIntoEditor(expectedContnetInPomXml);
}
}