Skip to content

Commit

Permalink
[ARCHETYPE-689] Restore removed public methods in ArchetypeGeneration…
Browse files Browse the repository at this point in the history
…Request
  • Loading branch information
slawekjaranowski committed Oct 21, 2024
1 parent e24ef2c commit 2d7b2e5
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,41 @@
import java.util.Properties;

import org.apache.maven.archetype.catalog.Archetype;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;

/** @author Jason van Zyl */
/**
* <b>NOTICE</b> all setters method are public for technical reasons, should be recognised as internals,
* so should not be used directly.
*
* @author Jason van Zyl
*/
public class ArchetypeGenerationRequest {
private ProjectBuildingRequest projectBuildingRequest;

private boolean offline;

private MavenSession mavenSession;

private RepositorySystemSession repositorySession;

private RepositorySystem repositorySystem;

private boolean interactiveMode;

private boolean askForDefaultPropertyValues;

private String outputDirectory;

private List<RemoteRepository> remoteArtifactRepositories = Collections.emptyList();
private ArtifactRepository localRepository;

private List<ArtifactRepository> remoteArtifactRepositories;

private List<RemoteRepository> remoteRepositories = Collections.emptyList();

// Archetype definition
private String archetypeName;
Expand Down Expand Up @@ -70,7 +90,7 @@ public class ArchetypeGenerationRequest {
private Properties properties = new Properties();

/**
* @since 2.1
* @since 2.1
*/
private String filter;

Expand All @@ -80,14 +100,20 @@ public ArchetypeGenerationRequest() {

public ArchetypeGenerationRequest(Archetype archetype) {
this.archetypeGroupId = archetype.getGroupId();

this.archetypeArtifactId = archetype.getArtifactId();

this.archetypeVersion = archetype.getVersion();

this.archetypeRepository = archetype.getRepository();
}

public MavenSession getMavenSession() {
return mavenSession;
}

public ArchetypeGenerationRequest setMavenSession(MavenSession mavenSession) {
this.mavenSession = mavenSession;
return this;
}

public RepositorySystemSession getRepositorySession() {
return repositorySession;
}
Expand All @@ -97,6 +123,28 @@ public ArchetypeGenerationRequest setRepositorySession(RepositorySystemSession r
return this;
}

public RepositorySystem getRepositorySystem() {
return repositorySystem;
}

public ArchetypeGenerationRequest setRepositorySystem(RepositorySystem repositorySystem) {
this.repositorySystem = repositorySystem;
return this;
}

/**
* @deprecated please use {@link #getMavenSession()} and {@link MavenSession#getProjectBuildingRequest()}
*/
@Deprecated
public ProjectBuildingRequest getProjectBuildingRequest() {
return projectBuildingRequest;
}

public ArchetypeGenerationRequest setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) {
this.projectBuildingRequest = projectBuildingRequest;
return this;
}

public String getArchetypeGroupId() {
return archetypeGroupId;
}
Expand Down Expand Up @@ -143,7 +191,6 @@ public ArchetypeGenerationRequest setArchetypeName(String archetypeName) {
}

/**
*
* @return the URL of the archetype repository
* @deprecated see ARCHETYPE-439
*/
Expand All @@ -153,7 +200,6 @@ public String getArchetypeRepository() {
}

/**
*
* @param archetypeRepository the URL of the archetype repository
* @return this request
* @deprecated see ARCHETYPE-439
Expand Down Expand Up @@ -211,6 +257,20 @@ public ArchetypeGenerationRequest setProperties(Properties additionalProperties)
return this;
}

/**
* @deprecated please use {@link #getRepositorySession()} and {@link RepositorySystemSession#getLocalRepository()}
*/
@Deprecated
public ArtifactRepository getLocalRepository() {
return localRepository;
}

public ArchetypeGenerationRequest setLocalRepository(ArtifactRepository localRepository) {
this.localRepository = localRepository;

return this;
}

public String getOutputDirectory() {
return outputDirectory;
}
Expand Down Expand Up @@ -238,12 +298,41 @@ public ArchetypeGenerationRequest setAskForDefaultPropertyValues(boolean askForD
return this;
}

public List<RemoteRepository> getRemoteArtifactRepositories() {
/**
* @deprecated please use {@link #getRepositorySession()} and {@link RepositorySystemSession#isOffline()}
* or {@link #getMavenSession()} and {@link MavenSession#isOffline()}
*/
@Deprecated
public boolean isOffline() {
return offline;
}

public ArchetypeGenerationRequest setOffline(boolean offline) {
this.offline = offline;
return this;
}

/**
* @deprecated please use {@link #getRemoteRepositories()}
*/
@Deprecated
public List<ArtifactRepository> getRemoteArtifactRepositories() {
return remoteArtifactRepositories;
}

public ArchetypeGenerationRequest setRemoteArtifactRepositories(List<RemoteRepository> remoteArtifactRepositories) {
public ArchetypeGenerationRequest setRemoteArtifactRepositories(
List<ArtifactRepository> remoteArtifactRepositories) {
this.remoteArtifactRepositories = remoteArtifactRepositories;

return this;
}

public List<RemoteRepository> getRemoteRepositories() {
return remoteRepositories;
}

public ArchetypeGenerationRequest setRemoteRepositories(List<RemoteRepository> remoteRepositories) {
this.remoteRepositories = remoteRepositories;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private File getArchetypeFile(ArchetypeGenerationRequest request) throws Archety
throw new ArchetypeNotDefined("The archetype is not defined");
}

List<RemoteRepository> repos = new ArrayList<>(request.getRemoteArtifactRepositories());
List<RemoteRepository> repos = new ArrayList<>(request.getRemoteRepositories());

RemoteRepository remoteRepo = null;
if (request != null && request.getArchetypeRepository() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void createArchetype(ArchetypeGenerationRequest request)
request.getArchetypeGroupId(),
request.getArchetypeArtifactId(),
request.getArchetypeVersion(),
request.getRemoteArtifactRepositories(),
request.getRemoteRepositories(),
request.getRepositorySession());

createArchetype(request, archetypeFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void testArchetype() throws Exception {
.setArchetypeGroupId("org.apache.maven.archetypes")
.setArchetypeArtifactId("maven-archetype-quickstart")
.setArchetypeVersion("1.0-alpha-1-SNAPSHOT")
.setRemoteArtifactRepositories(remoteRepositories)
.setRemoteRepositories(remoteRepositories)
.setRepositorySession(repositorySession)
.setOutputDirectory(getTestFile("target").getAbsolutePath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.eclipse.aether.RepositorySystem;

/**
* Generates a new project from an archetype, or updates the actual project if using a partial archetype.
Expand All @@ -66,6 +67,9 @@ public class CreateProjectFromArchetypeMojo extends AbstractMojo implements Cont
@Component
private Invoker invoker;

@Component
private RepositorySystem repositorySystem;

/**
* The archetype's artifactId.
*/
Expand Down Expand Up @@ -171,8 +175,14 @@ public void execute() throws MojoExecutionException {
.setArchetypeArtifactId(archetypeArtifactId)
.setArchetypeVersion(archetypeVersion)
.setOutputDirectory(outputDirectory.getAbsolutePath())
.setRemoteArtifactRepositories(project.getRemoteProjectRepositories())
.setRemoteRepositories(project.getRemoteProjectRepositories())
.setRemoteArtifactRepositories(project.getRemoteArtifactRepositories())
.setMavenSession(session)
.setRepositorySession(session.getRepositorySession())
.setRepositorySystem(repositorySystem)
.setProjectBuildingRequest(session.getProjectBuildingRequest())
.setLocalRepository(session.getLocalRepository())
.setOffline(session.isOffline())
.setFilter(filter)
.setAskForDefaultPropertyValues(askForDefaultPropertyValues);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void configureArchetype(
createRepository(repositorySession, request.getArchetypeRepository(), ad.getArtifactId() + "-repo");
repositories.add(archetypeRepository);
}
if (request.getRemoteArtifactRepositories() != null) {
repositories.addAll(request.getRemoteArtifactRepositories());
if (request.getRemoteRepositories() != null) {
repositories.addAll(request.getRemoteRepositories());
}

if (!archetypeArtifactManager.exists(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void selectArchetype(ArchetypeGenerationRequest request, Boolean interact
return;
}

Map<String, List<Archetype>> archetypes = getArchetypesByCatalog(
request.getRepositorySession(), request.getRemoteArtifactRepositories(), catalogs);
Map<String, List<Archetype>> archetypes =
getArchetypesByCatalog(request.getRepositorySession(), request.getRemoteRepositories(), catalogs);

if (StringUtils.isNotBlank(request.getFilter())) {
// applying some filtering depending on filter parameter
Expand Down

0 comments on commit 2d7b2e5

Please sign in to comment.