package org.jenkinsci.plugins.p4.tasks; import hudson.FilePath.FileCallable; import hudson.remoting.VirtualChannel; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.filters.Filter; import org.jenkinsci.plugins.p4.filters.FilterPathImpl; import org.jenkinsci.plugins.p4.filters.FilterPerChangeImpl; import org.jenkinsci.plugins.p4.filters.FilterUserImpl; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.AccessException; import com.perforce.p4java.exception.RequestException; import com.perforce.p4java.impl.generic.core.Changelist; public class PollTask extends AbstractTask implements FileCallable<List<Integer>>, Serializable { private static final long serialVersionUID = 1L; private final List<Filter> filter; private final boolean perChange; private String pin; public PollTask(List<Filter> filter) { this.filter = filter; // look for incremental filter option boolean incremental = false; if (filter != null) { for (Filter f : filter) { if (f instanceof FilterPerChangeImpl) { if (((FilterPerChangeImpl) f).isPerChange()) { incremental = true; } } } } this.perChange = incremental; } public List<Integer> invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { List<Integer> changes = new ArrayList<Integer>(); ClientHelper p4 = getConnection(); try { // Check connection (might be on remote slave) if (!checkConnection(p4)) { return changes; } // find changes... if (pin != null && !pin.isEmpty()) { List<Integer> have = p4.listHaveChanges(pin); int last = 0; if (!have.isEmpty()) { last = have.get(have.size() - 1); } p4.log("P4: Polling with label/change: " + last + "," + pin); changes = p4.listChanges(last, pin); } else { List<Integer> have = p4.listHaveChanges(); int last = 0; if (!have.isEmpty()) { last = have.get(have.size() - 1); } p4.log("P4: Polling with label/change: " + last + ",now"); changes = p4.listChanges(last); } } catch (Exception e) { p4.log("P4: Unable to fetch changes:" + e); p4.disconnect(); } // filter changes... try { List<Integer> remainder = new ArrayList<Integer>(); for (int c : changes) { Changelist changelist = p4.getChange(c); // add unfiltered changes to remainder list if (!filterChange(changelist, filter)) { remainder.add(changelist.getId()); p4.log("... found change: " + changelist.getId()); } } changes = remainder; } catch (Exception e) { p4.log("P4: Unable to filter changes:" + e); } finally { p4.disconnect(); } // if build per change... if (!changes.isEmpty() && perChange) { int lowest = changes.get(changes.size() - 1); changes = Arrays.asList(lowest); p4.log("next change: " + lowest); } return changes; } public void setLimit(String expandedPin) { pin = expandedPin; } /** * Returns true if change should be filtered * * @param changelist * @return * @throws AccessException * @throws RequestException * @throws Exception */ private boolean filterChange(Changelist changelist, List<Filter> scmFilter) throws Exception { // exit early if no filters if (scmFilter == null) { return false; } String user = changelist.getUsername(); List<IFileSpec> files = changelist.getFiles(true); for (Filter f : scmFilter) { // Scan through User filters if (f instanceof FilterUserImpl) { // return is user matches filter String u = ((FilterUserImpl) f).getUser(); if (u.equalsIgnoreCase(user)) { return true; } } // Scan through Path filters if (f instanceof FilterPathImpl) { // add unmatched files to remainder list List<IFileSpec> remainder = new ArrayList<IFileSpec>(); String path = ((FilterPathImpl) f).getPath(); for (IFileSpec s : files) { String p = s.getDepotPathString(); if (!p.startsWith(path)) { remainder.add(s); } } // update files with remainder files = remainder; // add if all files are removed then remove change if (files.isEmpty()) { return true; } } } return false; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 12956 | Sven Erik Knop | Bumped Jenkins version number | ||
#1 | 12955 | Sven Erik Knop | Branching using sknop.p4jenkins-main | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/tasks/PollTask.java | |||||
#4 | 12417 | Paul Allen |
Extend Jenkins support back to 1.568 - remove @Override annotations - remove jenkins.security.Roles |
||
#3 | 11626 | Paul Allen |
Workflow support. - Updated the plugin to the latest LTS Jenkins release 1.580.3. - Updated P4Java to 2014.1 Tested with simple ‘static’ workspace, there may be limitations with ‘manual’ workspace. Plan to add DSL support by extending the SCMStep class. #review-11537 JENKINS-24206 |
||
#2 | 11367 | Paul Allen |
Fixes to Remote slave polling - Missing Serializable on Filter classes - Pass a list of changes using return |
||
#1 | 11335 | Paul Allen | Remote slave support for Polling. | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/tasks/CheckoutChanges.java | |||||
#1 | 11334 | Paul Allen |
Remote slave support for Publish Perforce Publish commands need to be executed from the remote slave. - Includes refactoring into task package |
||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/CheckoutChanges.java | |||||
#1 | 10801 | Paul Allen |
Improvements to SCM Polling Moved change list calculation into a new class CheckoutChanges. Should enable normal build to build every thing and poll to follow polling behaviour: limit based on pin and per-change if set. JENKINS-25300 |