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