Skip to content

Commit

Permalink
Merge pull request #181 from offa/deprecations
Browse files Browse the repository at this point in the history
Replace deprecated API calls
  • Loading branch information
jglick committed Jan 4, 2023
2 parents 8f4e7ab + dea9b3e commit 7e729d0
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 25 deletions.
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);
} 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

0 comments on commit 7e729d0

Please sign in to comment.