/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.branch; import java.util.ArrayList; import java.util.Arrays; 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 left = P4Utils.getRepoLocation( client, files.getBasedir() ); if ( left == null ) { left = ( (P4ScmProviderRepository) repo ).getPath(); } 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() ); } /** * Gets the tokenized (by whitespace) jobs. * * @param jobs the jobs * @return the jobs */ private List<String> getJobs( String jobs ) { if ( jobs != null ) { String[] tokens = jobs.trim().split( "\\s+" ); if ( tokens != null && tokens.length > 0 ) { return new ArrayList<String>( Arrays.asList( tokens ) ); } } return null; } private String branchePath2BranchName( String branchPath ) { return StringUtils.replace( StringUtils.replace( branchPath, "/", "-" ), "--", "" ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 9519 | dantran | folder rename to match with its artifactId | ||
#6 | 9498 | dantran |
- Setup Maven site for documetation - Implement ~/m2/p4maven-settings.xml to store external config overridable by system properties. All global settings now can be retrieved va P4Utils |
||
#5 | 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 |
||
#4 | 9267 | dantran | More swapping of P4Executor for P4Utils | ||
#3 | 9251 | dantran | Use P4Utils instead of P4Executor which will be retire | ||
#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/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 |