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 | 0 | 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 | 0 | if ( version != null && StringUtils.isNotEmpty( version.getName() ) ) |
63 | |
{ |
64 | 0 | throw new ScmException( "This provider can't handle tags." ); |
65 | |
} |
66 | |
|
67 | 0 | File workingDir = fileSet.getBasedir(); |
68 | |
|
69 | |
|
70 | 0 | String[] updateCmd = new String[] { BazaarConstants.PULL_CMD }; |
71 | 0 | ScmResult updateResult = BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), workingDir, |
72 | |
updateCmd ); |
73 | |
|
74 | 0 | if ( !updateResult.isSuccess() ) |
75 | |
{ |
76 | 0 | return new UpdateScmResult( null, null, updateResult ); |
77 | |
} |
78 | |
|
79 | |
|
80 | 0 | int currentRevision = BazaarUtils.getCurrentRevisionNumber( getLogger(), workingDir ); |
81 | 0 | int previousRevision = currentRevision - 1; |
82 | 0 | String[] diffCmd = |
83 | |
new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision }; |
84 | 0 | BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer( getLogger(), workingDir ); |
85 | 0 | ScmResult diffResult = BazaarUtils.execute( diffConsumer, getLogger(), workingDir, diffCmd ); |
86 | |
|
87 | |
|
88 | 0 | List<ScmFile> updatedFiles = new ArrayList<ScmFile>(); |
89 | 0 | List<CharSequence> changes = new ArrayList<CharSequence>(); |
90 | 0 | List<ScmFile> diffFiles = diffConsumer.getChangedFiles(); |
91 | 0 | Map<String, CharSequence> diffChanges = diffConsumer.getDifferences(); |
92 | 0 | for ( Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); ) |
93 | |
{ |
94 | 0 | ScmFile file = it.next(); |
95 | 0 | changes.add( diffChanges.get( file ) ); |
96 | 0 | if ( file.getStatus() == ScmFileStatus.MODIFIED ) |
97 | |
{ |
98 | 0 | updatedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.PATCHED ) ); |
99 | |
} |
100 | |
else |
101 | |
{ |
102 | 0 | updatedFiles.add( file ); |
103 | |
} |
104 | 0 | } |
105 | |
|
106 | 0 | return new UpdateScmResultWithRevision( updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf( currentRevision ), diffResult ); |
107 | |
} |
108 | |
|
109 | |
|
110 | |
protected ChangeLogCommand getChangeLogCommand() |
111 | |
{ |
112 | 0 | BazaarChangeLogCommand command = new BazaarChangeLogCommand(); |
113 | 0 | command.setLogger( getLogger() ); |
114 | 0 | return command; |
115 | |
} |
116 | |
} |