View Javadoc
1   package org.apache.maven.scm.provider.starteam.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 org.apache.maven.scm.ScmBranch;
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
26  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
27  import org.apache.maven.scm.command.changelog.ChangeLogSet;
28  import org.apache.maven.scm.provider.ScmProviderRepository;
29  import org.apache.maven.scm.provider.starteam.command.StarteamCommand;
30  import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
31  import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
32  import org.codehaus.plexus.util.StringUtils;
33  import org.codehaus.plexus.util.cli.CommandLineException;
34  import org.codehaus.plexus.util.cli.CommandLineUtils;
35  import org.codehaus.plexus.util.cli.Commandline;
36  
37  import java.util.Date;
38  
39  /**
40   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
41   * @author Olivier Lamy
42   *
43   */
44  public class StarteamChangeLogCommand
45      extends AbstractChangeLogCommand
46      implements StarteamCommand
47  {
48      // ----------------------------------------------------------------------
49      // AbstractChangeLogCommand Implementation
50      // ----------------------------------------------------------------------
51  
52      /** {@inheritDoc} */
53      protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
54                                                            Date startDate, Date endDate, ScmBranch branch,
55                                                            String datePattern )
56          throws ScmException
57      {
58          if ( ( branch != null || StringUtils.isNotEmpty( ( branch == null ) ? null : branch.getName() ) )
59              && ( getLogger().isWarnEnabled() ) )
60          {
61              getLogger().warn( "This provider doesn't support changelog with on a given branch." );
62          }
63  
64          StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
65  
66          // TODO: revision
67          Commandline cl = createCommandLine( repository, fileSet, startDate );
68  
69          StarteamChangeLogConsumer consumer =
70              new StarteamChangeLogConsumer( fileSet.getBasedir(), getLogger(), startDate, endDate, datePattern );
71  
72          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
73  
74          int exitCode;
75  
76          try
77          {
78              exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
79          }
80          catch ( CommandLineException ex )
81          {
82              throw new ScmException( "Error while executing command.", ex );
83          }
84  
85          if ( exitCode != 0 )
86          {
87              return new ChangeLogScmResult( cl.toString(), "The 'stcmd' command failed.", stderr.getOutput(), false );
88          }
89  
90          return new ChangeLogScmResult( cl.toString(),
91                                         new ChangeLogSet( consumer.getModifications(), startDate, endDate ) );
92      }
93  
94      // ----------------------------------------------------------------------
95      //
96      // ----------------------------------------------------------------------
97  
98      public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet workingDirectory,
99                                                   Date startDate )
100     {
101         //return the full history since we dont know to get hist log from
102         //  creation date to a specific date yet
103         return StarteamCommandLineUtils.createStarteamCommandLine( "hist", null, workingDirectory, repo );
104 
105         /**
106          * unfortunately the below option only gives the hist from view creation date to
107          * the specified date.  What good is that?????
108          */
109 
110         /*
111         if ( startDate != null )
112         {
113             SimpleDateFormat localFormat = new SimpleDateFormat();
114 
115             cl.createArg().setValue( "-cfgd" );
116 
117             cl.createArg().setValue( localFormat.format( startDate ).toString() );
118         }
119         */
120 
121     }
122 }