/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.branch; import java.util.List; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmResult; import org.apache.maven.scm.command.branch.AbstractBranchCommand; import org.apache.maven.scm.command.branch.BranchScmResult; 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.maven.scm.provider.p4.repository.P4ScmProviderRepository; 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.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.option.client.PopulateFilesOptions; /** * The class uses the Perforce integrate command to prepares the propagation of change from source files to target files */ public class P4BranchCommand extends AbstractBranchCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce integrate command"; private IClient client; public void setClient( IClient client ) { this.client = client; } /** * @see org.apache.maven.scm.command.branch.AbstractBranchCommand#executeBranchCommand * (org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, java.lang.String, * java.lang.String) */ /* * (non-Javadoc) * @see * org.apache.maven.scm.command.branch.AbstractBranchCommand#executeBranchCommand(org.apache.maven.scm.provider. * ScmProviderRepository, org.apache.maven.scm.ScmFileSet, java.lang.String, java.lang.String) */ protected ScmResult executeBranchCommand( ScmProviderRepository repo, ScmFileSet files, String branchPath, String message ) throws ScmException { if ( StringUtils.isBlank( branchPath ) ) { throw new ScmException( "Branch name must be specified" ); } branchPath = P4Utils.encodeWildcards( branchPath.trim() ); P4BranchResult p4Result = new P4BranchResult(); try { String repoPath = ( (P4ScmProviderRepository) repo ).getPath();; String left = repoPath; if ( ! P4Utils.isRepoPathValid( client, left )) { left = P4Utils.getRepoLocation( client, files.getBasedir() ); } if ( left == null ) { throw new ScmException( "Invalid path: " + repoPath + "|" + files.getBasedir() ); } String right = branchPath; left = P4Utils.getCanonicalRepoPath( left ); right = P4Utils.getCanonicalRepoPath( right ); List<IFileSpec> leftFileSpecs = FileSpecBuilder.makeFileSpecList( left ); List<IFileSpec> rightFileSpecs = FileSpecBuilder.makeFileSpecList( right ); List<IFileSpec> retFileSpecs = client.populateFiles( leftFileSpecs.get( 0 ), rightFileSpecs, new PopulateFilesOptions() ); /* * ViewMap<IBranchMapping> viewMap = new ViewMap<IBranchMapping>(); viewMap.addEntry( new * BranchSpec.BranchViewMapping( 0, left + " " + right ) ); String branchName = this.branchePath2BranchName( * branchPath ); IBranchSpec newBranch = new BranchSpec( branchName, client.getOwnerName(), message, false, * null, null, viewMap ); client.getServer().createBranchSpec( newBranch ); IBranchSpec branchSpec = * client.getServer().getBranchSpec( branchName ); if ( branchSpec == null ) { throw new ScmException( * "Fail to create branch spec." ); } IChangelist newChangelistImpl = new Changelist( IChangelist.UNKNOWN, * client.getName(), client.getOwnerName(), ChangelistStatus.NEW, new Date(), message, false, (Server) * client.getServer() ); IChangelist retChangelist = client.createChangelist( newChangelistImpl ); * retChangelist = client.getServer().getChangelist( retChangelist.getId() ); IntegrateFilesOptions * integrateFilesOptions = new IntegrateFilesOptions(); integrateFilesOptions.setChangelistId( * retChangelist.getId() ); List<IFileSpec> retFileSpecs = client.integrateFiles( null, null, branchName, * integrateFilesOptions ); ResolveFilesAutoOptions resolveFilesAutoOptions = new ResolveFilesAutoOptions(); * resolveFilesAutoOptions.setAcceptTheirs( true ); retFileSpecs = client.resolveFilesAuto( retFileSpecs, * resolveFilesAutoOptions ); if ( retChangelist.canUpdate() ) { retChangelist.update(); } if ( * retChangelist.canRefresh() ) { retChangelist.refresh(); } List<String> jobs = getJobs( * System.getProperty( P4ScmProviderRepository.P4_JOBS_PROPERTY ) ); SubmitOptions submitOptions = new * SubmitOptions(); if ( jobs != null ) { submitOptions.setJobIds( jobs ); } retFileSpecs = * retChangelist.submit( submitOptions ); p4Result.process( retFileSpecs ); */ p4Result.process( retFileSpecs ); } catch ( P4JavaException e ) { throw new ScmException( e.getLocalizedMessage(), e ); } return new BranchScmResult( command, p4Result.getCommandResult() ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 11272 | jkovisto |
Populate //guest/joel_kovisto/p4maven/... from //guest/perforce_software/p4maven/.... |
||
//guest/perforce_software/p4maven/main/p4maven-provider/src/main/java/com/perforce/maven/scm/provider/p4/command/branch/P4BranchCommand.java | |||||
#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/branch/P4BranchCommand.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/branch/P4BranchCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |