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/06 06:28:06 UTC

[GitHub] [maven-release] cstamas commented on a diff in pull request #118: [MRELEASE-1087] Upgrade Maven to 3.2.5 (and de-plexus)

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


##########
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 );

Review Comment:
   Unified all loggers, they are obtained in same way everywhere



##########
maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractInputVariablesPhase.java:
##########
@@ -0,0 +1,309 @@
+package org.apache.maven.shared.release.phase;
+
+/*
+ * 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.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.provider.ScmProvider;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.apache.maven.shared.release.ReleaseExecutionException;
+import org.apache.maven.shared.release.ReleaseResult;
+import org.apache.maven.shared.release.config.ReleaseDescriptor;
+import org.apache.maven.shared.release.env.ReleaseEnvironment;
+import org.apache.maven.shared.release.policy.PolicyException;
+import org.apache.maven.shared.release.policy.naming.NamingPolicy;
+import org.apache.maven.shared.release.policy.naming.NamingPolicyRequest;
+import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
+import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
+import org.apache.maven.shared.release.util.ReleaseUtil;
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
+import org.codehaus.plexus.interpolation.PrefixedPropertiesValueSource;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.util.StringUtils;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Input any variables that were not yet configured.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public abstract class AbstractInputVariablesPhase
+        extends AbstractReleasePhase
+{
+    /**
+     * Component used to prompt for input.
+     */
+    private final AtomicReference<Prompter> prompter;
+
+    /**
+     * Tool that gets a configured SCM repository from release configuration.
+     */
+    private final ScmRepositoryConfigurator scmRepositoryConfigurator;
+
+    /**
+     * Component used for custom or default naming policy
+     */
+    private final Map<String, NamingPolicy> namingPolicies;
+
+    /**
+     * Whether this is a branch or a tag operation.
+     */
+    private final boolean branchOperation;
+
+    /**
+     * The default naming policy to apply, if any
+     */
+    private final String defaultNamingPolicy;
+
+    protected AbstractInputVariablesPhase( Prompter prompter, ScmRepositoryConfigurator scmRepositoryConfigurator,
+                                        Map<String, NamingPolicy> namingPolicies, boolean branchOperation,
+                                        String defaultNamingPolicy )
+    {
+        this.prompter = new AtomicReference<>( requireNonNull( prompter ) );
+        this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator );
+        this.namingPolicies = requireNonNull( namingPolicies );
+        this.branchOperation = branchOperation;
+        this.defaultNamingPolicy = defaultNamingPolicy;
+    }
+
+    /**
+     * For easier testing only!
+     */
+    public void setPrompter( Prompter prompter )
+    {
+        this.prompter.set( prompter );
+    }
+
+    boolean isBranchOperation()
+    {
+        return branchOperation;
+    }
+
+    /**
+     * <p>getScmProvider.</p>
+     *
+     * @param releaseDescriptor  a {@link ReleaseDescriptor} object
+     * @param releaseEnvironment a {@link ReleaseEnvironment} object
+     * @return a {@link ScmProvider} object
+     * @throws ReleaseScmRepositoryException if any.
+     * @throws ReleaseExecutionException     if any.
+     */
+    protected ScmProvider getScmProvider( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment )
+            throws ReleaseScmRepositoryException, ReleaseExecutionException
+    {
+        try
+        {
+            ScmRepository repository =
+                    scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor,
+                            releaseEnvironment.getSettings() );
+
+            return scmRepositoryConfigurator.getRepositoryProvider( repository );
+        }
+        catch ( ScmRepositoryException e )
+        {
+            throw new ReleaseScmRepositoryException(
+                    e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages() );
+        }
+        catch ( NoSuchScmProviderException e )
+        {
+            throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e );
+        }
+    }
+
+    @Override
+    public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
+                                  List<MavenProject> reactorProjects )
+            throws ReleaseExecutionException
+    {
+        ReleaseResult result = new ReleaseResult();
+
+        // get the root project
+        MavenProject project = ReleaseUtil.getRootProject( reactorProjects );
+
+        String tag = releaseDescriptor.getScmReleaseLabel();
+
+        if ( tag == null )
+        {
+            // Must get default version from mapped versions, as the project will be the incorrect snapshot
+            String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
+            String releaseVersion = releaseDescriptor.getProjectReleaseVersion( key );
+            if ( releaseVersion == null )
+            {
+                throw new ReleaseExecutionException( "Project tag cannot be selected if version is not yet mapped" );
+            }
+
+            String suggestedName;
+            String scmTagNameFormat = releaseDescriptor.getScmTagNameFormat();
+            if ( releaseDescriptor.getProjectNamingPolicyId() != null )
+            {
+                try
+                {
+                    suggestedName =
+                            resolveSuggestedName( releaseDescriptor.getProjectNamingPolicyId(), releaseVersion,
+                                    project );
+                }
+                catch ( PolicyException e )
+                {
+                    throw new ReleaseExecutionException( e.getMessage(), e );
+                }
+            }
+            else if ( scmTagNameFormat != null )
+            {
+                Interpolator interpolator = new StringSearchInterpolator( "@{", "}" );
+                List<String> possiblePrefixes = java.util.Arrays.asList( "project", "pom" );

Review Comment:
   Fixed



-- 
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