Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/addCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Dohbedoh committed Oct 11, 2024
2 parents 23ee500 + 14660fe commit 86ddfc9
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 74 deletions.
5 changes: 2 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
buildPlugin(useContainerAgent: true, configurations: [
[platform: 'windows', jdk: '17'],
[platform: 'linux', jdk: '11'],
[platform: 'linux', jdk: '21'],
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 17]
])
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.1</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -67,7 +67,7 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<jenkins.version>2.462.3</jenkins.version>
<jenkins.version>2.479</jenkins.version>
<hpi.compatibleSinceVersion>1372</hpi.compatibleSinceVersion>
</properties>

Expand All @@ -88,8 +88,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.452.x</artifactId>
<version>3208.vb_21177d4b_cd9</version>
<artifactId>bom-2.462.x</artifactId>
<version>3435.v238d66a_043fb_</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.AnnotationHandler;
import org.kohsuke.stapler.InjectedParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Indicates that this parameter is injected by evaluating
* {@link StaplerRequest#getAncestors()} and searching for a credentials context with the parameter type.
* {@link StaplerRequest2#getAncestors()} and searching for a credentials context with the parameter type.
* You can enhance the lookup by ensuring that there are query parameters of {@code $provider} and {@code $token}
* that correspond to the context's {@link CredentialsSelectHelper.ContextResolver} FQCN and
* {@link CredentialsSelectHelper.ContextResolver#getToken(ModelObject)} respectively.
Expand All @@ -29,7 +29,8 @@
@InjectedParameter(ContextInPath.HandlerImpl.class)
public @interface ContextInPath {
class HandlerImpl extends AnnotationHandler<ContextInPath> {
public Object parse(StaplerRequest request, ContextInPath contextInPath, Class type, String parameterName)
@Override
public Object parse(StaplerRequest2 request, ContextInPath contextInPath, Class type, String parameterName)
throws
ServletException {
String $provider = request.getParameter("$provider");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static String getMenuItemIconUrl(String url) {
if (url == null) {
return null;
}
String contextPath = Stapler.getCurrentRequest().getContextPath();
String contextPath = Stapler.getCurrentRequest2().getContextPath();
return (StringUtils.isBlank(contextPath)? "" : contextPath) + (url.startsWith("images/")
? Functions.getResourcePath()
: "") + (url.startsWith("/") ? url : '/' + url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Descriptor for credentials.
Expand Down Expand Up @@ -116,7 +116,7 @@ public ListBoxModel doFillScopeItems(@ContextInPath ModelObject context) {
@Restricted(NoExternalUse.class)
@RestrictedSince("2.1.5")
public boolean isScopeRelevant() {
Ancestor ancestor = Stapler.getCurrentRequest().findAncestor(Object.class);
Ancestor ancestor = Stapler.getCurrentRequest2().findAncestor(Object.class);
while (ancestor != null) {
if (ancestor.getObject() instanceof ModelObject) {
ModelObject context = unwrapContext((ModelObject) ancestor.getObject());
Expand Down Expand Up @@ -177,7 +177,7 @@ public boolean isScopeRelevant(CredentialsStoreAction.DomainWrapper wrapper) {
return isScopeRelevant(wrapper.getStore().getContext());
}
CredentialsStoreAction action =
Stapler.getCurrentRequest().findAncestorObject(CredentialsStoreAction.class);
Stapler.getCurrentRequest2().findAncestorObject(CredentialsStoreAction.class);
if (action != null) {
return isScopeRelevant(action.getStore().getContext());
}
Expand All @@ -199,7 +199,7 @@ public boolean isScopeRelevant(CredentialsStoreAction.CredentialsWrapper wrapper
return isScopeRelevant(wrapper.getStore().getContext());
}
CredentialsStoreAction action =
Stapler.getCurrentRequest().findAncestorObject(CredentialsStoreAction.class);
Stapler.getCurrentRequest2().findAncestorObject(CredentialsStoreAction.class);
if (action != null) {
return isScopeRelevant(action.getStore().getContext());
}
Expand All @@ -221,7 +221,7 @@ public boolean isScopeRelevant(CredentialsSelectHelper.WrappedCredentialsStore w
return isScopeRelevant(wrapper.getStore().getContext());
}
CredentialsStoreAction action =
Stapler.getCurrentRequest().findAncestorObject(CredentialsStoreAction.class);
Stapler.getCurrentRequest2().findAncestorObject(CredentialsStoreAction.class);
if (action != null) {
return isScopeRelevant(action.getStore().getContext());
}
Expand Down Expand Up @@ -301,7 +301,7 @@ public static ModelObject lookupContext(String provider, String token) {
}

/**
* Attempts to resolve the credentials context from the {@link Stapler#getCurrentRequest()} (includes special
* Attempts to resolve the credentials context from the {@link Stapler#getCurrentRequest2()} (includes special
* handling of the HTTP Referer to enable resolution from AJAX requests).
*
* @param type the type of context.
Expand All @@ -311,21 +311,21 @@ public static ModelObject lookupContext(String provider, String token) {
*/
@CheckForNull
public static <T extends ModelObject> T findContextInPath(@NonNull Class<T> type) {
return findContextInPath(Stapler.getCurrentRequest(), type);
return findContextInPath(Stapler.getCurrentRequest2(), type);
}

/**
* Attempts to resolve the credentials context from the {@link StaplerRequest} (includes special
* Attempts to resolve the credentials context from the {@link StaplerRequest2} (includes special
* handling of the HTTP Referer to enable resolution from AJAX requests).
*
* @param request the {@link StaplerRequest}.
* @param request the {@link StaplerRequest2}.
* @param type the type of context.
* @param <T> the type of context.
* @return the context from the request
* @since 2.1.5
*/
@CheckForNull
public static <T extends ModelObject> T findContextInPath(@NonNull StaplerRequest request, @NonNull Class<T> type) {
public static <T extends ModelObject> T findContextInPath(@NonNull StaplerRequest2 request, @NonNull Class<T> type) {
List<Ancestor> ancestors = request.getAncestors();
for (int i = ancestors.size() - 1; i >= 0; i--) {
Ancestor a = ancestors.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Comparator to alphabetically sort credentials drop down list in ascending order by Credential Name.
Expand Down Expand Up @@ -83,7 +83,7 @@ public CredentialsNameComparator(@CheckForNull Locale locale) {
*/
public CredentialsNameComparator(@CheckForNull Locale locale, boolean ignoreCase) {
if (locale == null) {
StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
if (req != null) {
locale = req.getLocale();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.springframework.security.core.Authentication;

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) {
* {@inheritDoc}
*/
@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
public ParameterValue createValue(StaplerRequest2 req, JSONObject jo) {
CredentialsParameterValue value = req.bindJSON(CredentialsParameterValue.class, jo);
if ((isRequired() && StringUtils.isBlank(value.getValue()))) {
return new CredentialsParameterValue(value.getName(), getDefaultValue(), getDescription(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public String describe() {
if (StringUtils.isBlank(value)) {
return "";
}
final Run run = Stapler.getCurrentRequest().findAncestorObject(Run.class);
final Run run = Stapler.getCurrentRequest2().findAncestorObject(Run.class);
if (run == null) {
throw new IllegalStateException("Should only be called from value.jelly");
}
Expand All @@ -139,7 +139,7 @@ public String iconClassName() {
if (StringUtils.isBlank(value)) {
return "";
}
final Run run = Stapler.getCurrentRequest().findAncestorObject(Run.class);
final Run run = Stapler.getCurrentRequest2().findAncestorObject(Run.class);
if (run == null) {
throw new IllegalStateException("Should only be called from value.jelly");
}
Expand All @@ -163,7 +163,7 @@ public String url() {
if (StringUtils.isBlank(value)) {
return null;
}
final Run run = Stapler.getCurrentRequest().findAncestorObject(Run.class);
final Run run = Stapler.getCurrentRequest2().findAncestorObject(Run.class);
if (run == null) {
throw new IllegalStateException("Should only be called from value.jelly");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
Expand Down Expand Up @@ -1865,7 +1865,7 @@ private static class ListBoxModelOptionComparator implements Comparator<ListBoxM
private transient Collator collator;

public ListBoxModelOptionComparator() {
StaplerRequest req = Stapler.getCurrentRequest();
StaplerRequest2 req = Stapler.getCurrentRequest2();
if (req != null) {
locale = req.getLocale();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* Manages the various {@link CredentialsProvider} implementations in a {@link Jenkins}
Expand Down Expand Up @@ -422,7 +422,7 @@ public void setRestrictions(List<CredentialsProviderTypeRestriction> restriction
* {@inheritDoc}
*/
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
public boolean configure(StaplerRequest2 req, JSONObject json) throws FormException {
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
if (!json.has("restrictions")) {
// JENKINS-36090 stapler "helpfully" does not submit the restrictions if there are none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
Expand All @@ -58,8 +58,8 @@
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.Localizable;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ public ModelObject resolveContext(Object context) {
if (context instanceof ModelObject) {
return (ModelObject) context;
}
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
return request.findAncestorObject(ModelObject.class);
}
Expand All @@ -132,7 +132,7 @@ public List<StoreItem> getStoreItems(ModelObject context, boolean includeUser) {
Set<String> urls = new HashSet<>();
List<StoreItem> result = new ArrayList<>();
if (context == null) {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
context = request.findAncestorObject(ModelObject.class);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ public boolean hasCreatePermission(ModelObject context, boolean includeUser) {
}
}
if (context == null) {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
context = request.findAncestorObject(ModelObject.class);
}
Expand Down Expand Up @@ -596,7 +596,7 @@ public WrappedCredentialsStore(@NonNull ContextResolver resolver, @NonNull Crede
*/
@RequirePOST
@Restricted(NoExternalUse.class)
public JSONObject doAddCredentials(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public JSONObject doAddCredentials(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
store.checkPermission(CredentialsStoreAction.CREATE);
JSONObject data = req.getSubmittedForm();
String domainName = data.getString("domain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.springframework.security.core.Authentication;

/**
Expand Down Expand Up @@ -463,7 +463,7 @@ public String getRelativeLinkToContext() {
if (context instanceof Item) {
return Functions.getRelativeLinkTo((Item) context);
}
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request == null) {
return null;
}
Expand Down
Loading

0 comments on commit 86ddfc9

Please sign in to comment.