001package org.apache.maven.scm.provider.bazaar.command.diff; 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 org.apache.maven.scm.ScmException; 023import org.apache.maven.scm.ScmFileSet; 024import org.apache.maven.scm.ScmResult; 025import org.apache.maven.scm.ScmVersion; 026import org.apache.maven.scm.command.Command; 027import org.apache.maven.scm.command.diff.AbstractDiffCommand; 028import org.apache.maven.scm.command.diff.DiffScmResult; 029import org.apache.maven.scm.provider.ScmProviderRepository; 030import org.apache.maven.scm.provider.bazaar.BazaarUtils; 031import org.apache.maven.scm.provider.bazaar.command.BazaarConstants; 032import org.codehaus.plexus.util.StringUtils; 033 034/** 035 * @author <a href="mailto:torbjorn@smorgrav.org">Torbj�rn Eikli Sm�rgrav</a> 036 * 037 */ 038public class BazaarDiffCommand 039 extends AbstractDiffCommand 040 implements Command 041{ 042 /** {@inheritDoc} */ 043 protected DiffScmResult executeDiffCommand( ScmProviderRepository repo, ScmFileSet fileSet, 044 ScmVersion startRevision, ScmVersion endRevision ) 045 throws ScmException 046 { 047 048 String[] diffCmd; 049 if ( startRevision != null && StringUtils.isNotEmpty( startRevision.getName() ) ) 050 { 051 String revArg = startRevision.getName(); 052 if ( endRevision != null && StringUtils.isNotEmpty( endRevision.getName() ) ) 053 { 054 revArg += ".." + endRevision.getName(); 055 } 056 diffCmd = new String[]{BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, revArg}; 057 } 058 else 059 { 060 diffCmd = new String[]{BazaarConstants.DIFF_CMD}; 061 } 062 063 diffCmd = BazaarUtils.expandCommandLine( diffCmd, fileSet ); 064 BazaarDiffConsumer consumer = new BazaarDiffConsumer( getLogger(), fileSet.getBasedir() ); 065 066 ScmResult result = BazaarUtils.execute( consumer, getLogger(), fileSet.getBasedir(), diffCmd ); 067 068 return new DiffScmResult( consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch(), result ); 069 } 070}