View Javadoc

1   package org.apache.maven.continuum.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.ScmException;
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.ScmVersion;
25  import org.apache.maven.scm.command.update.UpdateScmResult;
26  import org.apache.maven.scm.manager.NoSuchScmProviderException;
27  import org.apache.maven.scm.provider.ScmProvider;
28  import org.apache.maven.scm.repository.ScmRepository;
29  import org.apache.maven.scm.repository.ScmRepositoryException;
30  import org.apache.maven.settings.Settings;
31  import org.apache.maven.shared.release.ReleaseExecutionException;
32  import org.apache.maven.shared.release.ReleaseFailureException;
33  import org.apache.maven.shared.release.ReleaseResult;
34  import org.apache.maven.shared.release.config.ReleaseDescriptor;
35  import org.apache.maven.shared.release.phase.AbstractReleasePhase;
36  import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
37  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
38  import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
39  
40  import java.io.File;
41  import java.util.List;
42  
43  /**
44   * Update working copy
45   *
46   * @author Edwin Punzalan
47   * @version $Id: UpdateWorkingCopyPhase.java 729313 2008-12-24 13:41:11Z olamy $
48   */
49  public class UpdateWorkingCopyPhase
50      extends AbstractReleasePhase
51  {
52      /**
53       * Tool that gets a configured SCM repository from release configuration.
54       */
55      private ScmRepositoryConfigurator scmRepositoryConfigurator;
56  
57      private boolean copyUpdated = false;
58  
59      public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
60          throws ReleaseExecutionException, ReleaseFailureException
61      {
62          ReleaseResult relResult = new ReleaseResult();
63  
64          logInfo( relResult, "Updating local copy against the scm..." );
65  
66          ScmRepository repository;
67          ScmProvider provider;
68          try
69          {
70              repository = scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, settings );
71  
72              provider = scmRepositoryConfigurator.getRepositoryProvider( repository );
73          }
74          catch ( ScmRepositoryException e )
75          {
76              throw new ReleaseScmRepositoryException(
77                  e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages() );
78          }
79          catch ( NoSuchScmProviderException e )
80          {
81              throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e );
82          }
83  
84          UpdateScmResult result;
85          try
86          {
87              result = provider.update( repository, new ScmFileSet( new File( releaseDescriptor.getWorkingDirectory() ) ),
88                                        (ScmVersion) null );
89          }
90          catch ( ScmException e )
91          {
92              throw new ReleaseExecutionException( "An error occurred while updating your local copy: " + e.getMessage(),
93                                                   e );
94          }
95  
96          if ( !result.isSuccess() )
97          {
98              throw new ReleaseScmCommandException( "Unable to update current working copy", result );
99          }
100 
101         copyUpdated = ( result.getUpdatedFiles().size() > 0 );
102 
103         relResult.setResultCode( ReleaseResult.SUCCESS );
104 
105         return relResult;
106     }
107 
108     public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
109         throws ReleaseExecutionException, ReleaseFailureException
110     {
111         return execute( releaseDescriptor, settings, reactorProjects );
112     }
113 
114     public boolean isCopyUpdated()
115     {
116         return copyUpdated;
117     }
118 
119     public void setCopyUpdated( boolean copyUpdated )
120     {
121         this.copyUpdated = copyUpdated;
122     }
123 }