/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.checkout; import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFile; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmVersion; import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand; import org.apache.maven.scm.command.checkout.CheckOutScmResult; 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.P4Executor; import com.perforce.maven.scm.provider.p4.repository.P4ScmProviderRepository; 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.SyncOptions; /** * Use Perforce sync command to update files from the repository. It will * create a client if none is specified. */ public class P4CheckOutCommand extends AbstractCheckOutCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce sync command"; /** * @see org.apache.maven.scm.command.checkout.AbstractCheckOutCommand * executeCheckOutCommand * (org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.ScmVersion, * boolean) */ protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet files, ScmVersion version, boolean recursive) throws ScmException { P4CheckOutResult p4Result = new P4CheckOutResult(); P4ScmProviderRepository p4Repo = (P4ScmProviderRepository) repo; boolean persistCheckout = p4Repo.isPersistCheckout(); P4ClientExecutor executor = new P4ClientExecutor(p4Repo, files, getLogger()); boolean clientGenerated = executor.isClientNameGenerated(); List<IFileSpec> fileSpecs = null; StringBuilder filePathSuffix = new StringBuilder(); if (version != null && !P4Executor.isEmpty(version.getName())) { filePathSuffix.append("@").append(version.getName()); } List<File> fileList = files.getFileList(); if (fileList != null) { List<String> filePaths = new ArrayList<String>(); for (File f : fileList) { if (!f.getName().contentEquals(".")) { filePaths.add(P4Executor.encodeWildcards(f .getAbsolutePath()) + filePathSuffix); } } if (!filePaths.isEmpty()) { fileSpecs = FileSpecBuilder.makeFileSpecList(filePaths .toArray(new String[filePaths.size()])); } } if (fileSpecs == null || fileSpecs.isEmpty()) { if (P4Executor.isEmpty(files.getIncludes()) && P4Executor.isEmpty(files.getExcludes())) { StringBuilder repoPath = new StringBuilder(); repoPath.append(P4Executor.getCanonicalRepoPath(p4Repo .getPath())); repoPath.append(filePathSuffix.toString()); fileSpecs = FileSpecBuilder .makeFileSpecList(new String[] { repoPath.toString() }); } } File workingDirectory = new File(files.getBasedir().getAbsolutePath()); if (getLogger().isInfoEnabled()) { getLogger().info("Checkout working directory: " + workingDirectory); } try { SyncOptions syncOptions = new SyncOptions(false, false, false, false); String[] filesList = workingDirectory.list(); if (filesList == null || filesList.length == 0) { syncOptions.setForceUpdate(true); } List<IFileSpec> retFileSpecs = executor.getClient().sync(fileSpecs, syncOptions); p4Result.process(retFileSpecs); } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } finally { if (clientGenerated && !persistCheckout) { // See SCM-113 // Delete client created by Maven if it is not a persist // checkout try { executor.getServer().deleteClient(executor.getP4Client(), false); } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } } } else if (clientGenerated) { // See SCM-165 // Save client created by Maven for later usage in the // same // JVM instance. System.setProperty(P4Executor.P4_CLIENT_PROPERTY, executor.getP4Client()); } } if (!p4Result.isSuccess()) { if (getLogger().isInfoEnabled()) { getLogger().info(p4Result.getCommandOutput()); } return new CheckOutScmResult(command, "Unable to sync.", p4Result.getCommandOutput(), p4Result.isSuccess()); } if (getLogger().isInfoEnabled()) { if (p4Result.getCommandResult() != null) { for (ScmFile file : p4Result.getCommandResult()) { getLogger().info(file.toString()); } } } return new CheckOutScmResult(command, p4Result.getCommandResult()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 9519 | dantran | folder rename to match with its artifactId | ||
#6 | 9486 | dantran | Simplify update command and rely on AbstractUpdateCommand to gather the ChangeSet | ||
#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 | 9423 | dantran | get all test to use the same setup, handle checkout with tag, need to revisit how we handle ScmVersion | ||
#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/checkout/P4CheckOutCommand.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/checkout/P4CheckOutCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |