View Javadoc

1   package org.apache.maven.scm.provider.accurev.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.Iterator;
24  import java.util.List;
25  
26  import org.apache.maven.scm.CommandParameter;
27  import org.apache.maven.scm.CommandParameters;
28  import org.apache.maven.scm.ScmException;
29  import org.apache.maven.scm.ScmFileSet;
30  import org.apache.maven.scm.ScmFileStatus;
31  import org.apache.maven.scm.ScmResult;
32  import org.apache.maven.scm.command.checkin.CheckInScmResult;
33  import org.apache.maven.scm.log.ScmLogger;
34  import org.apache.maven.scm.provider.ScmProviderRepository;
35  import org.apache.maven.scm.provider.accurev.AccuRev;
36  import org.apache.maven.scm.provider.accurev.AccuRevException;
37  import org.apache.maven.scm.provider.accurev.AccuRevInfo;
38  import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
39  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand;
40  
41  public class AccuRevCheckInCommand
42      extends AbstractAccuRevCommand
43  {
44  
45      public AccuRevCheckInCommand( ScmLogger logger )
46      {
47          super( logger );
48      }
49  
50      @Override
51      protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
52                                                 CommandParameters parameters )
53          throws ScmException, AccuRevException
54      {
55  
56          AccuRev accuRev = repository.getAccuRev();
57  
58          String message = parameters.getString( CommandParameter.MESSAGE );
59          List<File> promotedFiles = null;
60  
61          File basedir = fileSet.getBasedir();
62          List<File> fileList = fileSet.getFileList();
63  
64          if ( fileList.isEmpty() )
65          {
66              // TODO the above test will be matched by a fileset where excludes and includes produce a set with no files.
67              // This is
68              // NOT the same as a fileset created with only a base directory. Raise maven-scm JIRA for this.
69              AccuRevInfo info = accuRev.info( basedir );
70  
71              if ( repository.isWorkSpaceRoot( info ) )
72              {
73                  promotedFiles = accuRev.promoteAll( basedir, message );
74              }
75              else
76              {
77                  throw new ScmException( String.format( "Unsupported recursive checkin for %s. Not the workspace root",
78                                                         basedir.getAbsolutePath() ) );
79              }
80          }
81          else
82          {
83              promotedFiles = accuRev.promote( basedir, fileList, message );
84          }
85  
86  
87          if ( promotedFiles != null )
88          {
89              Iterator<File> iter = promotedFiles.iterator();
90              while ( iter.hasNext() )
91              {
92                  if ( new File( basedir, iter.next().getPath() ).isDirectory() )
93                  {
94                      iter.remove();
95                  }
96              }
97              // TODO capture the transaction id from the promote
98              return new CheckInScmResult( accuRev.getCommandLines(), getScmFiles( promotedFiles,
99                                                                                   ScmFileStatus.CHECKED_IN ) );
100         }
101         else
102         {
103             return new CheckInScmResult( accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false );
104         }
105     }
106 
107     public CheckInScmResult checkIn( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
108         throws ScmException
109     {
110         return (CheckInScmResult) execute( repository, fileSet, parameters );
111     }
112 
113 }