package org.jenkinsci.plugins.p4; import hudson.Extension; import hudson.XmlFile; import hudson.model.Descriptor; import hudson.model.Saveable; import hudson.model.listeners.SaveableListener; import hudson.scm.SCM; import hudson.util.LogTaskListener; import jenkins.model.Jenkins; import org.jenkinsci.plugins.p4.PerforceScm.DescriptorImpl; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.publish.SubmitImpl; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @Extension public class ConfigurationListener extends SaveableListener { private static Logger logger = Logger.getLogger(ConfigurationListener.class.getName()); public void onChange(Saveable o, XmlFile xml) { Jenkins j = Jenkins.getInstance(); if (j == null) { return; } @SuppressWarnings("unchecked") Descriptor<SCM> scm = j.getDescriptor(PerforceScm.class); DescriptorImpl p4scm = (DescriptorImpl) scm; // Exit early if disabled if (!p4scm.isAutoSave()) { return; } try { String file = xml.getFile().getCanonicalPath(); logger.info(">>> onUpdated: " + file); // create Publish object String desc = "Configuration change"; boolean success = false; boolean delete = true; boolean reopen = false; String purge = ""; SubmitImpl publish = new SubmitImpl(desc, success, delete, reopen, purge); try (ClientHelper p4 = getClientHelper(p4scm)) { int ChangelistID = -1; if (!p4scm.isAutoSubmitOnChange()) { ChangelistID = p4.findPendingChangelistIDByDesc(desc, p4scm.getClientName()); } p4.versionFile(file, publish, ChangelistID, p4scm.isAutoSubmitOnChange()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private ClientHelper getClientHelper(DescriptorImpl p4scm) throws Exception { LogTaskListener listener = new LogTaskListener(logger, Level.INFO); String credential = p4scm.getCredential(); String clientName = p4scm.getClientName(); String depotPath = p4scm.getDepotPath(); // check path ends with '/...' if(!depotPath.endsWith("/...")) { depotPath = depotPath.endsWith("/") ? depotPath + "..." : depotPath + "/..."; } // quote path it it has spaces if(depotPath.contains(" ")) { depotPath = "\"" + depotPath + "\""; } Jenkins j = Jenkins.getInstance(); if (j == null) { return null; } String rootPath = j.getRootDir().getCanonicalPath(); StringBuffer view = new StringBuffer(); view.append(depotPath); view.append(" "); view.append("//" + clientName + "/..."); WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, "", "LOCAL", view.toString(), null, null, null, true); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("utf8", false, clientName, spec); workspace.setExpand(new HashMap<String, String>()); workspace.setRootPath(rootPath); ClientHelper p4 = new ClientHelper(Jenkins.getActiveInstance(), credential, listener, workspace); return p4; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 24481 | Paul Allen | Merging using p4-jenkins_main>dev | ||
#6 | 24426 | Paul Allen |
Merging using p4-jenkins_main>dev @24402 @24403 @24404 |
||
#5 | 23691 | Paul Allen | Cleanup P4Task: Remove disconnect and use Closeable. | ||
#4 | 23689 | Paul Allen | Cleanup P4Task: Combined Workspace setup | ||
#3 | 23688 | Paul Allen | Cleanup P4Task: Pass workspace to ClientHelper | ||
#2 | 23685 | Paul Allen | Copy main -> dev | ||
#1 | 20641 | Paul Allen | Copy main -> dev (jenkinsci/p4-plugin) | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/ConfigurationListener.java | |||||
#4 | 19581 | Paul Allen | Minor fixes to satisfy FindBugs Analysis. | ||
#3 | 19454 | Paul Allen |
Hide P4_TICKET for secure systems. An option in the global configuration to hide the P4_TICKET variable (not set by default). JENKINS-24591 |
||
#2 | 17263 | Paul Allen |
Added enable/disable option for auto versioning. Global option to activate Perforce versioning of Jenkins Configurations. |
||
#1 | 16836 | Paul Allen |
Versioning for Jenkins configuration pages. Add credential, depot path location and client workspace name, everything else should be automatic. JENKINS-25145 |