Skip to content

replaced deprecated jenkins.getInstance with replacements and minor cleanup #251

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class CompareAgainstBaselineCallable extends MasterToSlaveCallable<Polling
}

public ClassLoader getClassLoader() {
return Jenkins.getInstance().getPluginManager().uberClassLoader;
return Jenkins.get().getPluginManager().uberClassLoader;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/hudson/scm/SubversionChangeLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import hudson.scm.SubversionChangeLogSet.LogEntry;
import hudson.scm.SubversionChangeLogSet.Path;
import hudson.util.Digester2;
import jenkins.util.SystemProperties;
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/SubversionCredentialProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public abstract class SubversionCredentialProvider implements ExtensionPoint {
* All regsitered instances.
*/
public static ExtensionList<SubversionCredentialProvider> all() {
return Jenkins.getInstance().getExtensionList(SubversionCredentialProvider.class);
return Jenkins.get().getExtensionList(SubversionCredentialProvider.class);
}
}
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/SubversionEventHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static boolean startsWith(String p1, String p2) {

private static boolean equals(String p1, String p2) {
if (SVNFileUtil.isWindows || SVNFileUtil.isOpenVMS) {
return p1.toLowerCase().equals(p2.toLowerCase());
return p1.equalsIgnoreCase(p2);
}
return p1.equals(p2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/SubversionRepositoryStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static class JobTriggerListenerImpl extends Listener {
private JobProvider jobProvider = new JobProvider() {
@SuppressWarnings("rawtypes")
public List<Job> getAllJobs() {
return Jenkins.getInstance().getAllItems(Job.class);
return Jenkins.get().getAllItems(Job.class);
}
};

Expand Down
26 changes: 11 additions & 15 deletions src/main/java/hudson/scm/SubversionSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Chmod;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -884,7 +882,7 @@ public boolean requiresWorkspaceForPolling() {
// write out the revision file
try (PrintWriter w = new PrintWriter(new FileOutputStream(getRevisionFile(build)))) {
List<SvnInfoP> pList = workspace.act(new BuildRevisionMapTask(build, this, listener, externalsForAll, env));
List<SvnInfo> revList= new ArrayList<SvnInfo>(pList.size());
List<SvnInfo> revList= new ArrayList<>(pList.size());
for (SvnInfoP p: pList) {
if (p.pinned)
w.println( p.info.url +'/'+ p.info.revision + "::p");
Expand Down Expand Up @@ -1188,9 +1186,7 @@ public int compareTo(SvnInfo that) {
int r = this.url.compareTo(that.url);
if(r!=0) return r;

if(this.revision<that.revision) return -1;
if(this.revision>that.revision) return +1;
return 0;
return Long.compare(this.revision, that.revision);
}

@Override
Expand Down Expand Up @@ -1427,9 +1423,9 @@ public PollingResult compareRemoteRevisionWith(Job<?, ?> project, Launcher launc

Node node;
if (nodeName.equals("master")) {
node = Jenkins.getInstance();
node = Jenkins.get();
} else {
node = Jenkins.getInstance().getNode(nodeName);
node = Jenkins.get().getNode(nodeName);
}

// Reference: https://github.com/jenkinsci/subversion-plugin/pull/131
Expand Down Expand Up @@ -1696,7 +1692,7 @@ public void load() {
BulkChange bc = new BulkChange(this);
try {
mayHaveLegacyPerJobCredentials = true;
CredentialsStore store = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next();
CredentialsStore store = CredentialsProvider.lookupStores(Jenkins.get()).iterator().next();
for (Map.Entry<String, Credential> e : credentials.entrySet()) {
migrateCredentials(store, e.getKey(), e.getValue());
}
Expand All @@ -1718,7 +1714,7 @@ public void load() {
}
boolean allOk = true;

for (AbstractProject<?, ?> job : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
for (AbstractProject<?, ?> job : Jenkins.get().getAllItems(AbstractProject.class)) {
File jobCredentials = new File(job.getRootDir(), "subversion.credentials");
if (jobCredentials.isFile()) {
try {
Expand Down Expand Up @@ -1837,7 +1833,7 @@ public static abstract class Credential implements Serializable {
protected ItemGroup findItemGroup(ModelObject context) {
if (context instanceof ItemGroup) return (ItemGroup) context;
if (context instanceof Item) return ((Item) context).getParent();
return Jenkins.getInstance();
return Jenkins.get();
}
}

Expand Down Expand Up @@ -1931,7 +1927,7 @@ public SshPublicKeyCredential(String userName, String passphrase, File keyFile)
* Gets the location where the private key will be permanently stored.
*/
private File getKeyFile() {
File dir = new File(Jenkins.getInstance().getRootDir(),"subversion-credentials");
File dir = new File(Jenkins.get().getRootDir(),"subversion-credentials");
if(dir.mkdirs()) {
// make sure the directory exists. if we created it, try to set the permission to 600
// since this is sensitive information
Expand Down Expand Up @@ -2255,7 +2251,7 @@ public ISVNAuthenticationProvider createAuthenticationProvider() {
*/
// TODO: stapler should do multipart/form-data handling
public void doPostCredential(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
Jenkins.getInstance().checkPermission(Item.CONFIGURE);
Jenkins.get().checkPermission(Item.CONFIGURE);

MultipartFormDataParser parser = new MultipartFormDataParser(req);

Expand All @@ -2271,7 +2267,7 @@ public void doPostCredential(StaplerRequest req, StaplerResponse rsp) throws IOE
req.setAttribute("message",log.toString());
req.setAttribute("pre",true);
req.setAttribute("exception",e);
rsp.forward(Jenkins.getInstance(),"error",req);
rsp.forward(Jenkins.get(),"error",req);
}
}

Expand Down Expand Up @@ -2516,7 +2512,7 @@ public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item co
return FormValidation.ok();

// Test the connection only if we have admin permission
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER))
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER))
return FormValidation.ok();

try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/SubversionTagAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected void perform(TaskListener listener) {
}

public Descriptor<SubversionTagAction> getDescriptor() {
return Jenkins.getInstance().getDescriptorOrDie(getClass());
return Jenkins.get().getDescriptorOrDie(getClass());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/SubversionWorkspaceSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static class GetWorkspaceFormatSlaveToMasterCallable extends SlaveToMast
private static final long serialVersionUID = 6494337549896104453L;

public Integer call() {
return Jenkins.getInstance().getDescriptorByType(SubversionSCM.DescriptorImpl.class).getWorkspaceFormat();
return Jenkins.get().getDescriptorByType(SubversionSCM.DescriptorImpl.class).getWorkspaceFormat();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/UserProvidedCredential.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public UserProvidedCredential(String username, String password, File keyFile, Ab
* Parses the credential information from a form submission.
*/
public static UserProvidedCredential fromForm(StaplerRequest req, MultipartFormDataParser parser) throws IOException {
CrumbIssuer crumbIssuer = Jenkins.getInstance().getCrumbIssuer();
CrumbIssuer crumbIssuer = Jenkins.get().getCrumbIssuer();
if (crumbIssuer!=null && !crumbIssuer.validateCrumb(req, parser))
throw HttpResponses.error(SC_FORBIDDEN,new IOException("No crumb found"));

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/browsers/FishEyeSVN.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public FormValidation doCheckUrl(@QueryParameter(fixEmpty=true) String value) th
return FormValidation.errorWithMarkup("The URL should end like <code>.../browse/foobar/</code>");

// Connect to URL and check content only if we have admin permission
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER))
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER))
return FormValidation.ok();

final String finalValue = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public ISVNAuthenticationProvider createAuthenticationProvider(AbstractProject c

@CheckForNull
public FormValidation doCheckTagsDir(StaplerRequest req, @AncestorInPath Item context, @QueryParameter String value) {
Jenkins instance = Jenkins.getInstance();
Jenkins instance = Jenkins.getInstanceOrNull();
if (instance != null) {
SubversionSCM.ModuleLocation.DescriptorImpl desc = instance.getDescriptorByType(SubversionSCM.ModuleLocation.DescriptorImpl.class);
if (desc != null) {
Expand All @@ -394,7 +394,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item context, @Quer
if (context == null || !context.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel();
}
return Jenkins.getInstance().getDescriptorByType(
return Jenkins.get().getDescriptorByType(
SubversionSCM.ModuleLocation.DescriptorImpl.class).fillCredentialsIdItems(context, tagsDir);
}

Expand All @@ -404,7 +404,7 @@ public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath I
if (context == null || !context.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
return Jenkins.getInstance().getDescriptorByType(
return Jenkins.get().getDescriptorByType(
SubversionSCM.ModuleLocation.DescriptorImpl.class).checkCredentialsId(req, context, tagsDir, value);
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public String getDisplayName() {
*/
public SubversionSCM.DescriptorImpl getSubversionSCMDescriptor() {
if(scmDescriptor == null) {
scmDescriptor = (SubversionSCM.DescriptorImpl) Jenkins.getInstance().getDescriptor(SubversionSCM.class);
scmDescriptor = (SubversionSCM.DescriptorImpl) Jenkins.get().getDescriptor(SubversionSCM.class);
}
return scmDescriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
public abstract class WorkspaceUpdaterDescriptor extends Descriptor<WorkspaceUpdater> {

public static DescriptorExtensionList<WorkspaceUpdater,WorkspaceUpdaterDescriptor> all() {
return Jenkins.getInstance().getDescriptorList(WorkspaceUpdater.class);
return Jenkins.get().getDescriptorList(WorkspaceUpdater.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public int getReadTimeout(SVNRepository repository) {
if (uuid == null) { // TODO is this even possible? Javadoc is unclear.
throw new IOException("Could not find UUID for " + repoURL);
}
File cacheFile = new File(new File(Jenkins.getInstance().getRootDir(), "caches"), "svn-" + uuid + ".db");
File cacheFile = new File(new File(Jenkins.get().getRootDir(), "caches"), "svn-" + uuid + ".db");

cacheFile.getParentFile().mkdirs();
DB cache = null;
Expand Down