Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated API calls #181

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/main/java/jenkins/scm/api/SCMEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.util.ClassLoaderSanityThreadFactory;
import hudson.util.DaemonThreadFactory;
import hudson.util.NamingThreadFactory;
Expand All @@ -47,8 +48,6 @@
import javax.servlet.http.HttpServletRequest;
import jenkins.security.ImpersonatingScheduledExecutorService;
import jenkins.util.SystemProperties;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -541,17 +540,16 @@ public void run() {
event.getClass(), event.getTimestamp(), oldName)
);
for (final SCMEventListener l : ExtensionList.lookup(SCMEventListener.class)) {
SecurityContext context = ACL.impersonate(ACL.SYSTEM);
try {
fire(l, event);
} catch (LinkageError e) {
log(l, e);
} catch (Error e) {
throw e;
} catch (Throwable e) {
log(l, e);
} finally {
SecurityContextHolder.setContext(context);
try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
try {
fire(l, event);
Comment on lines 542 to +545
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} catch (LinkageError e) {
log(l, e);
} catch (Error e) {
throw e;
} catch (Throwable e) {
log(l, e);
}
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ private SCMHeadMixin.Equality create(@NonNull Class<? extends SCMHead> type) {
SCMHeadMixin.Equality.class);

try {
return c.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return c.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
// fallback to reflection
}
return new ReflectiveEquality(properties.values().toArray(new Method[0]));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/jenkins/scm/api/SCMHeadObserverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import org.hamcrest.Matchers;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/jenkins/scm/api/SCMNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.*;

public class SCMNameTest {
@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/jenkins/scm/api/SCMRevisionActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import jenkins.scm.impl.mock.MockSCMSource;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;

public class SCMRevisionActionTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;

@RunWith(Theories.class)
public class ChangeRequestSCMHeadCategoryTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public String getUrlName() {
}

public HttpResponse doIndex() {
return HttpResponses.plainText(AvatarCache.buildUrl(url, size));
return HttpResponses.text(AvatarCache.buildUrl(url, size));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void before() throws Throwable {
* @param text text to write
*/
public final void write(String rel, String text) throws IOException {
FileUtils.write(new File(sampleRepo, rel), text);
FileUtils.write(new File(sampleRepo, rel), text, StandardCharsets.UTF_8);
}

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ protected final void run(String tool, String... cmds) throws Exception {
* Like {@link #fileUrl} but expressed only as a path, not a URL with protocol.
*/
public final String bareUrl() throws UnsupportedEncodingException {
return URLEncoder.encode(toString(), StandardCharsets.UTF_8.name());
return URLEncoder.encode(toString(), StandardCharsets.UTF_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
import hudson.util.StreamTaskListener;
import java.io.File;
import java.util.Arrays;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.AssumptionViolatedException;
import org.junit.Rule;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static void run(boolean probing, File cwd, String... cmds) throws Excepti
if (probing) {
Assume.assumeThat(message, r, is(0));
} else {
Assert.assertThat(message, r, is(0));
assertThat(message, r, is(0));
}
} catch (Exception x) {
if (probing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.*;

public class WildcardSCMHeadFilterTraitTest {
@ClassRule
Expand Down