Skip to content

Commit

Permalink
Merge pull request #899 from MarkEWaite/reduce-deprecation-warnings
Browse files Browse the repository at this point in the history
Resolve deprecations in main
  • Loading branch information
MarkEWaite authored Jun 5, 2020
2 parents 7b34da2 + b279163 commit a3d4ec8
Show file tree
Hide file tree
Showing 47 changed files with 310 additions and 130 deletions.
151 changes: 100 additions & 51 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,116 @@
#!groovy
#!/usr/bin/env groovy

Random random = new Random() // Randomize which Jenkins version is selected for more testing
def use_newer_jenkins = random.nextBoolean() // Use newer Jenkins on one build but slightly older on other
import java.util.Collections

// Test plugin compatibility to recommended configurations
subsetConfiguration = [ [ jdk: '8', platform: 'windows', jenkins: null ],
// Compile with Java 8, test 2.204.6 or 2.222.1 depending on random use_newer_jenkins
[ jdk: '8', platform: 'linux', jenkins: !use_newer_jenkins ? '2.204.6' : '2.222.1', javaLevel: '8' ],
// Compile with Java 11, test the Jenkins version that Java 8 did *not* test
[ jdk: '11', platform: 'linux', jenkins: use_newer_jenkins ? '2.204.6' : '2.222.1', javaLevel: '8' ]
]
// Clean the agents used for the build
// Remove when https://github.com/jenkins-infra/pipeline-library/pull/141 is merged
def temporary_clean(Map params = [:]) {
def failFast = params.containsKey('failFast') ? params.failFast : true
def timeoutValue = params.containsKey('timeout') ? params.timeout : 60
def forceAci = params.containsKey('forceAci') ? params.forceAci : false
def useAci = params.containsKey('useAci') ? params.useAci : forceAci
if(timeoutValue > 180) {
echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption"
timeoutValue = 180
}

buildPlugin(configurations: subsetConfiguration, failFast: false)
Map tasks = [failFast: failFast]
getConfigurations(params).each { config ->
String label = config.platform
String jdk = config.jdk
String jenkinsVersion = config.jenkins
String javaLevel = config.javaLevel

def branches = [:]

branches["ATH"] = {
node("docker && highmem") {
def checkoutGit
stage("ATH: Checkout") {
checkoutGit = pwd(tmp:true) + "/athgit"
dir(checkoutGit) {
checkout scm
infra.runMaven(["clean", "package", "-DskipTests"])
// Include experimental git-client in target dir for ATH
// This Git plugin requires experimental git-client
infra.runMaven(["dependency:copy", "-Dartifact=org.jenkins-ci.plugins:git-client:3.0.0-beta3:hpi", "-DoutputDirectory=target", "-Dmdep.stripVersion=true"])
dir("target") {
stash name: "localPlugins", includes: "*.hpi"
}
String stageIdentifier = "${label}-${jdk}${jenkinsVersion ? '-' + jenkinsVersion : ''}"
boolean first = tasks.size() == 1
boolean runFindbugs = first && params?.findbugs?.run
boolean runCheckstyle = first && params?.checkstyle?.run
boolean archiveFindbugs = first && params?.findbugs?.archive
boolean archiveCheckstyle = first && params?.checkstyle?.archive
boolean skipTests = params?.tests?.skip
boolean addToolEnv = !useAci

if(useAci && (label == 'linux' || label == 'windows')) {
String aciLabel = jdk == '8' ? 'maven' : 'maven-11'
if(label == 'windows') {
aciLabel += "-windows"
}
label = aciLabel
}
def metadataPath = checkoutGit + "/essentials.yml"
stage("Run ATH") {
def athFolder=pwd(tmp:true) + "/ath"
dir(athFolder) {
runATH metadataFile: metadataPath

tasks[stageIdentifier] = {
node(label) {
timeout(timeoutValue) {
stage("TmpClean (${stageIdentifier})") {
if (isUnix()) {
sh(script: 'git clean -xffd > /dev/null 2>&1',
label:'Clean for incrementals',
returnStatus: true) // Ignore failure if CLI git is not available or this is not a git repository
} else {
bat(script: 'git clean -xffd 1> nul 2>&1',
label:'Clean for incrementals',
returnStatus: true) // Ignore failure if CLI git is not available or this is not a git repository
}
}
}
}
}
}
parallel(tasks)
}
branches["PCT"] = {
node("docker && highmem") {
def metadataPath
env.RUN_PCT_LOCAL_PLUGIN_SOURCES_STASH_NAME = "localPluginsPCT"
stage("PCT: Checkout") {
def checkoutGit = pwd(tmp:true) + "/pctgit"
dir(checkoutGit) {
dir("git") {
checkout scm
}
stash name: "localPluginsPCT", useDefaultExcludes: false
}
metadataPath = checkoutGit + "/git/essentials.yml"

List<Map<String, String>> getConfigurations(Map params) {
boolean explicit = params.containsKey("configurations")
boolean implicit = params.containsKey('platforms') || params.containsKey('jdkVersions') || params.containsKey('jenkinsVersions')

if (explicit && implicit) {
error '"configurations" option can not be used with either "platforms", "jdkVersions" or "jenkinsVersions"'
}

def configs = params.configurations
configs.each { c ->
if (!c.platform) {
error("Configuration field \"platform\" must be specified: $c")
}
if (!c.jdk) {
error("Configuration field \"jdk\" must be specified: $c")
}
stage("Run PCT") {
def pctFolder = pwd(tmp:true) + "/pct"
dir(pctFolder) {
runPCT metadataFile: metadataPath
}

if (explicit) return params.configurations

def platforms = params.containsKey('platforms') ? params.platforms : ['linux', 'windows']
def jdkVersions = params.containsKey('jdkVersions') ? params.jdkVersions : [8]
def jenkinsVersions = params.containsKey('jenkinsVersions') ? params.jenkinsVersions : [null]

def ret = []
for (p in platforms) {
for (jdk in jdkVersions) {
for (jenkins in jenkinsVersions) {
ret << [
"platform": p,
"jdk": jdk,
"jenkins": jenkins,
"javaLevel": null // not supported in the old format
]
}
}
}
return ret
}

// Intentionally disabled until tests are more reliable
// parallel branches
// Valid Jenkins versions for test
def testJenkinsVersions = [ '2.204.1', '2.204.6', '2.222.1', '2.222.4', '2.235', '2.238' ]
Collections.shuffle(testJenkinsVersions)

// Test plugin compatibility to subset of Jenkins versions
subsetConfiguration = [ [ jdk: '8', platform: 'windows', jenkins: testJenkinsVersions[0], javaLevel: '8' ],
[ jdk: '8', platform: 'linux', jenkins: testJenkinsVersions[1], javaLevel: '8' ],
[ jdk: '11', platform: 'linux', jenkins: testJenkinsVersions[2], javaLevel: '8' ]
]

// Clean before build so that `git status -s` will have empty output for incrementals
// Remove when https://github.com/jenkins-infra/pipeline-library/pull/141 is merged
temporary_clean(configurations: subsetConfiguration, failFast: false)

buildPlugin(configurations: subsetConfiguration, failFast: false)
8 changes: 2 additions & 6 deletions src/main/java/hudson/plugins/git/GitChangeLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ public List<GitChangeSet> parse(@NonNull List<String> changelog) {
@Override public GitChangeSetList parse(Run build, RepositoryBrowser<?> browser, File changelogFile)
throws IOException, SAXException {
// Parse the log file into GitChangeSet items - each one is a commit
LineIterator lineIterator = null;
try {
lineIterator = FileUtils.lineIterator(changelogFile,"UTF-8");
return new GitChangeSetList(build, browser, parse(lineIterator));
} finally {
LineIterator.closeQuietly(lineIterator);
try (LineIterator lineIterator = FileUtils.lineIterator(changelogFile, "UTF-8")) {
return new GitChangeSetList(build, browser, parse(lineIterator));
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/hudson/plugins/git/GitPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Result;
import hudson.plugins.git.extensions.impl.PerBuildTag;
import hudson.plugins.git.opt.PreBuildMergeOptions;
import hudson.scm.SCM;
import hudson.tasks.BuildStepDescriptor;
Expand Down Expand Up @@ -184,7 +185,8 @@ public boolean perform(AbstractBuild<?, ?> build,
// If we're pushing the merge back...
if (pushMerge) {
try {
if (!gitSCM.getSkipTag()) {
if (gitSCM.getExtensions().get(PerBuildTag.class) != null) {
// if PerBuildTag, then tag every build
// We delete the old tag generated by the SCM plugin
String buildnumber = "jenkins-" + projectName.replace(" ", "_") + "-" + buildNumber;
if (git.tagExists(buildnumber))
Expand All @@ -196,6 +198,7 @@ public boolean perform(AbstractBuild<?, ?> build,
git.tag(buildnumber, "Jenkins Build #" + buildNumber);
}

@SuppressWarnings("deprecation") // Too much work to replace with non-deprecated
PreBuildMergeOptions mergeOptions = gitSCM.getMergeOptions();

String mergeTarget = environment.expand(mergeOptions.getMergeTarget());
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import hudson.plugins.git.browser.GithubWeb;
import static hudson.scm.PollingResult.*;
import hudson.Util;
import hudson.plugins.git.extensions.impl.ScmName;
import hudson.util.LogTaskListener;
import hudson.util.ReflectionUtils;
import java.util.Map.Entry;
Expand Down Expand Up @@ -268,6 +269,7 @@ private void updateFromUserData() throws GitException {
}
}

@SuppressWarnings("deprecation") // `source` field is deprecated but required
public Object readResolve() throws IOException {
// Migrate data

Expand All @@ -276,7 +278,7 @@ public Object readResolve() throws IOException {
configVersion = 0L;
}


// Deprecated field needed to retain compatibility
if (source != null) {
remoteRepositories = new ArrayList<>();
branches = new ArrayList<>();
Expand Down Expand Up @@ -415,7 +417,7 @@ public void setBrowser(GitRepositoryBrowser browser) {
return new BitbucketWeb(url);
}
if (url.startsWith("https://gitlab.com/")) {
return new GitLab(url, "");
return new GitLab(url);
}
if (url.startsWith("https://github.com/")) {
return new GithubWeb(url);
Expand Down Expand Up @@ -469,9 +471,9 @@ public String getParamLocalBranch(Run<?, ?> build) throws IOException, Interrupt
* @return parameter-expanded local branch name in build.
*/
public String getParamLocalBranch(Run<?, ?> build, TaskListener listener) throws IOException, InterruptedException {
String branch = getLocalBranch();
LocalBranch localBranch = getExtensions().get(LocalBranch.class);
// substitute build parameters if available
return getParameterString(branch != null ? branch : null, build.getEnvironment(listener));
return getParameterString(localBranch == null ? null : localBranch.getLocalBranch(), build.getEnvironment(listener));
}

@Deprecated
Expand Down Expand Up @@ -849,7 +851,7 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
StandardUsernameCredentials.class,
project,
project instanceof Queue.Task
? Tasks.getDefaultAuthenticationOf((Queue.Task)project)
? ((Queue.Task) project).getDefaultAuthentication()
: ACL.SYSTEM,
URIRequirementBuilder.fromUri(url).build()
);
Expand All @@ -874,7 +876,9 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,

@NonNull
private BuildData fixNull(BuildData bd) {
return bd != null ? bd : new BuildData(getScmName(), getUserRemoteConfigs()) /*dummy*/;
ScmName sn = getExtensions().get(ScmName.class);
String scmName = sn == null ? null : sn.getName();
return bd != null ? bd : new BuildData(scmName, getUserRemoteConfigs());
}

/**
Expand Down Expand Up @@ -1340,6 +1344,8 @@ private void computeChangeLog(GitClient git, Revision revToBuild, TaskListener l
}
}

@Override
@Deprecated // Overrides a deprecated implementation, must also be deprecated
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
buildEnvironment(build, env);
}
Expand Down Expand Up @@ -1741,9 +1747,9 @@ public List<BranchSpec> getBranches() {
}

@Override public String getKey() {
String name = getScmName();
if (name != null) {
return name;
ScmName scmName = getExtensions().get(ScmName.class);
if (scmName != null) {
return scmName.getName();
}
StringBuilder b = new StringBuilder("git");
for (RemoteConfig cfg : getRepositories()) {
Expand Down Expand Up @@ -1792,11 +1798,13 @@ public BuildData getBuildData(Run build, boolean clone) {
*/
public BuildData copyBuildData(Run build) {
BuildData base = getBuildData(build);
ScmName sn = getExtensions().get(ScmName.class);
String scmName = sn == null ? null : sn.getName();
if (base==null)
return new BuildData(getScmName(), getUserRemoteConfigs());
return new BuildData(scmName, getUserRemoteConfigs());
else {
BuildData buildData = base.clone();
buildData.setScmName(getScmName());
buildData.setScmName(scmName);
return buildData;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/git/GitStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,10 @@ public PollingScheduledResponseContributor(Item project) {
* {@inheritDoc}
*/
@Override
@SuppressWarnings("deprecation")
public void addHeaders(StaplerRequest req, StaplerResponse rsp) {
// Calls a deprecated getAbsoluteUrl() method because this is a remote API case
// as described in the Javadoc of the deprecated getAbsoluteUrl() method.
rsp.addHeader("Triggered", project.getAbsoluteUrl());
}

Expand Down Expand Up @@ -540,7 +543,10 @@ public ScheduledResponseContributor(Item project) {
* {@inheritDoc}
*/
@Override
@SuppressWarnings("deprecation")
public void addHeaders(StaplerRequest req, StaplerResponse rsp) {
// Calls a deprecated getAbsoluteUrl() method because this is a remote API case
// as described in the Javadoc of the deprecated getAbsoluteUrl() method.
rsp.addHeader("Triggered", project.getAbsoluteUrl());
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/hudson/plugins/git/RemoteConfigConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ public RemoteConfig toRemote() throws URISyntaxException {
*/
public RemoteConfigConverter(XStream xStream) {
mapper = xStream.getMapper();
converter = new SerializableConverter(mapper,
@SuppressWarnings("deprecation")
SerializableConverter tempConvertor = new SerializableConverter(mapper,
xStream.getReflectionProvider());
converter = tempConvertor;
}

public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
Expand Down Expand Up @@ -224,6 +226,7 @@ public void close() {
}
};
try {
@SuppressWarnings("deprecation")
CustomObjectInputStream objectInput = CustomObjectInputStream
.getInstance(context, callback);
proxy.readExternal(objectInput);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/git/SubmoduleCombinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void makeCombination(Map<IndexEntry, Revision> settings) throws Interr
// Assume we are checked out
String name = "combine-" + tid + "-" + (idx++);
git.branch(name);
git.checkout(name);
git.checkout().ref(name).execute();

StringBuilder commit = new StringBuilder(
"Jenkins generated combination of:\n");
Expand All @@ -156,7 +156,7 @@ protected void makeCombination(Map<IndexEntry, Revision> settings) throws Interr
IndexEntry submodule = setting.getKey();
Revision branch = setting.getValue();
GitClient subGit = git.subGit(submodule.getFile());
subGit.checkout(branch.getSha1().name());
subGit.checkout().ref(branch.getSha1().name()).execute();
git.add(submodule.getFile());
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/hudson/plugins/git/UserRemoteConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project,
return new StandardListBoxModel().includeCurrentValue(credentialsId);
}
if (project == null) {
/* Construct a fake project */
project = new FreeStyleProject(Jenkins.get(), "fake-" + UUID.randomUUID().toString());
/* Construct a fake project, suppress the deprecation warning because the
* replacement for the deprecated API isn't accessible in this context. */
@SuppressWarnings("deprecation")
Item fakeProject = new FreeStyleProject(Jenkins.get(), "fake-" + UUID.randomUUID().toString());
project = fakeProject;
}
return new StandardListBoxModel()
.includeEmptyValue()
Expand Down
Loading

0 comments on commit a3d4ec8

Please sign in to comment.