/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.add; import java.io.File; import java.io.IOException; import java.util.ArrayList; 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.add.AbstractAddCommand; import org.apache.maven.scm.command.add.AddScmResult; 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.AddFilesOptions; /** * The class uses the Perforce add command to open new files to add to the * Perforce depot. */ public class P4AddCommand extends AbstractAddCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce add command"; /** * @see org.apache.maven.scm.command.add.AbstractAddCommand#executeAddCommand * (org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet, java.lang.String, boolean) */ protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet files, String message, boolean binary) throws ScmException { P4AddResult p4Result = new P4AddResult(); P4ScmProviderRepository p4Repo = (P4ScmProviderRepository) repo; P4ClientExecutor executor = new P4ClientExecutor(p4Repo, files, getLogger()); // Default the "includes" to the "**" pattern if (P4Executor.isEmpty(files.getIncludes())) { try { files = new ScmFileSet(files.getBasedir(), "**", files.getExcludes()); } catch (IOException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } } } List<IFileSpec> fileSpecs = null; @SuppressWarnings("unchecked") List<File> fileList = files.getFileList(); if (fileList != null) { List<String> filePaths = new ArrayList<String>(); for (File f : fileList) { if (!f.getName().contentEquals(".")) { // Ignore the "." file filePaths.add(f.getAbsolutePath()); } } if (!filePaths.isEmpty()) { fileSpecs = FileSpecBuilder.makeFileSpecList(filePaths .toArray(new String[filePaths.size()])); } } // Note: add command doesn't support "..." as a filespec if (fileSpecs != null && !fileSpecs.isEmpty()) { AddFilesOptions addFilesOptions = new AddFilesOptions(); // Allow adding files with filenames that contain wildcard // characters. Filenames that contain the special characters // '@', '#', '%' or '*' are reformatted to encode the characters // using ASCII hexadecimal representation. After the files are // added, you must refer to them using the reformatted file // name, because Perforce does not recognize the local // filesystem name. addFilesOptions.setUseWildcards(true); try { List<IFileSpec> retFileSpecs = executor.getClient().addFiles( fileSpecs, addFilesOptions); // Process the result filespecs p4Result.process(retFileSpecs); // Process the result filespecs as additions p4Result.processAdditions(retFileSpecs); } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } } List<String> additions = p4Result.getAdditions(); return new AddScmResult(command, additions); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 9519 | dantran | folder rename to match with its artifactId | ||
#6 | 9476 | dantran |
- Each managed client now has its own server to prevent concurrency - Validate managed client and server instances |
||
#5 | 9422 | dantran | add update, changelog TCK | ||
#4 | 9342 | dantran | Add CheckIn TCK | ||
#3 | 9250 | dantran | caching client across mutiple commands | ||
#2 | 9177 | dantran |
Compatible with maven-scm-api-1.5+. The current 1.4 is too old |
||
#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/add/P4AddCommand.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/add/P4AddCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |