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  /**
45   * 
46   */
47  public class AccuRevExportCommand
48      extends AbstractAccuRevExtractSourceCommand
49  {
50  
51      public AccuRevExportCommand( ScmLogger logger )
52      {
53          super( logger );
54      }
55  
56      public ExportScmResult export( ScmProviderRepository repository, ScmFileSet scmFileSet, CommandParameters params )
57          throws ScmException
58      {
59          return (ExportScmResult) execute( repository, scmFileSet, params );
60      }
61  
62      @Override
63      protected List<File> extractSource( AccuRevScmProviderRepository repository, File basedir, AccuRevVersion version )
64          throws AccuRevException
65      {
66          AccuRev accuRev = repository.getAccuRev();
67          AccuRevInfo info = accuRev.info( basedir );
68          String basisStream = version.getBasisStream();
69          String transactionId = version.getTimeSpec();
70  
71          if ( !AccuRevVersion.isNow( transactionId )
72              && !AccuRevCapability.POPULATE_TO_TRANSACTION.isSupported( accuRev.getClientVersion() ) )
73          {
74              getLogger().warn(
75                                String.format( "Ignoring transaction id %s, Export can only extract current sources",
76                                               transactionId ) );
77              transactionId = "now";
78          }
79          else
80          {
81              //We might be heading to a transaction id that is not yet available on a replica
82              accuRev.syncReplica();            
83          }
84  
85          boolean removedWorkspace = false;
86  
87          // We'll do a pop -V.
88  
89          if ( info.isWorkSpace() )
90          {
91  
92              String stat = accuRev.stat( basedir );
93  
94              if ( stat != null )
95              {
96                  throw new AccuRevException( String.format( "Cannot populate %s, as it is a non-ignored "
97                                                                 + "subdirectory of workspace %s rooted at %s.",
98                                                             basedir.getAbsolutePath(), info.getWorkSpace(),
99                                                             info.getTop() ) );
100             }
101 
102             // ok, the subdirectory must be ignored. temporarily remove the workspace.
103             removedWorkspace = accuRev.rmws( info.getWorkSpace() );
104 
105         }
106 
107         try
108         {
109             File path = new File( repository.getDepotRelativeProjectPath() );
110             return accuRev.popExternal( basedir, basisStream, transactionId, Collections.singletonList( path ) );
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 }