Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1122 from daspilker/JENKINS-50750
[JENKINS-50750] fixed anonymous class warning
  • Loading branch information
daspilker committed Apr 14, 2018
2 parents c094cd7 + 50f7860 commit 0466f20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docs/Home.md
Expand Up @@ -38,6 +38,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* Fixed problem with
[Pipeline Multibranch Plugin](https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Plugin)
([JENKINS-50119](https://issues.jenkins-ci.org/browse/JENKINS-50119))
* Fixed anonymous class warning
([JENKINS-50750](https://issues.jenkins-ci.org/browse/JENKINS-50750))
* Support for older versions of the
[CloudBees Folders Plugin](https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Folders+Plugin) is deprecated, see
[Migration](Migration#migrating-to-169)
Expand Down
Expand Up @@ -5,6 +5,8 @@
import jenkins.model.Jenkins;
import org.apache.commons.io.FilenameUtils;

import java.util.function.Function;

/**
* A JobLookupStrategy encapsulates where a seed job will look for existing jobs
* and where it will create new jobs. This matters when you use relative names in
Expand All @@ -14,26 +16,17 @@ public enum LookupStrategy {
/**
* Using this naming strategy jobs with relative path names are absolute names.
*/
JENKINS_ROOT("Jenkins Root") {
@Override
protected ItemGroup getContext(Item seedJob) {
return Jenkins.getInstance();
}
},
JENKINS_ROOT("Jenkins Root", (seedJob) -> Jenkins.getInstance()),

/**
* Using this naming strategy jobs with relative path names are created relative
* to the seed job's parent folder.
*/
SEED_JOB("Seed Job") {
@Override
protected ItemGroup getContext(Item seedJob) {
return seedJob.getParent();
}
};
SEED_JOB("Seed Job", Item::getParent);

LookupStrategy(String displayName) {
LookupStrategy(String displayName, Function<Item, ItemGroup> context) {
this.displayName = displayName;
this.context = context;
}

/**
Expand All @@ -60,7 +53,9 @@ public <T extends Item> T getItem(Item seedJob, String path, Class<T> type) {
* @param seedJob a seed job
* @return the context
*/
protected abstract ItemGroup getContext(Item seedJob);
protected ItemGroup getContext(Item seedJob) {
return context.apply(seedJob);
}

/**
* Get the parent {@link hudson.model.ItemGroup} of the item addressed by the given path.
Expand Down Expand Up @@ -93,6 +88,7 @@ public String getDisplayName() {
}

private final String displayName;
private final Function<Item, ItemGroup> context;

private static ItemGroup getItemGroup(String path) {
Jenkins instance = Jenkins.getInstance();
Expand Down

0 comments on commit 0466f20

Please sign in to comment.