View Javadoc

1   package org.apache.maven.scm.provider.accurev.command.export;
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.Collections;
24  import java.util.List;
25  
26  import org.apache.maven.scm.CommandParameters;
27  import org.apache.maven.scm.ScmException;
28  import org.apache.maven.scm.ScmFile;
29  import org.apache.maven.scm.ScmFileSet;
30  import org.apache.maven.scm.ScmResult;
31  import org.apache.maven.scm.ScmVersion;
32  import org.apache.maven.scm.command.export.ExportScmResult;
33  import org.apache.maven.scm.command.export.ExportScmResultWithRevision;
34  import org.apache.maven.scm.log.ScmLogger;
35  import org.apache.maven.scm.provider.ScmProviderRepository;
36  import org.apache.maven.scm.provider.accurev.AccuRev;
37  import org.apache.maven.scm.provider.accurev.AccuRevCapability;
38  import org.apache.maven.scm.provider.accurev.AccuRevException;
39  import org.apache.maven.scm.provider.accurev.AccuRevInfo;
40  import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
41  import org.apache.maven.scm.provider.accurev.AccuRevVersion;
42  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevExtractSourceCommand;
43  
44  public class AccuRevExportCommand
45      extends AbstractAccuRevExtractSourceCommand
46  {
47  
48      public AccuRevExportCommand( ScmLogger logger )
49      {
50          super( logger );
51      }
52  
53      public ExportScmResult export( ScmProviderRepository repository, ScmFileSet scmFileSet, CommandParameters params )
54          throws ScmException
55      {
56          return (ExportScmResult) execute( repository, scmFileSet, params );
57      }
58  
59      @Override
60      protected List<File> extractSource( AccuRevScmProviderRepository repository, File basedir, AccuRevVersion version )
61          throws AccuRevException
62      {
63          AccuRev accuRev = repository.getAccuRev();
64          AccuRevInfo info = accuRev.info( basedir );
65          String basisStream = version.getBasisStream();
66          String transactionId = version.getTimeSpec();
67  
68          if ( !AccuRevVersion.isNow( transactionId )
69              && !AccuRevCapability.POPULATE_TO_TRANSACTION.isSupported( accuRev.getClientVersion() ) )
70          {
71              getLogger().warn(
72                                String.format( "Ignoring transaction id %s, Export can only extract current sources",
73                                               transactionId ) );
74              transactionId = "now";
75          } else {
76              //We might be heading to a transaction id that is not yet available on a replica
77              accuRev.syncReplica();            
78          }
79  
80          boolean removedWorkspace = false;
81  
82          // We'll do a pop -V.
83  
84          if ( info.isWorkSpace() )
85          {
86  
87              String stat = accuRev.stat( basedir );
88  
89              if ( stat != null )
90              {
91                  throw new AccuRevException(
92                                              String.format(
93                                                             "Cannot populate %s, as it is a non-ignored subdirectory of workspace %s rooted at %s.",
94                                                             basedir.getAbsolutePath(), info.getWorkSpace(),
95                                                             info.getTop() ) );
96              }
97  
98              // ok, the subdirectory must be ignored. temporarily remove the workspace.
99              removedWorkspace = accuRev.rmws( info.getWorkSpace() );
100 
101         }
102 
103         try
104         {
105             return accuRev.popExternal(
106                                         basedir,
107                                         basisStream,
108                                         transactionId,
109                                         Collections.singletonList( new File( repository.getDepotRelativeProjectPath() ) ) );
110 
111         }
112         finally
113         {
114             if ( removedWorkspace )
115             {
116                 accuRev.reactivate( info.getWorkSpace() );
117             }
118         }
119     }
120 
121     @Override
122     protected ScmResult getScmResult( AccuRevScmProviderRepository repository, List<ScmFile> scmFiles,
123                                       ScmVersion scmVersion )
124     {
125         AccuRev accuRev = repository.getAccuRev();
126         if ( scmFiles != null )
127         {
128             if ( scmVersion == null )
129             {
130                 return new ExportScmResult( accuRev.getCommandLines(), scmFiles );
131             }
132             else
133             {
134                 return new ExportScmResultWithRevision( accuRev.getCommandLines(), scmFiles, scmVersion.toString() );
135             }
136         }
137         else
138         {
139             return new ExportScmResult( accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false );
140         }
141     }
142 
143 }