/** * Copyright (c) 2010 Perforce Software. All rights reserved. */ package com.perforce.maven.scm.provider.p4.command.tag; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Date; 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.ScmTagParameters; import org.apache.maven.scm.command.tag.AbstractTagCommand; import org.apache.maven.scm.command.tag.TagScmResult; 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.ILabel; import com.perforce.p4java.core.ILabelMapping; import com.perforce.p4java.core.ViewMap; import com.perforce.p4java.core.file.FileSpecBuilder; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.impl.generic.core.Label; import com.perforce.p4java.impl.generic.core.Label.LabelMapping; import com.perforce.p4java.option.client.LabelSyncOptions; /** * The class uses the Perforce label command to create or update a label to * include the mapping that controls the set of files that are allowed to be * included in the label. */ public class P4TagCommand extends AbstractTagCommand implements P4Command { /** The Constant command. */ public static final String command = "Perforce label command"; /** * @see org.apache.maven.scm.command.tag.AbstractTagCommand#executeTagCommand * (org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet, java.lang.String, java.lang.String) */ protected ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet files, String tag, String message) throws ScmException { return executeTagCommand(repo, files, tag, new ScmTagParameters(message)); } /** * @see org.apache.maven.scm.command.tag.AbstractTagCommand#executeTagCommand * (org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet, java.lang.String, * org.apache.maven.scm.ScmTagParameters) */ protected ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet files, String tag, ScmTagParameters scmTagParameters) throws ScmException { P4TagResult p4Result = new P4TagResult(); ILabel retLabel = null; String retStatusMessage = ""; boolean locked = Boolean.valueOf( System.getProperty(P4Executor.P4_LOCK_TAG_PROPERTY, "false")) .booleanValue(); P4ScmProviderRepository p4Repo = (P4ScmProviderRepository) repo; P4ClientExecutor executor = new P4ClientExecutor(p4Repo, files, getLogger()); List<IFileSpec> fileSpecs = null; List<String> filePaths = new ArrayList<String>(); List<File> fileList = files.getFileList(); try { if (fileList != null) { for (File file : fileList) { if (!file.getName().contentEquals(".")) { String canfile; canfile = file.getCanonicalPath(); 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); } throw new ScmException(e.getLocalizedMessage(), 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 { String canRepoPath = P4Executor.getCanonicalRepoPath(executor .getRepoPath(p4Repo, files.getBasedir())); // Build the view map for the label. // Only the left hand side of a mapping is used for labels. ViewMap<ILabelMapping> viewMap = new ViewMap<ILabelMapping>(); String[] viewPaths = new String[] { canRepoPath }; for (int i = 0; i < viewPaths.length; i++) { ILabelMapping entry = new LabelMapping(i + 1, viewPaths[i]); viewMap.addEntry((LabelMapping) entry); } // Update existing label. retLabel = executor.getServer().getLabel(tag); if (retLabel != null) { if (!P4Executor.isEmpty((executor.getP4User()))) { retLabel.setOwnerName(executor.getP4User()); } retLabel.setLastUpdate(new Date()); retLabel.setLocked(false); if (viewMap != null && viewMap.getSize() > 0) { retLabel.setViewMapping(viewMap); } retStatusMessage = executor.getServer().updateLabel( retLabel); } else { // Create new label. Date lastAccess = null; Date lastUpdate = null; retLabel = new Label(tag, executor.getP4User(), lastAccess, lastUpdate, null, null, false, viewMap); retStatusMessage = executor.getServer().createLabel( retLabel); } retLabel = executor.getServer().getLabel(tag); if (retLabel != null) { p4Result.setSuccess(true); LabelSyncOptions labelSyncOptions = new LabelSyncOptions(); List<IFileSpec> retFileSpecs = executor.getClient() .labelSync(fileSpecs, tag, labelSyncOptions); p4Result.processTagged(retFileSpecs); retLabel.setLocked(locked); executor.getServer().updateLabel(retLabel); } } catch (P4JavaException e) { if (getLogger().isErrorEnabled()) { getLogger().error(e); } throw new ScmException(e.getLocalizedMessage(), e); } } if (!p4Result.isSuccess()) { return new TagScmResult(command, "Tag failed", retStatusMessage, false); } return new TagScmResult(command, p4Result.getTagged()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#13 | 9519 | dantran | folder rename to match with its artifactId | ||
#12 | 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 |
||
#11 | 9267 | dantran | More swapping of P4Executor for P4Utils | ||
#10 | 9259 | dantran |
hookup with maven-scm-test. Pickup user/password from system properties |
||
#9 | 9251 | dantran | Use P4Utils instead of P4Executor which will be retire | ||
#8 | 9250 | dantran | caching client across mutiple commands | ||
#7 | 9189 | dantran | tag should be locked by default per documentation | ||
#6 | 9185 | dantran |
more comment on tagging with latesgt changelist. Add <SCM> to parent pom |
||
#5 | 9184 | dantran | Correctly handle perforce protocols rather then hardwire only 'ssl' | ||
#4 | 9183 | dantran | refactor P4TagCommand for code readability and introduce tagging using changelist when the ScmFileSet input is empty | ||
#3 | 9178 | dantran | One more round of pom cleanup with the introduction of dependencyManagement at parent pom | ||
#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/tag/P4TagCommand.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/tag/P4TagCommand.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |