Skip to content

Commit

Permalink
Move off session as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Dec 16, 2023
1 parent 2a51421 commit b0a9e56
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,15 @@
*/
package org.apache.maven.project.inheritance;

import javax.inject.Inject;

import java.io.File;
import java.util.Collections;

import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.project.AbstractMavenProjectTestCase;
import org.apache.maven.session.scope.internal.SessionScope;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.BeforeEach;

import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
*/
public abstract class AbstractProjectInheritanceTestCase extends AbstractMavenProjectTestCase {

@Inject
SessionScope sessionScope;

@BeforeEach
public void setUpSession() {
RepositorySystemSession repositorySystemSession = mock(RepositorySystemSession.class);
when(repositorySystemSession.getConfigProperties()).thenReturn(Collections.emptyMap());
InternalSession internalSession = mock(InternalSession.class);
when(internalSession.getSession()).thenReturn(repositorySystemSession);

sessionScope.enter();
sessionScope.seed(InternalSession.class, internalSession);
}

protected String getTestSeries() {
String className = getClass().getPackage().getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*
*/
class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase {

// ----------------------------------------------------------------------
//
// p4 inherits from p3
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.execution.ProjectExecutionEvent;
import org.apache.maven.execution.ProjectExecutionListener;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator;
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
Expand All @@ -48,9 +47,6 @@
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.session.scope.internal.SessionScope;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -59,8 +55,6 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class LifecycleExecutorTest extends AbstractCoreMavenComponentTestCase {
@Inject
Expand All @@ -75,20 +69,6 @@ class LifecycleExecutorTest extends AbstractCoreMavenComponentTestCase {
@Inject
private MojoDescriptorCreator mojoDescriptorCreator;

@Inject
SessionScope sessionScope;

@BeforeEach
public void setUp() {
RepositorySystemSession repositorySystemSession = mock(RepositorySystemSession.class);
when(repositorySystemSession.getConfigProperties()).thenReturn(Collections.emptyMap());
InternalSession internalSession = mock(InternalSession.class);
when(internalSession.getSession()).thenReturn(repositorySystemSession);

sessionScope.enter();
sessionScope.seed(InternalSession.class, internalSession);
}

protected String getProjectsDirectory() {
return "src/test/projects/lifecycle-executor";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,16 @@
import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.session.scope.internal.SessionScope;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase {
@Inject
private LifecycleDependencyResolver resolver;

@Inject
SessionScope sessionScope;

@BeforeEach
public void setUp() {
RepositorySystemSession repositorySystemSession = mock(RepositorySystemSession.class);
when(repositorySystemSession.getConfigProperties()).thenReturn(Collections.emptyMap());
InternalSession internalSession = mock(InternalSession.class);
when(internalSession.getSession()).thenReturn(repositorySystemSession);

sessionScope.enter();
sessionScope.seed(InternalSession.class, internalSession);
}

@Override
protected String getProjectsDirectory() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,29 @@

import javax.inject.Inject;

import java.util.Collections;
import java.util.List;

import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.session.scope.internal.SessionScope;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class PluginManagerTest extends AbstractCoreMavenComponentTestCase {
@Inject
private DefaultBuildPluginManager pluginManager;

@Inject
SessionScope sessionScope;

@BeforeEach
public void setUp() {
RepositorySystemSession repositorySystemSession = mock(RepositorySystemSession.class);
when(repositorySystemSession.getConfigProperties()).thenReturn(Collections.emptyMap());
InternalSession internalSession = mock(InternalSession.class);
when(internalSession.getSession()).thenReturn(repositorySystemSession);

sessionScope.enter();
sessionScope.seed(InternalSession.class, internalSession);
}

@Override
protected String getProjectsDirectory() {
return "src/test/projects/plugin-manager";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.maven.project;

import javax.inject.Inject;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -33,17 +31,13 @@
import org.apache.commons.io.FileUtils;
import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.building.FileModelSource;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.session.scope.internal.SessionScope;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -60,24 +54,8 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class ProjectBuilderTest extends AbstractCoreMavenComponentTestCase {
@Inject
SessionScope sessionScope;

@BeforeEach
public void setUp() {
RepositorySystemSession repositorySystemSession = mock(RepositorySystemSession.class);
when(repositorySystemSession.getConfigProperties()).thenReturn(Collections.emptyMap());
InternalSession internalSession = mock(InternalSession.class);
when(internalSession.getSession()).thenReturn(repositorySystemSession);

sessionScope.enter();
sessionScope.seed(InternalSession.class, internalSession);
}

@Override
protected String getProjectsDirectory() {
return "src/test/projects/project-builder";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,22 @@
*/
package org.apache.maven.project;

import javax.inject.Inject;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.session.scope.internal.SessionScope;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.repository.RemoteRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
Expand All @@ -48,8 +42,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Test cases for the project {@code ModelResolver} implementation.
Expand All @@ -58,18 +50,11 @@
*/
class ProjectModelResolverTest extends AbstractMavenProjectTestCase {

@Inject
SessionScope sessionScope;

@BeforeEach
public void setUp() {
RepositorySystemSession repositorySystemSession = mock(RepositorySystemSession.class);
when(repositorySystemSession.getConfigProperties()).thenReturn(Collections.emptyMap());
InternalSession internalSession = mock(InternalSession.class);
when(internalSession.getSession()).thenReturn(repositorySystemSession);

sessionScope.enter();
sessionScope.seed(InternalSession.class, internalSession);
/**
* Creates a new {@code ProjectModelResolverTest} instance.
*/
public ProjectModelResolverTest() {
super();
}

@Test
Expand Down
Loading

0 comments on commit b0a9e56

Please sign in to comment.