View Javadoc
1   package org.apache.maven.shared.release.phase;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.manager.NoSuchScmProviderException;
23  import org.apache.maven.scm.provider.ScmProvider;
24  import org.apache.maven.scm.repository.ScmRepository;
25  import org.apache.maven.scm.repository.ScmRepositoryException;
26  import org.apache.maven.shared.release.ReleaseExecutionException;
27  import org.apache.maven.shared.release.ReleaseFailureException;
28  import org.apache.maven.shared.release.config.ReleaseDescriptor;
29  import org.apache.maven.shared.release.env.ReleaseEnvironment;
30  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
31  import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
32  
33  /**
34   * Abstract release POM phase.
35   *
36   * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
37   */
38  public abstract class AbstractReleasePomsPhase extends AbstractReleasePhase
39  {
40      /**
41       * Tool that gets a configured SCM repository from release configuration.
42       *
43       * @plexus.requirement
44       */
45      private ScmRepositoryConfigurator scmRepositoryConfigurator;
46  
47      protected ScmRepository getScmRepository( ReleaseDescriptor releaseDescriptor,
48                                                ReleaseEnvironment releaseEnvironment )
49          throws ReleaseFailureException, ReleaseExecutionException
50      {
51          try
52          {
53              return scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor,
54                                                                        releaseEnvironment.getSettings() );
55          }
56          catch ( ScmRepositoryException exception )
57          {
58              throw new ReleaseScmRepositoryException( exception.getMessage(), exception.getValidationMessages() );
59          }
60          catch ( NoSuchScmProviderException exception )
61          {
62              throw new ReleaseExecutionException( "Unable to configure SCM repository: " + exception.getMessage(),
63                                                   exception );
64          }
65      }
66  
67      protected ScmProvider getScmProvider( ScmRepository scmRepository )
68          throws ReleaseExecutionException
69      {
70          try
71          {
72              return scmRepositoryConfigurator.getRepositoryProvider( scmRepository );
73          }
74          catch ( NoSuchScmProviderException exception )
75          {
76              throw new ReleaseExecutionException( "Unable to configure SCM repository: " + exception.getMessage(),
77                                                   exception );
78          }
79      }
80  }