/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.changelog; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.maven.scm.ChangeFile; import org.apache.maven.scm.ChangeSet; import org.apache.maven.scm.ScmBranch; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmVersion; import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand; import org.apache.maven.scm.command.changelog.ChangeLogScmResult; import org.apache.maven.scm.command.changelog.ChangeLogSet; import org.apache.maven.scm.provider.ScmProviderRepository; import org.codehaus.plexus.util.StringUtils; import com.perforce.maven.scm.provider.p4.command.P4Command; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.IChangelist; import com.perforce.p4java.core.IChangelistSummary; import com.perforce.p4java.core.file.FileSpecBuilder; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.option.server.GetChangelistsOptions; import com.perforce.p4java.server.IOptionsServer; /** * Use Perforce changes command to get a list of submitted changelists. For each changelist it will issue the Perforce * describe command to get the changelist details. */ public class P4ChangeLogCommand extends AbstractChangeLogCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce changes command"; private IClient client; public void setClient( IClient client ) { this.client = client; } /** * @see org.apache.maven.scm.command.changelog.AbstractChangeLogCommand executeChangeLogCommand * (org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, * org.apache.maven.scm.ScmVersion, org.apache.maven.scm.ScmVersion, java.lang.String) */ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion, String datePattern ) throws ScmException { return executeChangeLogCommand( repo, fileSet, null, null, null, datePattern, startVersion, endVersion ); } /** * @see org.apache.maven.scm.command.changelog.AbstractChangeLogCommand executeChangeLogCommand * (org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, java.util.Date, * java.util.Date, org.apache.maven.scm.ScmBranch, java.lang.String) */ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern ) throws ScmException { if ( branch != null && StringUtils.isNotEmpty( branch.getName() ) ) { throw new ScmException( "This SCM doesn't support branches." ); } return executeChangeLogCommand( repo, fileSet, startDate, endDate, branch, datePattern, null, null ); } /** * Execute change log command. * * @param repo the repo * @param fileSet the file set * @param startDate the start date * @param endDate the end date * @param branch the branch * @param datePattern the date pattern * @param startVersion the start version * @param endVersion the end version * @return the change log scm result * @throws ScmException the scm exception */ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion ) throws ScmException { // Construct file path revision suffix with start date DateFormat dateFormat = new SimpleDateFormat( "yyyy/MM/dd:HH:mm:ss" ); StringBuilder filePathSuffix = new StringBuilder(); if ( startDate != null ) { filePathSuffix.append( "@" ).append( dateFormat.format( startDate ) ).append( "," ); if ( endDate != null ) { filePathSuffix.append( dateFormat.format( endDate ) ); } else { filePathSuffix.append( "now" ); } } // Construct file path revision suffix with start version if ( startVersion != null ) { filePathSuffix.append( "@" ).append( startVersion.getName() ).append( "," ); if ( endVersion != null ) { filePathSuffix.append( endVersion.getName() ); } else { filePathSuffix.append( "now" ); } } // Construct file path String filePath = fileSet.getBasedir() + "/..." + filePathSuffix.toString(); List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList( filePath ); List<ChangeSet> changeSets = new ArrayList<ChangeSet>(); try { GetChangelistsOptions getChangelistsOptions = new GetChangelistsOptions(); IOptionsServer server = (IOptionsServer) client.getServer(); List<IChangelistSummary> retChangelistSummaries = server.getChangelists( fileSpecs, getChangelistsOptions ); // Convert result changelists to changesets for ( IChangelistSummary changelistSummary : retChangelistSummaries ) { IChangelist changelist = server.getChangelist( changelistSummary.getId() ); List<IFileSpec> files = changelist.getFiles( true ); ChangeSet changeSet = new ChangeSet(); changeSet.setAuthor( changelistSummary.getUsername() ); changeSet.setComment( changelistSummary.getDescription().trim() );// p4 adds extra /n and fails TCK changeSet.setDate( changelistSummary.getDate() ); changeSet.setRevision( String.valueOf( changelistSummary.getId() ) ); if ( files != null ) { for ( IFileSpec file : files ) { ChangeFile changeFile = new ChangeFile( file.getDepotPath().getPathString(), String.valueOf( file.getEndRevision() ) ); changeSet.addFile( changeFile ); } } changeSets.add( changeSet ); } } catch ( P4JavaException e ) { throw new ScmException( e.getLocalizedMessage(), e ); } ChangeLogSet cls = new ChangeLogSet( changeSets, null, null ); cls.setStartVersion( startVersion ); cls.setEndVersion( endVersion ); return new ChangeLogScmResult( command, cls ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 9519 | dantran | folder rename to match with its artifactId | ||
#8 | 9487 | dantran |
Trim down Checkout and ChangeLog results to use only depo path (rather than a concatinating of every thing and not usable. This helps passed mavn-scm-test update command TCK test |
||
#7 | 9486 | dantran | Simplify update command and rely on AbstractUpdateCommand to gather the ChangeSet | ||
#6 | 9452 | dantran |
current client is now correctly discoverable. Use absolute path at ChangeLog command |
||
#5 | 9424 | dantran | add list and status TCK | ||
#4 | 9423 | dantran | get all test to use the same setup, handle checkout with tag, need to revisit how we handle ScmVersion | ||
#3 | 9295 | dantran | More migratoin using P4Utils.scmFileSet2P4FileSpecs | ||
#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/changelog/P4ChangeLogCommand.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/changelog/P4ChangeLogCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |