1 package org.apache.maven.scm.provider.bazaar.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.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.apache.maven.scm.ChangeSet;
29 import org.apache.maven.scm.ScmException;
30 import org.apache.maven.scm.ScmFile;
31 import org.apache.maven.scm.ScmFileSet;
32 import org.apache.maven.scm.ScmFileStatus;
33 import org.apache.maven.scm.ScmResult;
34 import org.apache.maven.scm.ScmVersion;
35 import org.apache.maven.scm.command.Command;
36 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
37 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
38 import org.apache.maven.scm.command.update.UpdateScmResult;
39 import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
40 import org.apache.maven.scm.provider.ScmProviderRepository;
41 import org.apache.maven.scm.provider.bazaar.BazaarUtils;
42 import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
43 import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer;
44 import org.apache.maven.scm.provider.bazaar.command.changelog.BazaarChangeLogCommand;
45 import org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer;
46 import org.codehaus.plexus.util.StringUtils;
47
48
49
50
51
52 public class BazaarUpdateCommand
53 extends AbstractUpdateCommand
54 implements Command
55 {
56
57
58 protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
59 throws ScmException
60 {
61
62 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
63 {
64 throw new ScmException( "This provider can't handle tags." );
65 }
66
67 File workingDir = fileSet.getBasedir();
68
69
70 String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
71 ScmResult updateResult = BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), workingDir,
72 updateCmd );
73
74 if ( !updateResult.isSuccess() )
75 {
76 return new UpdateScmResult( null, null, updateResult );
77 }
78
79
80 int currentRevision = BazaarUtils.getCurrentRevisionNumber( getLogger(), workingDir );
81 int previousRevision = currentRevision - 1;
82 String[] diffCmd =
83 new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
84 BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer( getLogger(), workingDir );
85 ScmResult diffResult = BazaarUtils.execute( diffConsumer, getLogger(), workingDir, diffCmd );
86
87
88 List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
89 List<CharSequence> changes = new ArrayList<CharSequence>();
90 List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
91 Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
92 for ( Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); )
93 {
94 ScmFile file = it.next();
95 changes.add( diffChanges.get( file ) );
96 if ( file.getStatus() == ScmFileStatus.MODIFIED )
97 {
98 updatedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.PATCHED ) );
99 }
100 else
101 {
102 updatedFiles.add( file );
103 }
104 }
105
106 return new UpdateScmResultWithRevision( updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf( currentRevision ), diffResult );
107 }
108
109
110 protected ChangeLogCommand getChangeLogCommand()
111 {
112 BazaarChangeLogCommand command = new BazaarChangeLogCommand();
113 command.setLogger( getLogger() );
114 return command;
115 }
116 }