Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Component --> @Inject #243

Merged
merged 15 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,20 @@ public class FilesetArchetypeCreator implements ArchetypeCreator {
private static final String DEFAULT_OUTPUT_DIRECTORY =
"target" + File.separator + "generated-sources" + File.separator + "archetype";

@Inject
private ArchetypeFilesResolver archetypeFilesResolver;

@Inject
private PomManager pomManager;

@Inject
private Invoker invoker;

@Inject
public FilesetArchetypeCreator(
ArchetypeFilesResolver archetypeFilesResolver, PomManager pomManager, Invoker invoker) {
this.archetypeFilesResolver = archetypeFilesResolver;
this.pomManager = pomManager;
this.invoker = invoker;
}

@Override
@SuppressWarnings("checkstyle:MethodLength")
public void createArchetype(ArchetypeCreationRequest request, ArchetypeCreationResult result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,41 @@
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
@Singleton
public class DefaultArchetypeGenerator implements ArchetypeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultArchetypeGenerator.class);

@Inject
private ArchetypeArtifactManager archetypeArtifactManager;

@Inject
private FilesetArchetypeGenerator filesetGenerator;

@Inject
private OldArchetype oldArchetype;

@Inject
private RepositorySystem repositorySystem;

@Inject
public DefaultArchetypeGenerator(
ArchetypeArtifactManager archetypeArtifactManager,
FilesetArchetypeGenerator filesetGenerator,
OldArchetype oldArchetype,
RepositorySystem repositorySystem) {
this.archetypeArtifactManager = archetypeArtifactManager;
this.filesetGenerator = filesetGenerator;
this.oldArchetype = oldArchetype;
this.repositorySystem = repositorySystem;
}

private File getArchetypeFile(ArchetypeGenerationRequest request) throws ArchetypeException {
if (!isArchetypeDefined(request)) {
throw new ArchetypeNotDefined("The archetype is not defined");
}

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

RemoteRepository remoteRepo = null;
if (request != null && request.getArchetypeRepository() != null) {
RepositorySystemSession repositorySession = request.getRepositorySession();
remoteRepo = createRepository(
RemoteRepository remoteRepo = createRepository(
repositorySession, request.getArchetypeRepository(), request.getArchetypeArtifactId() + "-repo");

repos.add(remoteRepo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,26 @@
public class DefaultFilesetArchetypeGenerator implements FilesetArchetypeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFilesetArchetypeGenerator.class);

@Inject
private ArchetypeArtifactManager archetypeArtifactManager;

@Inject
private ArchetypeFilesResolver archetypeFilesResolver;

@Inject
private PomManager pomManager;

@Inject
private VelocityComponent velocity;

@Inject
public DefaultFilesetArchetypeGenerator(
ArchetypeArtifactManager archetypeArtifactManager,
ArchetypeFilesResolver archetypeFilesResolver,
PomManager pomManager,
VelocityComponent velocity) {
this.archetypeArtifactManager = archetypeArtifactManager;
this.archetypeFilesResolver = archetypeFilesResolver;
this.pomManager = pomManager;
this.velocity = velocity;
}

/**
* Pattern used to detect tokens in a string. Tokens are any text surrounded
* by the delimiter <code>__</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ public class DefaultOldArchetype implements OldArchetype {
// Components
// ----------------------------------------------------------------------

@Inject
private VelocityComponent velocity;

@Inject
private ArchetypeArtifactManager archetypeArtifactManager;

@Inject
public DefaultOldArchetype(VelocityComponent velocity, ArchetypeArtifactManager archetypeArtifactManager) {
this.archetypeArtifactManager = archetypeArtifactManager;
this.velocity = velocity;
}

// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions maven-archetype-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
Expand Down Expand Up @@ -152,12 +157,27 @@
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provided

<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -190,6 +210,15 @@
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<executions>
<execution>
<id>index-project</id>
<goals>
<goal>main-index</goal>
<goal>test-index</goal>
</goals>
</execution>
</executions>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is defined in parent

</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
*/
package org.apache.maven.archetype.mojos;

import javax.inject.Inject;

import java.io.File;

import org.apache.maven.archetype.catalog.ArchetypeCatalog;
import org.apache.maven.archetype.repositorycrawler.RepositoryCrawler;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

Expand All @@ -41,9 +42,13 @@ public class CrawlRepositoryMojo extends AbstractMojo {
@Parameter(property = "catalog")
private File catalogFile;

@Component
private RepositoryCrawler crawler;

@Inject
public CrawlRepositoryMojo(RepositoryCrawler crawler) {
this.crawler = crawler;
}

/**
* The repository to crawl.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.archetype.mojos;

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -33,7 +35,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -99,18 +100,12 @@
@Execute(phase = LifecyclePhase.GENERATE_SOURCES)
public class CreateArchetypeFromProjectMojo extends AbstractMojo {

@Component
private ArchetypeCreationConfigurator configurator;

/**
* Enable the interactive mode to define the archetype from the project.
*/
@Parameter(property = "interactive", defaultValue = "false")
private boolean interactive;

@Component
private ArchetypeManager manager;

/**
* File extensions which are checked for project's text files (vs binary files).
*/
Expand Down Expand Up @@ -218,6 +213,16 @@ public class CreateArchetypeFromProjectMojo extends AbstractMojo {
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;

private ArchetypeCreationConfigurator configurator;

private ArchetypeManager manager;

@Inject
public CreateArchetypeFromProjectMojo(ArchetypeCreationConfigurator configurator, ArchetypeManager manager) {
this.configurator = configurator;
this.manager = manager;
}

@Override
public void execute() throws MojoExecutionException {

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

import javax.inject.Inject;

import java.io.File;
import java.util.Arrays;
import java.util.Properties;
Expand All @@ -32,7 +34,6 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.ContextEnabled;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -55,21 +56,30 @@
@Mojo(name = "generate", requiresProject = false)
@Execute(phase = LifecyclePhase.GENERATE_SOURCES)
public class CreateProjectFromArchetypeMojo extends AbstractMojo implements ContextEnabled {
@Component
private ArchetypeManager manager;

@Component
private ArchetypeSelector selector;

@Component
private ArchetypeGenerationConfigurator configurator;

@Component
private Invoker invoker;

@Component
private RepositorySystem repositorySystem;

@Inject
public CreateProjectFromArchetypeMojo(
ArchetypeManager manager,
ArchetypeSelector selector,
ArchetypeGenerationConfigurator configurator,
Invoker invoker,
RepositorySystem repositorySystem) {
this.manager = manager;
this.selector = selector;
this.configurator = configurator;
this.invoker = invoker;
this.repositorySystem = repositorySystem;
}

/**
* The archetype's artifactId.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.archetype.mojos;

import javax.inject.Inject;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -50,7 +52,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -131,18 +132,26 @@
@Mojo(name = "integration-test", requiresProject = true)
public class IntegrationTestMojo extends AbstractMojo {

@Component
private ArchetypeGenerator archetypeGenerator;

@Component
private Downloader downloader;

@Component
private Invoker invoker;

@Component
private ArchetypeGenerationConfigurator archetypeGenerationConfigurator;

@Inject
public IntegrationTestMojo(
ArchetypeGenerator archetypeGenerator,
Downloader downloader,
Invoker invoker,
ArchetypeGenerationConfigurator archetypeGenerationConfigurator) {
this.archetypeGenerator = archetypeGenerator;
this.downloader = downloader;
this.invoker = invoker;
this.archetypeGenerationConfigurator = archetypeGenerationConfigurator;
}

/**
* The archetype project to execute the integration tests on.
*/
Expand Down
Loading