package org.jenkinsci.plugins.p4.tasks; import com.perforce.p4java.core.IRepo; 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; import hudson.FilePath.FileCallable; import hudson.remoting.VirtualChannel; import jenkins.security.Roles; import org.jenkinsci.plugins.p4.changes.P4ChangeRef; import org.jenkinsci.plugins.p4.changes.P4LabelRef; import org.jenkinsci.plugins.p4.changes.P4Ref; 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.FilterUserImpl; import org.jenkinsci.plugins.p4.filters.FilterViewMaskImpl; import org.jenkinsci.remoting.RoleChecker; import org.jenkinsci.remoting.RoleSensitive; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.List; public class PollTask extends AbstractTask implements FileCallable<List<P4Ref>>, Serializable { private static final long serialVersionUID = 1L; private final List<Filter> filter; private final List<P4Ref> lastRefs; private String pin; public PollTask(List<Filter> filter, List<P4Ref> lastRefs) { this.filter = filter; this.lastRefs = lastRefs; } @SuppressWarnings("unchecked") public List<P4Ref> invoke(File workspace, VirtualChannel channel) throws IOException { return (List<P4Ref>) tryTask(); } @Override public Object task(ClientHelper p4) throws Exception { List<P4Ref> changes = new ArrayList<P4Ref>(); // find changes... if (pin != null && !pin.isEmpty()) { changes = p4.listHaveChanges(lastRefs, new P4LabelRef(pin)); } else { changes = p4.listHaveChanges(lastRefs); } // filter changes... List<P4Ref> remainder = new ArrayList<P4Ref>(); for (P4Ref c : changes) { int change = c.getChange(); if (change > 0) { Changelist changelist = p4.getChange(change); // add unfiltered changes to remainder list if (!filterChange(changelist, filter)) { remainder.add(new P4ChangeRef(changelist.getId())); p4.log("... found change: " + changelist.getId()); } } } changes = remainder; // Poll Graph commit changes if (p4.checkVersion(20171)) { List<IRepo> repos = p4.listRepos(); for (IRepo repo : repos) { P4Ref graphHead = p4.getGraphHead(repo.getName()); List<P4Ref> commits = p4.listCommits(lastRefs, graphHead); changes.addAll(commits); } } return changes; } public void setLimit(String expandedPin) { pin = expandedPin; } /** * Returns true if change should be filtered * * @param changelist * @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; } } // Scan through View Mask filters if (f instanceof FilterViewMaskImpl) { // at least one file in the change must be contained in the view mask List<IFileSpec> included = new ArrayList<IFileSpec>(); String viewMask = ((FilterViewMaskImpl) f).getViewMask(); for (IFileSpec s : files) { boolean isFileInViewMask = false; String p = s.getDepotPathString(); for (String maskPath : viewMask.split("\n")) { if (p.startsWith(maskPath)) { isFileInViewMask = true; } if (maskPath.startsWith("-")) { String excludedMaskPath = maskPath.substring(maskPath.indexOf("-") + 1); if (p.startsWith(excludedMaskPath)) { isFileInViewMask = false; } } } if (isFileInViewMask) { included.add(s); } } if (included.isEmpty()) { return true; } } } return false; } public void checkRoles(RoleChecker checker) throws SecurityException { checker.check((RoleSensitive) this, Roles.SLAVE); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#21 | 29794 | Paul Allen |
Merge pull request #191 from jenkinsci/PollingToLatest Add new feature to detect change beyond pinned changelist and trigger the build. |
||
#20 | 28002 | Paul Allen |
Merge pull request #131 from jorgenpt/support-windows-linebreaks Add support for Windows linebreaks in filters |
||
#19 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#18 | 23943 | Paul Allen |
Poll per change for Pipeline. JENKINS-47427 |
||
#17 | 23533 | Paul Allen |
Merge pull request #66 from jromigh/master. Implementing a Java Pattern filter for polling. JENKINS-41217 |
||
#16 | 22861 | Paul Allen | Use long for change number. | ||
#15 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#14 | 21077 | Paul Allen |
Switch polling back to build.xml Change in Polling behaviour; use last build details in the build.xml file. It gathers 'last' change details on the master thread and not a slave thread. JENKINS-37462 - updated and improved test case |
||
#13 | 20787 | Paul Allen |
Polling Fix for use with quiet period. Switched all uses of change/label to P4Revision object and implemented Comparable. The changes to build are now calculated at build time (after the quiet period) not during the polling phase. JENKINS-36883 #review-20780 |
||
#12 | 20224 | Paul Allen |
(@stuartr) Implementing View Mask Filter. JENKINS-30622 JENKINS-28225 #review-20188 @paul_allen @stuartr |
||
#11 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#10 | 19374 | Paul Allen |
Poll on Master (without workspace) New Polling Filter ‘Poll on Master using Last Build’. Only polls on the master and fetches it change from the last Build. Note that 0 is assumed if no previous build is found. JENKINS-32814 |
||
#9 | 19365 | Paul Allen |
Track syncs with a 'Change' field in the Workspace Description. Polling used ‘p4 cstat’ to determine the last sync’ed change in a workspace. However, if the have list is empty (such as in the Force Clean Populate mode) it would appear as if no changes have been synced. JENKINS-32518 JENKINS-32523 |
||
#8 | 16390 | Paul Allen |
Update change/file reporting. Use `p4 changes @=1234` to get change summary and `p4 files -m50 @=1234` to get limited file list. |
||
#7 | 15750 | Paul Allen |
Use a P4Revision object and not int/String as Object. In sure that there is no ambiguity with the revision specifier. Should fix change summary when using the Workflow plugin. JENKINS-30425 |
||
#6 | 15394 | Paul Allen |
Workflow-DSL functionality. Tested workflow DSL against 1.596.1 older functionality tested against 1.580.1 @sven_erik_knop |
||
#5 | 15293 | Paul Allen |
Add retry attempts to Perforce Tasks. If a task fails due to an exception then the task will retry based on the value specified in the connection Credential. |
||
#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 |