/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.diff; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.maven.scm.ScmFile; import org.apache.maven.scm.ScmFileStatus; import com.perforce.maven.scm.provider.p4.command.P4Result; import com.perforce.p4java.core.IFileDiff; /** * This class handles the result from the Perforce diff2 command. */ public class P4DiffResult extends P4Result { /** The file diff output. */ private String fileDiffOutput = ""; /** The change files. */ private List<ScmFile> changedFiles = new ArrayList<ScmFile>(); /** The differences. */ private Map<String, CharSequence> differences = new HashMap<String, CharSequence>(); /** The patch. */ private StringBuffer patch = new StringBuffer(); public P4DiffResult( List<IFileDiff> fileDiffs ) { this.processFileDiffs( fileDiffs ); } /** * Process message. * * @param message the message * @return the string * @see com.perforce.maven.scm.provider.p4.command.P4Result#processMessage (java.lang.String) */ @Override public String processMessage( String message ) { return null; } /** * Extracts diff output from the returned diff2 command result file diffs. * * @param fileDiffs the file diffs */ public void processFileDiffs( List<IFileDiff> fileDiffs ) { if ( fileDiffs != null ) { for ( IFileDiff fileDiff : fileDiffs ) { if ( fileDiff != null ) { StringBuilder sb = new StringBuilder(); if ( fileDiff.getStatus() != null ) { sb.append( "status" ).append( "=" ).append( fileDiff.getStatus() ).append( LINE_SEPARATOR ); } if ( fileDiff.getFileType1() != null ) { sb.append( "fileType1" ).append( "=" ).append( fileDiff.getFileType1() ).append( LINE_SEPARATOR ); } if ( fileDiff.getDepotFile1() != null ) { sb.append( "depotFile1" ).append( "=" ).append( fileDiff.getDepotFile1() ).append( LINE_SEPARATOR ); } if ( fileDiff.getRevision1() > -1 ) { sb.append( "revision1" ).append( "=" ).append( fileDiff.getRevision1() ).append( LINE_SEPARATOR ); } if ( fileDiff.getFileType2() != null ) { sb.append( "fileType2" ).append( "=" ).append( fileDiff.getFileType2() ).append( LINE_SEPARATOR ); } if ( fileDiff.getDepotFile2() != null ) { sb.append( "depotFile2" ).append( "=" ).append( fileDiff.getDepotFile2() ).append( LINE_SEPARATOR ); } if ( fileDiff.getRevision2() > -1 ) { sb.append( "revision2" ).append( "=" ).append( fileDiff.getRevision2() ).append( LINE_SEPARATOR ); } fileDiffOutput += sb.toString(); StringBuilder fileDiffPath = new StringBuilder(); if ( fileDiff.getStatus() != null ) { switch ( fileDiff.getStatus() ) { case LEFT_ONLY: fileDiffPath.append( fileDiff.getDepotFile1().toString() ).append( "#" ).append( fileDiff.getRevision1() ).append( " (" ).append( fileDiff.getFileType1() ).append( ")" ); fileDiffPath.append( " - " ); fileDiffPath.append( " <none> " ); fileDiffPath.append( " ==== " ); fileDiffPath.append( fileDiff.getStatus() ); break; case RIGHT_ONLY: fileDiffPath.append( fileDiff.getDepotFile2().toString() ).append( "#" ).append( fileDiff.getRevision2() ).append( " (" ).append( fileDiff.getFileType2() ).append( ")" ); fileDiffPath.append( " - " ); fileDiffPath.append( " <none> " ); fileDiffPath.append( " ==== " ); fileDiffPath.append( fileDiff.getStatus() ); break; case CONTENT: fileDiffPath.append( fileDiff.getDepotFile1().toString() ).append( "#" ).append( fileDiff.getRevision1() ).append( " (" ).append( fileDiff.getFileType1() ).append( ")" ); fileDiffPath.append( " - " ); fileDiffPath.append( fileDiff.getDepotFile2().toString() ).append( "#" ).append( fileDiff.getRevision2() ).append( " (" ).append( fileDiff.getFileType2() ).append( ")" ); fileDiffPath.append( " ==== " ); fileDiffPath.append( fileDiff.getStatus() ); break; case IDENTICAL: fileDiffPath.append( fileDiff.getDepotFile1().toString() ).append( "#" ).append( fileDiff.getRevision1() ).append( " (" ).append( fileDiff.getFileType1() ).append( ")" ); fileDiffPath.append( " - " ); fileDiffPath.append( fileDiff.getDepotFile2().toString() ).append( "#" ).append( fileDiff.getRevision2() ).append( " (" ).append( fileDiff.getFileType2() ).append( ")" ); fileDiffPath.append( " ==== " ); fileDiffPath.append( fileDiff.getStatus() ); break; default: break; } changedFiles.add( new ScmFile( fileDiffPath.toString(), ScmFileStatus.MODIFIED ) ); differences.put( fileDiffPath.toString(), fileDiff.getStatus().toString() ); patch.append( fileDiffPath.toString() ).append( LINE_SEPARATOR ); } } } } } /** * Gets the file diff output. * * @return the file diff output */ public String getFileDiffOutput() { return fileDiffOutput; } /** * Gets the changed files. * * @return the changed files */ public List<ScmFile> getChangedFiles() { return changedFiles; } /** * Gets the differences. * * @return the differences */ public Map<String, CharSequence> getDifferences() { return differences; } /** * Gets the patch. * * @return the patch */ public String getPatch() { return patch.toString(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9533 | dantran | source format | ||
#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/diff/P4DiffResult.java | |||||
#3 | 9471 | dantran |
- cleanup diff command - simplify branch command and full compliant with maven-scm-test - add checkout with branch - add repo's path as client manager lookup key in addition to p4port and rootdir so that we can handle mutiple clients on the same rootdir |
||
#2 | 9177 | dantran |
Compatible with maven-scm-api-1.5+. The current 1.4 is too old |
||
#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/diff/P4DiffResult.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/diff/P4DiffResult.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |