Skip to content
Permalink
Browse files

[JENKINS-43507] Refactoring names

  • Loading branch information...
stephenc committed May 2, 2017
1 parent ddd8e4f commit 006942840d9e2ca42ad32210368b88154268425b
@@ -46,6 +46,7 @@
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceCriteria;
import jenkins.scm.api.mixin.ChangeRequestSCMHead2;
import jenkins.scm.api.mixin.SCMHeadMixin;

/**
@@ -179,7 +180,7 @@ private static void record(@NonNull SCMHead head, SCMRevision revision, boolean
* @throws IOException if there is an I/O error.
* @throws InterruptedException if the operation was interrupted.
*/
public boolean isExcluded(@NonNull SCMHead head) throws IOException, InterruptedException {
public final boolean isExcluded(@NonNull SCMHead head) throws IOException, InterruptedException {
if (observerIncludes != null && !observerIncludes.contains(head)) {
return true;
}
@@ -209,7 +210,7 @@ public boolean isExcluded(@NonNull SCMHead head) throws IOException, Interrupted
* @throws IOException if there is an I/O error.
* @throws InterruptedException if the operation was interrupted.
*/
public boolean isTrusted(@NonNull SCMHead head) throws IOException, InterruptedException {
public final boolean isTrusted(@NonNull SCMHead head) throws IOException, InterruptedException {
for (SCMHeadAuthority authority : authorities) {
if (authority.isTrusted(this, head)) {
return true;
@@ -224,7 +225,7 @@ public boolean isTrusted(@NonNull SCMHead head) throws IOException, InterruptedE
* @return the {@link SCMSourceCriteria} being used for this request.
*/
@NonNull
public List<SCMSourceCriteria> getCriteria() {
public final List<SCMSourceCriteria> getCriteria() {
return criteria;
}

@@ -244,15 +245,15 @@ public boolean isTrusted(@NonNull SCMHead head) throws IOException, InterruptedE
*/
public final <H extends SCMHead, R extends SCMRevision> boolean process(final @NonNull H head,
final R revision,
@NonNull ProbeFactory<H, R> probeFactory,
@NonNull ProbeLambda<H, R> probeFactory,
@NonNull Witness... witnesses)
throws IOException, InterruptedException {
return process(head, new IntermediateFactory<R>() {
return process(head, new IntermediateLambda<R>() {
@Override
public R create() throws IOException, InterruptedException {
return revision;
}
}, probeFactory, new LazyRevisionFactory<H, SCMRevision, R>() {
}, probeFactory, new LazyRevisionLambda<H, SCMRevision, R>() {
@Override
public SCMRevision create(H head, R intermediate) throws IOException, InterruptedException {
return intermediate;
@@ -276,17 +277,17 @@ public SCMRevision create(H head, R intermediate) throws IOException, Interrupte
*/
public final <H extends SCMHead, R extends SCMRevision> boolean process(final @NonNull H head,
final @NonNull
RevisionFactory<H, R>
RevisionLambda<H, R>
revisionFactory,
@NonNull ProbeFactory<H, R> probeFactory,
@NonNull ProbeLambda<H, R> probeFactory,
@NonNull Witness... witnesses)
throws IOException, InterruptedException {
return process(head, new IntermediateFactory<R>() {
return process(head, new IntermediateLambda<R>() {
@Override
public R create() throws IOException, InterruptedException {
return revisionFactory.create(head);
}
}, probeFactory, new LazyRevisionFactory<H, SCMRevision, R>() {
}, probeFactory, new LazyRevisionLambda<H, SCMRevision, R>() {
@Override
public SCMRevision create(H head, R intermediate) throws IOException, InterruptedException {
return intermediate;
@@ -299,8 +300,8 @@ public SCMRevision create(H head, R intermediate) throws IOException, Interrupte
* the {@link SCMRevision} can be instantiated.
*
* @param head the {@link SCMHead} to process.
* @param intermediateFactory factory method that provides the seed information for both the {@link ProbeFactory}
* and the {@link LazyRevisionFactory}.
* @param intermediateFactory factory method that provides the seed information for both the {@link ProbeLambda}
* and the {@link LazyRevisionLambda}.
* @param probeFactory factory method that creates the {@link SCMProbe}.
* @param revisionFactory factory method that creates the {@link SCMRevision}.
* @param witnesses any {@link Witness} instances to be informed of the observation result.
@@ -313,11 +314,11 @@ public SCMRevision create(H head, R intermediate) throws IOException, Interrupte
* @throws InterruptedException if the processing was interrupted.
*/
public final <H extends SCMHead, I, R extends SCMRevision> boolean process(@NonNull H head,
@CheckForNull IntermediateFactory<I>
@CheckForNull IntermediateLambda<I>
intermediateFactory,
@NonNull ProbeFactory<H, I> probeFactory,
@NonNull ProbeLambda<H, I> probeFactory,
@NonNull
LazyRevisionFactory<H, R, I>
LazyRevisionLambda<H, R, I>
revisionFactory,
@NonNull Witness... witnesses)
throws IOException, InterruptedException {
@@ -415,26 +416,75 @@ public void close() throws IOException {
}
}

public interface RevisionFactory<H extends SCMHead, R extends SCMRevision> {
/**
* A lambda that will create the {@link SCMRevision} instance for a specific {@link SCMHead}.
*
* @param <H> the type of {@link SCMHead}.
* @param <R> the type of {@link SCMRevision}.
*/
public interface RevisionLambda<H extends SCMHead, R extends SCMRevision> {
@NonNull
R create(@NonNull H head) throws IOException, InterruptedException;
}

public interface ProbeFactory<H extends SCMHead, I> {
/**
* A lambda that will create a {@link SCMSourceCriteria.Probe} (ideally a {@link SCMProbe} but for legacy code
* migration we use {@link SCMSourceCriteria.Probe}) for a specified {@link SCMHead} and either a
* {@link SCMRevision} or some other type created by a {@link IntermediateLambda}.
*
* @param <H> the type of {@link SCMHead}
* @param <I> the type of side-value used to create the probe (typically a {@link SCMRevision} but if that is costly
* to instantiate it may be the return value from a {@link IntermediateLambda}.
* @see RevisionLambda
* @see IntermediateLambda
*/
public interface ProbeLambda<H extends SCMHead, I> {
@NonNull
SCMSourceCriteria.Probe create(@NonNull H head, @Nullable I revision) throws IOException, InterruptedException;
}

public interface LazyRevisionFactory<H extends SCMHead, R extends SCMRevision, I> {
/**
* A lambda that will create the {@link SCMRevision} instance for a specific {@link SCMHead} using the intermediate
* value produced by a {@link IntermediateLambda}.
* @param <H> the type of {@link SCMHead}
* @param <R> the type of {@link SCMRevision}.
* @param <I> the type of intermediate value produced by the {@link IntermediateLambda}.
* @see IntermediateLambda
*/
public interface LazyRevisionLambda<H extends SCMHead, R extends SCMRevision, I> {
@NonNull
R create(@NonNull H head, @Nullable I intermediate) throws IOException, InterruptedException;
}

public interface IntermediateFactory<I> {
/**
* A lambda that produces an intermediate summary used to drive creation of the {@link SCMSourceCriteria.Probe}
* and {@link SCMRevision} instances.
* <p>
* Some {@link SCMRevision} instances may be expensive to instantiate, for example a {@link ChangeRequestSCMHead2}
* may need to get the effective merge revision in order to comply with the equality and "offline" requirememt
* of a {@link SCMRevision} which could require either asking the remote server or performing a local trial merge.
* As this type of operation is only required if the {@link SCMHead} actually meets the {@link SCMSourceCriteria}
* it may be preferred to delay instantiation of the {@link SCMRevision} and instead create the
* {@link SCMSourceCriteria.Probe} from some intermediate. For example the {@link SCMSourceCriteria} may
* only be checking the existence of files, if the file is present in both the {@link ChangeRequestSCMHead2}
* and its {@link ChangeRequestSCMHead2#getTarget()} then it will also be present in the merge revision and hence
* the computation of the merge revision can be avoided completely.
*
* @param <I> the type of intermediate value or {@link Void} if no intermediate is required.
* @see LazyRevisionLambda
* @see ProbeLambda
*/
public interface IntermediateLambda<I> {
@Nullable
I create() throws IOException, InterruptedException;
}

/**
* Callback lambda to track the results of
* {@link #process(SCMHead, IntermediateLambda, ProbeLambda, LazyRevisionLambda, Witness[])}
* @param <H> the type of {@link SCMHead}
* @param <R> the type of {@link SCMRevision}
*/
public interface Witness<H extends SCMHead, R extends SCMRevision> {
void record(@NonNull H head, @CheckForNull R revision, boolean isMatch);
}
@@ -127,14 +127,14 @@ protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHe
if (request.isFetchBranches()) {
for (final String branch : controller().listBranches(repository)) {
if (request.process(new MockSCMHead(branch),
new SCMSourceRequest.RevisionFactory<MockSCMHead, MockSCMRevision>() {
new SCMSourceRequest.RevisionLambda<MockSCMHead, MockSCMRevision>() {
@Override
public MockSCMRevision create(MockSCMHead head) throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(repository, head.getName(), null, false);
return new MockSCMRevision(head, controller().getRevision(repository, branch));
}
}, new SCMSourceRequest.ProbeFactory<MockSCMHead, MockSCMRevision>() {
}, new SCMSourceRequest.ProbeLambda<MockSCMHead, MockSCMRevision>() {
@Override
public SCMSourceCriteria.Probe create(MockSCMHead head, MockSCMRevision revision) throws IOException, InterruptedException {
controller().applyLatency();
@@ -149,15 +149,15 @@ public MockSCMRevision create(MockSCMHead head) throws IOException, InterruptedE
if (request.isFetchTags()) {
for (final String tag : controller().listTags(repository)) {
if (request.process(new MockTagSCMHead(tag, controller().getTagTimestamp(repository, tag)),
new SCMSourceRequest.RevisionFactory<MockTagSCMHead, MockSCMRevision>() {
new SCMSourceRequest.RevisionLambda<MockTagSCMHead, MockSCMRevision>() {
@Override
public MockSCMRevision create(MockTagSCMHead head)
throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(repository, head.getName(), null, false);
return new MockSCMRevision(head, controller().getRevision(repository, tag));
}
}, new SCMSourceRequest.ProbeFactory<MockTagSCMHead, MockSCMRevision>() {
}, new SCMSourceRequest.ProbeLambda<MockTagSCMHead, MockSCMRevision>() {
@Override
public SCMSourceCriteria.Probe create(MockTagSCMHead head, MockSCMRevision revision)
throws IOException, InterruptedException {
@@ -183,7 +183,7 @@ public MockSCMRevision create(MockTagSCMHead head)
? new SCMHeadOrigin.Fork("fork")
: null,
number, target, strategy, singleStrategy),
new SCMSourceRequest.RevisionFactory<MockChangeRequestSCMHead, MockChangeRequestSCMRevision>() {
new SCMSourceRequest.RevisionLambda<MockChangeRequestSCMHead, MockChangeRequestSCMRevision>() {
@Override
public MockChangeRequestSCMRevision create(MockChangeRequestSCMHead head)
throws IOException, InterruptedException {
@@ -197,7 +197,7 @@ public MockChangeRequestSCMRevision create(MockChangeRequestSCMHead head)
new MockSCMRevision(head.getTarget(), targetRevision), revision);
}
},
new SCMSourceRequest.ProbeFactory<MockChangeRequestSCMHead, MockChangeRequestSCMRevision>() {
new SCMSourceRequest.ProbeLambda<MockChangeRequestSCMHead, MockChangeRequestSCMRevision>() {
@Override
public SCMSourceCriteria.Probe create(MockChangeRequestSCMHead head,
MockChangeRequestSCMRevision revision)

0 comments on commit 0069428

Please sign in to comment.
You can’t perform that action at this time.