001package org.apache.maven.scm.provider.synergy.command.changelog;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.ArrayList;
023import java.util.Date;
024import java.util.List;
025
026import org.apache.maven.scm.ChangeSet;
027import org.apache.maven.scm.ScmBranch;
028import org.apache.maven.scm.ScmException;
029import org.apache.maven.scm.ScmFileSet;
030import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
031import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
032import org.apache.maven.scm.command.changelog.ChangeLogSet;
033import org.apache.maven.scm.provider.ScmProviderRepository;
034import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
035import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
036import org.apache.maven.scm.provider.synergy.util.SynergyTask;
037import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
038
039/**
040 * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
041 * @author Olivier Lamy
042 *
043 */
044public class SynergyChangeLogCommand
045    extends AbstractChangeLogCommand
046    implements SynergyCommand
047{
048
049    /** {@inheritDoc} */
050    protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
051                                                          Date startDate, Date endDate, ScmBranch branch,
052                                                          String datePattern )
053        throws ScmException
054    {
055        if ( getLogger().isDebugEnabled() )
056        {
057            getLogger().debug( "executing changelog command..." );
058        }
059
060        SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
061
062        if ( getLogger().isDebugEnabled() )
063        {
064            getLogger().debug( "basedir: " + fileSet.getBasedir() );
065        }
066
067        String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
068
069        List<ChangeSet> csList = new ArrayList<ChangeSet>();
070
071        try
072        {
073            String projectSpec =
074                SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
075            if ( projectSpec == null )
076            {
077                throw new ScmException( "You should checkout a working project first" );
078            }
079            List<SynergyTask> tasks =
080                SynergyUtil.getCompletedTasks( getLogger(), projectSpec, startDate, endDate, ccmAddr );
081            for ( SynergyTask t : tasks )
082            {
083                ChangeSet cs = new ChangeSet();
084                cs.setAuthor( t.getUsername() );
085                cs.setComment( "Task " + t.getNumber() + ": " + t.getComment() );
086                cs.setDate( t.getModifiedTime() );
087                cs.setFiles( SynergyUtil.getModifiedObjects( getLogger(), t.getNumber(), ccmAddr ) );
088                csList.add( cs );
089            }
090        }
091        finally
092        {
093            SynergyUtil.stop( getLogger(), ccmAddr );
094        }
095
096        return new ChangeLogScmResult( "ccm query ...", new ChangeLogSet( csList, startDate, endDate ) );
097    }
098
099}