Skip to content

Commit

Permalink
[ARCHETYPE-650] point to archetype file in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Oct 7, 2023
1 parent 29048c8 commit 12e01de
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void generateArchetype(ArchetypeGenerationRequest request, File archetyp
} else if (archetypeArtifactManager.isOldArchetype(archetypeFile)) {
processOldArchetype(request, archetypeFile);
} else {
throw new ArchetypeGenerationFailure("The defined artifact is not an archetype");
throw new ArchetypeGenerationFailure("The defined artifact is not an archetype: " + archetypeFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.archetype.ui.generation;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
Expand Down Expand Up @@ -134,46 +135,27 @@ public void configureArchetype(

ArchetypeConfiguration archetypeConfiguration;

if (archetypeArtifactManager.isFileSetArchetype(
File archetypeFile = archetypeArtifactManager.getArchetypeFile(
ad.getGroupId(),
ad.getArtifactId(),
ad.getVersion(),
archetypeRepository,
localRepository,
repositories,
request.getProjectBuildingRequest())) {
request.getProjectBuildingRequest());
if (archetypeArtifactManager.isFileSetArchetype(archetypeFile)) {
org.apache.maven.archetype.metadata.ArchetypeDescriptor archetypeDescriptor =
archetypeArtifactManager.getFileSetArchetypeDescriptor(
ad.getGroupId(),
ad.getArtifactId(),
ad.getVersion(),
archetypeRepository,
localRepository,
repositories,
request.getProjectBuildingRequest());
archetypeArtifactManager.getFileSetArchetypeDescriptor(archetypeFile);

archetypeConfiguration = archetypeFactory.createArchetypeConfiguration(archetypeDescriptor, properties);
} else if (archetypeArtifactManager.isOldArchetype(
ad.getGroupId(),
ad.getArtifactId(),
ad.getVersion(),
archetypeRepository,
localRepository,
repositories,
request.getProjectBuildingRequest())) {
} else if (archetypeArtifactManager.isOldArchetype(archetypeFile)) {
org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor archetypeDescriptor =
archetypeArtifactManager.getOldArchetypeDescriptor(
ad.getGroupId(),
ad.getArtifactId(),
ad.getVersion(),
archetypeRepository,
localRepository,
repositories,
request.getProjectBuildingRequest());
archetypeArtifactManager.getOldArchetypeDescriptor(archetypeFile);

archetypeConfiguration = archetypeFactory.createArchetypeConfiguration(archetypeDescriptor, properties);
} else {
throw new ArchetypeGenerationConfigurationFailure("The defined artifact is not an archetype");
throw new ArchetypeGenerationConfigurationFailure(
"The defined artifact is not an archetype: " + archetypeFile);
}

List<String> propertiesRequired = archetypeConfiguration.getRequiredProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.archetype.ui.generation;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -74,19 +75,17 @@ public void setUp() throws Exception {

ArchetypeArtifactManager manager = EasyMock.createMock(ArchetypeArtifactManager.class);

File archetype = new File("archetype.jar");
List<ArtifactRepository> x = new ArrayList<>();
EasyMock.expect(manager.exists(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(true);
EasyMock.expect(manager.isFileSetArchetype(
EasyMock.expect(manager.getArchetypeFile(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(true);
EasyMock.expect(manager.isOldArchetype(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(false);
EasyMock.expect(manager.getFileSetArchetypeDescriptor(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(descriptor);
.andReturn(archetype);
EasyMock.expect(manager.isFileSetArchetype(archetype)).andReturn(true);
EasyMock.expect(manager.isOldArchetype(archetype)).andReturn(false);
EasyMock.expect(manager.getFileSetArchetypeDescriptor(archetype)).andReturn(descriptor);

EasyMock.replay(manager);
configurator.setArchetypeArtifactManager(manager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.archetype.ui.generation;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -54,20 +55,18 @@ public void setUp() throws Exception {

ArchetypeArtifactManager manager = EasyMock.createMock(ArchetypeArtifactManager.class);

File archetype = new File("archetype.jar");
List<ArtifactRepository> x = new ArrayList<>();
EasyMock.expect(manager.exists(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(true);
EasyMock.expect(manager.isFileSetArchetype(
EasyMock.expect(manager.getArchetypeFile(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(false);
EasyMock.expect(manager.isOldArchetype(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(true);
.andReturn(archetype);
EasyMock.expect(manager.isFileSetArchetype(archetype)).andReturn(false);
EasyMock.expect(manager.isOldArchetype(archetype)).andReturn(true);

EasyMock.expect(manager.getOldArchetypeDescriptor(
"archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
.andReturn(new ArchetypeDescriptor());
EasyMock.expect(manager.getOldArchetypeDescriptor(archetype)).andReturn(new ArchetypeDescriptor());

EasyMock.replay(manager);
configurator.setArchetypeArtifactManager(manager);
Expand Down

0 comments on commit 12e01de

Please sign in to comment.