package org.jenkinsci.plugins.p4.tagging; import hudson.model.AbstractBuild; import hudson.scm.AbstractScmTagAction; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import com.perforce.p4java.client.IClientViewMapping; import com.perforce.p4java.core.ILabelMapping; import com.perforce.p4java.core.ViewMap; import com.perforce.p4java.impl.generic.client.ClientView; import com.perforce.p4java.impl.generic.core.Label; import com.perforce.p4java.impl.generic.core.Label.LabelMapping; public class TagAction extends AbstractScmTagAction { private String tag; private List<String> tags = new ArrayList<String>(); private String credential; private String client; private Object buildChange; public TagAction(AbstractBuild<?, ?> build) { super(build); } public String getIconFileName() { if (!getACL().hasPermission(PerforceScm.TAG)) return null; return "/plugin/p4/icons/label.gif"; } public String getDisplayName() { if (isTagged()) return "Perforce Label"; else return "Label This Build"; } @Override public boolean isTagged() { return tags != null && !tags.isEmpty(); } public void doSubmit(StaplerRequest req, StaplerResponse rsp) throws Exception, ServletException { getACL().checkPermission(PerforceScm.TAG); String description = req.getParameter("desc"); String name = req.getParameter("name"); labelBuild(name, description); rsp.sendRedirect("."); } public void labelBuild(String name, String description) throws Exception { tag = name; ClientHelper p4 = new ClientHelper(credential, null, client); Label label = new Label(); label.setDescription(description); label.setName(name); label.setRevisionSpec("@" + buildChange); // set label view to match workspace ViewMap<ILabelMapping> viewMapping = new ViewMap<ILabelMapping>(); ClientView view = p4.getClientView(); for (IClientViewMapping entry : view) { String left = entry.getLeft(); LabelMapping lblMap = new LabelMapping(); lblMap.setLeft(left); viewMapping.addEntry(lblMap); } label.setViewMapping(viewMapping); // save label if (!tags.contains(name)) { tags.add(name); build.save(); } // update Perforce p4.setLabel(label); p4.disconnect(); } public void setBuildChange(Object buildChange) { this.buildChange = buildChange; } public Object getBuildChange() { return buildChange; } public String getClient() { return client; } public void setCredential(String credential) { this.credential = credential; } public void setClient(String client) { this.client = client; } public String getTag() { return tag; } public List<String> getTags() { return tags; } /** * Method used by Jelly code to show Label information (do not remove) * * @param tag * @return * @throws Exception */ public Label getLabel(String tag) throws Exception { ClientHelper p4 = new ClientHelper(credential, null, client); Label label = p4.getLabel(tag); return label; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 11080 | Paul Allen |
#review-11081 Removed unused code/comments. @mjoubert |
||
#5 | 11072 | mjoubert |
Committing review to DEV branch for further investigation @pallen |
||
#4 | 11063 | mjoubert |
Approve changes for Dev branch. Unit tests are failing; needs investigation. @pallen |
||
#3 | 11055 | Paul Allen | Run auto format to tidy up changes. | ||
#2 | 11054 | Paul Allen | Import of Morne Joubert changes. | ||
#1 | 11053 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/tagging/TagAction.java | |||||
#7 | 9986 | Paul Allen | Re-added getLabel method used by Jelly. | ||
#6 | 9984 | Paul Allen |
Set P4_CHANGELIST to change for Automatic Labels. P4_CHANGELIST is set to a change number or label if defined in Populate as pinned or a build parameter. |
||
#5 | 9851 | Paul Allen | Merging using p4-jenkins | ||
#4 | 9819 | Paul Allen | Merging using p4-jenkins | ||
#3 | 9769 | Paul Allen | Copying using p4-jenkins | ||
#2 | 9696 | Paul Allen | Updated install notes and removed old ref to p4-client | ||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4/tagging/TagAction.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/tagging/TagAction.java | |||||
#3 | 9126 | Paul Allen | Added Perforce label icon to TagAction. | ||
#2 | 9077 | Paul Allen |
Added support for automatic Labels as a post-build Action. Ported original code for promoted builds, but not tested. |
||
#1 | 9069 | Paul Allen |
Adding initial support for tagging Jenkins builds as Perforce Automatic Labels. Only implements TagAction (manual labels); TagNotifier and test cases TODO. |