You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/05/03 07:35:47 UTC

[GitHub] [maven-release] cstamas commented on a diff in pull request #118: Catch up

cstamas commented on code in PR #118:
URL: https://github.com/apache/maven-release/pull/118#discussion_r863535359


##########
maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManager.java:
##########
@@ -37,38 +42,56 @@
 import org.apache.maven.shared.release.phase.ReleasePhase;
 import org.apache.maven.shared.release.phase.ResourceGenerator;
 import org.apache.maven.shared.release.strategy.Strategy;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Implementation of the release manager.
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  */
-@Component( role = ReleaseManager.class )
+@Singleton
+@Named
 public class DefaultReleaseManager
-    extends AbstractLogEnabled
     implements ReleaseManager
 {
-    @Requirement
-    private Map<String, Strategy> strategies;
+    private static final Logger LOGGER = LoggerFactory.getLogger( DefaultReleaseManager.class );
+
+    private final Map<String, Strategy> strategies;
 
     /**
      * The available phases.
      */
-    @Requirement
-    private Map<String, ReleasePhase> releasePhases;
+    private final Map<String, ReleasePhase> releasePhases;
 
     /**
      * The configuration storage.
      */
-    @Requirement( hint = "properties" )
-    private ReleaseDescriptorStore configStore;
+    private final AtomicReference<ReleaseDescriptorStore> configStore;
 
     private static final int PHASE_SKIP = 0, PHASE_START = 1, PHASE_END = 2, GOAL_END = 12, ERROR = 99;
 
+    @Inject
+    public DefaultReleaseManager( Map<String, Strategy> strategies,
+                                  Map<String, ReleasePhase> releasePhases,
+                                  @Named( "properties" ) ReleaseDescriptorStore configStore )
+    {
+        this.strategies = requireNonNull( strategies );
+        this.releasePhases = requireNonNull( releasePhases );
+        this.configStore = new AtomicReference<>( requireNonNull( configStore ) );

Review Comment:
   A few lines lower there is a **setter** for config store, that is used in UT ONLY. Simply put: for sanity sake, to keep ctor injection and keep all member final, BUT to not completely rewrite tests, I did it like this. The setter has comment on it.
   
   This pattern is applied on several places, as sadly UTs were written with "plexus on mind", so they lookup component from container and then change members to some mocks... changed to pure ctor injection where I could, but there are some complicated UTs that I just gave up, and added setter + atomic ref to save my sanity :smile: 
   
   All this should not bother anything at "runtime" (in prod), when plugin runs in build.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org