Skip to content

Commit

Permalink
[FIXED JENKINS-42542] SCMHeadObserver.observe(SCMHead,SCMRevision) sh…
Browse files Browse the repository at this point in the history
…ould be allowed to throw IO and Interrupted exceptions
  • Loading branch information
stephenc committed Mar 7, 2017
1 parent c835fb7 commit 0204ff9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -34,7 +34,7 @@
</parent>

<artifactId>scm-api</artifactId>
<version>2.0.9-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>SCM API Plugin</name>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jenkins/scm/api/SCMHeadEvent.java
Expand Up @@ -30,6 +30,7 @@
import hudson.model.Item;
import hudson.scm.SCM;
import hudson.triggers.SCMTrigger;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -250,7 +251,8 @@ private Validated(O delegate, SCMSource source) {
* {@inheritDoc}
*/
@Override
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision)
throws IOException, InterruptedException {
if (untrusted.containsKey(head)) {
trusted.put(head, revision);
untrusted.remove(head);
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/jenkins/scm/api/SCMHeadObserver.java
Expand Up @@ -25,6 +25,7 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -45,8 +46,11 @@ public abstract class SCMHeadObserver {
*
* @param head the head.
* @param revision the revision.
* @throws IOException if processing of the observation could not be completed due to an {@link IOException}.
* @throws InterruptedException if processing of the observation was interrupted
*/
public abstract void observe(@NonNull SCMHead head, @NonNull SCMRevision revision);
public abstract void observe(@NonNull SCMHead head, @NonNull SCMRevision revision)
throws IOException, InterruptedException;

/**
* Returns information about whether the observer wants more results.
Expand Down Expand Up @@ -197,7 +201,8 @@ public AllFinished(@NonNull Iterable<SCMHeadObserver> observers) {
* {@inheritDoc}
*/
@Override
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision)
throws IOException, InterruptedException {
for (SCMHeadObserver observer : observers) {
if (observer.isObserving()) {
observer.observe(head, revision);
Expand Down Expand Up @@ -290,7 +295,8 @@ public OneFinished(@NonNull Iterable<SCMHeadObserver> observers) {
* {@inheritDoc}
*/
@Override
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision)
throws IOException, InterruptedException {
for (SCMHeadObserver observer : observers) {
if (observer.isObserving()) {
observer.observe(head, revision);
Expand Down Expand Up @@ -582,7 +588,8 @@ public boolean isObserving() {
* {@inheritDoc}
*/
@Override
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision)
throws IOException, InterruptedException {
delegate.observe(head, revision);
}

Expand Down Expand Up @@ -632,7 +639,8 @@ public Filter(O delegate, SCMHead... heads) {
* {@inheritDoc}
*/
@Override
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision)
throws IOException, InterruptedException {
if (remaining.contains(head)) {
remaining.remove(head);
super.observe(head, revision);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/jenkins/scm/api/SCMEventTest.java
Expand Up @@ -209,7 +209,7 @@ public void originOfForwardedRequestMultiHop() throws Exception {
Mockito.when(req.getHeader("X-Forwarded-Port")).thenReturn("443");
Mockito.when(req.getHeader("X-Forwarded-For")).thenReturn("scm.example.com, gateway.example.com, proxy.example.com");
Mockito.when(req.getRequestURI()).thenReturn("/jenkins/notify");
Mockito.when(req.getLocalPort()).thenReturn(8080);
Mockito.when(req.getRemotePort()).thenReturn(8080);
Mockito.when(req.getRemoteHost()).thenReturn(null);
Mockito.when(req.getRemoteAddr()).thenReturn("203.0.113.1");
assertThat(SCMEvent.originOf(req), is("scm.example.com → gateway.example.com → proxy.example.com → 203.0.113.1 ⇒ https://jenkins.example.com/jenkins/notify"));
Expand Down

0 comments on commit 0204ff9

Please sign in to comment.