package org.jenkinsci.plugins.p4.changes; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.Run; import hudson.scm.ChangeLogParser; import hudson.scm.RepositoryBrowser; import hudson.scm.ChangeLogSet; import hudson.scm.ChangeLogSet.Entry; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Stack; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class P4ChangeParser extends ChangeLogParser { /** * Uses the "index.jelly" view to render the changelist details and use the * "digest.jelly" view of to render the summary page. */ @SuppressWarnings("rawtypes") @Override public ChangeLogSet<? extends Entry> parse(Run build, RepositoryBrowser<?> browser, File file) throws IOException, SAXException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); ChangeLogHandler handler = new ChangeLogHandler(build, browser); parser.parse(file, handler); P4ChangeSet changeSet = handler.getChangeLogSet(); return changeSet; } catch (Exception e) { throw new SAXException("Could not parse perforce changelog: ", e); } } public static class ChangeLogHandler extends DefaultHandler { private Stack<P4ChangeEntry> objects = new Stack<P4ChangeEntry>(); private StringBuffer text = new StringBuffer(); private List<P4ChangeEntry> changeEntries; private P4ChangeSet changeSet; private Run<?, ?> run; private RepositoryBrowser<?> browser; public ChangeLogHandler(Run<?, ?> run, RepositoryBrowser<?> browser) { this.run = run; this.browser = browser; } @Override public void characters(char[] ch, int start, int length) throws SAXException { text.append(ch, start, length); } @Override public void startDocument() throws SAXException { changeEntries = new ArrayList<P4ChangeEntry>(); changeSet = new P4ChangeSet(run, browser, changeEntries); } @Override public void endDocument() throws SAXException { } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { text.setLength(0); if (qName.equalsIgnoreCase("changelog")) { // this is the root, so don't do anything return; } if (qName.equalsIgnoreCase("entry")) { objects.push(new P4ChangeEntry(changeSet)); return; } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase("changelog")) { // this is the root, so don't do anything return; } if (qName.equalsIgnoreCase("entry")) { P4ChangeEntry entry = (P4ChangeEntry) objects.pop(); changeEntries.add(entry); return; } if (objects.peek() instanceof P4ChangeEntry) { P4ChangeEntry entry = (P4ChangeEntry) objects.peek(); try { // Find Credential ID and Workspace for this build AbstractBuild<?, ?> build = (AbstractBuild<?, ?>) run; AbstractProject<?, ?> project = build.getProject(); PerforceScm scm = (PerforceScm) project.getScm(); String credential = scm.getCredential(); // Log in to Perforce and find change-list ConnectionHelper p4 = new ConnectionHelper(credential, null); // Add changelist to entry if (qName.equalsIgnoreCase("changenumber")) { int id = new Integer(text.toString()); entry.setChange(p4, id); } // Add label to entry if (qName.equalsIgnoreCase("label")) { String id = text.toString(); entry.setLabel(p4, id); } // disconnect from Perforce p4.disconnect(); return; } catch (Exception e) { e.printStackTrace(); } } } public P4ChangeSet getChangeLogSet() { return changeSet; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 9854 | Paul Allen | Upgrade plugin (1.569) to support Job/Run | ||
#3 | 9800 | Paul Allen |
Limited files to 50 for Change reporting. Moved client less functions out of ClientHelper and moved login to parent class. |
||
#2 | 9736 | Paul Allen |
Custom build args for Workspace names. Takes `${parameter}` and replaces it with the value if defined or uses the tag (`parameter` in this case). Includes substitution for a space ` ` with `_` as per P4 behaviour. |
||
#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/changes/P4ChangeParser.java | |||||
#3 | 9055 | Paul Allen |
Label support. Build at a label using the pram 'label'. This includes adding the label to the ChangeEntry, building the change reports and Browser links to Swarm. (TPI-102) |
||
#2 | 8940 | Paul Allen |
Major refactor for the ConnectionHelper class to simplify serialisation. Fixed remote Jenkins JNLP slave connection issue. ClientHelper now extends ConnectionHelper and takes on all methods that require a client workspace. P4StandardCredentials is sent to the remote node instead of Credentials ID due to an issue accessing the Credentials store over a remote connection. For simplicity Client ID (workspace name) is serialised instead of the Workspace object. |
||
#1 | 8915 | Paul Allen |
Support for ChangeLog and RepoBrowser. - Added RepoBrowser for Swarm (porting the others should be easy) - ChangeLog XML file now only stores the changelist number all other information is fetched from Perforce |