Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
lanwen committed Aug 31, 2015
1 parent b5db64c commit 061d849
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 41 deletions.
67 changes: 67 additions & 0 deletions src/main/java/com/cloudbees/jenkins/Credential.java
@@ -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();
}
}
1 change: 0 additions & 1 deletion src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java
Expand Up @@ -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;
Expand Down
Expand Up @@ -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}
Expand Down

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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
}

/**
Expand Down
@@ -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;
Expand Down

0 comments on commit 061d849

Please sign in to comment.