[ 
https://issues.apache.org/jira/browse/MNG-7401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17570328#comment-17570328
 ] 

ASF GitHub Bot commented on MNG-7401:
-------------------------------------

michael-o commented on code in PR #743:
URL: https://github.com/apache/maven/pull/743#discussion_r928140254


##########
maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilderTest.java:
##########
@@ -0,0 +1,102 @@
+package org.apache.maven.lifecycle.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.maven.execution.AbstractExecutionListener;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.DefaultMavenExecutionResult;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
+import 
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder;
+import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
+import 
org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
+import org.apache.maven.lifecycle.internal.stub.LoggerStub;
+import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.ContainerConfiguration;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.logging.Logger;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+public class LifecycleModuleBuilderTest extends PlexusTestCase
+{
+    @Override
+    protected void customizeContainerConfiguration( ContainerConfiguration 
configuration )
+    {
+        configuration.setAutoWiring( true );
+        configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
+
+    }
+
+    public void testCurrentProject() throws Exception
+    {
+        List<MavenProject> currentProjects = new ArrayList<>();
+        MojoExecutorStub mojoExecutor = new MojoExecutorStub()
+        {
+            @Override
+            public void execute( MavenSession session, List<MojoExecution> 
mojoExecutions, ProjectIndex projectIndex )
+                    throws LifecycleExecutionException
+            {
+                super.execute( session, mojoExecutions, projectIndex );
+                currentProjects.add( session.getCurrentProject() );
+            }
+        };
+
+        final DefaultMavenExecutionResult defaultMavenExecutionResult = new 
DefaultMavenExecutionResult();
+        MavenExecutionRequest mavenExecutionRequest = new 
DefaultMavenExecutionRequest();
+        mavenExecutionRequest.setExecutionListener( new 
AbstractExecutionListener() );
+        mavenExecutionRequest.setGoals( Arrays.asList( "clean" ) );
+        mavenExecutionRequest.setDegreeOfConcurrency( 1 );

Review Comment:
   This is the default value. Any specific reason to set it explicitly?





> Make MavenSession#getCurrentProject() using a thread local
> ----------------------------------------------------------
>
>                 Key: MNG-7401
>                 URL: https://issues.apache.org/jira/browse/MNG-7401
>             Project: Maven
>          Issue Type: Improvement
>            Reporter: Christoph Läubrich
>            Assignee: Guillaume Nodet
>            Priority: Major
>             Fix For: 3.9.0, waiting-for-feedback
>
>
> I noticed that a session is often cloned due to change the current project 
> for a while.
> As this works for everyone passing down the session, consumers of the "upper 
> session" (e.g. a SessionScoped Component) would never see this if they are 
> (indirectly) called and e.g. use Session#getCurrentProject().
> I wonder if MavenSession could simply use a ThreadLocal for the 
> currentProject (that is shared accross all cloned sessions), that way one 
> would always get the correct value.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to