Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-39580 - Allow configuring which DisplayUrlProvider to use
- Loading branch information
James Dumay
committed
Dec 4, 2016
1 parent
b713157
commit 8e35b65
Showing
8 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/org/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.jenkinsci.plugins.displayurlapi.user; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Lists; | ||
import hudson.Extension; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
public class PreferredProviderUserProperty extends UserProperty { | ||
|
||
@Extension | ||
public static final UserPropertyDescriptor DESCRIPTOR = new PreferredProviderUserPropertyDescriptor(); | ||
|
||
@Nullable | ||
private String providerId; | ||
|
||
@DataBoundConstructor | ||
public PreferredProviderUserProperty(@Nullable String providerId) { | ||
this.providerId = providerId; | ||
} | ||
|
||
public ProviderOption getProvider() { | ||
final DisplayURLProvider provider = getConfiguredProvider(); | ||
return provider == null ? ProviderOption.DEFAULT_OPTION : new ProviderOption(provider.getClass().getName(), provider.getDisplayName()); | ||
} | ||
|
||
public DisplayURLProvider getConfiguredProvider() { | ||
return Iterables.find(DisplayURLProvider.all(), new Predicate<DisplayURLProvider>() { | ||
@Override | ||
public boolean apply(DisplayURLProvider input) { | ||
return input.getClass().getName().equals(providerId); | ||
} | ||
}, null); | ||
} | ||
|
||
public List<ProviderOption> getAll() { | ||
Iterable<ProviderOption> options = Iterables.transform(DisplayURLProvider.all(), new Function<DisplayURLProvider, ProviderOption>() { | ||
@Override | ||
public ProviderOption apply(DisplayURLProvider input) { | ||
return new ProviderOption(input.getClass().getName(), input.getDisplayName()); | ||
} | ||
}); | ||
return ImmutableList.copyOf(Iterables.concat(Lists.newArrayList(ProviderOption.DEFAULT_OPTION), options)); | ||
} | ||
|
||
public boolean isSelected(String providerId) { | ||
return getProvider().getId().equals(providerId); | ||
} | ||
|
||
public static class ProviderOption { | ||
|
||
public static final ProviderOption DEFAULT_OPTION = new ProviderOption("default", "Default"); | ||
|
||
private final String id; | ||
private final String name; | ||
|
||
public ProviderOption(String id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ava/org/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserPropertyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jenkinsci.plugins.displayurlapi.user; | ||
|
||
import hudson.model.User; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
import org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty.ProviderOption; | ||
|
||
public class PreferredProviderUserPropertyDescriptor extends UserPropertyDescriptor { | ||
|
||
public PreferredProviderUserPropertyDescriptor() { | ||
super(PreferredProviderUserProperty.class); | ||
} | ||
|
||
@Override | ||
public UserProperty newInstance(User user) { | ||
return new PreferredProviderUserProperty(ProviderOption.DEFAULT_OPTION.getId()); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Preferred UI"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...urces/org/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserProperty/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<f:block> | ||
<f:entry name="providerId" title="Preferred UI" field="providerId"> | ||
<select name="providerId"> | ||
<j:forEach var="provider" items="${instance.all}"> | ||
<j:choose> | ||
<j:when test="${instance.isSelected(provider.getId())}"> | ||
<option value="${provider.getId()}" selected="true">${provider.getName()}</option> | ||
</j:when> | ||
<j:otherwise> | ||
<option value="${provider.getId()}">${provider.getName()}</option> | ||
</j:otherwise> | ||
</j:choose> | ||
</j:forEach> | ||
</select> | ||
</f:entry> | ||
</f:block> | ||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters