1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package org.apache.maven.scm.provider.bazaar.command.tag; |
21 | |
|
22 | |
import java.io.File; |
23 | |
|
24 | |
import org.apache.maven.scm.ScmException; |
25 | |
import org.apache.maven.scm.ScmFileSet; |
26 | |
import org.apache.maven.scm.ScmFileStatus; |
27 | |
import org.apache.maven.scm.ScmResult; |
28 | |
import org.apache.maven.scm.ScmTagParameters; |
29 | |
import org.apache.maven.scm.command.tag.AbstractTagCommand; |
30 | |
import org.apache.maven.scm.command.tag.TagScmResult; |
31 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
32 | |
import org.apache.maven.scm.provider.bazaar.BazaarUtils; |
33 | |
import org.apache.maven.scm.provider.bazaar.command.BazaarConstants; |
34 | |
import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer; |
35 | |
import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository; |
36 | |
import org.codehaus.plexus.util.StringUtils; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class BazaarTagCommand extends AbstractTagCommand { |
43 | |
protected ScmResult executeTagCommand( ScmProviderRepository repository, |
44 | |
ScmFileSet fileSet, String tagName, |
45 | |
ScmTagParameters scmTagParameters ) throws ScmException |
46 | |
{ |
47 | 0 | if ( tagName == null || StringUtils.isEmpty( tagName.trim() ) ) { |
48 | 0 | throw new ScmException( "tag name must be specified" ); |
49 | |
} |
50 | |
|
51 | 0 | if ( !fileSet.getFileList().isEmpty() ) { |
52 | 0 | throw new ScmException( "tagging specific files is not allowed" ); |
53 | |
} |
54 | |
|
55 | |
|
56 | 0 | File bazaarRoot = fileSet.getBasedir(); |
57 | 0 | BazaarConsumer consumer = new BazaarConsumer( getLogger() ); |
58 | 0 | String[] tagCmd = new String[] { BazaarConstants.TAG_CMD, tagName }; |
59 | 0 | ScmResult tagResult = BazaarUtils.execute( consumer, getLogger(), bazaarRoot, tagCmd ); |
60 | 0 | if ( !tagResult.isSuccess() ) { |
61 | 0 | return new TagScmResult( null, tagResult ); |
62 | |
} |
63 | |
|
64 | |
|
65 | 0 | BazaarLsConsumer lsConsumer = |
66 | |
new BazaarLsConsumer( getLogger(), bazaarRoot, ScmFileStatus.TAGGED ); |
67 | 0 | String[] lsCmd = new String[] { |
68 | |
BazaarConstants.LS_CMD, |
69 | |
BazaarConstants.RECURSIVE_OPTION, |
70 | |
BazaarConstants.REVISION_OPTION, |
71 | |
"tag:" + tagName |
72 | |
}; |
73 | 0 | ScmResult lsResult = BazaarUtils.execute(lsConsumer, getLogger(), bazaarRoot, lsCmd); |
74 | 0 | if ( !lsResult.isSuccess() ) { |
75 | 0 | return new TagScmResult( null, lsResult ); |
76 | |
} |
77 | |
|
78 | |
|
79 | 0 | BazaarScmProviderRepository bazaarRepository = (BazaarScmProviderRepository) repository; |
80 | 0 | if ( !bazaarRepository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) && repository.isPushChanges() ) |
81 | |
{ |
82 | 0 | String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, bazaarRepository.getURI() }; |
83 | 0 | ScmResult pushResult = |
84 | |
BazaarUtils.execute( new BazaarConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), pushCmd ); |
85 | 0 | if ( !pushResult.isSuccess() ) { |
86 | 0 | return new TagScmResult( null, pushResult ); |
87 | |
} |
88 | |
} |
89 | |
|
90 | 0 | return new TagScmResult( lsConsumer.getListedFiles(), tagResult ); |
91 | |
} |
92 | |
} |