Skip to content
Permalink
Browse files
[FIXES JENKINS-30223] return back com.cloudbees.jenkins.Credential
as of it makes fail to boot jenkins after installation of plugin which depends on this class.
Also remove migration to another package for this class and use it directly

(cherry picked from commit 061d849)
  • Loading branch information
lanwen committed Sep 2, 2015
1 parent 0dbb10d commit b10ad388815a35617fe5fbb79171f116eb814a64
@@ -0,0 +1,67 @@
package com.cloudbees.jenkins;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.kohsuke.github.GitHub;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.CheckForNull;
import java.io.IOException;

import static org.jenkinsci.plugins.github.util.FluentIterableWrapper.from;

/**
* Credential to access GitHub.
* Used only for migration.
*
* @author Kohsuke Kawaguchi
* @see org.jenkinsci.plugins.github.config.GitHubPluginConfig
* @see GitHubServerConfig
* @deprecated since 1.13.0 plugin uses credentials-plugin to manage tokens. All configuration moved to
* {@link org.jenkinsci.plugins.github.config.GitHubPluginConfig} which can be fetched via
* {@link GitHubPlugin#configuration()}. You can fetch corresponding config with creds by
* {@link org.jenkinsci.plugins.github.config.GitHubPluginConfig#findGithubConfig(Predicate)} which returns
* iterable over authorized nonnull {@link GitHub}s matched your predicate
*/
@Deprecated
public class Credential {
@SuppressWarnings("visibilitymodifier")
public final transient String username;
@SuppressWarnings("visibilitymodifier")
public final transient String apiUrl;
@SuppressWarnings("visibilitymodifier")
public final transient String oauthAccessToken;

@DataBoundConstructor
public Credential(String username, String apiUrl, String oauthAccessToken) {
this.username = username;
this.apiUrl = apiUrl;
this.oauthAccessToken = oauthAccessToken;
}

public String getUsername() {
return username;
}

public String getApiUrl() {
return apiUrl;
}

public String getOauthAccessToken() {
return oauthAccessToken;
}

/**
* @return authorized first {@link GitHub} from global config or null if no any
* @throws IOException never thrown, but in signature for backward compatibility
* @deprecated see class javadoc. Now any instance return same GH. Please use new api to fetch another
*/
@CheckForNull
@Deprecated
public GitHub login() throws IOException {
return from(GitHubPlugin.configuration().findGithubConfig(Predicates.<GitHubServerConfig>alwaysTrue()))
.first().orNull();
}
}
@@ -18,7 +18,6 @@
import org.apache.commons.jelly.XMLOutput;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.config.GitHubPluginConfig;
import org.jenkinsci.plugins.github.deprecated.Credential;
import org.jenkinsci.plugins.github.internal.GHPluginConfigException;
import org.jenkinsci.plugins.github.migration.Migrator;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -191,6 +191,11 @@ public static String tokenFor(String credentialsId) {
/**
* Returns true if given host is part of stored (or default if blank) api url
*
* For example:
* withHost(api.github.com).apply(config for ~empty~) = true
* withHost(api.github.com).apply(config for api.github.com) = true
* withHost(api.github.com).apply(config for github.company.com) = false
*
* @param host host to find in api url
*
* @return predicate to match against {@link GitHubServerConfig}

This file was deleted.

@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.github.migration;

import com.cloudbees.jenkins.Credential;
import com.cloudbees.jenkins.GitHubPushTrigger;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.google.common.annotations.VisibleForTesting;
@@ -9,7 +10,6 @@
import org.jenkinsci.plugins.github.config.GitHubPluginConfig;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.jenkinsci.plugins.github.config.GitHubTokenCredentialsCreator;
import org.jenkinsci.plugins.github.deprecated.Credential;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -92,10 +92,13 @@ public GitHubServerConfig apply(Credential input) {
}

/**
* - Old plain credentials moved to deprecated package as used only for migration
* Enable xml migration from deprecated nodes to new
*
* Can be used for example as
* Jenkins.XSTREAM2.addCompatibilityAlias("com.cloudbees.jenkins.Credential", Credential.class);
*/
public static void enableCompatibilityAliases() {
Jenkins.XSTREAM2.addCompatibilityAlias("com.cloudbees.jenkins.Credential", Credential.class);
// not used at this moment
}

/**
@@ -1,12 +1,12 @@
package org.jenkinsci.plugins.github.migration;

import com.cloudbees.jenkins.Credential;
import com.cloudbees.jenkins.GitHubPushTrigger;
import com.cloudbees.jenkins.GitHubWebHook;
import hudson.model.FreeStyleProject;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.jenkinsci.plugins.github.deprecated.Credential;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

0 comments on commit b10ad38

Please sign in to comment.