1 package org.apache.maven.scm.provider.accurev.command.update;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Date;
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.ScmVersion;
33 import org.apache.maven.scm.command.update.UpdateScmResult;
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.AccuRevException;
38 import org.apache.maven.scm.provider.accurev.AccuRevInfo;
39 import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
40 import org.apache.maven.scm.provider.accurev.AccuRevVersion;
41 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand;
42
43 public class AccuRevUpdateCommand
44 extends AbstractAccuRevCommand
45 {
46
47 public AccuRevUpdateCommand( ScmLogger logger )
48 {
49 super( logger );
50 }
51
52 @Override
53 protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
54 CommandParameters parameters )
55 throws ScmException, AccuRevException
56 {
57
58 AccuRev accuRev = repository.getAccuRev();
59
60 File basedir = fileSet.getBasedir();
61
62 AccuRevInfo info = accuRev.info( basedir );
63
64 if ( !info.isWorkSpace() )
65 {
66 throw new AccuRevException( "No workspace at " + basedir.getAbsolutePath() );
67 }
68
69 String startRevision = getStartRevision( repository, parameters, info );
70
71 ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null );
72
73 String updateTransactionId = null;
74
75 if ( scmVersion != null )
76 {
77 AccuRevVersion updateVersion = repository.getAccuRevVersion( scmVersion );
78
79
80 String newBasisStream = updateVersion.getBasisStream();
81 if ( newBasisStream != null
82 && ( !( newBasisStream.equals( info.getWorkSpace() ) || newBasisStream.equals( info.getBasis() ) ) ) )
83 {
84 getLogger().info( "Reparenting " + info.getWorkSpace() + " to " + newBasisStream );
85 accuRev.chws( basedir, info.getWorkSpace(), newBasisStream );
86 }
87
88 if ( !updateVersion.isNow() )
89 {
90 updateTransactionId = updateVersion.getTimeSpec();
91 }
92 }
93
94 if ( updateTransactionId == null )
95 {
96 updateTransactionId = repository.getDepotTransactionId( info.getWorkSpace(), "now" );
97 }
98
99 String endRevision = repository.getRevision( info.getWorkSpace(), updateTransactionId );
100
101 List<File> updatedFiles = accuRev.update( basedir, updateTransactionId );
102
103 if ( updatedFiles != null )
104 {
105 return new AccuRevUpdateScmResult( accuRev.getCommandLines(), getScmFiles( updatedFiles,
106 ScmFileStatus.UPDATED ),
107 startRevision, endRevision );
108 }
109 else
110 {
111 return new AccuRevUpdateScmResult( accuRev.getCommandLines(), "AccuRev error", accuRev.getErrorOutput(),
112 null, null, false );
113 }
114 }
115
116
117
118
119
120 private String getStartRevision( AccuRevScmProviderRepository repository, CommandParameters parameters,
121 AccuRevInfo info )
122 throws ScmException, AccuRevException
123 {
124
125 boolean runChangeLog = parameters.getBoolean( CommandParameter.RUN_CHANGELOG_WITH_UPDATE );
126 Date startDate = parameters.getDate( CommandParameter.START_DATE, null );
127 String workspace = info.getWorkSpace();
128
129 if ( !runChangeLog )
130 {
131 return null;
132 }
133 else
134 {
135 return startDate == null ? repository.getWorkSpaceRevision( workspace )
136 : repository.getRevision( workspace, startDate );
137 }
138
139 }
140
141 public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
142 throws ScmException
143 {
144 return (UpdateScmResult) execute( repository, fileSet, parameters );
145 }
146
147 }