Search in sources :

Example 26 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeGeneratorTest method testArchetypeNotDefined.

public void testArchetypeNotDefined() throws Exception {
    System.out.println("testArchetypeNotDefined");
    Archetype archetype = new Archetype("archetypes", null, "1.0");
    ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-2", archetype);
    ArchetypeGenerationResult result = generateProjectFromArchetypeWithFailure(request);
    assertEquals("Exception not correct", "The archetype is not defined", result.getCause().getMessage());
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult)

Example 27 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeGeneratorTest method testPropertiesNotDefined.

public void testPropertiesNotDefined() throws Exception {
    System.out.println("testPropertiesNotDefined");
    ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-3", ARCHETYPE_BASIC);
    request.setProperties(new Properties());
    ArchetypeGenerationResult result = generateProjectFromArchetypeWithFailure(request);
    assertTrue("Exception not correct", result.getCause().getMessage().startsWith("Archetype archetypes:basic:1.0 is not configured") && result.getCause().getMessage().endsWith("Property property-without-default-4 is missing."));
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult) Properties(java.util.Properties)

Example 28 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeGeneratorTest method testGenerateArchetypePartialWithoutPoms.

public void testGenerateArchetypePartialWithoutPoms() throws Exception {
    System.out.println("testGenerateArchetypePartialWithoutPoms");
    ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-6", ARCHETYPE_PARTIAL);
    File projectFile = new File(projectDirectory, "pom.xml");
    FileUtils.forceDelete(projectDirectory);
    generateProjectFromArchetype(request);
    Model model = readPom(projectFile);
    assertNull(model.getParent());
    assertEquals("file-value", model.getGroupId());
    assertEquals("file-value", model.getArtifactId());
    assertEquals("file-value", model.getVersion());
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) Model(org.apache.maven.model.Model) File(java.io.File)

Example 29 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeGeneratorTest method testGenerateArchetypePartialOnChildDontOverride.

public void testGenerateArchetypePartialOnChildDontOverride() throws Exception {
    System.out.println("testGenerateArchetypePartialOnChildDontOverride");
    ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-9", ARCHETYPE_PARTIAL);
    File projectFile = new File(projectDirectory, "pom.xml");
    File projectFileSample = new File(projectDirectory, "pom.xml.sample");
    copy(projectFileSample, projectFile);
    FileUtils.forceDelete(new File(projectDirectory, "src"));
    generateProjectFromArchetype(request);
    Model model = readPom(projectFile);
    assertNotNull(model.getParent());
    assertEquals("org.apache.maven.archetype", model.getGroupId());
    assertEquals("file-value", model.getArtifactId());
    assertEquals("1.0-SNAPSHOT", model.getVersion());
    assertTrue(model.getModules().isEmpty());
    assertFalse(model.getDependencies().isEmpty());
    assertEquals("1.0", ((Dependency) model.getDependencies().get(0)).getVersion());
    assertFalse(model.getBuild().getPlugins().isEmpty());
    assertEquals("1.0", ((Plugin) model.getBuild().getPlugins().get(0)).getVersion());
    assertFalse(model.getReporting().getPlugins().isEmpty());
    assertEquals("1.0", ((ReportPlugin) model.getReporting().getPlugins().get(0)).getVersion());
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) Model(org.apache.maven.model.Model) File(java.io.File)

Example 30 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeGeneratorTest method testGenerateArchetypePartialOnParent.

public void testGenerateArchetypePartialOnParent() throws Exception {
    System.out.println("testGenerateArchetypePartialOnParent");
    ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-7", ARCHETYPE_PARTIAL);
    File projectFile = new File(outputDirectory, "pom.xml");
    File projectFileSample = new File(outputDirectory, "pom.xml.sample");
    copy(projectFileSample, projectFile);
    FileUtils.forceDelete(new File(outputDirectory, "src"));
    generateProjectFromArchetype(request);
    Model model = readPom(getProjectFile());
    assertNull(model.getParent());
    assertEquals("org.apache.maven.archetype", model.getGroupId());
    assertEquals("test-generate-7", model.getArtifactId());
    assertEquals("1.0-SNAPSHOT", model.getVersion());
    assertTrue(model.getModules().isEmpty());
    assertFalse(model.getBuild().getPlugins().isEmpty());
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) Model(org.apache.maven.model.Model) File(java.io.File)

Aggregations

ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)33 File (java.io.File)19 Model (org.apache.maven.model.Model)14 Properties (java.util.Properties)13 ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)10 Archetype (org.apache.maven.archetype.catalog.Archetype)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)7 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)7 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)7 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)5 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)5 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)5 MockControl (org.easymock.MockControl)5 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 ArchetypeCreationRequest (org.apache.maven.archetype.ArchetypeCreationRequest)3 ArchetypeCreationResult (org.apache.maven.archetype.ArchetypeCreationResult)3 ArchetypeCatalogXpp3Writer (org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer)3