/** * 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 | 9519 | dantran | folder rename to match with its artifactId | ||
//guest/dantran/p4maven/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/blame/P4BlameCommand.java | |||||
#5 | 9489 | dantran | back to scm-test 1.9 to prep for another release | ||
#4 | 9488 | dantran | Implement Blame TCK | ||
#3 | 9476 | dantran |
- Each managed client now has its own server to prevent concurrency - Validate managed client and server instances |
||
#2 | 9250 | dantran | caching client across mutiple commands | ||
#1 | 9167 | dantran |
Populate //guest/dantran/p4maven/... from //guest/perforce_software/p4maven/main/.... |
||
//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 |