Skip to content

Commit

Permalink
Merge branch 'jenkinsci:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
skumar7322 authored Nov 9, 2023
2 parents 9966551 + d92fb0d commit cd677e1
Show file tree
Hide file tree
Showing 32 changed files with 1,025 additions and 383 deletions.
7 changes: 7 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Release notes

### Release 1.14.3 (major features/fixes)

[@29812](https://swarm.workshop.perforce.com/changes/29812) - Merge pull request #178 from joel-f-brown/master. Do not call "p4 counter" for integer counter name. JENKINS-70219

[@29794](https://swarm.workshop.perforce.com/changes/29794) - Merge pull request #191 from jenkinsci/PollingToLatest. Add new feature to detect change beyond pinned changelist and trigger the build. JENKINS-65246, JENKINS-63879


### Release 1.14.2 (major features/fixes)

[@29672](https://swarm.workshop.perforce.com/changes/29672) - Merge pull request #180 from skumar7322/UpdateP4JavaVersion. Update p4Java version to: 2022.2.2444480
Expand Down
3 changes: 2 additions & 1 deletion docs/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Click the **Add a new build filter** button and select a filter from the dropdow
- **Exclude changes from outside Java pattern:** Changes can be filtered to not trigger a build if none of the files within a change match the Java patterns (regular expression) listed. For examples, see [Exclude Changes From Outside Java Pattern](POLLBUILDFILTEREXCJAVAPATTERN.md).
- **Exclude changes outside view mask:** Changes can be filtered to not trigger a build if none of the files within a change are contained in the view mask. For examples, see [Exclude Changes Outside view mask](POLLBUILDFILTEREXCVIEWMASK.md).
- **Polling per Change:** A build is carried out for every change that is submitted. The polling event will only return the oldest unbuilt change, resulting in incremental builds.

- **Polling latest change:** A build is carried out for the latest change found during polling.
- **Polling latest change with pin:** In case of a pinned checkout, polling ignores the pin or the label specified in the checkout step and polls till the latest change.
### Repository browser
Repository browsing allows Jenkins to use an external browser, to navigate files and changes associated with a Jenkins build. The Helix Swam browser is recommended.
To enable the feature select the browser from the **Repository browser** dropdown list, and provide the full URL to the browser.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>p4</artifactId>
<version>1.14.3-SNAPSHOT</version>
<version>1.14.4-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>P4 Plugin</name>
Expand All @@ -25,7 +25,7 @@
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>p4-1.14.2</tag>
<tag>p4-1.14.3</tag>
</scm>

<developers>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jenkinsci/plugins/p4/PerforceScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public String getKey() {
if (workspace instanceof StreamWorkspaceImpl) {
StreamWorkspaceImpl ws = (StreamWorkspaceImpl) workspace;
key.append(ws.getStreamName());
key.append(ws.getStreamAtChange());
key.append(ws.getName());
}
if (workspace instanceof SpecWorkspaceImpl) {
Expand Down Expand Up @@ -705,7 +706,7 @@ public String getScriptPath(Item item) {
}

CpsScmFlowDefinition cps = (CpsScmFlowDefinition) definition;
if (!this.equals(cps.getScm())) {
if (!(cps.getScm() instanceof PerforceScm)) {
return null;
}

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/jenkinsci/plugins/p4/client/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.io.StringWriter;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -207,6 +208,10 @@ private void updateClient() throws Exception {
sb.append("... Stream: " + iclient.getStream());
sb.append("\n");
}
if (iclient.getStreamAtChange() > 0) {
sb.append("... Stream at change: " + iclient.getStreamAtChange());
sb.append("\n");
}
sb.append("... Root: " + iclient.getRoot());
sb.append("\n");
logger.finer(sb.toString());
Expand Down Expand Up @@ -243,7 +248,7 @@ private List<String> cleanMap(Map<String, Object> map) {
}

// remove set fields
String[] set = new String[]{"Type"};
String[] set = new String[]{"Type", "StreamAtChange"};
for (String key : set) {
map.remove(key);
}
Expand Down Expand Up @@ -493,12 +498,17 @@ private void tidyForceSyncImpl(String path, Populate populate) throws Exception
private void silentlyForceDelete(String root) throws IOException {
try {
FileUtils.forceDelete(new File(root));
} catch (FileNotFoundException ignored) {
} catch (FileNotFoundException | NoSuchFileException ignored) {
// ignore
} catch (IOException alt) {
Path pathToDelete = Paths.get(root);
if (!Files.exists(pathToDelete)) {
return;
}

log("Unable to delete, trying alternative method... " + alt.getLocalizedMessage());

List<Path> pathsToDelete = Files.walk(Paths.get(root))
List<Path> pathsToDelete = Files.walk(pathToDelete)
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
boolean success = true;
Expand Down Expand Up @@ -778,7 +788,7 @@ private void findChangeFiles(List<IFileSpec> files, boolean delete, boolean modt
statusOpts.setOutsideAdd(true);
statusOpts.setOutsideEdit(true);
statusOpts.setRemoved(delete);
if(checkVersion(20191)){
if (checkVersion(20191)) {
statusOpts.setFileType(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public boolean isCounter(String name) throws Exception {
if (name.equals("now")) {
return false;
}
// JENKINS-70219 - numeric counters are illegal in p4d
if (name.matches("(\\d*)")) {
return false;
}
try {
CounterOptions opts = new CounterOptions();
String counter = getConnection().getCounter(name, opts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static final class DescriptorImpl extends FilterDescriptor {

@Override
public String getDisplayName() {
return "Polling latest Change";
return "Polling latest change";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.jenkinsci.plugins.p4.filters;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.Serializable;
import java.util.List;

public class FilterLatestWithPinImpl extends Filter implements Serializable {
private static final long serialVersionUID = 1L;

private final boolean latestWithPin;

@DataBoundConstructor
public FilterLatestWithPinImpl(boolean latestWithPin) {
this.latestWithPin = latestWithPin;
}

public boolean isLatestWithPin() {
return latestWithPin;
}

@Extension
@Symbol("latestWithPin")
public static final class DescriptorImpl extends FilterDescriptor {

@NonNull
@Override
public String getDisplayName() {
return "Polling latest change with pin";
}
}

public static boolean isActive(List<Filter> filter) {
if (filter == null) {
return false;
}
for (Filter f : filter) {
if (f instanceof FilterLatestWithPinImpl) {
if (((FilterLatestWithPinImpl) f).isLatestWithPin()) {
return true;
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static final class DescriptorImpl extends FilterDescriptor {

@Override
public String getDisplayName() {
return "Polling per Change";
return "Polling per change";
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jenkinsci/plugins/p4/tasks/PollTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.FilterLatestWithPinImpl;
import org.jenkinsci.plugins.p4.filters.FilterPathImpl;
import org.jenkinsci.plugins.p4.filters.FilterPatternListImpl;
import org.jenkinsci.plugins.p4.filters.FilterUserImpl;
Expand Down Expand Up @@ -54,8 +55,11 @@ public List<P4Ref> invoke(File workspace, VirtualChannel channel) throws IOExcep
public Object task(ClientHelper p4) throws Exception {
List<P4Ref> changes = new ArrayList<P4Ref>();

//Fix for https://issues.jenkins.io/browse/JENKINS-63879
boolean pollLatestWithPin = FilterLatestWithPinImpl.isActive(filter);

// find changes...
if (pin != null && !pin.isEmpty()) {
if (pin != null && !pin.isEmpty() && !pollLatestWithPin) {
changes = p4.listHaveChanges(lastRefs, new P4LabelRef(pin));
} else {
changes = p4.listHaveChanges(lastRefs);
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/jenkinsci/plugins/p4/workflow/P4Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class P4Step extends SCMStep {
private final String credential;

private String stream = "";
private String streamAtChange = "";
private String depotPath = "";
private String template = "";

Expand All @@ -49,11 +50,22 @@ public String getStream() {
return stream;
}

public String getStreamAtChange() {
return streamAtChange;
}

@DataBoundSetter
public void setStream(String stream) {
this.stream = stream;
if (stream != null && !stream.isEmpty()) {
source = new StreamSource(stream);
}

@DataBoundSetter
public void setStreamAtChange(String streamAtChange) {
this.streamAtChange = streamAtChange;
if (stream != null && !stream.isEmpty() && !streamAtChange.isEmpty()) {
StreamSource streamSource = new StreamSource(stream);
streamSource.setStreamAtChange(streamAtChange);
source = streamSource;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import hudson.Extension;
import hudson.model.AutoCompletionCandidates;
import hudson.util.FormValidation;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.p4.workspace.StreamWorkspaceImpl;
import org.jenkinsci.plugins.p4.workspace.Workspace;
import org.jenkinsci.plugins.p4.workspace.WorkspaceDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;

public class StreamSource extends AbstractSource {

private final String stream;

private String streamAtChange = StringUtils.EMPTY;

@DataBoundConstructor
public StreamSource(String stream) {
this.stream = stream;
Expand All @@ -23,9 +27,20 @@ public String getStream() {
return stream;
}

public String getStreamAtChange() {
return streamAtChange;
}

@DataBoundSetter
public void setStreamAtChange(String streamAtChange) {
this.streamAtChange = streamAtChange;
}

@Override
public Workspace getWorkspace(String charset, String format) {
return new StreamWorkspaceImpl(charset, false, stream, format);
StreamWorkspaceImpl streamWorkspace = new StreamWorkspaceImpl(charset, false, stream, format);
streamWorkspace.setStreamAtChange(streamAtChange);
return streamWorkspace;
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import hudson.util.FormValidation;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.p4.client.ConnectionFactory;
import org.jenkinsci.plugins.p4.client.ViewMapHelper;
Expand Down Expand Up @@ -233,6 +234,12 @@ public IClient setClient(IOptionsServer connection, String user) throws Exceptio
}
iclient.setStream(streamFullName);

String streamAtChange = getSpec().getStreamAtChange();
if(StringUtils.isNotEmpty(streamAtChange)){
streamAtChange = getExpand().format(streamAtChange,true);
iclient.setStreamAtChange(Integer.parseInt(streamAtChange));
}

// Set Client view
iclient.setClientView(getClientView(connection, getSpec()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.perforce.p4java.impl.mapbased.client.Client;
import com.perforce.p4java.server.IOptionsServer;
import hudson.Extension;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import java.io.Serializable;
import java.util.logging.Logger;
Expand All @@ -16,6 +18,8 @@ public class StreamWorkspaceImpl extends Workspace implements Serializable {
private static final long serialVersionUID = 1L;

private final String streamName;

private String streamAtChange = StringUtils.EMPTY;
private String format;

private static Logger logger = Logger.getLogger(StreamWorkspaceImpl.class
Expand All @@ -25,6 +29,14 @@ public String getStreamName() {
return streamName;
}

public String getStreamAtChange() {
return streamAtChange;
}
@DataBoundSetter
public void setStreamAtChange(String streamAtChange) {
this.streamAtChange = streamAtChange;
}

public String getFormat() {
return format;
}
Expand Down Expand Up @@ -75,6 +87,11 @@ public IClient setClient(IOptionsServer connection, String user)
String streamFullName = getExpand().format(getStreamName(), true);
iclient.setStream(streamFullName);

if(StringUtils.isNotEmpty(streamAtChange)){
String atChange = getExpand().format(streamAtChange, true);
iclient.setStreamAtChange(Integer.parseInt(atChange));
}

// Set clobber on to ensure workspace is always good
IClientOptions options = iclient.getOptions();
options.setClobber(true);
Expand Down
Loading

0 comments on commit cd677e1

Please sign in to comment.