package org.jenkinsci.plugins.p4_client.changes; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.scm.ChangeLogParser; 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_client.PerforceScm; import org.jenkinsci.plugins.p4_client.client.ConnectionHelper; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import com.perforce.p4java.impl.generic.core.Changelist; 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(AbstractBuild build, File file) throws IOException, SAXException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); ChangeLogHandler handler = new ChangeLogHandler(build); 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 AbstractBuild<?, ?> build; public ChangeLogHandler(AbstractBuild<?, ?> build) { this.build = build; } @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(build, 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(); // Add changelist to entry if (qName.equalsIgnoreCase("changenumber")) { try { // Find Perforce Credential ID for this build AbstractProject<?, ?> project = build.getProject(); PerforceScm scm = (PerforceScm) project.getScm(); String cid = scm.getCredential(); // Log in to Perforce and find changelist ConnectionHelper p4 = new ConnectionHelper(cid, null); p4.login(); int id = new Integer(text.toString()); Changelist changelist = p4.getChange(id); entry.setChange(changelist); p4.disconnect(); } catch (Exception e) { e.printStackTrace(); } return; } } } public P4ChangeSet getChangeLogSet() { return changeSet; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
#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 |