/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.edit; import java.io.File; import java.io.IOException; import java.util.HashSet; 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.edit.AbstractEditCommand; import org.apache.maven.scm.command.edit.EditScmResult; 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.EditFilesOptions; /** * The class uses the Perforce edit command to open existing files for edit. */ public class P4EditCommand extends AbstractEditCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce edit command"; /** * @see org.apache.maven.scm.command.edit.AbstractEditCommand#executeEditCommand * (org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet) */ protected ScmResult executeEditCommand(ScmProviderRepository repo, ScmFileSet files) throws ScmException { P4EditResult p4Result = new P4EditResult(); P4ScmProviderRepository p4Repo = (P4ScmProviderRepository) repo; P4ClientExecutor executor = new P4ClientExecutor(p4Repo, files, getLogger()); List<IFileSpec> fileSpecs = null; try { File workingDir = files.getBasedir(); List<File> fileList = files.getFileList(); if (fileList != null) { String candir; candir = workingDir.getCanonicalPath(); HashSet<String> filePaths = new HashSet<String>(); for (File file : fileList) { if (!file.getName().contentEquals(".")) { String canfile = file.getCanonicalPath(); if (canfile.startsWith(candir)) { // Get the relative path canfile = canfile.substring(candir.length() + 1); } filePaths.add(P4Executor.encodeWildcards(canfile)); } } if (!filePaths.isEmpty()) { fileSpecs = FileSpecBuilder.makeFileSpecList(filePaths .toArray(new String[filePaths.size()])); } } } catch (IOException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } } if (fileSpecs == null || fileSpecs.isEmpty()) { if (P4Executor.isEmpty(files.getIncludes()) && P4Executor.isEmpty(files.getExcludes())) { StringBuffer filePath = new StringBuffer(); filePath.append("..."); fileSpecs = FileSpecBuilder .makeFileSpecList(new String[] { filePath.toString() }); } } if (fileSpecs != null && !fileSpecs.isEmpty()) { try { EditFilesOptions editFilesOptions = new EditFilesOptions(); List<IFileSpec> retFileSpecs = executor.getClient() .editFiles(fileSpecs, editFilesOptions); p4Result.process(retFileSpecs); } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } } return new EditScmResult(command, p4Result.isSuccess() ? "Edit successful" : "Unable to edit", p4Result.getCommandOutput(), p4Result.isSuccess()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 9519 | dantran | folder rename to match with its artifactId | ||
#7 | 9295 | dantran | More migratoin using P4Utils.scmFileSet2P4FileSpecs | ||
#6 | 9290 | dantran | Introduce the reusable P4Utils.scmFileSet2P4FileSpecs util, and have edit and checkin command to use it | ||
#5 | 9267 | dantran | More swapping of P4Executor for P4Utils | ||
#4 | 9266 | dantran |
fixed up P4EditCommand to comply ScmFileSpec where the internal filelist is always relative to its basedir. When Creating P4 FileSpec, must convert the relative path to absolute path otherwise p4 would use it currently directory to calculate the path. Will need to apply the same principal to all commands |
||
#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/edit/P4EditCommand.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/edit/P4EditCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |