Skip to content

Commit 631c3af

Browse files
author
Marcus Trautwig
committed
[JENKINS-17479] URL SCM always marks URL as changed with Poll SCM option
- implement 1.392 API methods, remove the obsolete ones
1 parent be6eef3 commit 631c3af

2 files changed

Lines changed: 28 additions & 39 deletions

File tree

src/main/java/hudson/plugins/URLSCM/URLDateAction.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package hudson.plugins.URLSCM;
22

3-
import hudson.model.Action;
43
import hudson.model.AbstractBuild;
5-
import hudson.model.AbstractModelObject;
4+
import hudson.scm.SCMRevisionState;
65

76
import java.io.IOException;
87
import java.text.DateFormat;
@@ -15,21 +14,18 @@
1514
import org.kohsuke.stapler.StaplerRequest;
1615
import org.kohsuke.stapler.StaplerResponse;
1716

18-
public class URLDateAction extends AbstractModelObject implements Action {
19-
/**
20-
*
21-
*/
22-
private static final long serialVersionUID = 1L;
17+
public class URLDateAction extends SCMRevisionState {
18+
private static final long serialVersionUID = 1L;
2319

24-
private final HashMap<String, Long> lastModified = new HashMap<String, Long>();
20+
private final HashMap<String, Long> lastModified = new HashMap<String, Long>();
2521

26-
private final AbstractBuild build;
22+
private final AbstractBuild<?, ?> build;
2723

28-
protected URLDateAction(final AbstractBuild build) {
24+
protected URLDateAction(final AbstractBuild<?, ?> build) {
2925
this.build = build;
3026
}
3127

32-
public AbstractBuild getBuild() {
28+
public AbstractBuild<?, ?> getBuild() {
3329
return build;
3430
}
3531

@@ -60,10 +56,12 @@ public Map<String, String> getUrlDates() {
6056
return ret;
6157
}
6258

59+
@Override
6360
public String getDisplayName() {
6461
return "URL Modification Dates";
6562
}
6663

64+
@Override
6765
public String getIconFileName() {
6866
return "save.gif";
6967
}
@@ -72,6 +70,7 @@ public String getSearchUrl() {
7270
return getUrlName();
7371
}
7472

73+
@Override
7574
public String getUrlName() {
7675
return "urlDates";
7776
}

src/main/java/hudson/plugins/URLSCM/URLSCM.java

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import hudson.model.AbstractBuild;
1010
import hudson.model.AbstractProject;
1111
import hudson.model.Hudson;
12-
import hudson.model.Run;
1312
import hudson.scm.ChangeLogParser;
1413
import hudson.scm.NullChangeLogParser;
1514
import hudson.scm.PollingResult;
@@ -118,20 +117,26 @@ public boolean requiresWorkspaceForPolling() {
118117
}
119118

120119
@Override
121-
public boolean pollChanges(final AbstractProject project,
122-
final Launcher launcher, final FilePath workspace,
123-
final TaskListener listener) throws IOException,
120+
public SCMRevisionState calcRevisionsFromBuild(
121+
final AbstractBuild<?, ?> project, final Launcher launcher,
122+
final TaskListener listener) throws IOException, InterruptedException {
123+
return null;
124+
}
125+
126+
@Override
127+
protected PollingResult compareRemoteRevisionWith(
128+
final AbstractProject<?, ?> project, final Launcher launcher,
129+
final FilePath workspace, final TaskListener listener,
130+
final SCMRevisionState state) throws IOException,
124131
InterruptedException {
125132
boolean change = false;
126-
final Run lastBuild = project.getLastBuild();
127-
if (lastBuild == null) {
128-
return true;
129-
}
130-
final URLDateAction dates = lastBuild.getAction(URLDateAction.class);
131-
if (dates == null) {
132-
return true;
133+
134+
if (state == null || !(state instanceof URLDateAction)) {
135+
listener.getLogger().println("Changes not yet tracked with last build, triggering a new one");
136+
return PollingResult.BUILD_NOW;
133137
}
134138

139+
final URLDateAction dates = (URLDateAction) state;
135140
for (final URLTuple tuple : urls) {
136141
final String urlString = tuple.getUrl();
137142
try {
@@ -155,9 +160,9 @@ public boolean pollChanges(final AbstractProject project,
155160
+ e.getMessage());
156161
}
157162
}
158-
return change;
163+
return change ? PollingResult.BUILD_NOW : PollingResult.NO_CHANGES;
159164
}
160-
165+
161166
public static final class URLTuple {
162167
private final String urlString;
163168

@@ -225,19 +230,4 @@ protected FormValidation check() throws IOException,
225230
}
226231
}
227232

228-
@Override
229-
public SCMRevisionState calcRevisionsFromBuild(
230-
final AbstractBuild<?, ?> arg0, final Launcher arg1,
231-
final TaskListener arg2) throws IOException, InterruptedException {
232-
return null;
233-
}
234-
235-
@Override
236-
protected PollingResult compareRemoteRevisionWith(
237-
final AbstractProject<?, ?> arg0, final Launcher arg1,
238-
final FilePath arg2, final TaskListener arg3,
239-
final SCMRevisionState arg4) throws IOException,
240-
InterruptedException {
241-
return PollingResult.BUILD_NOW;
242-
}
243233
}

0 commit comments

Comments
 (0)