View Javadoc

1   package org.apache.maven.scm.provider.bazaar.command.checkin;
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 java.io.File;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.ScmFile;
28  import org.apache.maven.scm.ScmFileSet;
29  import org.apache.maven.scm.ScmFileStatus;
30  import org.apache.maven.scm.ScmResult;
31  import org.apache.maven.scm.ScmVersion;
32  import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
33  import org.apache.maven.scm.command.checkin.CheckInScmResult;
34  import org.apache.maven.scm.command.status.StatusScmResult;
35  import org.apache.maven.scm.provider.ScmProviderRepository;
36  import org.apache.maven.scm.provider.bazaar.BazaarUtils;
37  import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
38  import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer;
39  import org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand;
40  import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository;
41  import org.codehaus.plexus.util.StringUtils;
42  
43  /**
44   * @author <a href="mailto:torbjorn@smorgrav.org">Torbjorn Eikli Smorgrav</a>
45   * @author Olivier Lamy
46   *
47   */
48  public class BazaarCheckInCommand
49      extends AbstractCheckInCommand
50  {
51      /** {@inheritDoc} */
52      protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
53                                                        ScmVersion version )
54          throws ScmException
55      {
56  
57          if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
58          {
59              throw new ScmException( "This provider can't handle tags." );
60          }
61  
62          // Get files that will be committed (if not specified in fileSet)
63          List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
64          List<File> files = fileSet.getFileList();
65          if ( files.isEmpty() )
66          { //Either commit all changes
67              BazaarStatusCommand statusCmd = new BazaarStatusCommand();
68              statusCmd.setLogger( getLogger() );
69              StatusScmResult status = statusCmd.executeStatusCommand( repo, fileSet );
70              List<ScmFile> statusFiles = status.getChangedFiles();
71              for ( ScmFile file : statusFiles )
72              {
73                  if ( file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED
74                      || file.getStatus() == ScmFileStatus.MODIFIED )
75                  {
76                      commitedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.CHECKED_IN ) );
77                  }
78              }
79  
80          }
81          else
82          { //Or commit spesific files
83              for ( File file : files )
84              {
85                  commitedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.CHECKED_IN ) );
86              }
87          }
88  
89          // Commit to local branch
90          String[] commitCmd = new String[]{BazaarConstants.COMMIT_CMD, BazaarConstants.MESSAGE_OPTION, message};
91          commitCmd = BazaarUtils.expandCommandLine( commitCmd, fileSet );
92          ScmResult result =
93              BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), commitCmd );
94  
95          // Push to parent branch if any
96          BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
97          if ( !repository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) && repo.isPushChanges() )
98          {
99              String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, BazaarConstants.NO_STRICT_OPTION, repository.getURI() };
100             result =
101                 BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), pushCmd );
102         }
103 
104         return new CheckInScmResult( commitedFiles, result );
105     }
106 }