Skip to content

Commit

Permalink
replaced deprecated NullStream and Jenkins.getInstance() with suggest…
Browse files Browse the repository at this point in the history
…ed replacements (#322)
  • Loading branch information
StefanSpieker authored May 3, 2024
1 parent 74b2a7c commit 75dda1d
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/maven/AbstractMavenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected String format(NumberFormat n, long nanoTime) {

// since reporters might be from plugins, use the uberjar to resolve them.
public ClassLoader getClassLoader() {
return Jenkins.getInstance().getPluginManager().uberClassLoader;
return Jenkins.get().getPluginManager().uberClassLoader;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/hudson/maven/MavenModuleSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public Object readResolve() {
// backward compatibility, maven-plugin used to have a dependency to the config-file-provider plugin
Plugin plugin = null;
if(StringUtils.isNotBlank(this.settingConfigId) || StringUtils.isNotBlank(this.globalSettingConfigId)) {
plugin = Jenkins.getInstance().getPlugin("config-file-provider");
plugin = Jenkins.get().getPlugin("config-file-provider");
if(plugin == null || !plugin.getWrapper().isEnabled()){
LOGGER.severe(Messages.MavenModuleSet_readResolve_missingConfigProvider());
}
Expand Down Expand Up @@ -391,7 +391,7 @@ public Object readResolve() {
* Use {@link #MavenModuleSet(ItemGroup, String)}
*/
public MavenModuleSet(String name) {
this(Jenkins.getInstance(), name);
this(Jenkins.get(), name);
}

public MavenModuleSet(ItemGroup parent, String name) {
Expand Down Expand Up @@ -1153,14 +1153,14 @@ public void setMaven(String mavenName) {
* Returns the {@link MavenModule}s that are in the queue.
*/
public List<Queue.Item> getQueueItems() {
return filter(Arrays.asList(Jenkins.getInstance().getQueue().getItems()));
return filter(Arrays.asList(Jenkins.get().getQueue().getItems()));
}

/**
* Returns the {@link MavenModule}s that are in the queue.
*/
public List<Queue.Item> getApproximateQueueItemsQuickly() {
return filter(Jenkins.getInstance().getQueue().getApproximateItemsQuickly());
return filter(Jenkins.get().getQueue().getApproximateItemsQuickly());

Check warning on line 1163 in src/main/java/hudson/maven/MavenModuleSet.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 318-1163 are not covered by tests
}

private List<Queue.Item> filter(Collection<Queue.Item> base) {
Expand Down Expand Up @@ -1293,7 +1293,7 @@ public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse
}

public DescriptorImpl getDescriptor() {
return (DescriptorImpl)Jenkins.getInstance().getDescriptorOrDie(getClass());
return (DescriptorImpl)Jenkins.get().getDescriptorOrDie(getClass());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/maven/MavenModuleSetBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVa
// we might have added new modules
if (needsDependencyGraphRecalculation) {
logger.println("Modules changed, recalculating dependency graph");
Jenkins.getInstance().rebuildDependencyGraph();
Jenkins.get().rebuildDependencyGraph();
}

// module builds must start with this build's number
Expand Down
1 change: 0 additions & 1 deletion src/main/java/hudson/maven/MojoInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.lang.reflect.Method;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hudson/maven/ProcessCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import hudson.remoting.RequestAbortedException;
import hudson.tasks.Maven.MavenInstallation;
import hudson.util.DelegatingOutputStream;
import hudson.util.NullStream;
import jenkins.security.MasterToSlaveCallable;

import java.io.IOException;
Expand Down Expand Up @@ -132,7 +131,7 @@ public void recycle() throws IOException {
if(age>=MAX_AGE || maxProcess==0)
discard();
else {
output.set(new NullStream());
output.set(OutputStream.nullOutputStream());
// make room for the new process and reuse.
synchronized(parent.processes) {
while(parent.processes.size()>=maxProcess)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/hudson/maven/SplittableBuildListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/hudson/maven/reporters/TestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
Expand All @@ -16,7 +15,6 @@
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;

import com.google.common.base.Function;
import com.google.common.collect.Iterators;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/maven/Maven36xBuildTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Maven.MavenInstallation configureMaven36() throws Exception {
Maven.MavenInstallation mvn = ToolInstallations.configureDefaultMaven("apache-maven-3.6.3", MavenInstallation.MAVEN_30);

Maven.MavenInstallation m3 = new Maven.MavenInstallation( "apache-maven-3.6.3", mvn.getHome(), JenkinsRule.NO_PROPERTIES);
Jenkins.getInstance().getDescriptorByType( Maven.DescriptorImpl.class).setInstallations( m3);
Jenkins.get().getDescriptorByType( Maven.DescriptorImpl.class).setInstallations( m3);
return m3;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/maven/MavenProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testCopyFromExistingMavenProject() throws Exception {
project.setGoals("abcdefg");
project.save();

MavenModuleSet copy = (MavenModuleSet) Jenkins.getInstance().copy((AbstractProject<?, ?>)project, "copy" + System.currentTimeMillis());
MavenModuleSet copy = (MavenModuleSet) Jenkins.get().copy((AbstractProject<?, ?>)project, "copy" + System.currentTimeMillis());
assertNotNull("Copied project must not be null", copy);
assertEquals(project.getGoals(), copy.getGoals());
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/hudson/maven/reporters/MavenMailerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.ToolInstallations;
import org.jvnet.mock_javamail.Mailbox;

import java.util.List;
Expand Down Expand Up @@ -94,7 +93,7 @@ public void testSingleMails() throws Exception {

public Mailbox runMailTest(boolean perModuleEamil) throws Exception {

final DescriptorImpl mailDesc = Jenkins.getInstance().getDescriptorByType(Mailer.DescriptorImpl.class);
final DescriptorImpl mailDesc = Jenkins.get().getDescriptorByType(Mailer.DescriptorImpl.class);

// intentionally give the whole thin in a double quote
Mailer.descriptor().setAdminAddress(EMAIL_ADMIN);
Expand Down

0 comments on commit 75dda1d

Please sign in to comment.