Search in sources :

Example 1 with MavenArchetype

use of org.eclipse.che.plugin.maven.shared.MavenArchetype in project che by eclipse.

the class ArchetypeGenerationStrategy method generateProject.

@Override
public void generateProject(final Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
    AttributeValue artifactId = attributes.get(ARTIFACT_ID);
    AttributeValue groupId = attributes.get(GROUP_ID);
    AttributeValue version = attributes.get(VERSION);
    if (groupId == null || artifactId == null || version == null) {
        throw new ServerException("Missed some required attribute (groupId, artifactId or version)");
    }
    String archetypeGroupId = null;
    String archetypeArtifactId = null;
    String archetypeVersion = null;
    String archetypeRepository = null;
    Map<String, String> archetypeProperties = new HashMap<>();
    //TODO: remove prop 'type' now it use only for detecting generation strategy
    options.remove("type");
    for (Entry<String, String> entry : options.entrySet()) {
        switch(entry.getKey()) {
            case "archetypeGroupId":
                archetypeGroupId = entry.getValue();
                break;
            case "archetypeArtifactId":
                archetypeArtifactId = entry.getValue();
                break;
            case "archetypeVersion":
                archetypeVersion = entry.getValue();
                break;
            case "archetypeRepository":
                archetypeRepository = entry.getValue();
                break;
            default:
                archetypeProperties.put(entry.getKey(), entry.getValue());
        }
    }
    if (isNullOrEmpty(archetypeGroupId) || isNullOrEmpty(archetypeArtifactId) || isNullOrEmpty(archetypeVersion)) {
        throw new ServerException("Missed some required option (archetypeGroupId, archetypeArtifactId or archetypeVersion)");
    }
    MavenArchetype mavenArchetype = new MavenArchetypeImpl(archetypeGroupId, archetypeArtifactId, archetypeVersion, archetypeRepository, archetypeProperties);
    final MavenArtifact mavenArtifact = new MavenArtifact();
    mavenArtifact.setGroupId(getFirst(groupId.getList(), projectPath.getName()));
    mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectPath.getName()));
    mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION));
    archetypeGenerator.generateFromArchetype(vfs.getRoot().toIoFile(), mavenArchetype, mavenArtifact);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) ServerException(org.eclipse.che.api.core.ServerException) MavenArchetypeImpl(org.eclipse.che.plugin.maven.generator.archetype.MavenArchetypeImpl) HashMap(java.util.HashMap) MavenArchetype(org.eclipse.che.plugin.maven.shared.MavenArchetype) MavenArtifact(org.eclipse.che.ide.maven.tools.MavenArtifact)

Example 2 with MavenArchetype

use of org.eclipse.che.plugin.maven.shared.MavenArchetype in project che by eclipse.

the class ArchetypeGeneratorTest method generateFromArchetype.

@Test
@Ignore
public void generateFromArchetype() throws Exception {
    MavenArchetype mavenArchetype = mock(MavenArchetype.class);
    when(mavenArchetype.getArtifactId()).thenReturn("tomee-webapp-archetype");
    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();
    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);
    String[] list = workDir.list();
    List<String> strings = Arrays.asList(list);
    Assert.assertTrue(strings.contains(artifactId));
}
Also used : MavenArchetype(org.eclipse.che.plugin.maven.shared.MavenArchetype) File(java.io.File) MavenArtifact(org.eclipse.che.ide.maven.tools.MavenArtifact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MavenArtifact (org.eclipse.che.ide.maven.tools.MavenArtifact)2 MavenArchetype (org.eclipse.che.plugin.maven.shared.MavenArchetype)2 File (java.io.File)1 HashMap (java.util.HashMap)1 ServerException (org.eclipse.che.api.core.ServerException)1 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)1 MavenArchetypeImpl (org.eclipse.che.plugin.maven.generator.archetype.MavenArchetypeImpl)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1