/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
package com.perforce.maven.scm.provider.p4.command.blame;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.command.blame.AbstractBlameCommand;
import org.apache.maven.scm.command.blame.BlameLine;
import org.apache.maven.scm.command.blame.BlameScmResult;
import org.apache.maven.scm.provider.ScmProviderRepository;
import com.perforce.maven.scm.provider.p4.command.P4Command;
import com.perforce.maven.scm.provider.p4.util.P4Utils;
import com.perforce.p4java.client.IClient;
import com.perforce.p4java.core.file.FileSpecBuilder;
import com.perforce.p4java.core.file.IFileAnnotation;
import com.perforce.p4java.core.file.IFileRevisionData;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.option.server.GetFileAnnotationsOptions;
import com.perforce.p4java.option.server.GetRevisionHistoryOptions;
import com.perforce.p4java.server.IOptionsServer;
/**
* Use Perforce annotate command to get file lines and their revisions. Use Perforce filelog command to get revision
* history of files.
*/
public class P4BlameCommand
extends AbstractBlameCommand
implements P4Command
{
/** The Constant command. */
public static final String command = "Perforce annotate command";
private IClient client;
public void setClient( IClient client )
{
this.client = client;
}
/**
* @see org.apache.maven.scm.command.blame.AbstractBlameCommand#executeBlameCommand
* (org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, java.lang.String)
*/
public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet workingDirectory, String filename )
throws ScmException
{
P4BlameResult p4Result = new P4BlameResult();
List<IFileSpec> fileSpecs =
FileSpecBuilder.makeFileSpecList( P4Utils.encodeWildcards( ( new File( workingDirectory.getBasedir(),
filename ) ).getAbsolutePath() ) );
try
{
// Get file annotations
IOptionsServer server = (IOptionsServer) client.getServer();
GetFileAnnotationsOptions getFileAnnotationsOptions = new GetFileAnnotationsOptions();
List<IFileAnnotation> fileAnnotations = server.getFileAnnotations( fileSpecs, getFileAnnotationsOptions );
// Process the file annotations as blame lines
p4Result.processBlameLines( fileAnnotations );
// Get revision history
GetRevisionHistoryOptions getRevisionHistoryOptions = new GetRevisionHistoryOptions();
Map<IFileSpec, List<IFileRevisionData>> revisionMap =
server.getRevisionHistory( fileSpecs, getRevisionHistoryOptions );
// Process the revision data map
p4Result.processRevisionHistory( revisionMap );
}
catch ( P4JavaException e )
{
throw new ScmException( e.getLocalizedMessage(), e );
}
// Combine the results
List<BlameLine> lines = p4Result.getBlameLines();
for ( int i = 0; i < lines.size(); i++ )
{
BlameLine line = (BlameLine) lines.get( i );
String revision = line.getRevision();
line.setAuthor( p4Result.getAuthor( revision ) );
line.setDate( p4Result.getDate( revision ) );
}
return new BlameScmResult( command, lines );
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
10055 |
Matt Attaway |
Pull over numerous changes from @dantran's branch. |
|
|
//guest/perforce_software/p4maven/main/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/blame/P4BlameCommand.java |
#1
|
8496 |
Matt Attaway |
Move P4Ant and P4Maven into their proper homes |
|
|
//public/perforce/p4maven/main/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/blame/P4BlameCommand.java |
#1
|
8270 |
Matt Attaway |
Initial add of P4Maven source code |
|
|