Skip to content

Commit

Permalink
Guice injection (#801)
Browse files Browse the repository at this point in the history
* Switch from PLexus Annotations to javax.inject
  • Loading branch information
elharo authored Dec 20, 2024
1 parent 6271ca1 commit 73d2f5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugin.failsafe;

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
Expand All @@ -30,7 +32,6 @@
import org.apache.maven.plugin.surefire.SurefireHelper;
import org.apache.maven.plugin.surefire.SurefireReportParameters;
import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand Down Expand Up @@ -152,6 +153,7 @@ public class VerifyMojo extends AbstractMojo implements SurefireReportParameters
*
* @deprecated since of 2.20.1
*/
@Deprecated
@Parameter(property = "encoding", defaultValue = "${project.reporting.outputEncoding}")
private String encoding;

Expand All @@ -161,13 +163,17 @@ public class VerifyMojo extends AbstractMojo implements SurefireReportParameters
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

@Component
private Logger logger;
private final Logger logger;

private Collection<CommandLineOption> cli;

private volatile PluginConsoleLogger consoleLogger;

@Inject
public VerifyMojo(Logger logger) {
this.logger = logger;
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
cli = commandLineOptions();
Expand Down Expand Up @@ -199,10 +205,6 @@ private Exception getBooterForkException(RunResult summary) {
return null;
}

void setLogger(Logger logger) {
this.logger = logger;
}

private PluginConsoleLogger getConsoleLogger() {
if (consoleLogger == null) {
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,26 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
*/
public class VerifyMojoTest {
private VerifyMojo mojo;

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

private Logger logger = mock(Logger.class);

@Before
public void init() throws UnsupportedEncodingException {
mojo = new VerifyMojo();
mojo = new VerifyMojo(logger);
mojo.setTestClassesDirectory(tempFolder.getRoot());
mojo.setReportsDirectory(getTestBaseDir());
}

private void setupExecuteMocks() {
Logger logger = mock(Logger.class);
when(logger.isErrorEnabled()).thenReturn(true);
when(logger.isWarnEnabled()).thenReturn(true);
when(logger.isInfoEnabled()).thenReturn(true);
when(logger.isDebugEnabled()).thenReturn(false);
mojo.setLogger(logger);

MavenSession session = mock(MavenSession.class);
MavenExecutionRequest request = mock(MavenExecutionRequest.class);
Expand Down

0 comments on commit 73d2f5d

Please sign in to comment.