View Javadoc

1   package org.apache.maven.scm.provider.synergy.command.changelog;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Date;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ChangeSet;
27  import org.apache.maven.scm.ScmBranch;
28  import org.apache.maven.scm.ScmException;
29  import org.apache.maven.scm.ScmFileSet;
30  import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
31  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
32  import org.apache.maven.scm.command.changelog.ChangeLogSet;
33  import org.apache.maven.scm.provider.ScmProviderRepository;
34  import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
35  import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
36  import org.apache.maven.scm.provider.synergy.util.SynergyTask;
37  import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
38  
39  /**
40   * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
41   * @author Olivier Lamy
42   *
43   */
44  public class SynergyChangeLogCommand
45      extends AbstractChangeLogCommand
46      implements SynergyCommand
47  {
48  
49      /** {@inheritDoc} */
50      protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
51                                                            Date startDate, Date endDate, ScmBranch branch,
52                                                            String datePattern )
53          throws ScmException
54      {
55          if ( getLogger().isDebugEnabled() )
56          {
57              getLogger().debug( "executing changelog command..." );
58          }
59  
60          SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
61  
62          if ( getLogger().isDebugEnabled() )
63          {
64              getLogger().debug( "basedir: " + fileSet.getBasedir() );
65          }
66  
67          String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
68  
69          List<ChangeSet> csList = new ArrayList<ChangeSet>();
70  
71          try
72          {
73              String projectSpec =
74                  SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
75              if ( projectSpec == null )
76              {
77                  throw new ScmException( "You should checkout a working project first" );
78              }
79              List<SynergyTask> tasks = SynergyUtil.getCompletedTasks( getLogger(), projectSpec, startDate, endDate, ccmAddr );
80              for ( SynergyTask t : tasks )
81              {
82                  ChangeSet cs = new ChangeSet();
83                  cs.setAuthor( t.getUsername() );
84                  cs.setComment( "Task " + t.getNumber() + ": " + t.getComment() );
85                  cs.setDate( t.getModifiedTime() );
86                  cs.setFiles( SynergyUtil.getModifiedObjects( getLogger(), t.getNumber(), ccmAddr ) );
87                  csList.add( cs );
88              }
89          }
90          finally
91          {
92              SynergyUtil.stop( getLogger(), ccmAddr );
93          }
94  
95          return new ChangeLogScmResult( "ccm query ...", new ChangeLogSet( csList, startDate, endDate ) );
96      }
97  
98  }