/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
package com.perforce.maven.scm.provider.p4.command;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.scm.ScmFileStatus;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.MessageSeverityCode;
/**
* This class handles the result from the Perforce command.
*/
public abstract class P4Result
{
/** Line separator for this system. */
public static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
/** The success. */
protected boolean success = true;
/** The command result. */
protected List<ScmFile> commandResult = new ArrayList<ScmFile>();
/** The command output. */
protected String commandOutput = "";
/**
* Processes the command result filespecs.
*
* @param fileSpecs the file specs
*/
public void process( List<IFileSpec> fileSpecs )
{
processResult( fileSpecs );
processOutput( fileSpecs );
}
public void removeResultStatusType( ScmFileStatus scmStatus )
{
List<ScmFile> newResults = new ArrayList<ScmFile>( commandResult.size() );
for ( ScmFile scmFile : commandResult )
{
if ( scmFile.getStatus() != scmStatus )
{
newResults.add( scmFile );
}
}
commandResult = newResults;
}
/**
* Extracts relevant info from the returned command filespecs as a string.
*
* @param fileSpecs the file specs
*/
private void processOutput( List<IFileSpec> fileSpecs )
{
if ( fileSpecs != null )
{
for ( IFileSpec fileSpec : fileSpecs )
{
if ( fileSpec != null )
{
StringBuilder sb = new StringBuilder();
if ( fileSpec.toString() != null )
{
sb.append( "fileSpec" ).append( "=" ).append( fileSpec.toString() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getOpStatus() != null )
{
sb.append( "opStatus" ).append( "=" ).append( fileSpec.getOpStatus() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getStatusMessage() != null )
{
sb.append( "statusMessage" ).append( "=" ).append( fileSpec.getStatusMessage() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getDepotPath() != null )
{
sb.append( "depotPath" ).append( "=" ).append( fileSpec.getDepotPath() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getEndRevision() >= 0 )
{
sb.append( "endRevision" ).append( "=" ).append( fileSpec.getEndRevision() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getChangelistId() >= 0 )
{
sb.append( "changelistId" ).append( "=" ).append( fileSpec.getChangelistId() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getAction() != null )
{
sb.append( "action" ).append( "=" ).append( fileSpec.getAction() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getFileType() != null )
{
sb.append( "fileType" ).append( "=" ).append( fileSpec.getFileType() ).append( LINE_SEPARATOR );
}
if ( fileSpec.getDate() != null )
{
sb.append( "date" ).append( "=" ).append( fileSpec.getDate() ).append( LINE_SEPARATOR );
}
commandOutput += sb.toString();
}
}
}
}
/**
* Converts the returned filespecs into ScmFile objects.
*
* @param fileSpecs the file specs
*/
private void processResult( List<IFileSpec> fileSpecs )
{
if ( fileSpecs != null )
{
for ( IFileSpec fileSpec : fileSpecs )
{
if ( fileSpec != null )
{
ScmFileStatus status = null;
StringBuilder sb = new StringBuilder();
if ( fileSpec.getDepotPath() != null )
{
sb.append( fileSpec.getDepotPath() );
if ( fileSpec.getAction() != null )
{
status = P4FileStatusMapper.getFileStatus( fileSpec.getAction().toString() );
}
commandResult.add( new ScmFile( sb.toString(), status ) );
if ( fileSpec.getOpStatus() != null )
{
// Mark failures
switch ( fileSpec.getOpStatus() )
{
case UNKNOWN:
success = false;
break;
case VALID:
break;
case INFO:
break;
case CLIENT_ERROR:
success = false;
break;
case ERROR:
if ( fileSpec.getSeverityCode() > MessageSeverityCode.E_WARN )
{
success = false;
}
break;
default:
break;
}
}
}
}
}
}
}
/**
* Process message.
*
* @param message the message
* @return the string
*/
public abstract String processMessage( String message );
/**
* Gets the command result.
*
* @return the command result
*/
public List<ScmFile> getCommandResult()
{
return commandResult;
}
/**
* Gets the command output.
*
* @return the command output
*/
public String getCommandOutput()
{
return commandOutput;
}
/**
* Checks if is success.
*
* @return true, if is success
*/
public boolean isSuccess()
{
return success;
}
/**
* Sets the success.
*
* @param success the new success
*/
public void setSuccess( boolean success )
{
this.success = success;
}
}
# |
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/P4Result.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/P4Result.java |
#1
|
8270 |
Matt Attaway |
Initial add of P4Maven source code |
|
|