/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.update; import java.util.List; import org.apache.maven.scm.CommandParameter; import org.apache.maven.scm.CommandParameters; 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.ChangeLogCommand; import org.apache.maven.scm.command.checkout.CheckOutScmResult; import org.apache.maven.scm.command.update.AbstractUpdateCommand; import org.apache.maven.scm.command.update.UpdateScmResult; import org.apache.maven.scm.command.update.UpdateScmResultWithRevision; import org.apache.maven.scm.provider.ScmProviderRepository; import com.perforce.maven.scm.provider.p4.command.P4ClientExecutor; import com.perforce.maven.scm.provider.p4.command.P4Command; import com.perforce.maven.scm.provider.p4.command.changelog.P4ChangeLogCommand; import com.perforce.maven.scm.provider.p4.command.checkout.P4CheckOutCommand; import com.perforce.maven.scm.provider.p4.repository.P4ScmProviderRepository; 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; /** * Use Perforce sync command to update files from the repository. */ public class P4UpdateCommand extends AbstractUpdateCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce sync command"; /** * @see org.apache.maven.scm.command.update.AbstractUpdateCommand * executeUpdateCommand(org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.ScmVersion) */ protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion scmVersion) throws ScmException { // Update is the same as checkout in Perforce P4CheckOutCommand command = new P4CheckOutCommand(); command.setLogger(getLogger()); CommandParameters params = new CommandParameters(); params.setScmVersion(CommandParameter.SCM_VERSION, scmVersion); CheckOutScmResult checkOutScmResult = (CheckOutScmResult) command .execute(repo, files, params); if (!checkOutScmResult.isSuccess()) { return new UpdateScmResult(checkOutScmResult.getCommandLine(), checkOutScmResult.getProviderMessage(), checkOutScmResult.getCommandOutput(), false); } int have = 0; P4ScmProviderRepository p4Repo = (P4ScmProviderRepository) repo; P4ClientExecutor executor = new P4ClientExecutor(p4Repo, files, getLogger()); try { GetChangelistsOptions getChangelistsOptions = new GetChangelistsOptions(); getChangelistsOptions.setMaxMostRecent(1); getChangelistsOptions.setType(IChangelist.Type.SUBMITTED); String clientName = executor.getP4Client(); if (clientName != null) { getChangelistsOptions.setClientName(clientName); } StringBuffer fileSpec = new StringBuffer("//" + clientName + "/...#have"); List<IFileSpec> fileSpecs = FileSpecBuilder .makeFileSpecList(new String[] { fileSpec.toString() }); List<IChangelistSummary> retChangelistSummaries = executor .getServer().getChangelists(fileSpecs, getChangelistsOptions); if (retChangelistSummaries != null) { for (IChangelistSummary changelistSummary : retChangelistSummaries) { have = changelistSummary.getId(); break; } } } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } return new UpdateScmResultWithRevision( checkOutScmResult.getCommandLine(), checkOutScmResult.getCheckedOutFiles(), String.valueOf(have)); } /** * @see org.apache.maven.scm.command.update.AbstractUpdateCommand#getChangeLogCommand * () */ protected ChangeLogCommand getChangeLogCommand() { P4ChangeLogCommand command = new P4ChangeLogCommand(); command.setLogger(getLogger()); return command; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 9519 | dantran | folder rename to match with its artifactId | ||
#5 | 9499 | dantran |
Discover latest revision expected by scm:update goal Check for error under IFileSpec during client discovery |
||
#4 | 9486 | dantran | Simplify update command and rely on AbstractUpdateCommand to gather the ChangeSet | ||
#3 | 9422 | dantran | add update, changelog TCK | ||
#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/update/P4UpdateCommand.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/update/P4UpdateCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |