1 package org.apache.maven.scm.provider.jazz.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ChangeSet;
23 import org.apache.maven.scm.ScmBranch;
24 import org.apache.maven.scm.ScmException;
25 import org.apache.maven.scm.ScmFileSet;
26 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
27 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
28 import org.apache.maven.scm.command.changelog.ChangeLogSet;
29 import org.apache.maven.scm.provider.ScmProviderRepository;
30 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
31 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
32 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
33 import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
34 import org.codehaus.plexus.util.StringUtils;
35
36 import java.util.ArrayList;
37 import java.util.Date;
38 import java.util.List;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public class JazzChangeLogCommand
67 extends AbstractChangeLogCommand
68 {
69
70
71
72 protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
73 Date startDate, Date endDate, ScmBranch branch,
74 String datePattern )
75 throws ScmException
76 {
77 if ( branch != null && StringUtils.isNotEmpty( branch.getName() ) )
78 {
79 throw new ScmException( "This SCM provider doesn't support branches." );
80 }
81
82 if ( getLogger().isDebugEnabled() )
83 {
84 getLogger().debug( "Executing changelog command..." );
85 }
86
87
88
89
90
91 List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
92 JazzScmCommand historyCommand = createHistoryCommand( repo, fileSet );
93 JazzHistoryConsumer changeLogConsumer = new JazzHistoryConsumer( repo, getLogger(), changeSets );
94 ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
95 int status = historyCommand.execute( changeLogConsumer, errConsumer );
96 if ( status != 0 || errConsumer.hasBeenFed() )
97 {
98 return new ChangeLogScmResult( historyCommand.getCommandString(),
99 "Error code for Jazz SCM history command - " + status,
100 errConsumer.getOutput(), false );
101 }
102
103
104 JazzScmCommand listChangesetsCommand = createListChangesetCommand( repo, fileSet, changeSets );
105 JazzListChangesetConsumer listChangesetConsumer =
106 new JazzListChangesetConsumer( repo, getLogger(), changeSets, datePattern );
107 errConsumer = new ErrorConsumer( getLogger() );
108 status = listChangesetsCommand.execute( listChangesetConsumer, errConsumer );
109 if ( status != 0 || errConsumer.hasBeenFed() )
110 {
111 return new ChangeLogScmResult( listChangesetsCommand.getCommandString(),
112 "Error code for Jazz SCM list changesets command - " + status,
113 errConsumer.getOutput(), false );
114 }
115
116
117 ChangeLogSet changeLogSet = new ChangeLogSet( changeSets, startDate, endDate );
118
119
120 return new ChangeLogScmResult( historyCommand.getCommandString(), changeLogSet );
121 }
122
123 protected JazzScmCommand createHistoryCommand( ScmProviderRepository repo, ScmFileSet fileSet )
124 {
125 JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_HISTORY, repo, fileSet, getLogger() );
126 command.addArgument( JazzConstants.ARG_MAXIMUM );
127 command.addArgument( "10000000" );
128
129
130
131 return command;
132 }
133
134 protected JazzScmCommand createListChangesetCommand( ScmProviderRepository repo, ScmFileSet fileSet,
135 List<ChangeSet> changeSets )
136 {
137 JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
138 JazzScmCommand command =
139 new JazzScmCommand( JazzConstants.CMD_LIST, JazzConstants.CMD_SUB_CHANGESETS, repo, fileSet, getLogger() );
140 command.addArgument( JazzConstants.ARG_WORKSPACE );
141 command.addArgument( jazzRepo.getWorkspace() );
142 for ( int i = 0; i < changeSets.size(); i++ )
143 {
144 command.addArgument( changeSets.get( i ).getRevision() );
145 }
146 return command;
147 }
148 }